Skip to content

Runtime: cap 2D storage descriptors during bindless::size_bindings sizing - #8168

Open
svds12343 wants to merge 1 commit into
ItsNotRexed:mainfrom
svds12343:fix/bindless-size-bindings-cap
Open

svds12343 wants to merge 1 commit into
ItsNotRexed:mainfrom
svds12343:fix/bindless-size-bindings-cap

Conversation

@svds12343

Copy link
Copy Markdown

Claim: unlisted D3D/runtime bug claimed at #7913 (comment) (active coordination board is now #8047).
Depends on: none (built on upstream/main dde82f27e994337094afc476ded0b1426f6e87e2; compatible with open PR #4811 because fits(headroom, set_limit) preserves its 2-argument call form via a default bool cap_2d = true parameter).

Problem

In leonida::bindless::size_bindings() (runtime/src/vulkan_bindless.h), apply(bool) only capped the four 2D storage bindings (counts[4] and counts[8..10]) to std::min(storage, counts[0]) at the very end (apply(true)). Everywhere else—inside fits() and before limit_ms_bindings() / Step 3 set_limit summation—it called apply(false), keeping 2D storage uncapped at storage even when images < storage:

  1. During Step 1's grow(images), fits() charged 4 * storage phantom 2D storage descriptors while trying to grow images, starving images down to 1 (zero usable 2D textures) under tight maxPerStageResources or maxUpdateAfterBindDescriptorsInAllPools limits, only for the final apply(true) to discard 4 * (storage - images) descriptors.
  2. When sampled_limit clamped images < 256, descriptors freed by capping 2D storage from storage down to images were never reclaimed for 2D-array, 3D, and 1D storage arrays.
  3. Between Step 1 and Step 3, apply(false) left counts[4, 8..10] uncapped when limit_ms_bindings() and the Step 3 set_limit total summed counts, and Step 3's fits() passed uncapped candidates (storage(2D) > count(2D)) to layout_supported.

Per docs/d3d12_vulkan.md §5, each storage array holds at most as many images as its dimension, and the 2D r32ui array matches the other 2D storage arrays.

Fix

  • runtime/src/vulkan_bindless.h:
    • Parameterize apply(bool cap_2d), fits(..., bool cap_2d = true), and grow(..., bool cap_2d = true) so 2D storage is uncapped only during Step 1's initial grow(storage) pass (when images is still 1).
    • Cap 2D storage by images during Step 1's grow(images), follow with a second Step 1 grow(storage) (capped) to reclaim freed descriptors for non-2D storage up to the 256 default when images < 256, call apply(true) before limit_ms_bindings() and set_limit, and keep capping enabled throughout Step 3 (including layout_supported queries).
  • runtime/test/bindless_sizing_test.cpp:
    • Add five synthetic regression cases covering tight maxPerStageResources, tight sampled-image limits alongside tight per-stage resource or storage limits, tight maxUpdateAfterBindDescriptorsInAllPools, and layout_supported candidate consistency.

Synthetic before/after reproduction (upstream/main dde82f27 vs f2b6ca34)

Synthetic limits upstream/main (dde82f27) After fix (f2b6ca34)
Plain, sampled=4000, storage=3584, resources=4500 2D=1, st2D=1, stArr/3D/1D=211 (0 usable 2D slots) 2D=169, st2D=169, stArr/3D/1D=211 (4500/4500 resources)
Plain, sampled=1600, storage=3584, resources=4500 2D=1, st2D=1, stArr/3D/1D=211 2D=64, st2D=64, stArr/3D/1D=256
Plain, sampled=1600, storage=2816 2D=64, st2D=64, stArr/3D/1D=201 2D=64, st2D=64, stArr/3D/1D=256 (2816/2816 storage)
UAB, pool_limit=6000 2D=9, st2D=9, stArr/3D/1D=245, sam=1024 (5056/6000) 2D=197, st2D=197, stArr/3D/1D=245, sam=1028 (6000/6000)
UAB, pool_limit=5900, maxPerSetDescriptors=1024, layout_supported 2D=7, st2D=7, sam=1024, asked=0 (4976/5900) 2D=191, st2D=191, sam=1028, asked=3 (all storage_consistent, 5900/5900)

A 20,000-profile randomized synthetic comparison between upstream/main and f2b6ca34 produced 12,164 identical profiles, 7,836 strictly improved profiles, 0 regressions in any binding count or MS class, 0 changes in the full return value, and 0 limit or storage_consistent violations.

Testing

  • AI-assisted: Yes (AI-assisted analysis, implementation, and test authoring; all builds and tests executed locally).
  • Tested revision: f2b6ca347dbecb5d9a32bf8c25091570ca099d14 (based on upstream/main dde82f27e994337094afc476ded0b1426f6e87e2).
  • Environment: Windows 11 x64, MSVC 19.44.35230.0 (VS 2022 BuildTools), Ninja, Vulkan SDK 1.4.363.0, NVIDIA GeForce RTX 3070 (driver 610.88). Synthetic inputs only; no game files.
  • Negative control: Compiling the new runtime/test/bindless_sizing_test.cpp against unmodified upstream/main:runtime/src/vulkan_bindless.h failed as expected at line 157: count(f, D::dim_2d) == 169 && storage(f, D::dim_2d) == 169 (exit code 1).
  • Build & CPU tests:
    • cmake -S runtime -B runtime/build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo
    • cmake --build runtime/build --target bindless_sizing_test descriptor_table_test vk_bindless_test d3d12_bindless_churn_test d3d12_descriptor_test vk_ps_sweep -> succeeded with 0 warnings in changed files.
    • ctest --test-dir runtime/build -R "^(bindless_sizing|descriptor_table)$" --output-on-failure -V -> 2/2 passed (descriptor_table, bindless_sizing).
  • GPU tests (NVIDIA GeForce RTX 3070, driver 610.88, LEONIDA_VK_VALIDATION=1):
    • ctest --test-dir runtime/build -R "^(vk_bindless_ps_tex|vk_bindless_ps_imgatomic|d3d12_descriptor|d3d12_bindless_churn|d3d12_bindless_churn_validated)$" --output-on-failure -V -> 5/5 passed (d3d12_descriptor, vk_bindless_ps_tex, vk_bindless_ps_imgatomic, d3d12_bindless_churn, d3d12_bindless_churn_validated).
  • Hygiene:
    • git diff --check -> clean.
    • python -I scripts/check_no_game_data.py runtime/src/vulkan_bindless.h runtime/test/bindless_sizing_test.cpp (plus PR body) -> clean.
    • python -m compileall -q make_game.py tools tests and python -I make_game.py --help -> passed.

@al3xar al3xar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested f2b6ca347 on NVIDIA GeForce RTX 3060, driver 621.24 (Vulkan 1.4.357), Windows 11 x64, MSVC 19.44.35230.0, CMake + Ninja RelWithDebInfo (no game files): pass.

  • Merges cleanly onto upstream/main (dde82f27e).
  • Built bindless_sizing_test and d3d12_bindless_churn_test with zero new warnings in runtime/src/vulkan_bindless.h and runtime/test/bindless_sizing_test.cpp.
  • bindless_sizing_test.exe and ctest -R "^bindless_sizing$": Passed (bindless sizing: synthetic limits gave the expected counts, exit 0).
  • d3d12_bindless_churn_test.exe on RTX 3060: Passed (exit 0; 96 frames direct & async compute, 98,304 texels compared, 0 wrong).
  • Negative control (runtime/src/vulkan_bindless.h reverted to upstream/main, PR test kept): fails as expected (line 157: count(f, D::dim_2d) == 169 && storage(f, D::dim_2d) == 169, exit 1).
  • python -I scripts/check_no_game_data.py runtime/src/vulkan_bindless.h runtime/test/bindless_sizing_test.cpp: clean (exit 0).
  • Diff review: parameterizing apply/fits/grow with bool cap_2d = true (leaving only the initial Step 1 grow(storage) uncapped and adding a capped follow-up grow(storage) to reclaim unused 2D storage slots) cleanly avoids starving 2D images under tight limits while keeping layout_supported candidates consistent.

AI-assisted.

@KarolKurzyna

Copy link
Copy Markdown
Contributor

Independent Windows 11 MSVC + dual-GPU review of f2b6ca347d (PASS, AI-assisted, synthetic tests only, no game data).

Environment

  • OS / Toolchain: Windows 11 x64, MSVC 19.52.37029 (x64, Ninja), CMake 4.3.1-msvc1, Vulkan loader 1.4.363, VK_LOADER_LAYERS_DISABLE=~implicit~, LEONIDA_VK_VALIDATION=1.
  • GPU 1: NVIDIA GeForce RTX 3070 Ti (driver 621.24, Vulkan 1.4.357).
  • GPU 2: Intel(R) UHD Graphics 770 (Xe-LP, driver 101.6129, Vulkan 1.3.295).

Build & Code Audit

  • Built cleanly with MSVC (0 new warnings) across bindless_sizing_test, descriptor_table_test, vk_bindless_test, d3d12_bindless_churn_test, and d3d12_descriptor_test.
  • Audited runtime/src/vulkan_bindless.h (size_bindings):
    • Leaving Step 1's initial grow(storage, ..., cap_2d=false) uncapped while images == 1 preserves balanced reservation before grow(images) runs.
    • Capping 2D storage by images (cap_2d=true) during grow(images), the follow-up grow(storage) reclamation pass, limit_ms_bindings(), set_limit summation, and Step 3 (layout_supported callbacks) preserves monotonicity for every binary search in grow() and ensures layout_supported never evaluates an inconsistent uncapped candidate (storage(2D) > count(2D)).
  • python -I scripts/check_no_game_data.py runtime/src/vulkan_bindless.h runtime/test/bindless_sizing_test.cpp: clean.

Test Results

  • CPU (ctest -R "^(bindless_sizing|descriptor_table)$"): 2/2 PASS (including all 5 new regression cases in bindless_sizing_test).
  • RTX 3070 Ti (LEONIDA_VK_VALIDATION=1, ctest -R "^(d3d12_descriptor|d3d12_bindless_churn|d3d12_bindless_churn_validated)$"): 3/3 PASS.
  • Intel UHD Graphics 770 (LEONIDA_VK_VALIDATION=1, same CTest filter): 3/3 PASS.

@AirKyzzZ

Copy link
Copy Markdown
Contributor

Tested f2b6ca347 on RTX 2060 (NVIDIA 566.14), Windows 10 22H2, clang-cl 23.1.6 with the MSVC 14.44 STL, RelWithDebInfo: pass.

Built bindless_sizing_test and ran ctest -R ^bindless_sizing$: passes. With main's runtime/src/vulkan_bindless.h and this test it fails at line 157: count(f, D::dim_2d) == 169 && storage(f, D::dim_2d) == 169, so the new cases catch the starved 2D count.

No game files. 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.

4 participants