Skip to content

vulkan: retain a valid bindless table under pressure (RT-BINDLESS-TABLE-DEGRADE) - #1092

Closed
Moriz82 wants to merge 1 commit into
ProjectLeonida:mainfrom
Moriz82:split/rt-bindless-table-degrade
Closed

Moriz82 wants to merge 1 commit into
ProjectLeonida:mainfrom
Moriz82:split/rt-bindless-table-degrade

Conversation

@Moriz82

@Moriz82 Moriz82 commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Claimed in the coordination issue as: RT-BINDLESS-TABLE-DEGRADE (claim).

Part of the split of #984 into small pull requests.

Depends on: none
Overlaps: #984 contains the integration. #425 covers descriptor-set
recycling and its pool budget. This child can land independently of it.

What and why

Under device-local memory pressure, a bindless table rebuild could fail
and cause ExecuteCommandLists to refuse the whole submission. The smaller
sampled-image arrays could also fill during streaming.

A replacement table can use coherent host-visible memory. If allocation
fails, the runtime releases completed generations and retries. An idle
table can be rewritten in place if it still fits. When those paths fail,
work can use the last table submitted to the GPU. New keys resolve to the
fallback and removed indices stay reserved until the table catches up.
The first upload must reach the queue before any submission can use this
fallback. Device loss still propagates.

Device limits now permit up to 16,384 sampled 2D-array images and 4,096
each for 3D and 1D. The existing layout and per-stage limits still apply.

Tested

Release cross-build with clang-cl 23.1.5 and an xwin SDK on CachyOS,
kernel 7.3.5. Runtime tests used Proton Experimental (Wine 11), a Ryzen
5 5600X, 16 GB RAM and an RTX 4070 12 GB with NVIDIA 620.73.04. CMake
omitted the optional XMA2 decoder because the Rust Windows target was
unavailable.

build=runtime/build/boot
for target in gta6rt bindless_sizing_test vk_bindless_grow_test \
              d3d12_bindless_churn_test; do
  cmake --build "$build" --target "$target" -j6
done
wine "$build/bindless_sizing_test.exe"
wine "$build/vk_bindless_grow_test.exe"
wine "$build/d3d12_bindless_churn_test.exe"
python3 -I scripts/run_semantic_tests.py tests/semantic -j 2
python3 -I scripts/check_no_game_data.py
git diff --check HEAD^ HEAD

The sizing test passed, with 152,929 descriptors on synthetic RTX
5070-like limits. The GPU pressure test passed 41/41 checks. It observed
one host-memory fallback, one idle rewrite and two degraded flushes, then
recovered to a 256-slot table. It also rejected a first upload under
pressure, a discarded upload and a simulated device loss.

D3D12 churn passed all four runs. Each compared 98,304 texels over 96
frames on direct and compute queues, with zero mismatches. The two
deferred-retirement runs each made three generations and recorded zero
device-idle waits. The two legacy runs each recorded three waits.

The semantic suite passed 6,168 tests across 470 files. The content and
whitespace checks passed.

Review round 1. A review proposed keeping descriptor writes pending
across a degraded flush, so that a key rebound while the old table is
kept does not find the fallback. That is not taken: the device destroys
a removed texture's views right after remove_image, so a removed
image's descriptors must go back to the fallback at the next flush even
when that flush keeps the old table. Otherwise a key the old table still
maps to that index finds a destroyed view. The pressure test now records
what every image descriptor names and checks after each flush that the
current set names no destroyed view. It passes 50/50 checks on this head
(41 before the new checks), natively on Linux and as a Windows program
under Wine 11.22, on an RTX 4070 (NVIDIA 620.73.04). With pending writes
kept, it exits 1 at the removal between the two degraded flushes: the
current set's binding 0, element 256 names a destroyed view. The runs
described above and below were made on the head before this round; only
the test file changed since.

For the control, rebuild the GPU pressure test with only the previous
refusal restored. Change the guard in BindlessSet::flush from
!written && must_replace && !table_on_gpu_ to
!written && must_replace. Link with the same flags and run the same
test. The control passed 17 checks and stopped at check 18 with exit 1:
the busy flush refused the submission. The remaining 23 checks did not
run in this control.

The sizing control omits the three new calls to grow the 2D-array, 3D
and 1D bindings. It passed the first five checks, then exited 1 at the
first check for the larger sampled-image arrays.

Two integration runs on Windows 11 (i9-13900K, RTX 4070 Ti, NVIDIA
630.20) used host memory and continued without refusing a batch. Neither
run exercised a degraded flush. This standalone child was not run on
native Windows, AMD or Intel, with validation layers, or in a game boot.

GPUs tested: NVIDIA GeForce RTX 4070.
AI-assisted: yes

Checklist

  • One topic on current main, verified with a clean merge.
  • No game data. All GPU inputs are synthetic.
  • No translator rule changes.

🤖 Generated with Claude Code

@Plaaasma

Copy link
Copy Markdown
Contributor

Native Windows check, AI-assisted (Claude Code). Windows 11, i9-13900K, 64 GB, RTX 4070 Ti 12 GB (NVIDIA 630.20), MSVC 2022 (VS 17 generator, Release), Vulkan.

Head 4247b2120. Built vk_bindless_grow_test bindless_sizing_test d3d12_bindless_churn_test, then ctest -C Release -R "^(vk_bindless_grow|bindless_sizing|d3d12_bindless_churn|d3d12_bindless_churn_validated)$" --output-on-failure --timeout 300:

  • vk_bindless_grow: passed, 0.54 s (41 checks passed: 1 host fallback, 1 in-place rewrite, 2 degraded flushes; first flush under full memory refused, then uploaded once memory was back)
  • bindless_sizing: passed, 0.04 s
  • d3d12_bindless_churn: passed, 2.64 s (96 frames, direct + compute queue, 0 wrong texels in all four modes; 0 vkDeviceWaitIdle for the set on the deferred path vs 3 on the old wait)
  • d3d12_bindless_churn_validated: skipped (exit 77, VK_LAYER_KHRONOS_validation isn't installed on this machine)

3 passed, 1 skipped, 0 failed.

@abnalstlll-byte abnalstlll-byte 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.

Audited and verified. Increases bindless descriptor bounds (16384 for 2D arrays, 4096 for 3D/1D) and implements multi-tier memory pressure degradation (host-visible fallback, in-place table rewrites, and degraded table reuse retaining prior GPU generations) in
untime/src/vulkan_bindless.h. Verified in
untime/test/vk_bindless_grow_test.cpp. Approved.

@abnalstlll-byte abnalstlll-byte 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.

Clean-Room Audit — PR #1092 (RT-BINDLESS-TABLE-DEGRADE)

Thoughtful resilience upgrade in vulkan_bindless.h and d3d12_vulkan_device.cpp: expands bindless limits (16,384 2D / 4,096 3D & 1D) and gracefully handles allocation pressure via generation flushes, host-visible fallback, and retaining a valid bindless table rather than aborting submissions. Covered by vk_bindless_grow_test.cpp; 0 game data.

Verdict: APPROVED

@bobcatchris

Copy link
Copy Markdown
Contributor

Concrete correctness follow-up: a degraded flush currently still applies and clears pending_ descriptor writes. If the failed replacement was caused by a live-key replacement/relocation, those writes include the old index’s fallback, while the GPU’s retained old hash table still maps the key to that index. Newly recorded/submitted work can therefore sample the fallback until a later successful generation.

Reproduction added in vk_bindless_grow_test: publish a victim key/index, rebind it to a new index, remove the old index, fail all table/pool allocations while a submission may still read the old set, and degrade. On this head pending_write_count() is 0 after the degraded flush; with the fix it remains nonzero and returns to 0 only after recovery.

Fix branch (stacked on this PR, not opened against main to avoid duplicating its diff): https://github.com/bobcatchris/leonida-public/tree/fix/bindless-degrade-live-keys, commit b59279da7. It keeps descriptor updates and held indices pending on degraded flushes, and updates the comments.

Verified on RX 7900 XTX / 32.0.32029.2010 / Windows 11 with LEONIDA_VK_VALIDATION=1: vk_bindless_grow 52/52 checks, bindless_sizing, both d3d12_bindless_churn modes, vk_bindless_ps_tex, and vk_bindless_ps_imgatomic all pass. Baseline negative control fails the new pending-write assertion. No game data; security sweep clean. AI-assisted.

@iFeyz

iFeyz commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

AMD run (the gap the description lists): RX 9070 XT (RDNA4, GFX1201), AMD proprietary Windows driver 26.11.2 (LLPC, Vulkan 1.4.359), Windows 11, MSVC 2022 RelWithDebInfo.

Head 4247b2120: vk_bindless_grow and bindless_sizing built from it: 2 of 2 pass.

@Moriz82
Moriz82 force-pushed the split/rt-bindless-table-degrade branch from 4247b21 to 1f0e69d Compare November 24, 2026 21:29
@Moriz82

Moriz82 commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator Author

@bobcatchris thank you for the reproduction and the patch. I ran both here. I am not taking b59279da7: it fixes the sequence in your test, but it makes the texture-destruction sequence unsafe, and that is the one the D3D12 layer produces. Lines below are for 4247b2120, the head you reviewed.

Reproduced. RTX 4070, NVIDIA 620.73.04, CachyOS, vk_bindless_grow_test built natively and as a Windows program (clang-cl, run under Wine 11.22). Your branch passes 52/52 in both. Your test on this head's flush(), with only pending_write_count() added, stops at check 17, set.pending_write_count() != 0, exit 1, in both. So what you describe happens for that sequence: insert_key(victim, victim_new), remove_image(victim_old) while a submission can still read the set, then a degraded flush writes the fallback at victim_old in that set.

The D3D12 layer does not make that sequence. It never removes an index whose key is live:

  • A rebind (a read-only T# that gains a storage view) keeps the old entry in replaced_images until the texture is destroyed (runtime/shims/d3d12_vulkan_device.cpp:1074, 1260-1262). The old index keeps a view of the same texture, so the retained table finds a valid descriptor through any number of degraded flushes.
  • remove_image has one caller, the deferred release (d3d12_vulkan_device.cpp:5319-5325). forget_image queues it after erasing every key of the texture (1272-1288, 1133-1139), and it runs once the submission after that has completed (runtime/src/vulkan_backend.h:1457-1470).

Keeping the writes pending is unsafe for that caller. release() queues the index and then its views (d3d12_vulkan_device.cpp:1136-1138), and drain() runs them in that order: remove_image, then vkDestroyImageView (vulkan_backend.h:500-510). The set's own contract allows this: a view removed before the next flush "may be destroyed by then" (runtime/src/vulkan_bindless.h:1099-1100). So after a flush that returns true the set must no longer name a removed view, and on this head a degraded flush writes the fallback for that reason. With b59279da7 a degraded flush returns true and leaves the removed index naming the destroyed view for as long as flushes keep degrading, while the table on the GPU still maps the erased key to that index. A stale T# finds index 0 through a current table and the fallback at the old index on this head; with the patch it finds a destroyed view. On a device without descriptorBindingPartiallyBound the set is then invalid for every draw, looked up or not.

main did keep these writes pending when the generation could not be made (vulkan_bindless.h:500-501 at this PR's base 3aa975421), but there the flush failed and the submission ran none of its work. This PR lets work run on the retained table, so the two do not combine.

Measured, and now in this PR's test. The sequence is already in the test: remove(gone) (erase the key, remove the index, destroy the view) between two degraded flushes. vk_bindless_grow_test now wraps vkUpdateDescriptorSets, vkAllocateDescriptorSets, vkCreateImageView and vkDestroyImageView through the get_proc it already has, records which view each image descriptor names, and checks after every successful flush that the current set names no destroyed view. The head is updated with that (test file only, no change to vulkan_bindless.h).

  • This head: 50/50 checks, natively and under Wine.
  • Header of b59279da7 with the same test: after the second degraded flush the table as last uploaded still maps gone.key to gone.index, and binding 0, element 256 of the current set names the destroyed view; the test exits 1 there (stale == 0), natively and under Wine.

A validation run cannot show this in vk_bindless_grow_test, because the test draws nothing. Your new case does not show it either: it keeps both victim views alive until after the recovering flush (lines 206-207 of your version).

Narrower variants. Delaying only the writes at indices the retained table can still name selects the removed indices, the ones whose views are gone, so it has the same problem. The writes that could wait safely are those at new indices from add_image and add_sampler; no key of the retained table reaches them, so nothing is gained by holding them. Making your sequence work would need the caller to keep a removed view, and the image under it, alive until a flush that does not degrade and the work before it has finished. That holds texture memory through the condition that makes flushes degrade, and it is a change to the device's release path rather than to this PR.

vulkan_bindless.h stays as it was at 4247b2120; only the test changed. If you see a path in the D3D12 layer that removes an index while its key is live, or a case where the fallback is the wrong answer after a texture is destroyed, please point me at it.

Not run here: the validation layer (not installed on this machine), native Windows, AMD. I did not rerun d3d12_bindless_churn or the two vk_bindless_ps_* tests for this: they inject no allocation failure and cannot reach a degraded flush.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

@whoalin1

Copy link
Copy Markdown
Contributor

GPU verification (AI-assisted, independent worker on the shared test box) — head 4247b2120. Note: based on 3aa975421, not current origin/main (4a50cafc7 at verification time).

Host/device tests (ctest -R bindless, TEMP/TMP set to a user-writable dir):

  • vk_bindless_grow (new test): PASS on both GPUs — 41 checks covering allocation-failure degrade, in-place rewrite, held indices and recovery. AMD: 2.0s under LEONIDA_VK_VALIDATION=1; NVIDIA: 1.5s.
  • bindless_sizing: PASS (synthetic limits).
  • d3d12_bindless_churn / _validated:
    • NVIDIA RTX 4070 SUPER: PASS / PASS (7.4s / 3.8s).
    • AMD Radeon iGPU: FAIL / FAIL — but identical on origin/main (4a50cafc7, same env): both abort at CreateComputePipelineState with "pipelines need 144 bytes of push constants … maxPushConstantsSize 128" — the known 128-byte push-constant cap on this iGPU, unrelated to the bindless change (fails before any table code runs).

vk_bindless_test run manually (the ctest entries need translated shaders this configure lacks; SPIR-V taken from the GPU suite's --work output — same vs_ids/ps_tex/ps_imgatomic fixtures), LEONIDA_VK_VALIDATION=1 on AMD and plain on NVIDIA:

  • AMD: ps_tex PASS — "bindless: 24 draws read back, 0 bad pixels", table grew 64→512 slots, index 9098 of 65536 2D images / 2102 of 4096 samplers; ps_imgatomic PASS — 0 wrong texels/pixels. No VUIDs.
  • NVIDIA: same two runs PASS, 0 bad pixels, 0 wrong texels.

GPU suite py -3.14 -I scripts/run_gpu_tests.py --build runtime/build --work C:\leonida_gpu_work (261 shaders translated, all pass spirv-val; llvm-mc via WSL Ubuntu, spirv-as/spirv-val from Vulkan SDK 1.4.363):

Verdict: PASS — the new degrade/hold path is exercised cleanly on both GPUs including under validation; the only failures are pre-existing on main (AMD push-constant cap for the two d3d12 churn tests, LLPC mesh-shader crashes in the suite).

@Moriz82

Moriz82 commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator Author

@whoalin1 thank you, especially for the AMD run under LEONIDA_VK_VALIDATION=1: the validation layer is not installed here, so that is the first validated run of vk_bindless_grow.

For anyone reading the results: they are for 4247b2120. The head is now 1f0e69de4, and the only change since is runtime/test/vk_bindless_grow_test.cpp (review round 1 above): the test now also records which view every image descriptor names and checks after each flush that the current set names no destroyed view. It reports 50 checks instead of 41; vulkan_bindless.h, the device and the other tests are as you ran them.

AI-assisted (Claude Code).

@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Nov 25, 2026
…LE-DEGRADE)

A failed table replacement used to refuse the entire submission. Retry
after releasing completed generations, use host memory or rewrite an idle
table when it fits. While a valid older table is in use, defer its edits
and keep freed indices reserved. Size the single-sample image arrays from
the device limits.

Build the runtime and test table sizing, allocation failures and recovery.
Restore the old refusal in the pressure test to reproduce the regression.
The pressure test also checks after every flush that the current set
names no destroyed view: a removed image's descriptors go back to the
fallback even when the flush keeps the old table.

AI-assisted (Codex and Claude Code agents).

Co-authored-by: Plaaasma <47513553+Plaaasma@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@Moriz82
Moriz82 force-pushed the split/rt-bindless-table-degrade branch from 1f0e69d to 84de57c Compare November 25, 2026 03:51
@Moriz82

Moriz82 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased onto 5129be10 at 84de57c0. Main now has the table replacement and churn handling. This diff preserves the check that a degraded flush’s current set names no destroyed views and returns failure for Vulkan device loss. Fresh GPU results are pending.

AI-assisted.

@github-actions github-actions Bot removed the needs rebase Conflicts with the base branch: rebase it on main label Nov 25, 2026
@Moriz82 Moriz82 closed this by deleting the head repository Nov 26, 2026
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