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

Open
github-bot wants to merge 1 commit from github-bot/gh-2587 into main AGit
Owner

@⁠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 · open

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).
**@⁠fuzeofficlal** on GitHub · 2026-11-25 16:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2587) `fuzeofficlal:fix/shader-host-empty-root-constants-av` → `main` · +93 −12 · 2 files · 1 commits · open ## 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`).
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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:09:49 +00:00
Author
Owner

@⁠DrDarkDK on GitHub · 2026-11-25 16:40 UTC · original

#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.

**@⁠DrDarkDK** on GitHub · 2026-11-25 16:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/2587#issuecomment-7168366323) #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](https://learn.microsoft.com/en-us/windows/win32/direct3d12/using-a-root-signature#command-list-semantic) 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.*
Author
Owner

@⁠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 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).

**@⁠fuzeofficlal** on GitHub · 2026-11-25 16:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/2587#issuecomment-7168591521) 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).
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 16:50 UTC · original

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.

**@⁠oni-swr** on GitHub · 2026-11-25 16:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/2587#issuecomment-7168612853) **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._
Author
Owner

@⁠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 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 #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.
**@⁠Vedoxdev123** on GitHub · 2026-11-25 18:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/2587#issuecomment-7171293371) **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 #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.
Author
Owner

@⁠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 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

  • heap_direct_texture_reads_mark_their_heap_index ... ok, on the hardware adapter
  • The new synthetic_tests::empty_root_constants_bind_zero_in_draw_and_dispatch ... ok
  • The suite runs to the end: 268 passed, 3 failed, 3 ignored. The 3 failures are the known NVIDIA ones (stride_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).

**@⁠qtLkz** on GitHub · 2026-11-25 20:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/2587#issuecomment-7173595822) 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` - `heap_direct_texture_reads_mark_their_heap_index ... ok`, on the hardware adapter - The new `synthetic_tests::empty_root_constants_bind_zero_in_draw_and_dispatch ... ok` - The suite runs to the end: 268 passed, 3 failed, 3 ignored. The 3 failures are the known NVIDIA ones (`stride_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).
Author
Owner

@⁠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 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

**@⁠Marvisak** on GitHub · 2026-11-25 22:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/2587#issuecomment-7176127274) · edited 2026-11-26 03:19 UTC <!-- victory-triage v1 head=8aae7ab3fa997e7fb618b1439f12bf3d6a6ffaf9 verdict=merge-candidate at=2026-11-26T03:19:29Z --> 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](https://claude.ai/code)_
Author
Owner

@⁠KainanP on GitHub · 2026-11-25 22:53 UTC · original

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 (AI-assisted)

**@⁠KainanP** on GitHub · 2026-11-25 22:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/2587#issuecomment-7176912841) 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: https://git.gtahub.st/github/Marvisak--VIctory/issues/2571 (AI-assisted)
Author
Owner

@⁠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_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.

**@⁠liandraraiane** on GitHub · 2026-11-26 02:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/2587#issuecomment-7181133000) 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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2587/head:github-bot/gh-2587'
git switch 'github-bot/gh-2587'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2587'
git switch 'github-bot/gh-2587'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2587'
git switch 'github-bot/gh-2587'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2587'
git switch 'main'
git merge --squash 'github-bot/gh-2587'
git switch 'main'
git merge --ff-only 'github-bot/gh-2587'
git switch 'main'
git merge 'github-bot/gh-2587'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2587
No description provided.