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

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

@⁠AscilCH on GitHub · 2026-11-25 00:52 UTC · original
AscilCH:fix/shader-own-bits-loop-carried-mask-stale → main · +181 −10 · 1 files · 1 commits · open

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

**@⁠AscilCH** on GitHub · 2026-11-25 00:52 UTC · [original](https://github.com/fxceless/victory-fork/pull/441) `AscilCH:fix/shader-own-bits-loop-carried-mask-stale` → `main` · +181 −10 · 1 files · 1 commits · open ## 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.)*
In `own_bits::Ctx::site`, the `STALE` check missed test-dependent lane masks that outlived their round in three ways:
1. `dep` propagation over `st.phi_masks` only checked the BDD support of incoming edge values, missing control-dependent mask phis whose per-edge `given(m, edge)` folded to constants (`TRUE`/`FALSE`) across a tainted branch or path.
2. The block check skipped every block in `lp` dominated by a test block `tb`. Because the own-bit test normally lives in the loop header (`tb == h`), `self.dominates(tb, b)` skipped every block in `lp`, including guards/uses before `ti` in `tb` and loop-carried mask phis at `h`.
3. The `st.masks` user check only flagged `User::Phi(b2, k2)` when `!lp[b2]`, ignoring live loop-header phis at `b2 == h`.

Propagate control-dependent taint into `st.phi_masks` when incoming edge values differ and a predecessor's reachability or branch condition is tainted, reject tainted loop-header mask phis at `h`, check guards and instruction mask users against instruction-level dominance after `(tb, ti)`, and treat live phi users at `h` as leaving the round. Add synthetic unit tests covering control-dependent loop-carried, control-dependent post-loop, and direct data-dependent loop-carried tainted masks.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:43:23 +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/441/head:github-bot/gh-441'
git switch 'github-bot/gh-441'

Merge

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