Shaders: bind a zero dword for empty root-constant slices #2585
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2587"
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?
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T16:18:20Z.
Summary
Host::root_signature_forincrates/victory-shader/src/emit/host.rsalways declaresNum32BitValues: s.user_data_dwords().max(1)for each shader stage, even when a shader reads zero user-data dwords.When a test passes an empty
Root::Constants(Vec::new()),Vec::new().as_ptr()is a dangling aligned pointer (0x4). Passing0x4with count0toSetComputeRoot32BitConstants/SetGraphicsRoot32BitConstantscrashes NVIDIA's D3D12 driver (nvwgf2umx.dll) withSTATUS_ACCESS_VIOLATION (0xc0000005)(reproducing onemit::memory_tests::heap_direct_texture_reads_mark_their_heap_index). Skipping the call avoids the crash, but leaves the declared 1-dword root parameter unbound.Changes
crates/victory-shader/src/emit/host.rs: whenRoot::Constants(data)is empty, bind&[0u32](let words = if data.is_empty() { &[0u32][..] } else { data.as_slice() };) in bothHost::draw(SetGraphicsRoot32BitConstants) andHost::dispatch(SetComputeRoot32BitConstants), keeping every declared root parameter defined with a valid pointer.crates/victory-shader/src/emit/synthetic_tests.rs: addempty_root_constants_bind_zero_in_draw_and_dispatchverifying bothHost::dispatchandHost::drawwith emptyRoot::Constants(Vec::new())on hardware and WARP.Verification
cargo test -p victory-shader --lib emit::synthetic_tests::empty_root_constants_bind_zero_in_draw_and_dispatch -- --exact— pass on RTX 5090 and WARP.cargo test -p victory-shader --lib emit::memory_tests— 4/4 pass on RTX 5090 (previously crashed with0xc0000005).cargo clippy -p victory-shader --all-targets -- -D warnings— pass (0 warnings).cargo xtask policy— pass (184 files ok).Imported from Marvisak/VIctory. Originally posted by fyernald on 2026-11-25T16:41:24Z.
Review: CHANGES_REQUESTED
This fixes the crash here too: RTX 3080 (617.42), Windows 10 (19045),
main67e8ae1+ #486.maindies with0xc0000005after 65 tests; with this PR it's 268 passed, 3 failed (the #1835 ones), and the new test passes.One problem with skipping the call, though. The root signature declares at least one constant whatever the shader uses:
Num32BitValues: s.user_data_dwords().max(1)athost.rs:162. IfSet*Root32BitConstantsisn't called, that declared parameter is never set in the list, and root arguments are undefined until they are set. It doesn't matter for this shader, which reads no user data, but the harness then dispatches with an unset root parameter that the signature declares. #2596 fixes the same crash by setting that one constant to 0, which keeps every declared parameter defined.Could this set
[0]for an empty list instead of skipping, or be closed in favour of #2596? The newempty_root_constants_are_skipped_in_draw_and_dispatchtest is worth keeping either way, renamed to match.Imported from Marvisak/VIctory. Originally posted by DrDarkDK on 2026-11-25T16:40:52Z.
#2596 addresses the same crash in #2571 by writing one zero.
root_signature_forstill declares one DWORD for a stage with no user data because it usesuser_data_dwords().max(1). With the skip here, that slot stays unset. Microsoft’s D3D12 guidance says to populate the slots declared by the current root signature before draw or dispatch.Could we keep this PR’s synthetic draw/dispatch coverage and use the one-zero binding from #2596? That would preserve the regression test and populate the declared slot.
Static review only. I didn’t run either patch.
AI-assisted with Codex.
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T16:49:39Z.
Thanks @fyernald and @DrDarkDK — good catch on the declared
user_data_dwords().max(1)slot!Updated (
df8ee8ef, rebased onto67e8ae14) to bind&[0u32]for emptyRoot::Constantsslices in bothHost::draw(SetGraphicsRoot32BitConstants) andHost::dispatch(SetComputeRoot32BitConstants), keeping every declared root parameter defined while avoiding the danglingVec::new().as_ptr()(0x4) dereference, and renamed the synthetic draw/dispatch regression test toempty_root_constants_bind_zero_in_draw_and_dispatch.Re-verified on RTX 5090 + WARP (
emit::memory_tests4/4 pass,empty_root_constants_bind_zero_in_draw_and_dispatchpass,clippy -D warningsandcargo xtask policypass).Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T16:50:30Z.
Verification of
df8ee8e(CPU-only; D3D12 tests deliberately not run)origin/main(67e8ae1).cargo test -p victory-shader --lib --no-run: builds.cargo clippy -p victory-shader --all-targets -- -D warnings: clean.empty_root_constants_bind_zero_in_draw_and_dispatch.victory-shader's test host (emit/host.rs) does not honorVICTORY_D3D12_WARP. It picks the first hardware adapter unlessVICTORY_WARP=1is set, and this test loops over("hardware", false)first, so running it opens the physical GPU. I did not run it on this machine, so nothing here shows the test passing on WARP or hardware.[0]for an empty slice, which matches the root signature'suser_data_dwords().max(1)(host.rs~L162). Every root parameter is still set. (I first reviewed8ceeb01, which skipped the call. The head moved to this approach while I was verifying, and this comment coversdf8ee8eonly.) The PR description still says the call is guarded withif !data.is_empty(), which no longer matches the code.Overlap with #2596 (same issue, #2571): the two PRs now make the same code change, setting
[0]in the same twoRoot::Constantsarms ofemit/host.rs(graphics and compute). They are duplicates, andgit merge-treeof the two heads reports a conflict in that file. #2587 adds a regression test, which is unrun here for the reason above. #2596 is the fix alone. A maintainer should land one and close or rebase the other.Independent verification by Claude Code (Claude Sonnet 5.5), an AI assistant, run for oni-swr. No game files, dumps, or shader names were used.
Imported from Marvisak/VIctory. Originally posted by fyernald on 2026-11-25T17:38:47Z.
Review: APPROVED
Thanks for the change. Retested
df8ee8eon the same RTX 3080 (617.42), Windows 10 (19045),main67e8ae1+ #486 (without #2596):mainstill crashes after 65 tests (0xc0000005). With this head,cargo test -p victory-shader --lib --locked -- --test-threads=1gives 268 passed, 3 failed (the #1835 ones). Every declared constant is now defined.It now does the same thing as #2596, so only one of the two needs to land. This one adds the dedicated test.
Imported from Marvisak/VIctory. Originally posted by Vedoxdev123 on 2026-11-25T18:42:53Z.
RTX 4060 test (AI-assisted)
Windows 64-bit, Ryzen 5 5600X, GeForce RTX 4060 (8 GB), on
main13f91ca+ this PR (df8ee8e).cargo test -p victory-shader:mainaborts with0xc0000005atemit::memory_tests::heap_direct_texture_reads_mark_their_heap_indexand prints no summary. With this PR the run completes: 268 passed, 3 failed, 3 ignored. The 3 failures are the known NVIDIA ones from #1835 (a_heap_buffer_read_by_element_takes_the_views_stride,a_heap_buffer_read_where_no_buffer_view_is_reads_zeros,gathers_at_a_level_match_the_hardware).cargo test -p victory-gpu --lib: 193 passed, 2 failed, 1 ignored, identical tomain(dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_views). No change from this PR.Imported from Marvisak/VIctory. Originally posted by qtLkz on 2026-11-25T20:23:18Z.
Tested on NVIDIA Ada: RTX 4070 Ti, driver 621.01, Windows 11 Pro build 26300, Rust 1.98.1 pinned, this PR merged onto main
13f91ca(clean merge).Plain main
13f91caon this card: the victory-shader lib run dies withSTATUS_ACCESS_VIOLATION(0xc0000005) atemit::memory_tests::heap_direct_texture_reads_mark_their_heap_index(#2571). The test passes on its own withVICTORY_WARP=1.With this PR:
cargo test -p victory-shader --lib --locked -- --test-threads=1heap_direct_texture_reads_mark_their_heap_index ... ok, on the hardware adaptersynthetic_tests::empty_root_constants_bind_zero_in_draw_and_dispatch ... okstride_tests×2,gathers_at_a_level_match_the_hardware; #2317, fixed by #2315 + #2322), not from this PR.#2596 fixes the crash on this card as well. This PR also covers the draw path and adds a regression test.
AI-assisted (Claude).
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T22:15:08Z.
Automated triage for the maintainers.
Verdict: merge candidate. Re-reviewed at
8aae7ab, which now merges cleanly intomain. Incrates/victory-shader/src/emit/host.rs,Host::drawandHost::dispatchnow bind a single zero dword whenRoot::Constantsis empty. This matches theuser_data_dwords().max(1)slot thatroot_signature_fordeclares, and it no longer passes the danglingVec::new()pointer that crashes NVIDIA's driver (#2571). The newempty_root_constants_bind_zero_in_draw_and_dispatchcovers both paths. Testers in this thread report it fails onmainand passes with the PR on several NVIDIA cards. #2596 makes the same code change without a test, and the two conflict, so only one should land.CI: passing. Recommending a look, not approving.
Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by KainanP on 2026-11-25T22:53:50Z.
Measured against the other #2571 PRs on an RTX 4060 (where
maincrashes), Intel UHD and WARP. This one passes the test 3 of 3, its host-level test fails onmainand passes here, and it adds no suite failure. Recommended in the comparison: https://github.com/Marvisak/VIctory/issues/2571#issuecomment-7176908308 (AI-assisted)Imported from Marvisak/VIctory. Originally posted by liandraraiane on 2026-11-26T02:48:14Z.
Confirmed on an RTX 3060 (Ampere, driver 610.88, Windows 11 26200). On
f3578e3,heap_direct_texture_reads_mark_their_heap_indexkills the test binary with STATUS_ACCESS_VIOLATION in the hardware dispatch (7/7 runs; WARP passes), and this PR'sempty_root_constants_bind_zero_in_draw_and_dispatch, applied alone on main, does the same. With this PR (8aae7ab) both pass, and the wholevictory-shadersuite runs to the end: 300 passed, 3 failed, 5/5 runs. The three left are the capped-heap failures of #1835 (a_heap_buffer_read_by_element_takes_the_views_stride,a_heap_buffer_read_where_no_buffer_view_is_reads_zeros,gathers_at_a_level_match_the_hardware). #2596 also fixes the crash here. Not tested: AMD, other NVIDIA generations.AI use: Claude Code ran the tests on this machine and drafted this comment.
upstream-sync referenced this pull request2026-11-26 05:04:09 +00:00
Imported from Marvisak/VIctory. Originally posted by kalberts0089-hash on 2026-11-27T05:09:11Z.
NVIDIA test report: RTX 4060 (driver 610.88), Windows 11 Pro, rustc 1.98.1. Head
8aae7abas fetched (basef3578e3),cargo test -p victory-shader --no-fail-fast.emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index: passes. On main63bcca4it kills the test process with0xc0000005on this card.empty_root_constants_bind_zero_in_draw_and_dispatchpasses.a_heap_buffer_read_by_element_takes_the_views_stride,a_heap_buffer_read_where_no_buffer_view_is_reads_zeros,gathers_at_a_level_match_the_hardware.Synthetic tests only, no game files. AI-assisted (Claude Code).
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.