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

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

@⁠AscilCH on GitHub · 2026-11-25 06:44 UTC · original
AscilCH:fix/shader-wave-exec-uni-and-wave64-mask-pair → main · +178 −34 · 1 files · 1 commits · open

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

**@⁠AscilCH** on GitHub · 2026-11-25 06:44 UTC · [original](https://github.com/fxceless/victory-fork/pull/759) `AscilCH:fix/shader-wave-exec-uni-and-wave64-mask-pair` → `main` · +178 −34 · 1 files · 1 commits · open ### 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.)*
Two soundness bugs in crates/victory-shader/src/emit/wave.rs:

1. `simulate()` never inserted section-start `EXEC`/`EXEC+1` SSA values or
   mid-section `s_mov_b*` writes to `EXEC`/`EXEC+1` into `uni`. Any in-section
   instruction reading `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 then read as the divergent host
   `waveActiveBallot(true)` (or rejected) instead of the section's constant
   mask (`0xFFFF_FFFF` or the mid-section constant). Seed `uni` with the
   section-start `EXEC`/`EXEC+1` values and update it on mid-section constant
   writes.

2. In wave64, whole-wave mask tracking checked only the low dword (`Value`):
   - `sections()` accepted 32-bit `s_or_saveexec_b32`/`s_nand_saveexec_b32` and
     32-bit restores that leave `exec_hi` unmodified.
   - `simulate()` accepted 32-bit `s_and_b32` as a wave64 mask derivation and
     never verified `code + 1` in `s_and_b64` or `v_cndmask_b32`, so clobbering
     the high dword of a saved/derived mask still produced a valid `Sym::Red`.
   Track `(Value, Option<Value>)` mask pairs in `masked`, require 64-bit start,
   restore, and `s_and_b64` in wave64, and match both dwords in `s_and_b64` and
   `v_cndmask_b32`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:50:28 +00:00
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/759/head:github-bot/gh-759'
git switch 'github-bot/gh-759'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-759'
git switch 'github-bot/gh-759'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-759'
git switch 'github-bot/gh-759'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-759'
git switch 'main'
git merge --squash 'github-bot/gh-759'
git switch 'main'
git merge --ff-only 'github-bot/gh-759'
git switch 'main'
git merge 'github-bot/gh-759'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.