Shaders/own_bits: reject escaping non-test lane masks written outside the loop body #789

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

@⁠AscilCH on GitHub · 2026-11-25 07:35 UTC · original
AscilCH:fix/shader-own-bits-non-test-mask-leaves → main · +72 −3 · 1 files · 1 commits · open

Summary

Fix an unsoundness hole in own_bits::Ctx::site (crates/victory-shader/src/emit/own_bits.rs):

  • The LEAVES check unconditionally skipped every is_mask(w) write outside the loop body (lp/pre), relying on the STALE check to catch escaping masks.
  • However, STALE seeded dep only with tests (v_cmp_ne (x & bit), 0). Any other lane mask written outside the body (such as v_cmp_eq_u32 s[14:15], s10, v0 in the latch depending on the round's bit index s10) was exempted from LEAVES and absent from STALE, allowing round-dependent masks to escape into post-loop instructions or guards even though wave64 and two split wave32 halves visit different rounds.

Changes

  • In LEAVES, only exempt an is_mask(w) write when its boolean support contains no atom defined inside lp or pre (preserving loop-invariant outer-EXEC saves while checking loop-dependent masks).
  • Seed dep with fresh Atom::Lane/Atom::Quad/Atom::Opaque atoms defined by non-body instructions inside lp so indirect escapes through EXEC or st.phi_masks into post-loop guards/exits are also caught by STALE.
  • Add own_bits::tests::a_non_test_mask_written_in_latch_cannot_escape_after_loop testing both direct post-loop v_cndmask_b32 reads and indirect escapes via s_and_saveexec_b64.

Verification

  • cargo test -p victory-shader --locked -- own_bits: 7 passed; 0 failed; 0 ignored.
  • cargo test -p victory-shader --locked -- wave64: 7 passed; 0 failed; 0 ignored.
  • 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 07:35 UTC · [original](https://github.com/fxceless/victory-fork/pull/789) `AscilCH:fix/shader-own-bits-non-test-mask-leaves` → `main` · +72 −3 · 1 files · 1 commits · open ## Summary Fix an unsoundness hole in `own_bits::Ctx::site` (`crates/victory-shader/src/emit/own_bits.rs`): - The `LEAVES` check unconditionally skipped every `is_mask(w)` write outside the loop body (`lp`/`pre`), relying on the `STALE` check to catch escaping masks. - However, `STALE` seeded `dep` only with `tests` (`v_cmp_ne (x & bit), 0`). Any other lane mask written outside the body (such as `v_cmp_eq_u32 s[14:15], s10, v0` in the latch depending on the round's bit index `s10`) was exempted from `LEAVES` and absent from `STALE`, allowing round-dependent masks to escape into post-loop instructions or guards even though wave64 and two split wave32 halves visit different rounds. ### Changes - In `LEAVES`, only exempt an `is_mask(w)` write when its boolean support contains no atom defined inside `lp` or `pre` (preserving loop-invariant outer-`EXEC` saves while checking loop-dependent masks). - Seed `dep` with fresh `Atom::Lane`/`Atom::Quad`/`Atom::Opaque` atoms defined by non-body instructions inside `lp` so indirect escapes through `EXEC` or `st.phi_masks` into post-loop guards/exits are also caught by `STALE`. - Add `own_bits::tests::a_non_test_mask_written_in_latch_cannot_escape_after_loop` testing both direct post-loop `v_cndmask_b32` reads and indirect escapes via `s_and_saveexec_b64`. ## Verification - `cargo test -p victory-shader --locked -- own_bits`: `7 passed; 0 failed; 0 ignored`. - `cargo test -p victory-shader --locked -- wave64`: `7 passed; 0 failed; 0 ignored`. - `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.)*
In `own_bits::Ctx::site` (`crates/victory-shader/src/emit/own_bits.rs`), the
`LEAVES` check unconditionally skipped every `is_mask(w)` write in `lp`/`pre`,
assuming the `STALE` check would catch escaping masks. However, `STALE` seeded
`dep` only with `tests` (`v_cmp_ne (x & bit), 0`).

As a result, any other lane mask written outside the body in `lp` or `pre`
(for example `v_cmp_eq_u32 s[14:15], s10, v0` in the latch, which depends on
the round's bit index `s10`) was exempted from `LEAVES` and absent from `STALE`,
allowing round-dependent masks to escape into post-loop instructions or guards
even though wave64 and two independent wave32 halves visit different rounds.

1. In `LEAVES`, only exempt an `is_mask(w)` write when its boolean support
   contains no atom defined inside `lp` or `pre` (preserving loop-invariant
   outer-`EXEC` saves while checking loop-dependent masks).
2. Seed `dep` with any fresh `Atom::Lane(w)` defined by a non-body instruction
   inside `lp`, so indirect escapes via `EXEC` or `st.phi_masks` into post-loop
   guards/exits are also caught by `STALE`.

Add `own_bits::tests::a_non_test_mask_written_in_latch_cannot_escape_after_loop`
covering both direct post-loop `v_cndmask_b32` reads and indirect escapes via
`s_and_saveexec_b64` guards.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:51:11 +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/789/head:github-bot/gh-789'
git switch 'github-bot/gh-789'

Merge

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