diff options
| author | quackottu <224479491+quackottu@users.noreply.github.com> | 2026-11-22 13:41:58 +0530 |
|---|---|---|
| committer | quackottu <224479491+quackottu@users.noreply.github.com> | 2026-11-22 13:41:58 +0530 |
| commit | ea512f284ce3b58c144850d70371091e1522ce72 (patch) | |
| tree | efb835351b30a9144fde72b55a8b13e93da10914 /runtime/test/bindless_sizing_test.cpp | |
| parent | c63773d51235d72250d48699f29830ac9ddafd60 (diff) | |
Runtime: size the bindless set's arrays from the device's descriptor limits
Set 0's 2D, sampler and storage arrays were constexpr (4096 2D images, 1024
samplers, 256 per storage array): one full D3D12 sampler heap (2048) did
not fit and bind_image/bind_sampler fell back. They are now sized once, when
the device creates the set, from the update-after-bind or plain limits:
today's sizes as the floor, then samplers up to min(4096,
maxSamplerAllocationCount - 64), 2D images up to 65536, storage up to 4096.
Sizing at creation keeps the set layout fixed for the pipelines built on it.
Diffstat (limited to 'runtime/test/bindless_sizing_test.cpp')
| -rw-r--r-- | runtime/test/bindless_sizing_test.cpp | 179 |
1 files changed, 179 insertions, 0 deletions
diff --git a/runtime/test/bindless_sizing_test.cpp b/runtime/test/bindless_sizing_test.cpp new file mode 100644 index 000000000..469274d56 --- /dev/null +++ b/runtime/test/bindless_sizing_test.cpp | |||
| @@ -0,0 +1,179 @@ | |||
| 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 | ||
| 3 | // has room, and less where it is below them. | ||
| 4 | #ifndef VK_NO_PROTOTYPES | ||
| 5 | #define VK_NO_PROTOTYPES | ||
| 6 | #endif | ||
| 7 | #include "../src/vulkan_bindless.h" | ||
| 8 | |||
| 9 | #include <cstdio> | ||
| 10 | |||
| 11 | #define EXPECT(condition) do { \ | ||
| 12 | if (!(condition)) { std::fprintf(stderr, "line %d: %s\n", __LINE__, #condition); return 1; } \ | ||
| 13 | } while (0) | ||
| 14 | |||
| 15 | using namespace leonida; | ||
| 16 | |||
| 17 | namespace { | ||
| 18 | |||
| 19 | struct Device { | ||
| 20 | VkPhysicalDeviceLimits limits{}; | ||
| 21 | VkPhysicalDeviceVulkan11Properties v11{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_PROPERTIES}; | ||
| 22 | VkPhysicalDeviceVulkan12Properties v12{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_PROPERTIES}; | ||
| 23 | }; | ||
| 24 | |||
| 25 | // The same descriptor limit for every type, update-after-bind or not; the others are unlimited. | ||
| 26 | Device uniform(std::uint32_t plain, std::uint32_t update_after_bind) { | ||
| 27 | Device d; | ||
| 28 | auto& l = d.limits; | ||
| 29 | l.maxPerStageDescriptorSampledImages = l.maxDescriptorSetSampledImages = plain; | ||
| 30 | l.maxPerStageDescriptorSamplers = l.maxDescriptorSetSamplers = plain; | ||
| 31 | l.maxPerStageDescriptorStorageImages = l.maxDescriptorSetStorageImages = plain; | ||
| 32 | l.maxPerStageResources = 0xffffffffu; | ||
| 33 | l.maxColorAttachments = 8; | ||
| 34 | l.maxSamplerAllocationCount = 4000; // NVIDIA's; the minimum Vulkan allows | ||
| 35 | auto& u = d.v12; | ||
| 36 | u.maxPerStageDescriptorUpdateAfterBindSampledImages = update_after_bind; | ||
| 37 | u.maxDescriptorSetUpdateAfterBindSampledImages = update_after_bind; | ||
| 38 | u.maxPerStageDescriptorUpdateAfterBindSamplers = u.maxDescriptorSetUpdateAfterBindSamplers = update_after_bind; | ||
| 39 | u.maxPerStageDescriptorUpdateAfterBindStorageImages = update_after_bind; | ||
| 40 | u.maxDescriptorSetUpdateAfterBindStorageImages = update_after_bind; | ||
| 41 | u.maxPerStageUpdateAfterBindResources = 0xffffffffu; | ||
| 42 | u.maxUpdateAfterBindDescriptorsInAllPools = 0xffffffffu; | ||
| 43 | d.v11.maxPerSetDescriptors = 0xffffffffu; | ||
| 44 | return d; | ||
| 45 | } | ||
| 46 | |||
| 47 | BindlessFeatures with_ms(bool update_after_bind) { | ||
| 48 | BindlessFeatures f{}; | ||
| 49 | f.update_after_bind = update_after_bind; | ||
| 50 | f.ms_samples.fill(VK_SAMPLE_COUNT_4_BIT); | ||
| 51 | return f; | ||
| 52 | } | ||
| 53 | |||
| 54 | struct Totals { std::uint32_t sampled = 0, samplers = 0, storage = 0, all = 0; }; | ||
| 55 | Totals totals(const BindlessFeatures& f) { | ||
| 56 | Totals t; | ||
| 57 | for (std::uint32_t b = 0; b < bindless::binding_count; ++b) { | ||
| 58 | if (!bindless::binding_enabled(b, f)) continue; | ||
| 59 | const auto type = bindless::bindings[b].type; | ||
| 60 | if (type == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE) t.sampled += f.counts[b]; | ||
| 61 | if (type == VK_DESCRIPTOR_TYPE_SAMPLER) t.samplers += f.counts[b]; | ||
| 62 | if (type == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) t.storage += f.counts[b]; | ||
| 63 | t.all += f.counts[b]; | ||
| 64 | } | ||
| 65 | return t; | ||
| 66 | } | ||
| 67 | |||
| 68 | std::uint32_t count(const BindlessFeatures& f, ImageDimension dimension) { | ||
| 69 | return f.counts[bindless::sampled_binding(dimension)]; | ||
| 70 | } | ||
| 71 | std::uint32_t storage(const BindlessFeatures& f, ImageDimension dimension) { | ||
| 72 | return f.counts[bindless::storage_binding(dimension, 0)]; | ||
| 73 | } | ||
| 74 | |||
| 75 | // Every storage array of a dimension, the r32ui one included, holds the same indices. | ||
| 76 | bool storage_consistent(const BindlessFeatures& f) { | ||
| 77 | for (std::uint32_t d = 0; d < 4; ++d) { | ||
| 78 | const auto dimension = ImageDimension(d); | ||
| 79 | const auto held = storage(f, dimension); | ||
| 80 | if (held > count(f, dimension)) return false; | ||
| 81 | for (std::uint32_t c = 0; c < 3; ++c) | ||
| 82 | if (f.counts[bindless::storage_binding(dimension, c)] != held) return false; | ||
| 83 | if (bindless::r32ui_binding(dimension) != bindless::no_binding && | ||
| 84 | f.counts[bindless::r32ui_binding(dimension)] != held) | ||
| 85 | return false; | ||
| 86 | } | ||
| 87 | return true; | ||
| 88 | } | ||
| 89 | |||
| 90 | } // namespace | ||
| 91 | |||
| 92 | int main() { | ||
| 93 | using D = ImageDimension; | ||
| 94 | constexpr auto defaults = bindless::default_counts(); | ||
| 95 | static_assert(defaults[0] == 4096 && defaults[bindless::sampler_binding] == 1024 && defaults[8] == 256); | ||
| 96 | |||
| 97 | // 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}) { | ||
| 99 | const Device d = uniform(1048576, 1048576); | ||
| 100 | BindlessFeatures f = with_ms(update_after_bind); | ||
| 101 | EXPECT(bindless::size_bindings(f, d.limits, d.v11, d.v12)); | ||
| 102 | EXPECT(count(f, D::dim_2d) == bindless::max_2d_images); | ||
| 103 | 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 | ||
| 105 | 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); | ||
| 107 | EXPECT(count(f, D::dim_2d_array) == 1024 && count(f, D::dim_3d) == 256 && count(f, D::dim_1d) == 256); | ||
| 108 | EXPECT(f.ms_samples[0] == VK_SAMPLE_COUNT_4_BIT && f.ms_samples[2] == VK_SAMPLE_COUNT_4_BIT); | ||
| 109 | EXPECT(storage_consistent(f)); | ||
| 110 | if (update_after_bind) | ||
| 111 | std::printf("RTX 5070-like: %u 2D images, %u samplers, %u storage indices in 2D, %u descriptors\n", | ||
| 112 | count(f, D::dim_2d), f.counts[bindless::sampler_binding], storage(f, D::dim_2d), totals(f).all); | ||
| 113 | } | ||
| 114 | |||
| 115 | // At today's sizes exactly (5632 sampled images, 1024 samplers, 3584 storage images): today's set, no MS pairs. | ||
| 116 | { | ||
| 117 | Device d = uniform(1048576, 1048576); | ||
| 118 | d.v12.maxPerStageDescriptorUpdateAfterBindSampledImages = 5632; | ||
| 119 | d.v12.maxPerStageDescriptorUpdateAfterBindSamplers = 1024; | ||
| 120 | d.v12.maxPerStageDescriptorUpdateAfterBindStorageImages = 3584; | ||
| 121 | BindlessFeatures f = with_ms(true); | ||
| 122 | 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 && | ||
| 124 | storage(f, D::dim_2d) == 256); | ||
| 125 | 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]); | ||
| 127 | EXPECT(f.ms_samples == (std::array{VK_SAMPLE_COUNT_1_BIT, VK_SAMPLE_COUNT_1_BIT, VK_SAMPLE_COUNT_1_BIT})); | ||
| 128 | EXPECT(storage_consistent(f)); | ||
| 129 | } | ||
| 130 | |||
| 131 | // A small device below today's sizes: smaller arrays that fit, and false. | ||
| 132 | { | ||
| 133 | Device d = uniform(1048576, 1048576); | ||
| 134 | d.limits.maxPerStageDescriptorSampledImages = 3000; | ||
| 135 | d.limits.maxPerStageDescriptorSamplers = 512; | ||
| 136 | d.limits.maxPerStageDescriptorStorageImages = 2000; | ||
| 137 | d.limits.maxPerStageResources = 4500; | ||
| 138 | BindlessFeatures f = with_ms(false); | ||
| 139 | EXPECT(!bindless::size_bindings(f, d.limits, d.v11, d.v12)); | ||
| 140 | const Totals t = totals(f); | ||
| 141 | EXPECT(t.sampled <= 3000 && t.samplers <= 512 && t.storage <= 2000 && t.sampled + t.storage + 1 + 8 <= 4500); | ||
| 142 | EXPECT(count(f, D::dim_2d) >= 1 && count(f, D::dim_2d) < 4096 && f.counts[bindless::sampler_binding] == 512); | ||
| 143 | EXPECT(f.ms_samples[0] == VK_SAMPLE_COUNT_1_BIT); | ||
| 144 | EXPECT(storage_consistent(f)); | ||
| 145 | } | ||
| 146 | |||
| 147 | // Update-after-bind and plain limits differ: each layout is sized by its own. | ||
| 148 | { | ||
| 149 | const Device d = uniform(16384, 1048576); | ||
| 150 | BindlessFeatures uab = with_ms(true), plain = with_ms(false); | ||
| 151 | EXPECT(bindless::size_bindings(uab, d.limits, d.v11, d.v12)); | ||
| 152 | EXPECT(bindless::size_bindings(plain, d.limits, d.v11, d.v12)); | ||
| 153 | EXPECT(count(uab, D::dim_2d) == bindless::max_2d_images); | ||
| 154 | const Totals t = totals(plain); | ||
| 155 | 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); | ||
| 157 | EXPECT(plain.ms_samples[0] == VK_SAMPLE_COUNT_4_BIT && storage_consistent(plain)); | ||
| 158 | EXPECT(plain.counts[bindless::sampler_binding] == 4000 - bindless::reserved_samplers); | ||
| 159 | } | ||
| 160 | |||
| 161 | // maxPerSetDescriptors stops growth but never takes a count below today's. | ||
| 162 | { | ||
| 163 | Device d = uniform(1048576, 1048576); | ||
| 164 | d.v11.maxPerSetDescriptors = 1024; | ||
| 165 | BindlessFeatures f = with_ms(true); | ||
| 166 | EXPECT(bindless::size_bindings(f, d.limits, d.v11, d.v12)); | ||
| 167 | EXPECT(count(f, D::dim_2d) == 4096 && f.counts[bindless::sampler_binding] == 1024 && | ||
| 168 | storage(f, D::dim_2d) == 256); | ||
| 169 | d.v11.maxPerSetDescriptors = 30000; | ||
| 170 | f = with_ms(true); | ||
| 171 | EXPECT(bindless::size_bindings(f, d.limits, d.v11, d.v12)); | ||
| 172 | EXPECT(totals(f).all <= 30000 && count(f, D::dim_2d) > 4096); | ||
| 173 | } | ||
| 174 | |||
| 175 | // The default features are today's counts, which the device-less users (vk_image_fuzz) still get. | ||
| 176 | EXPECT(BindlessFeatures{}.counts == defaults); | ||
| 177 | std::printf("bindless sizing: synthetic limits gave the expected counts\n"); | ||
| 178 | return 0; | ||
| 179 | } | ||