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

Open
AscilCH wants to merge 1 commit from upstream-pr/713 into main
AscilCH commented 2026-11-25 05:20:41 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by AscilCH on 2026-11-25T05:20:41Z.


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

<!-- greyfinch-sync:fxceless/victory-fork:issue:6597795190 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/713). Originally posted by [AscilCH](https://github.com/AscilCH) on 2026-11-25T05:20:41Z. --- ### 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.)*
JRamos1993 commented 2026-11-25 06:06:40 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by JRamos1993 on 2026-11-25T05:54:49Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7154258324 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/713#issuecomment-7154258324). Originally posted by [JRamos1993](https://github.com/JRamos1993) on 2026-11-25T05:54:49Z. --- **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 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/713:upstream-pr/713'
git switch 'upstream-pr/713'

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