Skip to content

Runtime: size the bindless set's arrays from the device's descriptor limits - #1199

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
quackottu:bindless-capacity
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
quackottu:bindless-capacity

Conversation

@quackottu

Copy link
Copy Markdown
Contributor

Set 0's 2D image, sampler and storage arrays were constexpr: 4096 sampled 2D images, 1024 samplers and 256 per storage array. One full D3D12 shader-visible sampler heap holds 2048 samplers, and the game streams far more than 4096 textures. Past those sizes, bind_image/bind_sampler logged "array is full" and shaders read the fallback. docs/d3d12_vulkan.md said to grow the set by recreating it, but that would invalidate every pipeline layout built on bindless_set_layout(). So the device now sizes the arrays once, when it creates the set. The translator declares runtime arrays, so no shader changes.

  • bindless::size_bindings (vulkan_bindless.h) is a pure function over VkPhysicalDeviceLimits and the Vulkan 1.1/1.2 properties.
  • It reads the update-after-bind limits when the set uses update-after-bind, and the plain ones otherwise. Per-stage and per-set limits both apply.
  • It starts from today's sizes, clamping (with a log line) where a device is below them, then adds the MS pairs that fit, as before.
  • It then grows samplers up to min(4096, maxSamplerAllocationCount − 64), 2D images up to 65536 and storage arrays up to 4096 each, leaving 64 of each limit for other sets.
  • Storage arrays: each holds the smaller of the storage count and its dimension's image count. Binding 4 (2D r32ui) now matches the other 2D storage arrays.
  • RTX 5070 (driver 621.24): 65536 2D images, 3936 samplers (maxSamplerAllocationCount is 4000), 4096 storage indices in 2D. That's 93,793 descriptors, about 3–6 MiB. The device prints the counts it chose, one line per device.
  • What a reviewer will notice:
  • read-only 2D images now start at index 4096, after the storage range;
  • read-only MS images start at 1.
  • Unchanged: 2D-array, 1D, 3D and MS arrays keep their sizes; vk_pipeline_check's fixed counts (runtime arrays); root_signature.cpp's 4096 sanity bound.
  • Known limit: BindlessSet::allocate() is still a linear scan.
main this PR
5001st SRV through the 2100th sampler (d3d12_descriptor_test) "bindless image array is full", "sampler array is full", reads 0,0,0,0 samples the texture
vk_bindless_test step 9, a 2D image past 5000 others and a sampler past 2100 add_image returns 0 past 4096 0 bad pixels, both configurations

Tests, on Windows 11 with an RTX 5070 (621.24), LEONIDA_VK_VALIDATION=1 and LEONIDA_D3D12=vulkan:

  • New CPU ctest bindless_sizing: synthetic limits for an RTX 5070-like device, a device exactly at today's sizes (gives today's set), a small device below them (clamped), UAB vs plain limits, and maxPerSetDescriptors at 1024 and 30000.
  • vk_bindless_test step 9 and the d3d12_descriptor_test capacity block: both fail on main and pass with this change.
  • Full ctest: 55/55, zero validation errors.

Not checked: AMD and Intel Windows drivers. If one reports a maxPerSetDescriptors below about 94k, growth stops there, and d3d12_descriptor_test's new block (5001 SRVs) isn't gated on the set's capacity. A test on those GPUs would help. #773 (D3D-78) edits the same table and storage_indices, which this replaces with storage_capacity(). Whichever lands second rebases; its dim_1d_array needs adding to image_capacity/storage_capacity/size_bindings.

AI-assisted.

…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.
@undeadhuman37

Copy link
Copy Markdown
Contributor

Tested ea512f2 on NVIDIA GeForce RTX 4070 SUPER, driver 621.01, Windows 11 Home 25H2 (26200.9974), VS 2022 Build Tools, Vulkan SDK 1.4.363.1: pass.

  • Build: 0 warnings. ctest: 56/56 passed, including bindless_sizing and vk_bindless.
  • bindless_sizing_test ("synthetic limits gave the expected counts") and d3d12_descriptor_test (T#/S# found in the bindless set, 64 RGBA8 and RGB9E5 texels matched): exit 0, also with LEONIDA_VK_VALIDATION=1 and 0 validation errors.

AI-assisted. No game files.

@whattheflop

Copy link
Copy Markdown
Contributor

AI-assisted review of ea512f284ce3b58c144850d70371091e1522ce72. Radeon iGPU PASS.

  • AMD Radeon(TM) Graphics (1002:13c0), AMD 25.10.30.02 (Windows driver 32.0.21030.2001, Vulkan driver 2.0.353), Vulkan API 1.4.315, subgroups 32–64. Windows 11 Pro 25H2 build 26200.9974. MSVC 19.38.33145.0, Windows SDK 10.0.26100.0, CMake 4.4.4, Ninja 1.13.2, Vulkan SDK/loader/validation 1.4.363.0, glslang 16.6.0, SPIRV-Tools 2026.4.rc2 (ef96ed76).
  • Reported limits with update-after-bind and partially-bound support: 4,294,967,295 for maxPerSetDescriptors, the update-after-bind pool, plain and update-after-bind stage resources, and per-stage/per-set samplers, sampled images, storage images and storage buffers. maxSamplerAllocationCount was 1,048,576. The runtime chose 65,536 2D images, 4,096 samplers, 1,024 2D-array images, 256 1D and 256 3D images, and 4,096 2D storage indices.
  • With synchronization validation enabled, a disposable valid-only wrapper linked to the exact PR runtime ran the PR's d3d12_descriptor_test capacity block and stock compute shader. Baseline and the 5,001st SRV through the 2,100th sampler each matched 64/64 texels. A separate shader readback confirmed actual image index 9,097 and sampler index 2,101. Exit 0, zero validation messages or errors through teardown, and no capacity-gated skip. spirv-val accepted both modules. Stock bindless_sizing ctest passed 1/1. No game data used.

The D3D12 capacity block still needs a capacity guard for lower-limit hardware. Intel and the standalone Vulkan test's plain configuration remain unverified by this run.

@TricksterG

Copy link
Copy Markdown
Contributor

Tested ea512f2 on RTX 5090 (Blackwell, driver 621.24), Windows 11 Pro 26300, MSVC 14.44 (VS 2022), Vulkan SDK 1.4.363.0 with validation layers, VS generator, Release, -DLEONIDA_SDL3=OFF: pass.

AI-assisted (Claude Code): it built the branch, ran the tests and wrote this comment.

  • Build: 0 warnings. ctest: 55/55 (gameinput disabled), including bindless_sizing, d3d12_descriptor, descriptor_table, gfx10_descriptors.
  • With LEONIDA_VK_VALIDATION=1, 0 VUIDs: bindless_sizing_test ("synthetic limits gave the expected counts"), d3d12_descriptor_test (T#/S# found in the bindless set by a shader, 64 RGBA8 and RGB9E5 texels matched).
  • run_gpu_tests.py --filter ps_tex under the validation layer: 8/8, ps_tex "bindless: 14 draws read back, 0 bad pixels, largest error 0", plus the ps_texture_* and ps_texoff fixtures.

@ItsNotRexed
ItsNotRexed merged commit 209f5e1 into ItsNotRexed:main Nov 22, 2026
10 of 11 checks passed
@Dom-in

Dom-in commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested ea512f2 on AMD Radeon RX 9070 (RDNA4), AMD 26.11.2 (LLPC), Windows 11 Pro 26300, MSVC 14.44, scripts\build_runtime.ps1: pass. This is an AMD data point next to the RTX 5070 one.

The device's update-after-bind limits are effectively unbounded: maxPerStageDescriptorUpdateAfterBind{Samplers,SampledImages}, maxDescriptorSetUpdateAfterBind{Samplers,SampledImages,StorageImages} are all 4294967295, and maxSamplerAllocationCount is 1048576. So every growth step reaches its maximum:

[rt] d3d12: bindless set: 65536 2D images, 4096 samplers, 1024 2D-array, 256 3D, 256 1D, 4096 storage indices in 2D

That's the first device in the PR where the sampler count isn't clamped by maxSamplerAllocationCount (4096 rather than the 5070's 3936).

I also read size_bindings for overflow with UINT32_MAX limits. The sums are uint64_t, within() adds the headroom in 64 bits, and the subtractions (resource_limit, creatable, pool_limit - samplers) are all clamped with std::min, so nothing wraps.

Test Result
bindless_sizing_test synthetic limits gave the expected counts
d3d12_descriptor_test exit 0, bindless capacity: the 5001th SRV through the 2100th sampler gave the texture
run_gpu_tests.py (includes vk_bindless_test via ps_tex) 110/110, ps_tex bindless: 14 draws read back, 0 bad pixels

The branch also merges cleanly with main at 0d61c35 (git merge-tree).

AI-assisted (Claude Code).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants