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

Merged
nathanbzrr merged 1 commit from upstream-pr/646 into main 2026-11-25 00:16:47 +00:00
nathanbzrr commented 2026-11-24 06:06:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by nathanbzrr on 2026-11-24T06:06:19Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6575762478 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/646). Originally posted by [nathanbzrr](https://github.com/nathanbzrr) on 2026-11-24T06:06:19Z. --- ## 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.
LAKSHYA-cmd-tech commented 2026-11-24 06:54:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by LAKSHYA-cmd-tech on 2026-11-24T06:14:57Z.

Review: APPROVED


Tested on Windows 11 with Rust 1.98.1 (x86_64-pc-windows-msvc).

  • cargo test -p victory-shader: all 73 unit tests passed cleanly (0 failed).
  • Verified constant() 64-bit vs 32-bit inline constant sign-extension, simulate() EXEC masking with & all, and prefix lane validation in per_lane().
  • cargo xtask policy: 151 files ok.
<!-- greyfinch-sync:Marvisak/VIctory:review:6034549113 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/646#pullrequestreview-6034549113). Originally posted by [LAKSHYA-cmd-tech](https://github.com/LAKSHYA-cmd-tech) on 2026-11-24T06:14:57Z. **Review:** APPROVED --- Tested on Windows 11 with Rust 1.98.1 (x86_64-pc-windows-msvc). - cargo test -p victory-shader: all 73 unit tests passed cleanly (0 failed). - Verified constant() 64-bit vs 32-bit inline constant sign-extension, simulate() EXEC masking with & all, and prefix lane validation in per_lane(). - cargo xtask policy: 151 files ok.
catminou4 commented 2026-11-24 11:03:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T10:18:21Z.

Review: APPROVED


Merges cleanly; merged into current main ffe310e (post-#566), macOS arm64, rustc 1.98.1, cargo test -p victory-shader --locked → 100 passed / 0 failed / 1 ignored.

Three fixes, each with targeted tests:

  • simulate now clamps EXEC to the wave width (& all) after s_mov_b64/exec_hi writes, so a 64-bit mask can't leak bits past lane 31/63 into the DPP guard logic.
  • constant() handles the NULL operand (→ 0) and sign-extends inline constants correctly for s_mov_b64 (wide) vs s_mov_b32 — the old code sign-extended everything to u64::MAX, which was wrong for b32 consumers reading the low dword only.
  • per_lane prefix validation is rewritten to track lane metadata and op separately, requiring a consistent op across lanes, a single-bit set for lanes without an op, and the identity check via op.identity(ident); lane 0 must be the identity for exclusive prefixes and a reduction for inclusive ones.

The four new 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) exercise exactly the changed paths with real encodings. These are wave32/64 shape-analysis fixes that run on macOS (no GPU needed for structure/wave).

<!-- greyfinch-sync:Marvisak/VIctory:review:6037404920 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/646#pullrequestreview-6037404920). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T10:18:21Z. **Review:** APPROVED --- Merges cleanly; merged into current main `ffe310e` (post-#566), macOS arm64, rustc 1.98.1, `cargo test -p victory-shader --locked` → **100 passed / 0 failed / 1 ignored**. Three fixes, each with targeted tests: - `simulate` now clamps EXEC to the wave width (`& all`) after `s_mov_b64`/`exec_hi` writes, so a 64-bit mask can't leak bits past lane 31/63 into the DPP guard logic. - `constant()` handles the NULL operand (→ 0) and sign-extends inline constants correctly for `s_mov_b64` (wide) vs `s_mov_b32` — the old code sign-extended everything to u64::MAX, which was wrong for b32 consumers reading the low dword only. - `per_lane` prefix validation is rewritten to track lane metadata and op separately, requiring a consistent op across lanes, a single-bit set for lanes without an op, and the identity check via `op.identity(ident)`; lane 0 must be the identity for exclusive prefixes and a reduction for inclusive ones. The four new 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`) exercise exactly the changed paths with real encodings. These are wave32/64 shape-analysis fixes that run on macOS (no GPU needed for `structure`/`wave`).
mercuryVM commented 2026-11-24 11:03:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T11:03:27Z.

Review: APPROVED


Tested 12eba49 on Windows 11, RTX 5070, MSVC: cargo test -p victory-shader -- --test-threads=1 73 passed, including the four new wave.rs tests. cargo clippy -p victory-shader --all-targets is clean. victory translate --validate --pipelines on the local title executable gives the same result at the merge base (d2a4bae) and at this head: 12 of 12 emitted, validated and built into pipelines.

  • constant(): sign-extending inline integers 128..=208 only for s_mov_b64 and zero-extending them for 32-bit moves matches how SOP1 widens inline constants. Returning None for float inline constants on s_mov_b64 is the conservative choice (they would be f64 bit patterns).
  • Masking both halves' EXEC writes with & all fixes the wave32 s_mov_b64 exec, -1 case, where the exec == all comparison never matched.
  • per_lane: validating (src, mask, ident, inclusive) for every lane, not only lanes that name an op, closes the gap where a single-lane op: None lane skipped the check. Requiring op.identity(ident) and the lane-0 shape matches the prefix invariant.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6038037851 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/646#pullrequestreview-6038037851). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T11:03:27Z. **Review:** APPROVED --- Tested 12eba49 on Windows 11, RTX 5070, MSVC: `cargo test -p victory-shader -- --test-threads=1` 73 passed, including the four new `wave.rs` tests. `cargo clippy -p victory-shader --all-targets` is clean. `victory translate --validate --pipelines` on the local title executable gives the same result at the merge base (d2a4bae) and at this head: 12 of 12 emitted, validated and built into pipelines. - `constant()`: sign-extending inline integers 128..=208 only for `s_mov_b64` and zero-extending them for 32-bit moves matches how SOP1 widens inline constants. Returning `None` for float inline constants on `s_mov_b64` is the conservative choice (they would be f64 bit patterns). - Masking both halves' EXEC writes with `& all` fixes the wave32 `s_mov_b64 exec, -1` case, where the `exec == all` comparison never matched. - `per_lane`: validating `(src, mask, ident, inclusive)` for every lane, not only lanes that name an op, closes the gap where a single-lane `op: None` lane skipped the check. Requiring `op.identity(ident)` and the lane-0 shape matches the prefix invariant. AI-assisted (Claude Code).
geiyiliyabumo commented 2026-11-24 11:04:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-24T10:47:20Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7129246160 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/646#issuecomment-7129246160). Originally posted by [geiyiliyabumo](https://github.com/geiyiliyabumo) on 2026-11-24T10:47:20Z. --- 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.*
molodayamama commented 2026-11-24 15:03:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by molodayamama on 2026-11-24T14:06:00Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7133838053 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/646#issuecomment-7133838053). Originally posted by [molodayamama](https://github.com/molodayamama) on 2026-11-24T14:06:00Z. --- 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.
upstream-sync closed this pull request 2026-11-25 01:04:37 +00:00
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!646
No description provided.