GPU+shader: clamp and place null buffer views within capped host descriptor heaps #2177
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2177
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2177"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@n-romanovich on GitHub · 2026-11-25 07:06 UTC · original
n-romanovich:pr/capped-descriptor-heaps→main· +237 −69 · 17 files · 6 commits · openSummary
When a host GPU caps shader-visible
CBV_SRV_UAVdescriptor heaps belowHEAP_VIEWS(e.g.1_000_000on NVIDIA), two issues occurred:HEAP_VIEWS - 1(2_097_151) and routed invalid buffer views inbuffer_guardtoNULL_BUFFER_VIEW(2_097_150), reading out of bounds past the1_000_000-slot heap.PORTABLE_VIEWS(e.g.1_245_184slots),HostHeap::newallocatedPORTABLE_VIEWS - MIN_DYNAMICtitle slots +MIN_DYNAMICdynamic slots, leaving0slots forcrate::memorycopy view pairs (pairs_end == count + extra).This change:
host_heap_views(), up toHEAP_VIEWS) and propagates it tovictory_shader::emit::set_host_heap_viewsandshader_cache::key.host_heap_views()andnull_buffer_view()(host_heap_views() - 2) inheap_handleandbuffer_guardso clamped indices and null SRV/UAV slots stay inside the allocated heap.CAPPED_PAIRS(24_576) andCAPPED_DYNAMIC(1 << 17) plus the 3 top null/clamp slots when a title heap must be capped, and throttles past-heap diagnostics inHostHeap::mirrorto populatedVIEW_TAGentries.stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zerosanddescriptor::host::tests::dynamic_slots_are_held_until_releasedto querymax_views()/host_heap_views().Verification
Tested on NVIDIA GeForce RTX 5060 Ti:
cargo test --release -p victory-shader --lib -- stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros:1 passed; 0 failedcargo test --release -p victory-gpu --lib -- descriptor::host::tests memory::tests shader_cache::tests:11 passed; 0 failed@sinan-cmyk on GitHub · 2026-11-25 07:55 UTC · original
Offline measurement on a retail dump
Result: no count change against
main.I merged head 1a3261fe onto
main940d32f(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 23,918 onmain, 23,918 with this PR.No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.
No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
@sinan-cmyk on GitHub · 2026-11-25 08:05 UTC · original
Shader tests on NVIDIA Ada
I ran
cargo test --locked -p victory-shader --libon an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter,VICTORY_WARPunset.main940d32fstride_tests::a_heap_buffer_read_by_element_takes_the_views_stride,stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros,synthetic_tests::gathers_at_a_level_match_the_hardware940d32fstride_tests::a_heap_buffer_read_by_element_takes_the_views_stride,synthetic_tests::gathers_at_a_level_match_the_hardwareSo on Ada this PR fixes
stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros, one of the three failures #1835 tracks. #2178 fixesstride_tests::a_heap_buffer_read_by_element_takes_the_views_stride. The two PRs conflict with each other invictory-gpu/src/shader_cache.rs(each one adds its own parameter tokey) and invictory-shader/src/emit/mod.rs, so I could not test them together.synthetic_tests::gathers_at_a_level_match_the_hardwarestill fails with both (lane 0 gives[0, 1, 0, 0], expected[0, 0, 0, 0]).AI-assisted (Claude Code).
@Venom2054 on GitHub · 2026-11-25 09:16 UTC · original
I found a remaining allocation-bound issue in this PR on an RTX 5070 Ti (16 GB, NVIDIA 621.01, Windows 11 Pro 26200).
Tested base: main
940d32f69b22265690a0b5a15d6ded572ba33baf+ this PR at1a3261fe2e2c054c7f93060958f7888316370703.For
HostHeap::new(false, 800_000)on a device capped at 1,000,000 views, the first allocation of 1,062,144 is rejected. The smaller fallback succeeds with 865,536 descriptors, but the shader clamp still reaches 999,999 and the null SRV index is 999,998. Both can lie beyond the actual allocation.The fallback needs to allocate at least
views:I also tested this regression in
descriptor/host.rs:Before the fix, the new test failed with
the fallback heap has 865536 slots, fewer than the shader clamp. After it, the GPU suite passed: 147 passed, 0 failed, 2 ignored on this isolated integration.Command:
Build, Clippy and asset policy also passed. The full workspace at this stage had 704 passed, 2 failed, 10 ignored; both failures also reproduced on original main (
a_heap_buffer_read_by_element_takes_the_views_strideandgathers_at_a_level_match_the_hardware). These numbers describe this PR plus the small fix, not my later integration with additional PRs.The test uses synthetic allocations and no game data. This fixes the allocation bound; it does not establish a fix for a separate title GPU crash.
Prepared and tested with assistance from OpenAI Codex. Feel free to incorporate the correction and regression test into this PR.
Venom
@steven-seagull27 on GitHub · 2026-11-25 10:49 UTC · original
I reproduced Venom2054’s allocation finding on a second NVIDIA model, an RTX 5080 with driver 621.40. With 800,000 title entries, the real
HostHeapfallback allocated 865,536 descriptors while the shader expected 1,000,000 and selected null SRV slot 999,998. A host-side assertion caught the discrepancy before dispatch.With Venom2054’s one-line correction, the same allocation returned 1,000,000 descriptors and a missing buffer slot read back 32/32 zeros. Built-in WARP allocated 2,097,152 descriptors in both builds, with null SRV slot 2,097,150. The A/B held #2178 and the rest of the combined tree fixed. Original finding · One-line commit directly on this PR head
To pick it onto
1a3261f:The corrected allocation also let me check 12-byte structured subviews through the production heap. Their offset-dependent read failures and the separate SRV fix are documented on #2178. Full paired results and runnable tests
@Marvisak on GitHub · 2026-11-25 13:28 UTC · original · edited 2026-11-26 00:22 UTC
Automated triage for the maintainers.
Merge candidate (worth a look). On a host that caps shader-visible view heaps (NVIDIA, 1,000,000), translated shaders clamped indices and placed null buffer views at
HEAP_VIEWS, past the heap. The head0497f58passes the probed limit (host::host_heap_views) through a newemit::Options::host_heap_viewsfield (0 =HEAP_VIEWS) intoShader::heap_handle/buffer_guard, and puts it inshader_cache::keyonly when it differs, so uncapped hosts keep their cache. InHostHeap::new(descriptor/host.rs) the capped branch now reservesCAPPED_DYNAMICdynamic slots plusCAPPED_PAIRScopy pairs below the null slots. CIcheckpasses and it merges cleanly.On your reply: I checked the three points. The process-wide atomic is gone. Title slots kept are now monotonic in
count: they grow withcountup tocap - CAPPED_DYNAMIC - CAPPED_PAIRS - 3(844,349 on a 1M heap) and stay there. That is belowmain's 934,464 for counts in between, a trade the RTX 5070 Ti prologue measurement in the thread supports (peak 101,530 dynamic slots held; 3,763 failed allocations and a hang with1 << 16). Remaining notes for the maintainer, not blockers:victory translatestill passes the default (uncapped) options, so offline output on a capped host differs from what the runtime emits;CAPPED_PAIRShas not been exercised by a measured workload yet (per the tester). This overlaps #2176 inOptionsandshader_cache::key; whichever lands second needs a rebase.Generated by Claude Code
@n-romanovich on GitHub · 2026-11-25 14:03 UTC · original
@Marvisak, updated
pr/capped-descriptor-heaps(d15c68b) to address the triage points:.max(views)in theMIN_DYNAMICfallback:HostHeap::newincrates/victory-gpu/src/descriptor/host.rsnow callsmake((count + MIN_DYNAMIC).max(views))instead ofmake(count + MIN_DYNAMIC), so heaps like800,000(865,536withMIN_DYNAMIC) are still sized to at leasthost_heap_views()and keep the clamp / null-view slots in bounds.descriptor::host::tests::min_dynamic_fallback_keeps_at_least_host_heap_views(HostHeap::new(false, 800_000)).shader_cache::keyandemit/mod.rs; whichever lands second will rebase cleanly onto the first.@Venom2054 on GitHub · 2026-11-25 14:56 UTC · original
I retested the updated PR at
d15c68bcon an RTX 5070 Ti, NVIDIA 621.01, Windows 11 build 26200. For 800,000 requested entries, the live D3D12 heap reported 1,000,000 descriptors. The shader limit was 1,000,000 and the null SRV index was 999,998.As a control, I restored the previous allocation expression in a scratch copy of the same commit. The heap then reported 865,536 descriptors and the new
min_dynamic_fallback_keeps_at_least_host_heap_viewstest failed its size assertion. Both measurements used the same test-only print of the heap descriptor count, shader limit, and null SRV index.On the unmodified PR, the full
victory-gpulibrary suite passed (147 passed, 0 failed, 2 ignored benchmarks). The separate missing-buffer shader test also passed on hardware and WARP, reading back 32 zeros on each. This verifies the allocation fix I reported earlier on this card.@Venom2054 on GitHub · 2026-11-25 15:17 UTC · original
I measured the dynamic reserve on an RTX 5070 Ti (621.01, Windows 11 build 26200) during the prologue. The title requested 1,245,184 descriptors from a host heap capped at 1,000,000. The first request that failed with
MIN_DYNAMICneeded just 9 consecutive slots, 58.9 seconds after launch.MIN_DYNAMICWith the PR reserve the game reached the yard and kept presenting until the 258 s cutoff. With
MIN_DYNAMIC, D3D12 reportedDXGI_ERROR_DEVICE_HUNGat 107.0 s and the process exited at 111.7 s. The refusals came first. One run per layout leaves the cause of the hang open.This supports keeping more than 65,536 dynamic slots for this workload. The largest single request was 256 slots in both runs. Neither run exercised the separate 24,576-slot reserve (12,288 pairs) or spilled a pair into the dynamic pool on this heap, so sizing
CAPPED_PAIRSstill needs a different workload.I used a local integration that reaches the yard and checked the allocator and capped layout against
d15c68bc. Both runs used the same executable, initial save, pipeline cache and scripted inputs. Only the reserve setting changed. Counters tracked individual allocations and releases and were logged every eight presents. Final samples were at 253.3 s and 99.6 s respectively. Failed calls can include retries.@n-romanovich on GitHub · 2026-11-25 22:57 UTC · original
@Marvisak Updated
pr/capped-descriptor-heaps(0497f58):host_heap_viewsintoemit::Options(andlower::Parts/Shader), removing the process-wideHOST_HEAP_VIEWSatomic so offlinevictory translateand runtime translation are pure functions ofOptions.HostHeap::newsotitle_slotsis monotonic incounton capped heaps (CAPPED_DYNAMICis used consistently in the capped branch).CAPPED_DYNAMICand noted the RTX 4060 / 1M-slot prologue measurement forCAPPED_PAIRS.main;victory-gpu/victory-shadertests and CIcheckpass.Note: I am also the author of #2178 and will reconcile whichever lands second immediately after the first merges.
@DenRakEiw on GitHub · 2026-11-25 07:24 UTC · original · approved these changes
Verified locally merged onto
origin/main(940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090, Rust 1.98.1 MSVC):cargo test -p victory-gpu— 143 passed, 0 failed (2 ignored) on NVIDIA RTX 5090 (resolves both 1M view-heap cap failures onmain940d32f)cargo test -p victory-shader --lib emit::stride_tests::— 5 passed, 1 failed on RTX 5090: directly fixesa_heap_buffer_read_where_no_buffer_view_is_reads_zeros! (The 1 remaining failure,a_heap_buffer_read_by_element_takes_the_views_stride, is the separate NVIDIA structured-view issue covered by #2178.)cargo clippy -p victory-gpu -p victory-shader --all-targets— 0 warningscargo xtask policy— ok (183 files ok)Clean clamping and null-buffer view placement within capped host descriptor heaps. (Note for triage: overlaps #2185 and #2121.)
AI-assisted (Gemini 4 Neon).
@catminou4 on GitHub · 2026-11-25 07:30 UTC · original · approved these changes
Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main
940d32f69b,cargo test -p victory-shader --locked(shader half; the GPU half is Windows-only).144 passed / 0 failed / 2 ignored. Null buffer views clamped and placed within capped host heaps — heap-cap safety for null views; mixed gpu+shader.
@fuzeofficlal on GitHub · 2026-11-26 16:52 UTC · original · requested changes
Verified
0497f58408a446e7d86566a141e39d6a7da63237merged cleanly onto63bcca43on Windows 11 with both an RTX 5090 (1,000,000-slot view heap cap,VICTORY_D3D12_DEBUG=1) and WARP (uncapped 2,097,152 slots via--features diagnostics,VICTORY_D3D12_WARP=1,VICTORY_D3D12_DEBUG=1).What already works well
63bcca43;crates/victory-shader/src/emit/lower.rsis521,078bytes (< 524,288limit);cargo xtask policy(191 files ok) andcargo clippy --locked -p victory-gpu -p victory-shader -p victory --all-targets -- -D warnings(default and--all-features) are clean.cargo test --locked -p victory-gpu --lib -- --test-threads=1: 232 passed, 0 failed, 1 ignored — resolves both pre-existing 1M view-heap cap failures (descriptor::host::tests::dynamic_slots_are_held_until_releasedandmemory::tests::lists_share_a_table_and_copies_keep_their_views).cargo test --locked -p victory-shader --lib -- --test-threads=1 emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros: 1 passed, 0 failed.--features diagnostics,VICTORY_D3D12_WARP=1):host_heap_views() == 2_097_152,null_buffer_view == 2_097_150, anddescriptor::host::tests:: memory::tests:: shader_cache::tests:: bindless::tests::pass 31/31 with uncapped cache keys preserved (shader_cache.rs:80).Blocking issue:
HostHeap::newDYNAMICbranch drops null buffer views andpairsroom forcountin713_278..=737_856on 1M-capped heaps (crates/victory-gpu/src/descriptor/host.rs:160)At
crates/victory-gpu/src/descriptor/host.rs:160:Because
viewsis now1_000_000on 1M-capped adapters,make((count + DYNAMIC).max(views))succeeds without accounting forCAPPED_PAIRS + 3(24_579slots for memory pairs plus the 3 top null UAV / null SRV / clamp slots at999_997..=999_999). ProbingHostHeap::new(false, req)directly on the RTX 5090 (host_heap_views=1_000_000,null_buffer_view=999_998):counttotalcountdynamicpairs_roomnull_fits(null > count + dynamic && null < total)713_2771_000_000713_277262_14424_576true737_8531_000_000737_853262_1440true737_8541_000_000737_854262_1442(slots999_998..=999_999!)false737_8561_000_000737_856262_1440false737_8571_000_000737_857131_072131_068trueAt
req = 737_854..=737_856:null > count + extra(descriptor/host.rs:218, 242) evaluates tofalse, so no null buffer views are installed and dynamic slots directly overlap999_997..=999_999.req = 737_854,pairs_endfalls back tototal(1_000_000), leavingpairsstarting at999_998— handing out the shader'snull_buffer_view(999_998) and clamp slot (999_999) as a livecrate::memorySRV/UAV pair.req = 713_278..=737_853,pairs_roomshrinks down to0before jumping back up to131_068at737_857.Suggested 1-line fix
Account for
CAPPED_PAIRS + 3in theDYNAMICbranch atcrates/victory-gpu/src/descriptor/host.rs:160:Tested locally with that one-line change on both RTX 5090 (
views=1_000_000) and WARP (views=2_097_152):req = 713_278..=737_856cleanly falls into theCAPPED_DYNAMICbranch with fullcount,131_072dynamic slots,131_069..=155_647pair slots, andnull_fits = trueacross every tested count from64to1_245_184.views=2_097_152), behavior for64..=1_245_184is unchanged (all keepDYNAMIC = 262_144andnull_fits = true).(Minor non-blocking nit: the safety comment at
crates/victory-gpu/src/descriptor/host.rs:542still saysHEAP_VIEWSwhere line 537 was updated tohost_heap_views().)View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.