Shaders/own_bits: fix STALE taint propagation for control-dependent and loop-carried mask phis #441

Open
AscilCH wants to merge 1 commit from upstream-pr/441 into main
AscilCH commented 2026-11-25 00:52:28 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by AscilCH on 2026-11-25T00:52:28Z.


Problem

In crates/victory-shader/src/emit/own_bits.rs, Ctx::site enforces that no lane mask depending on the own-bit test outlives its round (STALE), because host waves of 32 lanes may execute a different set of rounds than a 64-lane console wave. Three gaps let tainted masks escape that check:

  1. Missing control-dependence in dep propagation: st.phi_masks stores each incoming mask simplified under its edge condition (b.given(m, edge)). When a mask is assigned inside the own-bit body (e.g., s_mov_b64 s[14:15], exec or s_mov_b64 s[14:15], -1), given(m, edge) folds to Bool::TRUE, leaving no test atom in the edge value's support even though which edge is taken depends on the own-bit test.
  2. Whole-loop skip when tb == h: The block check skipped every block b in lp with self.dominates(tb, b). When the own-bit test lives in the loop header (tb == h), that skips every block in lp — including guards before ti in tb and loop-header mask phis carrying a previous round's mask.
  3. Unchecked loop-header phi users: The st.masks user loop only flagged User::Phi(b2, k2) when !lp[b2], allowing tainted masks to flow into live loop-header phis at b2 == h.

Fix

  • Propagate control-dependent taint through st.phi_masks when a phi's incoming edge masks are not all equal and any predecessor's st.reach[q] or st.exits[q] branch condition is tainted.
  • Reject (Err((head, STALE))) if any loop-header phi at h has Atom::Phi(phi.value) in dep.
  • Check per-instruction guards (st.guards[b][i]) and st.masks instruction users against instruction-level dominance after (tb, ti) (b == tb && i > ti || b != tb && self.dominates(tb, b)).
  • Flag live User::Phi(b2, k2) users of tainted masks when !lp[b2] || b2 == h.
  • Add synthetic unit test a_test_dependent_mask_carried_across_rounds_is_stale covering control-dependent loop-carried, control-dependent post-loop, and direct data-dependent loop-carried tainted masks.

Verification

  • cargo test -p victory-shader --locked own_bits: 7 passed, 0 failed
  • cargo xtask policy: 169 files ok
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings: clean
  • cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings: clean

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

<!-- greyfinch-sync:fxceless/victory-fork:issue:6594583057 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/441). Originally posted by [AscilCH](https://github.com/AscilCH) on 2026-11-25T00:52:28Z. --- ## Problem In `crates/victory-shader/src/emit/own_bits.rs`, `Ctx::site` enforces that no lane mask depending on the own-bit test outlives its round (`STALE`), because host waves of 32 lanes may execute a different set of rounds than a 64-lane console wave. Three gaps let tainted masks escape that check: 1. **Missing control-dependence in `dep` propagation**: `st.phi_masks` stores each incoming mask simplified under its edge condition (`b.given(m, edge)`). When a mask is assigned inside the own-bit body (e.g., `s_mov_b64 s[14:15], exec` or `s_mov_b64 s[14:15], -1`), `given(m, edge)` folds to `Bool::TRUE`, leaving no test atom in the edge value's support even though which edge is taken depends on the own-bit test. 2. **Whole-loop skip when `tb == h`**: The block check skipped every block `b` in `lp` with `self.dominates(tb, b)`. When the own-bit test lives in the loop header (`tb == h`), that skips every block in `lp` — including guards before `ti` in `tb` and loop-header mask phis carrying a previous round's mask. 3. **Unchecked loop-header phi users**: The `st.masks` user loop only flagged `User::Phi(b2, k2)` when `!lp[b2]`, allowing tainted masks to flow into live loop-header phis at `b2 == h`. ## Fix - Propagate control-dependent taint through `st.phi_masks` when a phi's incoming edge masks are not all equal and any predecessor's `st.reach[q]` or `st.exits[q]` branch condition is tainted. - Reject (`Err((head, STALE))`) if any loop-header phi at `h` has `Atom::Phi(phi.value)` in `dep`. - Check per-instruction guards (`st.guards[b][i]`) and `st.masks` instruction users against instruction-level dominance after `(tb, ti)` (`b == tb && i > ti || b != tb && self.dominates(tb, b)`). - Flag live `User::Phi(b2, k2)` users of tainted masks when `!lp[b2] || b2 == h`. - Add synthetic unit test `a_test_dependent_mask_carried_across_rounds_is_stale` covering control-dependent loop-carried, control-dependent post-loop, and direct data-dependent loop-carried tainted masks. ## Verification - `cargo test -p victory-shader --locked own_bits`: 7 passed, 0 failed - `cargo xtask policy`: 169 files ok - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings`: clean - `cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings`: clean *(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/441:upstream-pr/441'
git switch 'upstream-pr/441'

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/441'
git switch 'upstream-pr/441'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/441'
git switch 'upstream-pr/441'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/441'
git switch 'main'
git merge --squash 'upstream-pr/441'
git switch 'main'
git merge --ff-only 'upstream-pr/441'
git switch 'main'
git merge 'upstream-pr/441'
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!441
No description provided.