Skip to content

Shaders: bind a zero dword for empty root-constant slices - #2587

Open
fuzeofficlal wants to merge 1 commit into
Marvisak:mainfrom
fuzeofficlal:fix/shader-host-empty-root-constants-av
Open

fuzeofficlal wants to merge 1 commit into
Marvisak:mainfrom
fuzeofficlal:fix/shader-host-empty-root-constants-av

Conversation

@fuzeofficlal

@fuzeofficlal fuzeofficlal commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Host::root_signature_for in crates/victory-shader/src/emit/host.rs always declares Num32BitValues: 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). Passing 0x4 with count 0 to SetComputeRoot32BitConstants / SetGraphicsRoot32BitConstants crashes NVIDIA's D3D12 driver (nvwgf2umx.dll) with STATUS_ACCESS_VIOLATION (0xc0000005) (reproducing on emit::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: when Root::Constants(data) is empty, bind &[0u32] (let words = if data.is_empty() { &[0u32][..] } else { data.as_slice() };) in both Host::draw (SetGraphicsRoot32BitConstants) and Host::dispatch (SetComputeRoot32BitConstants), keeping every declared root parameter defined with a valid pointer.
  • crates/victory-shader/src/emit/synthetic_tests.rs: add empty_root_constants_bind_zero_in_draw_and_dispatch verifying both Host::dispatch and Host::draw with empty Root::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 with 0xc0000005).
  • cargo clippy -p victory-shader --all-targets -- -D warnings — pass (0 warnings).
  • cargo xtask policy — pass (184 files ok).

@DrDarkDK

Copy link
Copy Markdown

#2596 addresses the same crash in #2571 by writing one zero. root_signature_for still declares one DWORD for a stage with no user data because it uses user_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.

@fyernald fyernald left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes the crash here too: RTX 3080 (617.42), Windows 10 (19045), main 67e8ae1 + #486. main dies with 0xc0000005 after 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) at host.rs:162. If Set*Root32BitConstants isn'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 new empty_root_constants_are_skipped_in_draw_and_dispatch test is worth keeping either way, renamed to match.

@fuzeofficlal
fuzeofficlal force-pushed the fix/shader-host-empty-root-constants-av branch from 8ceeb01 to df8ee8e Compare November 25, 2026 16:49
@fuzeofficlal fuzeofficlal changed the title Shaders: skip Set*Root32BitConstants for empty root-constant slices Shaders: bind a zero dword for empty root-constant slices Nov 25, 2026
@fuzeofficlal

fuzeofficlal commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks @fyernald and @DrDarkDK — good catch on the declared user_data_dwords().max(1) slot!

Updated (df8ee8ef, rebased onto 67e8ae14) to bind &[0u32] for empty Root::Constants slices in both Host::draw (SetGraphicsRoot32BitConstants) and Host::dispatch (SetComputeRoot32BitConstants), keeping every declared root parameter defined while avoiding the dangling Vec::new().as_ptr() (0x4) dereference, and renamed the synthetic draw/dispatch regression test to empty_root_constants_bind_zero_in_draw_and_dispatch.

Re-verified on RTX 5090 + WARP (emit::memory_tests 4/4 pass, empty_root_constants_bind_zero_in_draw_and_dispatch pass, clippy -D warnings and cargo xtask policy pass).

@oni-swr

oni-swr commented Nov 25, 2026

Copy link
Copy Markdown

Verification of df8ee8e (CPU-only; D3D12 tests deliberately not run)

  • Merges cleanly onto origin/main (67e8ae1).
  • cargo test -p victory-shader --lib --no-run: builds. cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • Not run: the new test empty_root_constants_bind_zero_in_draw_and_dispatch. victory-shader's test host (emit/host.rs) does not honor VICTORY_D3D12_WARP. It picks the first hardware adapter unless VICTORY_WARP=1 is 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.
  • Diff review: the fix binds [0] for an empty slice, which matches the root signature's user_data_dwords().max(1) (host.rs ~L162). Every root parameter is still set. (I first reviewed 8ceeb01, which skipped the call. The head moved to this approach while I was verifying, and this comment covers df8ee8e only.) The PR description still says the call is guarded with if !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 two Root::Constants arms of emit/host.rs (graphics and compute). They are duplicates, and git merge-tree of 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.

@fyernald fyernald left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the change. Retested df8ee8e on the same RTX 3080 (617.42), Windows 10 (19045), main 67e8ae1 + #486 (without #2596): main still crashes after 65 tests (0xc0000005). With this head, cargo test -p victory-shader --lib --locked -- --test-threads=1 gives 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.

@Vedoxdev123

Copy link
Copy Markdown

RTX 4060 test (AI-assisted)
Windows 64-bit, Ryzen 5 5600X, GeForce RTX 4060 (8 GB), on main 13f91ca + this PR (df8ee8e).

  • cargo test -p victory-shader: main aborts with 0xc0000005 at emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index and prints no summary. With this PR the run completes: 268 passed, 3 failed, 3 ignored. The 3 failures are the known NVIDIA ones from NVIDIA D3D12 (70564ae): stride_tests & synthetic_tests fail due to HEAP_VIEWS (2M > 1M NVIDIA limit) and Stride::Structured with rawBufferLoad #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 to main (dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views). No change from this PR.

@qtLkz

qtLkz commented Nov 25, 2026

Copy link
Copy Markdown

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 13f91ca on this card: the victory-shader lib run dies with STATUS_ACCESS_VIOLATION (0xc0000005) at emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index (#2571). The test passes on its own with VICTORY_WARP=1.

With this PR: cargo test -p victory-shader --lib --locked -- --test-threads=1

#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 commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Verdict: merge candidate. Re-reviewed at 8aae7ab, which now merges cleanly into main. In crates/victory-shader/src/emit/host.rs, Host::draw and Host::dispatch now bind a single zero dword when Root::Constants is empty. This matches the user_data_dwords().max(1) slot that root_signature_for declares, and it no longer passes the dangling Vec::new() pointer that crashes NVIDIA's driver (#2571). The new empty_root_constants_bind_zero_in_draw_and_dispatch covers both paths. Testers in this thread report it fails on main and 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

root_signature_for declares user_data_dwords().max(1) root constants even when a shader reads no user data. Passing Vec::new().as_ptr() (0x4) with count 0 to SetComputeRoot32BitConstants or SetGraphicsRoot32BitConstants causes NVIDIA's D3D12 driver to dereference 0x4 (STATUS_ACCESS_VIOLATION), while skipping the call leaves the declared slot unset. Bind &[0u32] when the slice is empty and test both Host::dispatch and Host::draw on hardware and WARP.
@KainanP

KainanP commented Nov 25, 2026

Copy link
Copy Markdown

Measured against the other #2571 PRs on an RTX 4060 (where main crashes), Intel UHD and WARP. This one passes the test 3 of 3, its host-level test fails on main and passes here, and it adds no suite failure. Recommended in the comparison: #2571 (comment) (AI-assisted)

@liandraraiane

Copy link
Copy Markdown

Confirmed on an RTX 3060 (Ampere, driver 610.88, Windows 11 26200). On f3578e3, heap_direct_texture_reads_mark_their_heap_index kills the test binary with STATUS_ACCESS_VIOLATION in the hardware dispatch (7/7 runs; WARP passes), and this PR's empty_root_constants_bind_zero_in_draw_and_dispatch, applied alone on main, does the same. With this PR (8aae7ab) both pass, and the whole victory-shader suite 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants