Shaders: fix whole-wave EXEC inline constant sign-extension and prefix lane validation #646

Manually merged
github merged 1 commit from gh-pr/646/head into gh-pr/646/base 2026-11-26 04:11:22 +00:00
Owner

@⁠nathanbzrr on GitHub · 2026-11-24 06:06 UTC · original
nathanbzrr:shader/wave-exec-const-and-prefix-validation → main · +293 −22 · 1 files · 1 commits · merged 2026-11-25 00:16 UTC

Summary

Fixes two silent miscompilation bugs in whole-wave symbolic simulation (crates/victory-shader/src/emit/wave.rs):

  1. constant() collapsed all negative inline integer constants -2..=-16 (and negative 32-bit inline floats like -1.0f) to u64::MAX (-1), turning masked s_mov_b32 exec_lo, -2 / s_mov_b64 exec, -2 steps into exec == all, silently clobbering lane 0 and bypassing if exec != all guards. In addition, EXEC / EXEC + 1 updates in simulate() were not masked by & all, causing 64-bit exec writes in wave32 sections to miss exec == all.
  2. In per_lane(), op: None lanes with found == None hit (None, None) => continue before checking (src, mask, ident, inclusive), allowing mismatched lane 0 / lane 1 values in prefix scans to be silently accepted as valid Shape::Prefix.

Changes (crates/victory-shader/src/emit/wave.rs)

  • Update constant(inst) to distinguish 64-bit s_mov_b64 from 32-bit moves: decode NULL (125) as 0, sign-extend 64-bit inline integers (128..=208) via i64::from(x as i32) as u64, keep 32-bit inline constants zero-extended, and return None for non-integer inline constants on s_mov_b64.
  • Mask both EXEC and EXEC + 1 updates in simulate() by & all.
  • Track meta: Option<(Value, Value, u32, bool)> independently from op_found in per_lane() so every Sym::Red lane (including single-lane op: None lanes 0 and 1) validates (src, mask, ident, inclusive), op.identity(ident), and lanes[0] inclusive/exclusive invariants.
  • Add synthetic unit tests (constant_decodes_width_and_inline_kinds, exec_minus_two_masks_lane_zero_and_enforces_dpp_guard, wave32_mov_b64_all_lanes_keeps_exec_masked_for_dpp, per_lane_prefix_soundness).

Verification

Isolated verification on branch shader/wave-exec-const-and-prefix-validation (12eba49):

  • rustfmt --edition 2024 --config skip_children=true --check crates/victory-shader/src/emit/wave.rs (passed)
  • cargo test -p victory-shader -- --test-threads=1 (73 passed, 0 failed, 0 ignored)
  • cargo clippy -p victory-shader --all-targets (0 warnings)
  • cargo xtask policy (151 files ok)

No game files. AI-assisted; reviewed and verified with the tests above.

**@⁠nathanbzrr** on GitHub · 2026-11-24 06:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/646) `nathanbzrr:shader/wave-exec-const-and-prefix-validation` → `main` · +293 −22 · 1 files · 1 commits · merged 2026-11-25 00:16 UTC ## Summary Fixes two silent miscompilation bugs in whole-wave symbolic simulation (`crates/victory-shader/src/emit/wave.rs`): 1. `constant()` collapsed all negative inline integer constants `-2..=-16` (and negative 32-bit inline floats like `-1.0f`) to `u64::MAX` (`-1`), turning masked `s_mov_b32 exec_lo, -2` / `s_mov_b64 exec, -2` steps into `exec == all`, silently clobbering lane 0 and bypassing `if exec != all` guards. In addition, `EXEC` / `EXEC + 1` updates in `simulate()` were not masked by `& all`, causing 64-bit `exec` writes in wave32 sections to miss `exec == all`. 2. In `per_lane()`, `op: None` lanes with `found == None` hit `(None, None) => continue` before checking `(src, mask, ident, inclusive)`, allowing mismatched lane 0 / lane 1 values in prefix scans to be silently accepted as valid `Shape::Prefix`. ### Changes (`crates/victory-shader/src/emit/wave.rs`) - Update `constant(inst)` to distinguish 64-bit `s_mov_b64` from 32-bit moves: decode `NULL` (`125`) as `0`, sign-extend 64-bit inline integers (`128..=208`) via `i64::from(x as i32) as u64`, keep 32-bit inline constants zero-extended, and return `None` for non-integer inline constants on `s_mov_b64`. - Mask both `EXEC` and `EXEC + 1` updates in `simulate()` by `& all`. - Track `meta: Option<(Value, Value, u32, bool)>` independently from `op_found` in `per_lane()` so every `Sym::Red` lane (including single-lane `op: None` lanes 0 and 1) validates `(src, mask, ident, inclusive)`, `op.identity(ident)`, and `lanes[0]` inclusive/exclusive invariants. - Add synthetic unit tests (`constant_decodes_width_and_inline_kinds`, `exec_minus_two_masks_lane_zero_and_enforces_dpp_guard`, `wave32_mov_b64_all_lanes_keeps_exec_masked_for_dpp`, `per_lane_prefix_soundness`). ## Verification Isolated verification on branch `shader/wave-exec-const-and-prefix-validation` (`12eba49`): - `rustfmt --edition 2024 --config skip_children=true --check crates/victory-shader/src/emit/wave.rs` (passed) - `cargo test -p victory-shader -- --test-threads=1` (73 passed, 0 failed, 0 ignored) - `cargo clippy -p victory-shader --all-targets` (0 warnings) - `cargo xtask policy` (151 files ok) No game files. AI-assisted; reviewed and verified with the tests above.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:11:21 +00:00
github manually merged commit 12eba49503 into gh-pr/646/base 2026-11-26 04:11:22 +00:00
Author
Owner

@⁠geiyiliyabumo on GitHub · 2026-11-24 10:47 UTC · original

Independent verification & code review on Windows 11 Pro (build 26100) + AMD Radeon RX 9060 XT (RDNA4, driver 32.0.32029.2010, Rust 1.98.1), cleanly merged onto main (ffe310e):

  • cargo xtask policy: PASS (154 files ok)
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings: PASS
  • cargo clippy -p victory-shader --all-targets --features diagnostics --locked -- -D warnings: PASS
  • cargo test -p victory-shader --locked: 124 passed, 0 failed, 1 ignored (including all new emit::wave::tests::* cases)
  • VICTORY_D3D12_DEBUG=1 cargo test -p victory-shader --locked -- valu_tests: 13/13 PASS on RX 9060 XT and 13/13 PASS on WARP (VICTORY_WARP=1)

Diff review of crates/victory-shader/src/emit/wave.rs looks solid:

  • Sign-extending integer inline constants (128..=208) for s_mov_b64 fixes the -2..-16 -> u64::MAX bug while keeping float inline constants rejected on 64-bit B64 moves and zero-extending 32-bit literals per RDNA2 B64 rules.
  • Masking exec with all on both EXEC and EXEC+1 updates prevents high-half leakage in wave32.
  • Splitting meta and op_found in per_lane closes the single-lane op: None bypass and properly validates lanes[0] and op.identity(ident).

AI-assisted; synthetic tests only, no game files.

**@⁠geiyiliyabumo** on GitHub · 2026-11-24 10:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/646#issuecomment-7129246160) Independent verification & code review on Windows 11 Pro (build 26100) + AMD Radeon RX 9060 XT (RDNA4, driver `32.0.32029.2010`, Rust `1.98.1`), cleanly merged onto `main` (`ffe310e`): - `cargo xtask policy`: PASS (`154 files ok`) - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings`: PASS - `cargo clippy -p victory-shader --all-targets --features diagnostics --locked -- -D warnings`: PASS - `cargo test -p victory-shader --locked`: **124 passed, 0 failed, 1 ignored** (including all new `emit::wave::tests::*` cases) - `VICTORY_D3D12_DEBUG=1 cargo test -p victory-shader --locked -- valu_tests`: **13/13 PASS** on RX 9060 XT and **13/13 PASS** on WARP (`VICTORY_WARP=1`) Diff review of `crates/victory-shader/src/emit/wave.rs` looks solid: - Sign-extending integer inline constants (`128..=208`) for `s_mov_b64` fixes the `-2..-16 -> u64::MAX` bug while keeping float inline constants rejected on 64-bit `B64` moves and zero-extending 32-bit literals per RDNA2 `B64` rules. - Masking `exec` with `all` on both `EXEC` and `EXEC+1` updates prevents high-half leakage in wave32. - Splitting `meta` and `op_found` in `per_lane` closes the single-lane `op: None` bypass and properly validates `lanes[0]` and `op.identity(ident)`. *AI-assisted; synthetic tests only, no game files.*
Author
Owner

@⁠molodayamama on GitHub · 2026-11-24 14:06 UTC · original

Independent Windows check of 12eba495039d8018eb6959be95fcc10e387b7e33 (Windows 10 22H2 19045, Rust 1.98.1, MSVC x64).

  • cargo test -p victory-shader --locked --lib emit::wave::tests -- --test-threads=1 --nocapture: 6 passed.

The whole-wave fixtures covered inline constant kinds, signed EXEC = -2, DPP guarding with lane zero masked, and the wave32/wave64 prefix checks. This is a CPU-side analysis run.

Only source-built synthetic fixtures were used. AI-assisted verification.

**@⁠molodayamama** on GitHub · 2026-11-24 14:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/646#issuecomment-7133838053) Independent Windows check of `12eba495039d8018eb6959be95fcc10e387b7e33` (Windows 10 22H2 19045, Rust 1.98.1, MSVC x64). - `cargo test -p victory-shader --locked --lib emit::wave::tests -- --test-threads=1 --nocapture`: 6 passed. The whole-wave fixtures covered inline constant kinds, signed `EXEC = -2`, DPP guarding with lane zero masked, and the wave32/wave64 prefix checks. This is a CPU-side analysis run. Only source-built synthetic fixtures were used. AI-assisted verification.
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!646
No description provided.