Shaders: bind a zero dword for empty root-constant slices #2587
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!2587
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@fuzeofficlal on GitHub · 2026-11-25 16:18 UTC · original
fuzeofficlal:fix/shader-host-empty-root-constants-av→main· +93 −12 · 2 files · 1 commits · openSummary
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).@DrDarkDK on GitHub · 2026-11-25 16:40 UTC · original
#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.
@fuzeofficlal on GitHub · 2026-11-25 16:49 UTC · original
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).@oni-swr on GitHub · 2026-11-25 16:50 UTC · original
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.
@Vedoxdev123 on GitHub · 2026-11-25 18:42 UTC · original
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.@qtLkz on GitHub · 2026-11-25 20:23 UTC · original
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).
@Marvisak on GitHub · 2026-11-25 22:15 UTC · original · edited 2026-11-26 03:19 UTC
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
@KainanP on GitHub · 2026-11-25 22:53 UTC · original
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: #2571 (AI-assisted)@liandraraiane on GitHub · 2026-11-26 02:48 UTC · original
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.
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.