Shaders/wave: seed EXEC in uni map and validate full wave64 mask pairs #759

Open
AscilCH wants to merge 1 commit from upstream-pr/759 into main
AscilCH commented 2026-11-25 06:44:43 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by AscilCH on 2026-11-25T06:44:43Z.


Problem

Two soundness bugs in whole-wave section simulation (crates/victory-shader/src/emit/wave.rs):

  1. Missing EXEC entries in uni: simulate() never inserted section-start EXEC/EXEC+1 SSA values or mid-section s_mov_b* writes to EXEC/EXEC+1 into uni. An in-section read of exec_lo/exec_hi (e.g. s_mov_b32 s8, exec_lo or v_mov_b32 v2, exec_lo) fell back to Sym::Uni(exec_val) -> Shape::Value(exec_val), which lowering turned into the divergent host waveActiveBallot(true) (or failed to lower) instead of the section's constant mask (0xFFFF_FFFF or the mid-section constant).
  2. Wave64 masks checked low dword only:
    • sections() accepted 32-bit s_or_saveexec_b32/s_nand_saveexec_b32 and 32-bit exec_lo-only restores in wave64 even though lanes 32..63 are untouched.
    • simulate() accepted 32-bit s_and_b32 in wave64 and checked only the low dword Value in s_and_b64 and v_cndmask_b32, so overwriting the high dword of a saved or derived wave64 mask still produced a valid Sym::Red.

Fix

  • Seed uni with section-start EXEC/EXEC+1 constant values (u32::MAX) and update uni on mid-section constant s_mov_b* writes to EXEC/EXEC+1.
  • Track (Value, Option<Value>) mask pairs in masked, require 64-bit start, restore, and s_and_b64 in wave64, and match both low and high dwords in s_and_b64 and v_cndmask_b32.

Verification

  • cargo test -p victory-shader --locked -- emit::wave emit::wave64_tests: 15 passed; 0 failed (including new tests in_section_exec_reads_export_section_constants and wave64_mask_checks_high_dword_and_rejects_32bit_ops).
  • cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings: 0 warnings.
  • cargo xtask policy: 171 files ok.

(AI-assisted; synthetic unit tests only, no game data.)

<!-- greyfinch-sync:fxceless/victory-fork:issue:6598878310 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/759). Originally posted by [AscilCH](https://github.com/AscilCH) on 2026-11-25T06:44:43Z. --- ### Problem Two soundness bugs in whole-wave section simulation (`crates/victory-shader/src/emit/wave.rs`): 1. **Missing `EXEC` entries in `uni`**: `simulate()` never inserted section-start `EXEC`/`EXEC+1` SSA values or mid-section `s_mov_b*` writes to `EXEC`/`EXEC+1` into `uni`. An in-section read of `exec_lo`/`exec_hi` (e.g. `s_mov_b32 s8, exec_lo` or `v_mov_b32 v2, exec_lo`) fell back to `Sym::Uni(exec_val)` -> `Shape::Value(exec_val)`, which lowering turned into the divergent host `waveActiveBallot(true)` (or failed to lower) instead of the section's constant mask (`0xFFFF_FFFF` or the mid-section constant). 2. **Wave64 masks checked low dword only**: - `sections()` accepted 32-bit `s_or_saveexec_b32`/`s_nand_saveexec_b32` and 32-bit `exec_lo`-only restores in wave64 even though lanes 32..63 are untouched. - `simulate()` accepted 32-bit `s_and_b32` in wave64 and checked only the low dword `Value` in `s_and_b64` and `v_cndmask_b32`, so overwriting the high dword of a saved or derived wave64 mask still produced a valid `Sym::Red`. ### Fix - Seed `uni` with section-start `EXEC`/`EXEC+1` constant values (`u32::MAX`) and update `uni` on mid-section constant `s_mov_b*` writes to `EXEC`/`EXEC+1`. - Track `(Value, Option<Value>)` mask pairs in `masked`, require 64-bit start, restore, and `s_and_b64` in wave64, and match both low and high dwords in `s_and_b64` and `v_cndmask_b32`. ### Verification - `cargo test -p victory-shader --locked -- emit::wave emit::wave64_tests`: `15 passed; 0 failed` (including new tests `in_section_exec_reads_export_section_constants` and `wave64_mask_checks_high_dword_and_rejects_32bit_ops`). - `cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings`: 0 warnings. - `cargo xtask policy`: `171 files ok`. *(AI-assisted; synthetic unit tests only, no game data.)*
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/759:upstream-pr/759'
git switch 'upstream-pr/759'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/759'
git switch 'upstream-pr/759'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/759'
git switch 'upstream-pr/759'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/759'
git switch 'main'
git merge --squash 'upstream-pr/759'
git switch 'main'
git merge --ff-only 'upstream-pr/759'
git switch 'main'
git merge 'upstream-pr/759'
git push origin 'main'
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
fxceless/victory-fork!759
No description provided.