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

Manually merged
github merged 1 commit from github-bot/gh-2473 into main 2026-11-30 14:17:25 +00:00 AGit
Owner

@⁠fuzeofficlal on GitHub · 2026-11-29 13:22 UTC · original
fuzeofficlal:fix/shader-host-empty-root-constants-av → main · +101 −12 · 1 files · 1 commits · merged 2026-11-30 14:12 UTC

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). 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][..] in both Host::draw (SetGraphicsRoot32BitConstants) and Host::dispatch (SetComputeRoot32BitConstants), keeping every declared root parameter defined with a valid pointer.
  • crates/victory-shader/src/emit/host.rs: add emit::host::tests::empty_root_constants_bind_zero_in_draw_and_dispatch verifying both Host::dispatch and Host::draw with empty Root::Constants(Vec::new()) on NVIDIA hardware and WARP.

Verification

  • cargo test --locked -p victory-shader --lib emit::host:: — pass on RTX 5090 (VICTORY_ADAPTER=NVIDIA) and WARP.
  • cargo clippy --locked -p victory-shader --all-targets — 0 new warnings in touched files.
  • cargo run --quiet --locked -p xtask -- policy --staged — pass.
**@⁠fuzeofficlal** on GitHub · 2026-11-29 13:22 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2473) `fuzeofficlal:fix/shader-host-empty-root-constants-av` → `main` · +101 −12 · 1 files · 1 commits · merged 2026-11-30 14:12 UTC ## 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)`. 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][..]` in both `Host::draw` (`SetGraphicsRoot32BitConstants`) and `Host::dispatch` (`SetComputeRoot32BitConstants`), keeping every declared root parameter defined with a valid pointer. - `crates/victory-shader/src/emit/host.rs`: add `emit::host::tests::empty_root_constants_bind_zero_in_draw_and_dispatch` verifying both `Host::dispatch` and `Host::draw` with empty `Root::Constants(Vec::new())` on NVIDIA hardware and WARP. ## Verification - `cargo test --locked -p victory-shader --lib emit::host::` — pass on RTX 5090 (`VICTORY_ADAPTER=NVIDIA`) and WARP. - `cargo clippy --locked -p victory-shader --all-targets` — 0 new warnings in touched files. - `cargo run --quiet --locked -p xtask -- policy --staged` — pass.
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-29 13:22:56 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-29 13:23 UTC · original · approved these changes

Tested locally merged onto main (829188e9).

  • Merge: Clean merge in crates/victory-shader/src/emit/host.rs.
  • Tests (RTX 5090):
    • cargo test -p victory-shader --lib emit::host:: passed.
    • cargo test -p victory-shader --lib emit::tests:: passed (26 passed; 0 failed; 1 ignored).
    • cargo test -p victory-shader --lib emit::lower::tests:: passed (25 passed; 0 failed; 1 ignored).
  • 0 new warnings.

Clean fix binding a zero dword for empty root-constant slices in the shader host test runner. LGTM.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-29 13:23 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2473#pullrequestreview-6103059855) · **approved these changes** Tested locally merged onto `main` (`829188e9`). - **Merge**: Clean merge in `crates/victory-shader/src/emit/host.rs`. - **Tests (RTX 5090)**: - `cargo test -p victory-shader --lib emit::host::` passed. - `cargo test -p victory-shader --lib emit::tests::` passed (`26 passed; 0 failed; 1 ignored`). - `cargo test -p victory-shader --lib emit::lower::tests::` passed (`25 passed; 0 failed; 1 ignored`). - 0 new warnings. Clean fix binding a zero dword for empty root-constant slices in the shader host test runner. LGTM. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
github manually merged commit f00f9507a7 into main 2026-11-30 14:17:25 +00:00
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/trustno1-coder--VIctory-NVIDIA!2473
No description provided.