Skip to content

Runtime: erasing a bindless descriptor key no longer idles the GPU - #1863

Merged
ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
jsthope:perf/bindless-erase-no-idle
Nov 22, 2026
Merged

ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
jsthope:perf/bindless-erase-no-idle

Conversation

@jsthope

@jsthope jsthope commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: #1745 (comment)

What and why

DescriptorTable::erase backward-shifted the erased key's probe cluster. That moved other live entries, so BindlessSet::erase_key set existing_entries_changed_ and the next flush reported flush_needs_idle(). The bindless prepare hook (d3d12_vulkan_device.cpp) then ran vkDeviceWaitIdle under the submit lock. As a result, every texture release (Resource destructor → forget_image → erase_key) stalled the whole GPU on the next ExecuteCommandLists. This will matter once the game streams textures; today's synthetic tests release textures only at teardown.

The shift is not needed. Every lookup, both on the CPU (DescriptorTable::lookup/contains/insert_locked) and in the translated shaders (rdna2spirv.py desc_probe, and the GLSL references in runtime/test/glsl), compares all eight probe slots and never stops at an empty one. A hole therefore breaks no probe chain:

docs/d3d12_vulkan.md is updated to match.

Tested

  • descriptor_table_test (Windows 11, MSVCity, /std:c++20 /W4, and in the CMakeruntime build): all tests pass. The new test_erase_moves_no_other_entry erases a key in the middle of a five-key cluster that wraps the end of the table. It checks that every other slot stays byte-identical, that exactly one slot is marked changed, that the remaining keys are still found, and that a new key with the same home reuses the hole. Run against the previous descriptor_table.h, it fails, as does the updated test_change_tracking check.
  • vk_bindless_test through scripts/run_gpu_tests.py --filter ps_tex (NVIDIA GeForce RTX 3060 Ti, driver 591.86, Windows 11; llvm-mc 23.1.6, SPIRV-Tools 2026.4): PASS, 24 draws read back, 0 bad pixels, largest error 0. The expectation after erasing the T# is now !flush_needs_idle(), and the draw that follows still reads the zero fallback for the miss. Not run with Khronos validation (the Vulkan SDK is not installed here).

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (Not applicable: no translator change.)

AI-assisted

DescriptorTable::erase backward-shifted the key's probe cluster, which moved
other live entries, so BindlessSet::erase_key flagged the next flush as
needing idle and every texture release ended in vkDeviceWaitIdle on the next
submit.

The shift is not needed: every lookup, on the CPU and in the translated
shaders (rdna2spirv.py desc_probe), compares all eight probe slots and never
stops at an empty one. Erase now empties only the key's own slot, and inserts
reuse the hole. An erase uploads like an add (one slot, no idle). Replacing a
live key's index, a relocating insert and table growth still require idle.

Tests: descriptor_table_test checks that an erase in the middle of a cluster
leaves every other slot byte-identical and marks one changed slot (it fails
on the old erase); vk_bindless_test now expects no idle after an erase.
@tumbione

Copy link
Copy Markdown
Contributor

Tested 174ca0ad on NVIDIA GeForce RTX 5090, driver 616.56, Windows 11 (10.0.26300): pass

Built with scripts/build_runtime.ps1 (VS 2022 Build Tools, Ninja, RelWithDebInfo, Vulkan SDK 1.4.363.0), llvm-mc 21.1.8. This includes the Khronos validation runs the description says were not possible.

Run Result
descriptor_table_test, 3 runs pass 3/3 (all tests passed (0 failures))
run_gpu_tests.py --filter ps_tex, 3 runs 9/9 passed each time; ps_tex: bindless: 24 draws read back, 0 bad pixels, largest error 0
vk_bindless_test directly, LEONIDA_VK_VALIDATION=1, implicit layers off pass, validation on, 0 VUIDs
Full ctest 1 failed of 101: d3d12_draw (the known fence clash on this branch's base 89b047cd: fence signal 4 is not above 20, #1793); 5 skipped (bink_decode, fsr_dispatch, bvh_builder, bink_audio, d3d12_rgb9e5_rtv), gameinput disabled
Full ctest, LEONIDA_VK_VALIDATION=1, implicit layers off same result; the only VUID in the whole run is VUID-vkDestroyPipeline-pipeline-00765 inside d3d12_draw, part of that same known failure
Full run_gpu_tests.py 127/166 passed, 39 skipped (no 64-wide subgroup / run by the D3D12 tests), 0 failed

Not covered: I did not measure the removed vkDeviceWaitIdle stall itself, only that the tests pass and stay validation-clean without it.

No game data involved. AI-assisted (Claude Code): it built the tree and ran everything above on this machine.

@Bj0rnis

Bj0rnis commented Nov 22, 2026

Copy link
Copy Markdown

Tested 174ca0ad on NVIDIA GeForce RTX 5070 Ti (Blackwell), NVIDIA 621.24 (Vulkan 1.4.357) and AMD Radeon(TM) Graphics (iGPU, AMD 2026.04.17, Vulkan 1.4.315), Windows 11: pass

Built with MSVC 19.44 / Ninja / Windows SDK 10.0.26100.0 / Vulkan SDK 1.4.363.0 (scripts\build_runtime.ps1), run with Khronos Vulkan validation enabled (LEONIDA_VK_VALIDATION=1, DISABLE_VULKAN_OBS_CAPTURE=1):

  • RTX 5070 Ti: descriptor_table, bindless_sizing, d3d12_multithread, d3d12_vulkan_device, d3d12_descriptor, d3d12_compute, vk_descriptor_bench_selftest — 7/7 passed, 0 Vulkan validation errors.
  • AMD Radeon iGPU (LEONIDA_VK_DEVICE=AMD): d3d12_multithread, d3d12_descriptor, d3d12_compute — 3/3 passed, 0 Vulkan validation errors.

(Note: vk_bindless_test via run_gpu_tests.py was not run here as llvm-mc is not installed on this machine; d3d12_draw failed on an unrelated pre-existing base-branch issue where the bundle blend test signals fence 4 after the preceding 0x0 viewport test signals 20.)

AI-assisted (Antigravity / Gemini); no game files used.

@emirhan-karaca

Copy link
Copy Markdown
Contributor

Tested 174ca0ad (CPU test + static review), Windows 11, MinGW-w64 g++ 16.2.0 (-std=c++20 -O2), Vulkan-Headers 1.4.363.0: pass

  • descriptor_table_test: PASS (all tests passed (0 failures), including test_erase_moves_no_other_entry).
  • vk_bindless_test.cpp: compiles cleanly (SPIR-V shaders not built locally — no glslangValidator on this host, so GPU run not executed here).
  • Static check: confirmed both DescriptorTable::lookup() (runtime/src/descriptor_table.h:97-105) and rdna2spirv.py's desc_probe() (tools/rdna2spirv.py:7048+) iterate all kDescriptorProbes (8) slots without stopping at an empty slot, and insert_locked() reuses the first empty slot in the window. Emptying only found_slot in erase_locked() and keeping existing_entries_changed_ false in BindlessSet::erase_key() looks sound.

AI-assisted.

@ItsNotRexed
ItsNotRexed merged commit 33507d4 into ItsNotRexed:main Nov 22, 2026
@jsthope
jsthope deleted the perf/bindless-erase-no-idle branch November 22, 2026 15:23
@sanakontorov-sys

Copy link
Copy Markdown

Tested 174ca0a on NVIDIA GeForce RTX 5060 (Blackwell, driver 617.42, Vulkan 1.4.351), Windows 11 Pro build 26300, MSVC (VS 2026), LLVM_MC set, scripts\build_runtime.ps1, then ctest -j 4: builds, and descriptor_table and bindless_sizing pass. 100 of 101 run tests pass; the one failure is d3d12_draw ("fence signal 4 is not above 20"), the same pre-existing fence failure that #1807 fixes, unrelated to this PR. Not covered: vk_bindless_test builds but is not part of ctest (it needs vs_ids.spv / ps_tex.spv), so I did not run it.

(Run with an AI coding agent.)

@Gabzinnn12

Copy link
Copy Markdown

Tested 174ca0a on AMD Radeon RX 7600 (RDNA3), AMD 26.11.2 (LLPC), Windows 11, MSVC 19.44, Vulkan SDK 1.4.363.0: pass.

  • descriptor_table_test: all tests passed, including test_erase_moves_no_other_entry.
  • d3d12_descriptor_test: exit 0 with and without LEONIDA_VK_VALIDATION=1 (+ sync validation), no Vulkan validation errors reported.
  • ctest: 1 failed out of 98, d3d12_draw (bundle blend pixel). The same check also fails on main 003e781; this PR's merge base 89b047c was not tested.
  • Not run: vk_bindless_test needs two SPIR-V arguments and is not registered in ctest.

AI-assisted (Claude Code, reviewed with Codex). No game files.

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.

7 participants