upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/test/bindless_sizing_test.cpp
diff options
context:
space:
mode:
authorkirigayakazima <46666711+kirigayakazima@users.noreply.github.com>2026-11-29 11:02:12 +0800
committerkirigayakazima <46666711+kirigayakazima@users.noreply.github.com>2026-11-29 11:02:12 +0800
commit85b87608fa3bc7aef8606a0debbd794b7e760f9f (patch)
tree17f969b3144832a832e5017152d196938aef64c2 /runtime/test/bindless_sizing_test.cpp
parentbb27da204adb88f5d3c1178583f460dd7483c632 (diff)
parentc8bf0e7b6568f471b42540010e335ca6413d4c58 (diff)
Merge current main and reconcile glb_writer coverage
Diffstat (limited to 'runtime/test/bindless_sizing_test.cpp')
-rw-r--r--runtime/test/bindless_sizing_test.cpp105
1 files changed, 94 insertions, 11 deletions
diff --git a/runtime/test/bindless_sizing_test.cpp b/runtime/test/bindless_sizing_test.cpp
index 4553f25b6..b83294852 100644
--- a/runtime/test/bindless_sizing_test.cpp
+++ b/runtime/test/bindless_sizing_test.cpp
@@ -1,6 +1,6 @@
1// bindless::size_bindings with synthetic device limits: no GPU. The counts of set 0 come from the device's descriptor 1// bindless::size_bindings with synthetic device limits: no GPU. The counts of set 0 come from the device's descriptor
2// limits (vulkan_bindless.h): today's sizes where a device is at them, larger 2D, sampler and storage arrays where it 2// limits (vulkan_bindless.h): today's sizes where a device is at them, larger image, sampler and storage arrays where
3// has room, and less where it is below them. 3// it has room, and less where it is below them.
4#ifndef VK_NO_PROTOTYPES 4#ifndef VK_NO_PROTOTYPES
5#define VK_NO_PROTOTYPES 5#define VK_NO_PROTOTYPES
6#endif 6#endif
@@ -84,6 +84,13 @@ bool storage_consistent(const BindlessFeatures& f) {
84 f.counts[bindless::r32ui_binding(dimension)] != held) 84 f.counts[bindless::r32ui_binding(dimension)] != held)
85 return false; 85 return false;
86 } 86 }
87 // 1D arrays have no sampled capacity, but all three storage classes are always present.
88 const auto array = ImageDimension::dim_1d_array;
89 const auto held = storage(f, array);
90 for (std::uint32_t c = 0; c < 3; ++c) {
91 const auto binding = bindless::storage_binding(array, c);
92 if (!held || !bindless::binding_enabled(binding, f) || f.counts[binding] != held) return false;
93 }
87 return true; 94 return true;
88} 95}
89 96
@@ -93,18 +100,51 @@ int main() {
93 using D = ImageDimension; 100 using D = ImageDimension;
94 constexpr auto defaults = bindless::default_counts(); 101 constexpr auto defaults = bindless::default_counts();
95 static_assert(defaults[0] == 4096 && defaults[bindless::sampler_binding] == 1024 && defaults[8] == 256); 102 static_assert(defaults[0] == 4096 && defaults[bindless::sampler_binding] == 1024 && defaults[8] == 256);
103 static_assert(bindless::sampled_binding(D::dim_1d_array) == bindless::no_binding);
104 static_assert(bindless::storage_binding(D::dim_1d_array, 0) == 26 &&
105 bindless::storage_binding(D::dim_1d_array, 1) == 27 &&
106 bindless::storage_binding(D::dim_1d_array, 2) == 28);
107 static_assert(bindless::sampled_binding(D::dim_2d_ms, 0) == 20 &&
108 bindless::sampled_binding(D::dim_2d_ms_array, 0) == 21 &&
109 bindless::sampled_binding(D::dim_2d_ms, 1) == 22 &&
110 bindless::sampled_binding(D::dim_2d_ms_array, 1) == 23 &&
111 bindless::sampled_binding(D::dim_2d_ms, 2) == 24 &&
112 bindless::sampled_binding(D::dim_2d_ms_array, 2) == 25);
113
114 // SetLayout compacts disabled MS pairs without renumbering either the enabled pair or the storage-only tail.
115 {
116 BindlessFeatures f{};
117 f.update_after_bind = f.partially_bound = true;
118 f.ms_samples[1] = VK_SAMPLE_COUNT_4_BIT;
119 const bindless::SetLayout layout(f);
120 EXPECT(layout.info.bindingCount == 25 && layout.flags_info.bindingCount == 25);
121 EXPECT(layout.entries[20].binding == 22 && layout.entries[21].binding == 23);
122 for (std::uint32_t c = 0; c < 3; ++c) {
123 const auto& entry = layout.entries[22 + c];
124 EXPECT(entry.binding == 26 + c && entry.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE &&
125 entry.descriptorCount == 256);
126 EXPECT(layout.flags[22 + c] ==
127 (VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT | VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT));
128 }
129 }
96 130
97 // An RTX 5070 (driver 621.24): 1048576 of each descriptor type, update-after-bind or not, 4000 samplers. 131 // An RTX 5070 (driver 621.24): 1048576 of each descriptor type, update-after-bind or not, 4000 samplers.
98 for (const bool update_after_bind : {true, false}) { 132 for (const bool update_after_bind : {true, false}) {
99 const Device d = uniform(1048576, 1048576); 133 const Device d = uniform(1048576, 1048576);
100 BindlessFeatures f = with_ms(update_after_bind); 134 BindlessFeatures f = with_ms(update_after_bind);
101 EXPECT(bindless::size_bindings(f, d.limits, d.v11, d.v12)); 135 EXPECT(bindless::size_bindings(f, d.limits, d.v11, d.v12));
102 EXPECT(count(f, D::dim_2d) == bindless::max_2d_images); 136 EXPECT(count(f, D::dim_2d) == bindless::max_images);
103 EXPECT(f.counts[bindless::sampler_binding] == 4000 - bindless::reserved_samplers); 137 EXPECT(f.counts[bindless::sampler_binding] == 4000 - bindless::reserved_samplers);
104 EXPECT(f.counts[bindless::sampler_binding] > 2048); // a full sampler heap and the fallback 138 EXPECT(f.counts[bindless::sampler_binding] > 2048); // a full sampler heap and the fallback
105 EXPECT(storage(f, D::dim_2d) == bindless::max_storage_indices); 139 EXPECT(storage(f, D::dim_2d) == bindless::max_storage_indices);
106 EXPECT(storage(f, D::dim_2d_array) == 1024 && storage(f, D::dim_3d) == 256 && storage(f, D::dim_1d) == 256); 140 // The other dimensions grow as far as 2D (a title's textures are of whichever dimension it chose); their
107 EXPECT(count(f, D::dim_2d_array) == 1024 && count(f, D::dim_3d) == 256 && count(f, D::dim_1d) == 256); 141 // storage arrays hold as many indices as the 2D one. The storage-only 1D array keeps its 256.
142 EXPECT(count(f, D::dim_2d_array) == bindless::max_images && count(f, D::dim_3d) == bindless::max_images &&
143 count(f, D::dim_1d) == bindless::max_images);
144 EXPECT(storage(f, D::dim_2d_array) == bindless::max_storage_indices &&
145 storage(f, D::dim_3d) == bindless::max_storage_indices &&
146 storage(f, D::dim_1d) == bindless::max_storage_indices);
147 EXPECT(storage(f, D::dim_1d_array) == 256 && totals(f).all == 325729);
108 EXPECT(f.ms_samples[0] == VK_SAMPLE_COUNT_4_BIT && f.ms_samples[2] == VK_SAMPLE_COUNT_4_BIT); 148 EXPECT(f.ms_samples[0] == VK_SAMPLE_COUNT_4_BIT && f.ms_samples[2] == VK_SAMPLE_COUNT_4_BIT);
109 EXPECT(storage_consistent(f)); 149 EXPECT(storage_consistent(f));
110 if (update_after_bind) 150 if (update_after_bind)
@@ -112,12 +152,50 @@ int main() {
112 count(f, D::dim_2d), f.counts[bindless::sampler_binding], storage(f, D::dim_2d), totals(f).all); 152 count(f, D::dim_2d), f.counts[bindless::sampler_binding], storage(f, D::dim_2d), totals(f).all);
113 } 153 }
114 154
115 // At today's sizes exactly (5632 sampled images, 1024 samplers, 3584 storage images): today's set, no MS pairs. 155 // RADV (Mesa 26.3, a Raphael iGPU and an RX 7900 XTX alike) and llvmpipe: their update-after-bind limits hold
156 // every sampled dimension at the full size. A world run kept 4090 live 1D textures, filling the 4096 1D indices
157 // the set used to stop at whatever the device held; now 1D, 3D and 2D-array images get as many as 2D.
158 {
159 Device radv = uniform(8388606, 8388606);
160 radv.limits.maxPerStageResources = radv.v12.maxPerStageUpdateAfterBindResources = 8388606;
161 radv.v12.maxUpdateAfterBindDescriptorsInAllPools = 67108863;
162 radv.v11.maxPerSetDescriptors = 22369621;
163 radv.limits.maxSamplerAllocationCount = 4294967295u;
164 Device lvp = uniform(1015808, 1015808);
165 lvp.limits.maxPerStageResources = lvp.v12.maxPerStageUpdateAfterBindResources = 1015808;
166 lvp.v11.maxPerSetDescriptors = 1015808;
167 lvp.limits.maxSamplerAllocationCount = 32768;
168 for (const Device* d : {&radv, &lvp}) {
169 BindlessFeatures f = with_ms(true);
170 EXPECT(bindless::size_bindings(f, d->limits, d->v11, d->v12));
171 for (const D dimension : {D::dim_2d, D::dim_2d_array, D::dim_3d, D::dim_1d}) {
172 EXPECT(count(f, dimension) == bindless::max_images);
173 EXPECT(count(f, dimension) > 4096 + 1); // more than 4096 live images and the fallback
174 }
175 EXPECT(storage_consistent(f));
176 }
177 }
178
179 // A device whose limits stop growth short of max_images: the 2D-array, 3D and 1D arrays share what is left alike,
180 // whichever is grown first.
181 {
182 Device d = uniform(1048576, 1048576);
183 d.v12.maxPerStageDescriptorUpdateAfterBindSampledImages = 65536 + 3 * 20000 + 6 * 256 + bindless::growth_headroom;
184 BindlessFeatures f = with_ms(true);
185 EXPECT(bindless::size_bindings(f, d.limits, d.v11, d.v12));
186 EXPECT(count(f, D::dim_2d) == bindless::max_images);
187 EXPECT(count(f, D::dim_2d_array) == count(f, D::dim_3d) && count(f, D::dim_3d) == count(f, D::dim_1d));
188 EXPECT(count(f, D::dim_1d) > 4096 && count(f, D::dim_1d) <= 20000);
189 EXPECT(totals(f).sampled + bindless::growth_headroom <= d.v12.maxPerStageDescriptorUpdateAfterBindSampledImages);
190 EXPECT(storage_consistent(f));
191 }
192
193 // At today's sizes exactly (5632 sampled images, 1024 samplers, 4352 storage images): no MS pairs.
116 { 194 {
117 Device d = uniform(1048576, 1048576); 195 Device d = uniform(1048576, 1048576);
118 d.v12.maxPerStageDescriptorUpdateAfterBindSampledImages = 5632; 196 d.v12.maxPerStageDescriptorUpdateAfterBindSampledImages = 5632;
119 d.v12.maxPerStageDescriptorUpdateAfterBindSamplers = 1024; 197 d.v12.maxPerStageDescriptorUpdateAfterBindSamplers = 1024;
120 d.v12.maxPerStageDescriptorUpdateAfterBindStorageImages = 3584; 198 d.v12.maxPerStageDescriptorUpdateAfterBindStorageImages = 4352;
121 BindlessFeatures f = with_ms(true); 199 BindlessFeatures f = with_ms(true);
122 EXPECT(bindless::size_bindings(f, d.limits, d.v11, d.v12)); 200 EXPECT(bindless::size_bindings(f, d.limits, d.v11, d.v12));
123 EXPECT(count(f, D::dim_2d) == 4096 && f.counts[bindless::sampler_binding] == 1024 && 201 EXPECT(count(f, D::dim_2d) == 4096 && f.counts[bindless::sampler_binding] == 1024 &&
@@ -125,6 +203,7 @@ int main() {
125 for (std::uint32_t b = 0; b < bindless::first_ms_binding; ++b) 203 for (std::uint32_t b = 0; b < bindless::first_ms_binding; ++b)
126 if (bindless::bindings[b].type != VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) EXPECT(f.counts[b] == defaults[b]); 204 if (bindless::bindings[b].type != VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) EXPECT(f.counts[b] == defaults[b]);
127 EXPECT(f.ms_samples == (std::array{VK_SAMPLE_COUNT_1_BIT, VK_SAMPLE_COUNT_1_BIT, VK_SAMPLE_COUNT_1_BIT})); 205 EXPECT(f.ms_samples == (std::array{VK_SAMPLE_COUNT_1_BIT, VK_SAMPLE_COUNT_1_BIT, VK_SAMPLE_COUNT_1_BIT}));
206 EXPECT(totals(f).storage == 4352 && storage(f, D::dim_1d_array) == 256);
128 EXPECT(storage_consistent(f)); 207 EXPECT(storage_consistent(f));
129 } 208 }
130 209
@@ -150,7 +229,7 @@ int main() {
150 BindlessFeatures uab = with_ms(true), plain = with_ms(false); 229 BindlessFeatures uab = with_ms(true), plain = with_ms(false);
151 EXPECT(bindless::size_bindings(uab, d.limits, d.v11, d.v12)); 230 EXPECT(bindless::size_bindings(uab, d.limits, d.v11, d.v12));
152 EXPECT(bindless::size_bindings(plain, d.limits, d.v11, d.v12)); 231 EXPECT(bindless::size_bindings(plain, d.limits, d.v11, d.v12));
153 EXPECT(count(uab, D::dim_2d) == bindless::max_2d_images); 232 EXPECT(count(uab, D::dim_2d) == bindless::max_images);
154 const Totals t = totals(plain); 233 const Totals t = totals(plain);
155 EXPECT(count(plain, D::dim_2d) > 4096 && count(plain, D::dim_2d) < 16384); 234 EXPECT(count(plain, D::dim_2d) > 4096 && count(plain, D::dim_2d) < 16384);
156 EXPECT(t.sampled + bindless::growth_headroom <= 16384 && t.storage + bindless::growth_headroom <= 16384); 235 EXPECT(t.sampled + bindless::growth_headroom <= 16384 && t.storage + bindless::growth_headroom <= 16384);
@@ -178,16 +257,20 @@ int main() {
178 Device d = uniform(1048576, 1048576); 257 Device d = uniform(1048576, 1048576);
179 d.v11.maxPerSetDescriptors = 6159; 258 d.v11.maxPerSetDescriptors = 6159;
180 d.limits.maxSamplerAllocationCount = 4000; 259 d.limits.maxSamplerAllocationCount = 4000;
181 unsigned asked = 0, asked_within = 0; 260 unsigned asked = 0, asked_within = 0, missing_storage = 0;
182 const auto all_supported = [&](const BindlessFeatures& candidate) { 261 const auto all_supported = [&](const BindlessFeatures& candidate) {
183 ++asked; 262 ++asked;
184 asked_within += totals(candidate).all <= 6159; 263 asked_within += totals(candidate).all <= 6159;
264 const bindless::SetLayout layout(candidate);
265 const auto& last = layout.entries[layout.info.bindingCount - 1];
266 missing_storage += last.binding != 28 || last.descriptorType != VK_DESCRIPTOR_TYPE_STORAGE_IMAGE ||
267 last.descriptorCount != storage(candidate, D::dim_1d_array);
185 return true; 268 return true;
186 }; 269 };
187 BindlessFeatures f = with_ms(true); 270 BindlessFeatures f = with_ms(true);
188 EXPECT(bindless::size_bindings(f, d.limits, d.v11, d.v12, all_supported)); 271 EXPECT(bindless::size_bindings(f, d.limits, d.v11, d.v12, all_supported));
189 EXPECT(asked > 0 && asked_within == 0); 272 EXPECT(asked > 0 && asked_within == 0 && missing_storage == 0);
190 EXPECT(count(f, D::dim_2d) == bindless::max_2d_images && 273 EXPECT(count(f, D::dim_2d) == bindless::max_images &&
191 f.counts[bindless::sampler_binding] == 4000 - bindless::reserved_samplers); 274 f.counts[bindless::sampler_binding] == 4000 - bindless::reserved_samplers);
192 EXPECT(storage(f, D::dim_2d) == bindless::max_storage_indices && storage_consistent(f)); 275 EXPECT(storage(f, D::dim_2d) == bindless::max_storage_indices && storage_consistent(f));
193 276