Shaders: validate active masks against block reachability and respect wide branches in resource tracking #713

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

@⁠AscilCH on GitHub · 2026-11-25 05:20 UTC · original
AscilCH:fix/shader-structure-active-mask-and-resource-wide-edge → main · +145 −12 · 2 files · 1 commits · open

Summary

Fixes two lane-mask soundness bugs in crates/victory-shader:

  1. Structured::active unsound for widened EXEC inside divergent blocks (crates/victory-shader/src/structure.rs):
    • mask_dword() (emit/lower.rs) emits waveActiveBallot at a mask's defining block whenever st.active.contains(&lo), which is only sound if every lane where the mask can be set actually executes that defining block (m => cond[def_block]).
    • step() and v_cmp_* previously inserted r.exec, masks implying mutable now, and VALU compares under widened EXEC into self.active even inside a divergent block where cond[def_block] is strictly narrower than m, causing waveActiveBallot to silently zero inactive lanes.
    • finish() now filters self.active after cond converges, retaining a mask only when self.b.implies(m, cond[def_block]) (keeping entry EXEC inputs unconditionally).
  2. only_edge() and lane_phi() ignored lanes.wide (crates/victory-shader/src/resource.rs):
    • Unlike structure.rs::edge(), only_edge() and lane_phi() pushed (when, taken == block) onto known for every LaneExit::Branch even when lanes.wide.contains(&q).
    • On a wave-wide branch, every lane follows the wave's branch together regardless of its individual when bit. Adding !lanes.wide.contains(&q) prevents falsely collapsing a descriptor join onto one predecessor or dropping a live LanePhi incoming edge as None (which lowers as heap index 0).

Verification

  • cargo test -p victory-shader --locked -- structure::tests resource::tests emit::lower::tests emit::waterfall_tests emit::wave64_tests: 70 passed, 0 failed, 1 ignored (including new tests widened_exec_inside_divergent_branch_is_not_active and wide_branch_does_not_drop_predecessor_edges_in_only_edge_or_lane_phi)
  • cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings: clean (0 warnings)
  • cargo xtask policy: 169 files ok

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

**@⁠AscilCH** on GitHub · 2026-11-25 05:20 UTC · [original](https://github.com/fxceless/victory-fork/pull/713) `AscilCH:fix/shader-structure-active-mask-and-resource-wide-edge` → `main` · +145 −12 · 2 files · 1 commits · open ### Summary Fixes two lane-mask soundness bugs in `crates/victory-shader`: 1. **`Structured::active` unsound for widened `EXEC` inside divergent blocks** (`crates/victory-shader/src/structure.rs`): - `mask_dword()` (`emit/lower.rs`) emits `waveActiveBallot` at a mask's defining block whenever `st.active.contains(&lo)`, which is only sound if every lane where the mask can be set actually executes that defining block (`m => cond[def_block]`). - `step()` and `v_cmp_*` previously inserted `r.exec`, masks implying mutable `now`, and VALU compares under widened `EXEC` into `self.active` even inside a divergent block where `cond[def_block]` is strictly narrower than `m`, causing `waveActiveBallot` to silently zero inactive lanes. - `finish()` now filters `self.active` after `cond` converges, retaining a mask only when `self.b.implies(m, cond[def_block])` (keeping entry `EXEC` inputs unconditionally). 2. **`only_edge()` and `lane_phi()` ignored `lanes.wide`** (`crates/victory-shader/src/resource.rs`): - Unlike `structure.rs::edge()`, `only_edge()` and `lane_phi()` pushed `(when, taken == block)` onto `known` for every `LaneExit::Branch` even when `lanes.wide.contains(&q)`. - On a wave-wide branch, every lane follows the wave's branch together regardless of its individual `when` bit. Adding `!lanes.wide.contains(&q)` prevents falsely collapsing a descriptor join onto one predecessor or dropping a live `LanePhi` incoming edge as `None` (which lowers as heap index `0`). ### Verification - `cargo test -p victory-shader --locked -- structure::tests resource::tests emit::lower::tests emit::waterfall_tests emit::wave64_tests`: **70 passed, 0 failed, 1 ignored** (including new tests `widened_exec_inside_divergent_branch_is_not_active` and `wide_branch_does_not_drop_predecessor_edges_in_only_edge_or_lane_phi`) - `cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings`: clean (0 warnings) - `cargo xtask policy`: `169 files ok` *(AI-assisted; synthetic unit tests only, no game data.)*
Fixes two lane-mask analysis bugs in `crates/victory-shader`:
1. `structure.rs`: `step()` previously inserted widened `EXEC` writes,
   masks derived from mutable `now`, and `v_cmp_*` results into
   `Structured::active` even when written inside a divergent block where
   only `cond[block]` lanes run. In DXIL, `mask_dword()` emits
   `waveActiveBallot` at the defining block, which silently drops lanes
   outside `cond[block]`. Filter `active` in `finish()` after `cond`
   converges, keeping a mask only when `self.b.implies(m, cond[def_block])`.
2. `resource.rs`: `only_edge()` and `lane_phi()` previously constrained
   `known` with `(when, taken == block)` on every `LaneExit::Branch`,
   ignoring `lanes.wide.contains(&q)` (unlike `structure.rs::edge`). When
   block `q` is a wave-wide branch, all lanes take the same edge together
   regardless of each lane's `when` bit; assuming per-lane constraints could
   collapse a join onto the wrong predecessor or drop a live `LanePhi` edge
   as `None` (heap index 0). Guard both sites with `!lanes.wide.contains(&q)`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:49:29 +00:00
Author
Owner

@⁠JRamos1993 on GitHub · 2026-11-25 05:54 UTC · original

Offline check on the retail shader pack: this PR loses 1,289 programs that validate on main. All of them now stop with "a lane mask holding lanes elsewhere read as data".

Setup: RTX 5090, Windows 11. victory translate --validate --list over the title's full shader pack (26,084 programs), main 310c6eb against this head merged onto it, default settings.

main 310c6eb this PR
validated 25,382 24,093
newly validated 0
lost 1,289

Where the 1,289 now stop:

stage programs reason
compute 897 emit: a lane mask holding lanes elsewhere read as data
pixel 386 same
mesh 6 same

The programs that still validate emit byte-identical DXIL to main.

My reading, not checked line by line: the narrower Structured::active set leaves those masks out. Lower::mask_dword then no longer takes them as a ballot of the running lanes, and refuses the read. If the narrower set is right in general, these 1,289 programs would need another way to read their masks before this can land.

AI use: Claude Code with Claude Opus 5.5 ran the pack and wrote this. Nothing from the title is in it.

**@⁠JRamos1993** on GitHub · 2026-11-25 05:54 UTC · [original](https://github.com/fxceless/victory-fork/pull/713#issuecomment-7154258324) **Offline check on the retail shader pack: this PR loses 1,289 programs that validate on `main`.** All of them now stop with "a lane mask holding lanes elsewhere read as data". **Setup:** RTX 5090, Windows 11. `victory translate --validate --list` over the title's full shader pack (26,084 programs), `main` `310c6eb` against this head merged onto it, default settings. | | `main` `310c6eb` | this PR | |---|---|---| | validated | 25,382 | **24,093** | | newly validated | | 0 | | lost | | **1,289** | Where the 1,289 now stop: | stage | programs | reason | |---|---|---| | compute | 897 | `emit: a lane mask holding lanes elsewhere read as data` | | pixel | 386 | same | | mesh | 6 | same | The programs that still validate emit byte-identical DXIL to `main`. My reading, not checked line by line: the narrower `Structured::active` set leaves those masks out. `Lower::mask_dword` then no longer takes them as a ballot of the running lanes, and refuses the read. If the narrower set is right in general, these 1,289 programs would need another way to read their masks before this can land. AI use: Claude Code with Claude Opus 5.5 ran the pack and wrote this. Nothing from the title is in it.
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/713/head:github-bot/gh-713'
git switch 'github-bot/gh-713'

Merge

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