GPU, Shaders: a capped view heap clamps shader heap indices from the first shader #2628
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!2628
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2628"
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?
@moe-miau on GitHub · 2026-11-25 17:10 UTC · original
moe-miau:port/heapclamp→main· +243 −128 · 9 files · 3 commits · openProblem
On NVIDIA the shader-visible CBV/SRV/UAV heap holds at most 1,000,000 descriptors, while translated shaders clamp their heap indices below
HEAP_VIEWS(2^21).mainalready rebuilds tables past the cap and falls back to fewer dynamic slots (3827767,3c81420,e8d3b64). The translator still lets a shader index anywhere belowHEAP_VIEWS, including programs translated before the title made its heap. On a capped heap those indices name descriptors that do not exist.On an RTX 4070 SUPER this is visible in
main's own tests.cargo test -p victory-gpufailsdynamic_slots_are_held_until_releasedandlists_share_a_table_and_copies_keep_their_views(NumDescriptors >= HEAP_VIEWS).Change
HEAP_VIEWSview heap (portable_view_heap). If it cannot, every heap uses the portable layout (PORTABLE_VIEWS,MIN_DYNAMICdynamic slots).emit::Options::view_heap_limit). Indices at or past it go to null views.view_layout), so a redirected index never reaches a live resource.PORTABLE_TITLE_VIEWS) reads the null view, so it never reaches the dynamic slots that follow them. Table indices keep the heap-wide clamp.maindrops to 2^16 there, which ran out in game). The title keeps about 737,000 slots, above the highest it was seen to use (about 720,000).HEAP_VIEWS, the layout matchesmain.Ported from Zettrox/ztrx (commit
578d459:probe_view_limit,set_view_heap_limit), which is based on fxceless/victory-fork. Both are GPL-3.0-or-later. Unlike the fork, the probe asks for the size actually used (HEAP_VIEWS, not 1,000,001), and the null slots are reserved on large heaps too.Tested
RTX 4070 SUPER, driver 32.0.16.1742, Windows 11 26300.
cargo test -p victory-gpu --locked: 197 passed, 0 failed (also at36ccd6e);mainfails the two tests above here. New tests cover the probe choosing the layout before translation, every requested heap size, and mirrored and dynamic slots ending before the null views.cargo test -p victory-shader --lib, with--skip heap_direct_texture_reads_mark_their_heap_index, which crashes the test process onmainhere too: 267 passed. 3 failed (stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride,a_heap_buffer_read_where_no_buffer_view_is_reads_zeros,synthetic_tests::gathers_at_a_level_match_the_hardware), as onmainwith NVIDIA.cargo clippy --workspace --all-targets --locked -- -D warnings, also with--all-features: clean.cargo xtask policy: ok.67e8ae1+ #1906 + #2098 + both PRs runs 6 min without a device removal and reaches the world.main+ #1906 + #2098 dies at 30 s on the format-115 target, which is the other PR's fix. With review fixes folded in (head11339f3), a second 6-minute run: no device removal,no host texture0, 141 compute pipelines refused (theWaveSize(64)programs of #189). The world stays black at about 8 s a frame on this stack because it leaves out #2178 (structured views as raw), which no longer merges withmain. That run still dropped draws for lack of dynamic slots (40 times); with36ccd6e(the full dynamic range) a third 6-minute run dropped none, with no device removal.AI-assisted (Claude Code, with a review pass by Codex). Runs done on my machine.
🤖 Generated with Claude Code
@moe-miau on GitHub · 2026-11-25 17:21 UTC · original
Overlaps #2461 (lhnizdo), the same port from victory-fork/ztrx, opened earlier today. #2461 conflicts with
mainnow; this one merges. I took #2461's point about the dynamic range:36ccd6ekeeps all 2^18 dynamic slots on a capped heap, after a game run here dropped draws with 2^16. If #2461 is rebased and preferred, close this one.@moe-miau on GitHub · 2026-11-25 17:51 UTC · original
@DrDarkDK Thanks, you're right. Moving the dynamic slots down to the title's end (
36ccd6e) let a title index from about 737,853 to 999,996 reach a live dynamic descriptor. Onmainthat index was still a title slot. Fixed in46d530a:emit::PORTABLE_TITLE_VIEWS(= 1,000,000 − 3 − 2^18 = 737,853) is the title's slot count on the portable heap.Shader::clamp_title_heap_indexsends a title index past it to the general null view,view_limit - 1.buffer_guard, which every heap-handle path goes through, but only when every path of the descriptor comes from the resource heap itself (is_heap_only). Table indices may name dynamic slots (tables rebuilt per draw), so they keep the heap-wide clamp. The stride lookup for heap-direct buffer reads (view_stride) uses the same clamp.PORTABLE_TITLE_VIEWS == PORTABLE_VIEWS - 3 - DYNAMIC, and the layout test checks that a large title heap gets exactly that many slots. If either side changes, the build fails.HEAP_VIEWSheap are unchanged: the clamp returns the index as it is.Tests: the new
bitcode::tests::title_indices_past_the_portable_title_slots_read_the_null_viewchecks the redirect on the portable heap and that there is none on the full heap.victory-gpu: 197 passed, 0 failed.victory-shader --lib: 268 passed, and the same 3 NVIDIA failures asmain. Clippy is clean in both configurations, andxtask policyis ok.I didn't write the end-to-end test you suggested (fill a dynamic slot, read a title index with the same number). The shader test harness doesn't build the host's heap layout, so it would mean new harness work. The unit test checks the generated select and compare instead.
In game (RTX 4070 SUPER, with #2464 on top so that the world draws): a 6-minute run with no device removal, no draws dropped for lack of dynamic slots, and the world draws at 0.6–1.7 fps.
@kotekompotek on GitHub · 2026-11-25 17:52 UTC · original
Reviewed: pulling
PORTABLE_VIEWS/HEAP_VIEWS/HEAP_SAMPLERSfromvictory_shader::emitmakes the shader-side index clamps and the host heap cap come from one constant — the right dependency direction (the compiler must know what the runtime caps). Thevisible_heapprobe for tier-3 extra capacity is a clean capability check. CI pending at review time.@alonso49noob on GitHub · 2026-11-25 18:08 UTC · original
First independent run, on Blackwell: RTX 5060 8 GB, driver 621.01, Windows 11, Rust 1.98.1. Base is
main13f91ca+ #2357 + #2587, so the shader suite is not stopped by the #2571 crash or the two fixture failures. These are local merges, and each tree is built in its own target dir.cargo test -p victory-gpu --libcargo test -p victory-shader --libdynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_views)a_heap_buffer_read_where_no_buffer_view_is_reads_zeros)36ccd6e)bd76752), for comparisonThis PR merges cleanly onto
13f91catogether with #2357 and #2587. The shader test that still fails stops atstride_tests.rs:352withdispatch failed(E_INVALIDARG). The shader crate's own test host still makes theView::NullBuffersheap withHEAP_VIEWSslots (emit/host.rs:1466), and this PR does not change that host. #1777 sizes that heap withheap_views(), which is why the test passes there. This matches the result reported above on the 4070 SUPER, so it is outside this PR's scope rather than a regression.Written with AI help (Claude Code); the numbers are from runs on my machine.
@Vedoxdev123 on GitHub · 2026-11-25 18:57 UTC · original
RTX 4060 test (AI-assisted)
Windows 64-bit, Ryzen 5 5600X, GeForce RTX 4060 (8 GB), on
main13f91ca+ this PR (46d530a).cargo test -p victory-gpu --lib: 197 passed, 0 failed, 1 ignored (main: 193 passed, 2 failed).cargo test -p victory-shader --libwith--skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index(it crashes the process onmain, #2571): 268 passed, 3 failed, 3 ignored (main: 266 passed, 3 failed). The 3 are the known NVIDIA ones, includinga_heap_buffer_read_where_no_buffer_view_is_reads_zeros(dispatch failed: The parameter is incorrect., the same asmain).@moe-miau on GitHub · 2026-11-25 19:04 UTC · original
Thanks @alonso49noob and @Vedoxdev123 for the RTX 5060 and 4060 runs: the same 197/0 here. Agreed on
a_heap_buffer_read_where_no_buffer_view_is_reads_zeros: it fails because the shader crate's own test host (emit/host.rs) still makes its null-buffer heap withHEAP_VIEWSslots, which this PR leaves alone on purpose. #1777 sizes that heap, so the two together clear it.@Marvisak on GitHub · 2026-11-25 22:16 UTC · original · edited 2026-11-26 07:18 UTC
Automated triage for the maintainers.
Thanks. Noted: if #1777 lands first, you will rebase this as a follow-up that keeps only the full
DYNAMICrange and the title-index null redirect. The verdict stays the same (needs the maintainer's decision between this PR and #1777). CI: passing.Generated by Claude Code
@moe-miau on GitHub · 2026-11-26 04:30 UTC · original
On the choice with #1777: whichever the maintainer prefers. If #1777 lands, I'll rebase this onto it as a follow-up carrying only what #1777 doesn't have: the full
DYNAMICrange on a capped heap (withMIN_DYNAMICthe RTX 4070 SUPER dropped draws for want of dynamic slots in the cutscene) and the title-index redirect pastPORTABLE_TITLE_VIEWSto the null view (DrDarkDK's review case). If this one is preferred, I'm happy to credit #1777's author for the probe.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.