diff options
| author | Andrey <lopsin232@gmail.com> | 2026-11-30 13:37:43 +0300 |
|---|---|---|
| committer | Andrey <lopsin232@gmail.com> | 2026-11-30 13:37:43 +0300 |
| commit | 7df404beeed356c190207146ab620de901e63309 (patch) | |
| tree | a1b8ec52e1b2006bf7b38e6c1ac634dd2b7c6342 /runtime/test/bindless_sizing_test.cpp | |
| parent | 7798e28e11779b88f59f65d7c1315ec3c9825789 (diff) | |
| parent | 012b79a6787cd47d31dcf023eb2b67a1eac6d77f (diff) | |
Merge upstream/main into fix/ttpf-assets-stage-cleanup
Diffstat (limited to 'runtime/test/bindless_sizing_test.cpp')
| -rw-r--r-- | runtime/test/bindless_sizing_test.cpp | 131 |
1 files changed, 120 insertions, 11 deletions
diff --git a/runtime/test/bindless_sizing_test.cpp b/runtime/test/bindless_sizing_test.cpp index 4553f25b6..435bf42c9 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 |
| @@ -83,6 +83,14 @@ bool storage_consistent(const BindlessFeatures& f) { | |||
| 83 | if (bindless::r32ui_binding(dimension) != bindless::no_binding && | 83 | if (bindless::r32ui_binding(dimension) != bindless::no_binding && |
| 84 | f.counts[bindless::r32ui_binding(dimension)] != held) | 84 | f.counts[bindless::r32ui_binding(dimension)] != held) |
| 85 | return false; | 85 | return false; |
| 86 | if (dimension == ImageDimension::dim_2d && f.counts[bindless::r64ui_binding] != held) return false; | ||
| 87 | } | ||
| 88 | // 1D arrays have no sampled capacity, but all three storage classes are always present. | ||
| 89 | const auto array = ImageDimension::dim_1d_array; | ||
| 90 | const auto held = storage(f, array); | ||
| 91 | for (std::uint32_t c = 0; c < 3; ++c) { | ||
| 92 | const auto binding = bindless::storage_binding(array, c); | ||
| 93 | if (!held || !bindless::binding_enabled(binding, f) || f.counts[binding] != held) return false; | ||
| 86 | } | 94 | } |
| 87 | return true; | 95 | return true; |
| 88 | } | 96 | } |
| @@ -93,18 +101,51 @@ int main() { | |||
| 93 | using D = ImageDimension; | 101 | using D = ImageDimension; |
| 94 | constexpr auto defaults = bindless::default_counts(); | 102 | constexpr auto defaults = bindless::default_counts(); |
| 95 | static_assert(defaults[0] == 4096 && defaults[bindless::sampler_binding] == 1024 && defaults[8] == 256); | 103 | static_assert(defaults[0] == 4096 && defaults[bindless::sampler_binding] == 1024 && defaults[8] == 256); |
| 104 | static_assert(bindless::sampled_binding(D::dim_1d_array) == bindless::no_binding); | ||
| 105 | static_assert(bindless::storage_binding(D::dim_1d_array, 0) == 26 && | ||
| 106 | bindless::storage_binding(D::dim_1d_array, 1) == 27 && | ||
| 107 | bindless::storage_binding(D::dim_1d_array, 2) == 28); | ||
| 108 | static_assert(bindless::sampled_binding(D::dim_2d_ms, 0) == 20 && | ||
| 109 | bindless::sampled_binding(D::dim_2d_ms_array, 0) == 21 && | ||
| 110 | bindless::sampled_binding(D::dim_2d_ms, 1) == 22 && | ||
| 111 | bindless::sampled_binding(D::dim_2d_ms_array, 1) == 23 && | ||
| 112 | bindless::sampled_binding(D::dim_2d_ms, 2) == 24 && | ||
| 113 | bindless::sampled_binding(D::dim_2d_ms_array, 2) == 25); | ||
| 114 | |||
| 115 | // SetLayout compacts disabled MS pairs without renumbering either the enabled pair or the storage-only tail. | ||
| 116 | { | ||
| 117 | BindlessFeatures f{}; | ||
| 118 | f.update_after_bind = f.partially_bound = true; | ||
| 119 | f.ms_samples[1] = VK_SAMPLE_COUNT_4_BIT; | ||
| 120 | const bindless::SetLayout layout(f); | ||
| 121 | EXPECT(layout.info.bindingCount == 25 && layout.flags_info.bindingCount == 25); | ||
| 122 | EXPECT(layout.entries[20].binding == 22 && layout.entries[21].binding == 23); | ||
| 123 | for (std::uint32_t c = 0; c < 3; ++c) { | ||
| 124 | const auto& entry = layout.entries[22 + c]; | ||
| 125 | EXPECT(entry.binding == 26 + c && entry.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE && | ||
| 126 | entry.descriptorCount == 256); | ||
| 127 | EXPECT(layout.flags[22 + c] == | ||
| 128 | (VK_DESCRIPTOR_BINDING_UPDATE_AFTER_BIND_BIT | VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT)); | ||
| 129 | } | ||
| 130 | } | ||
| 96 | 131 | ||
| 97 | // An RTX 5070 (driver 621.24): 1048576 of each descriptor type, update-after-bind or not, 4000 samplers. | 132 | // 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}) { | 133 | for (const bool update_after_bind : {true, false}) { |
| 99 | const Device d = uniform(1048576, 1048576); | 134 | const Device d = uniform(1048576, 1048576); |
| 100 | BindlessFeatures f = with_ms(update_after_bind); | 135 | BindlessFeatures f = with_ms(update_after_bind); |
| 101 | EXPECT(bindless::size_bindings(f, d.limits, d.v11, d.v12)); | 136 | EXPECT(bindless::size_bindings(f, d.limits, d.v11, d.v12)); |
| 102 | EXPECT(count(f, D::dim_2d) == bindless::max_2d_images); | 137 | EXPECT(count(f, D::dim_2d) == bindless::max_images); |
| 103 | EXPECT(f.counts[bindless::sampler_binding] == 4000 - bindless::reserved_samplers); | 138 | 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 | 139 | 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); | 140 | 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); | 141 | // 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); | 142 | // storage arrays hold as many indices as the 2D one. The storage-only 1D array keeps its 256. |
| 143 | EXPECT(count(f, D::dim_2d_array) == bindless::max_images && count(f, D::dim_3d) == bindless::max_images && | ||
| 144 | count(f, D::dim_1d) == bindless::max_images); | ||
| 145 | EXPECT(storage(f, D::dim_2d_array) == bindless::max_storage_indices && | ||
| 146 | storage(f, D::dim_3d) == bindless::max_storage_indices && | ||
| 147 | storage(f, D::dim_1d) == bindless::max_storage_indices); | ||
| 148 | 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); | 149 | EXPECT(f.ms_samples[0] == VK_SAMPLE_COUNT_4_BIT && f.ms_samples[2] == VK_SAMPLE_COUNT_4_BIT); |
| 109 | EXPECT(storage_consistent(f)); | 150 | EXPECT(storage_consistent(f)); |
| 110 | if (update_after_bind) | 151 | if (update_after_bind) |
| @@ -112,12 +153,50 @@ int main() { | |||
| 112 | count(f, D::dim_2d), f.counts[bindless::sampler_binding], storage(f, D::dim_2d), totals(f).all); | 153 | count(f, D::dim_2d), f.counts[bindless::sampler_binding], storage(f, D::dim_2d), totals(f).all); |
| 113 | } | 154 | } |
| 114 | 155 | ||
| 115 | // At today's sizes exactly (5632 sampled images, 1024 samplers, 3584 storage images): today's set, no MS pairs. | 156 | // RADV (Mesa 26.3, a Raphael iGPU and an RX 7900 XTX alike) and llvmpipe: their update-after-bind limits hold |
| 157 | // every sampled dimension at the full size. A world run kept 4090 live 1D textures, filling the 4096 1D indices | ||
| 158 | // the set used to stop at whatever the device held; now 1D, 3D and 2D-array images get as many as 2D. | ||
| 159 | { | ||
| 160 | Device radv = uniform(8388606, 8388606); | ||
| 161 | radv.limits.maxPerStageResources = radv.v12.maxPerStageUpdateAfterBindResources = 8388606; | ||
| 162 | radv.v12.maxUpdateAfterBindDescriptorsInAllPools = 67108863; | ||
| 163 | radv.v11.maxPerSetDescriptors = 22369621; | ||
| 164 | radv.limits.maxSamplerAllocationCount = 4294967295u; | ||
| 165 | Device lvp = uniform(1015808, 1015808); | ||
| 166 | lvp.limits.maxPerStageResources = lvp.v12.maxPerStageUpdateAfterBindResources = 1015808; | ||
| 167 | lvp.v11.maxPerSetDescriptors = 1015808; | ||
| 168 | lvp.limits.maxSamplerAllocationCount = 32768; | ||
| 169 | for (const Device* d : {&radv, &lvp}) { | ||
| 170 | BindlessFeatures f = with_ms(true); | ||
| 171 | EXPECT(bindless::size_bindings(f, d->limits, d->v11, d->v12)); | ||
| 172 | for (const D dimension : {D::dim_2d, D::dim_2d_array, D::dim_3d, D::dim_1d}) { | ||
| 173 | EXPECT(count(f, dimension) == bindless::max_images); | ||
| 174 | EXPECT(count(f, dimension) > 4096 + 1); // more than 4096 live images and the fallback | ||
| 175 | } | ||
| 176 | EXPECT(storage_consistent(f)); | ||
| 177 | } | ||
| 178 | } | ||
| 179 | |||
| 180 | // A device whose limits stop growth short of max_images: the 2D-array, 3D and 1D arrays share what is left alike, | ||
| 181 | // whichever is grown first. | ||
| 182 | { | ||
| 183 | Device d = uniform(1048576, 1048576); | ||
| 184 | d.v12.maxPerStageDescriptorUpdateAfterBindSampledImages = 65536 + 3 * 20000 + 6 * 256 + bindless::growth_headroom; | ||
| 185 | BindlessFeatures f = with_ms(true); | ||
| 186 | EXPECT(bindless::size_bindings(f, d.limits, d.v11, d.v12)); | ||
| 187 | EXPECT(count(f, D::dim_2d) == bindless::max_images); | ||
| 188 | EXPECT(count(f, D::dim_2d_array) == count(f, D::dim_3d) && count(f, D::dim_3d) == count(f, D::dim_1d)); | ||
| 189 | EXPECT(count(f, D::dim_1d) > 4096 && count(f, D::dim_1d) <= 20000); | ||
| 190 | EXPECT(totals(f).sampled + bindless::growth_headroom <= d.v12.maxPerStageDescriptorUpdateAfterBindSampledImages); | ||
| 191 | EXPECT(storage_consistent(f)); | ||
| 192 | } | ||
| 193 | |||
| 194 | // At today's sizes exactly (5632 sampled images, 1024 samplers, 4352 storage images): no MS pairs. | ||
| 116 | { | 195 | { |
| 117 | Device d = uniform(1048576, 1048576); | 196 | Device d = uniform(1048576, 1048576); |
| 118 | d.v12.maxPerStageDescriptorUpdateAfterBindSampledImages = 5632; | 197 | d.v12.maxPerStageDescriptorUpdateAfterBindSampledImages = 5632; |
| 119 | d.v12.maxPerStageDescriptorUpdateAfterBindSamplers = 1024; | 198 | d.v12.maxPerStageDescriptorUpdateAfterBindSamplers = 1024; |
| 120 | d.v12.maxPerStageDescriptorUpdateAfterBindStorageImages = 3584; | 199 | d.v12.maxPerStageDescriptorUpdateAfterBindStorageImages = 4352; |
| 121 | BindlessFeatures f = with_ms(true); | 200 | BindlessFeatures f = with_ms(true); |
| 122 | EXPECT(bindless::size_bindings(f, d.limits, d.v11, d.v12)); | 201 | 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 && | 202 | EXPECT(count(f, D::dim_2d) == 4096 && f.counts[bindless::sampler_binding] == 1024 && |
| @@ -125,6 +204,7 @@ int main() { | |||
| 125 | for (std::uint32_t b = 0; b < bindless::first_ms_binding; ++b) | 204 | 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]); | 205 | 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})); | 206 | EXPECT(f.ms_samples == (std::array{VK_SAMPLE_COUNT_1_BIT, VK_SAMPLE_COUNT_1_BIT, VK_SAMPLE_COUNT_1_BIT})); |
| 207 | EXPECT(totals(f).storage == 4352 && storage(f, D::dim_1d_array) == 256); | ||
| 128 | EXPECT(storage_consistent(f)); | 208 | EXPECT(storage_consistent(f)); |
| 129 | } | 209 | } |
| 130 | 210 | ||
| @@ -150,7 +230,7 @@ int main() { | |||
| 150 | BindlessFeatures uab = with_ms(true), plain = with_ms(false); | 230 | BindlessFeatures uab = with_ms(true), plain = with_ms(false); |
| 151 | EXPECT(bindless::size_bindings(uab, d.limits, d.v11, d.v12)); | 231 | EXPECT(bindless::size_bindings(uab, d.limits, d.v11, d.v12)); |
| 152 | EXPECT(bindless::size_bindings(plain, d.limits, d.v11, d.v12)); | 232 | EXPECT(bindless::size_bindings(plain, d.limits, d.v11, d.v12)); |
| 153 | EXPECT(count(uab, D::dim_2d) == bindless::max_2d_images); | 233 | EXPECT(count(uab, D::dim_2d) == bindless::max_images); |
| 154 | const Totals t = totals(plain); | 234 | const Totals t = totals(plain); |
| 155 | EXPECT(count(plain, D::dim_2d) > 4096 && count(plain, D::dim_2d) < 16384); | 235 | 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); | 236 | EXPECT(t.sampled + bindless::growth_headroom <= 16384 && t.storage + bindless::growth_headroom <= 16384); |
| @@ -178,16 +258,20 @@ int main() { | |||
| 178 | Device d = uniform(1048576, 1048576); | 258 | Device d = uniform(1048576, 1048576); |
| 179 | d.v11.maxPerSetDescriptors = 6159; | 259 | d.v11.maxPerSetDescriptors = 6159; |
| 180 | d.limits.maxSamplerAllocationCount = 4000; | 260 | d.limits.maxSamplerAllocationCount = 4000; |
| 181 | unsigned asked = 0, asked_within = 0; | 261 | unsigned asked = 0, asked_within = 0, missing_storage = 0; |
| 182 | const auto all_supported = [&](const BindlessFeatures& candidate) { | 262 | const auto all_supported = [&](const BindlessFeatures& candidate) { |
| 183 | ++asked; | 263 | ++asked; |
| 184 | asked_within += totals(candidate).all <= 6159; | 264 | asked_within += totals(candidate).all <= 6159; |
| 265 | const bindless::SetLayout layout(candidate); | ||
| 266 | const auto& last = layout.entries[layout.info.bindingCount - 1]; | ||
| 267 | missing_storage += last.binding != 28 || last.descriptorType != VK_DESCRIPTOR_TYPE_STORAGE_IMAGE || | ||
| 268 | last.descriptorCount != storage(candidate, D::dim_1d_array); | ||
| 185 | return true; | 269 | return true; |
| 186 | }; | 270 | }; |
| 187 | BindlessFeatures f = with_ms(true); | 271 | BindlessFeatures f = with_ms(true); |
| 188 | EXPECT(bindless::size_bindings(f, d.limits, d.v11, d.v12, all_supported)); | 272 | EXPECT(bindless::size_bindings(f, d.limits, d.v11, d.v12, all_supported)); |
| 189 | EXPECT(asked > 0 && asked_within == 0); | 273 | EXPECT(asked > 0 && asked_within == 0 && missing_storage == 0); |
| 190 | EXPECT(count(f, D::dim_2d) == bindless::max_2d_images && | 274 | EXPECT(count(f, D::dim_2d) == bindless::max_images && |
| 191 | f.counts[bindless::sampler_binding] == 4000 - bindless::reserved_samplers); | 275 | f.counts[bindless::sampler_binding] == 4000 - bindless::reserved_samplers); |
| 192 | EXPECT(storage(f, D::dim_2d) == bindless::max_storage_indices && storage_consistent(f)); | 276 | EXPECT(storage(f, D::dim_2d) == bindless::max_storage_indices && storage_consistent(f)); |
| 193 | 277 | ||
| @@ -221,6 +305,31 @@ int main() { | |||
| 221 | 305 | ||
| 222 | // The default features are today's counts, which the device-less users (vk_image_fuzz) still get. | 306 | // The default features are today's counts, which the device-less users (vk_image_fuzz) still get. |
| 223 | EXPECT(BindlessFeatures{}.counts == defaults); | 307 | EXPECT(BindlessFeatures{}.counts == defaults); |
| 308 | |||
| 309 | // Binding 29 (2D r64ui storage images) is gated on shader_image_int64_atomics and tracks 2D storage capacity. | ||
| 310 | { | ||
| 311 | static_assert(bindless::binding_count == 30 && bindless::r64ui_binding == 29); | ||
| 312 | static_assert(defaults[bindless::r64ui_binding] == 1024); | ||
| 313 | BindlessFeatures f{}; | ||
| 314 | f.update_after_bind = f.partially_bound = true; | ||
| 315 | f.shader_image_int64_atomics = true; | ||
| 316 | EXPECT(bindless::binding_enabled(bindless::r64ui_binding, f)); | ||
| 317 | const bindless::SetLayout layout(f); | ||
| 318 | EXPECT(layout.info.bindingCount == 24 && layout.flags_info.bindingCount == 24); | ||
| 319 | const auto& last = layout.entries[layout.info.bindingCount - 1]; | ||
| 320 | EXPECT(last.binding == bindless::r64ui_binding && | ||
| 321 | last.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE && | ||
| 322 | last.descriptorCount == 1024); | ||
| 323 | |||
| 324 | const Device d = uniform(1048576, 1048576); | ||
| 325 | BindlessFeatures sized = with_ms(true); | ||
| 326 | sized.shader_image_int64_atomics = true; | ||
| 327 | EXPECT(bindless::size_bindings(sized, d.limits, d.v11, d.v12)); | ||
| 328 | EXPECT(sized.counts[bindless::r64ui_binding] == bindless::max_storage_indices); | ||
| 329 | EXPECT(totals(sized).all == 325729 + bindless::max_storage_indices); | ||
| 330 | EXPECT(storage_consistent(sized)); | ||
| 331 | } | ||
| 332 | |||
| 224 | std::printf("bindless sizing: synthetic limits gave the expected counts\n"); | 333 | std::printf("bindless sizing: synthetic limits gave the expected counts\n"); |
| 225 | return 0; | 334 | return 0; |
| 226 | } | 335 | } |