shader: lower lane-mask phis, post-loop ballots, and wave32 movk masks #541

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

@⁠Sheffy007 on GitHub · 2026-11-28 01:32 UTC · original
Sheffy007:feat/lane-mask-phi-data → main · +1431 −34 · 5 files · 1 commits · open

Closes #528
Refs #4, #258, #525

Problem

  1. "a lane mask holding lanes elsewhere read as data: a program input" (93 shaders in the 28 November corpus, 32 in #521): Lower::mask_number searched only p.blocks[b].insts for masks outside st.active, so any lane-mask Phi node outside a uniform_join failed with .ok_or(INPUT).
  2. Loop-carried false-resolved mask accumulators in st.active: when Lanes::join resolved a loop-header mask phi to Bool::FALSE (which holds only in lanes still looping, not in lanes that exited on earlier iterations), downstream s_or accumulators (s_next = s_phi | vcc) entered st.active and were balloted inside the divergent loop instead of at OEND (refusing split wave64 with DIVERGENT_EXCHANGE or dropping earlier iterations' bits).
  3. "written by a scalar instruction of the other width" (5 shaders in #521): wave32 s_movk_i32 / s_cmovk_i32 masks tracked in Lanes::sop missed the _b32 suffix strip in Lower::mask_number.

Changes

  • crates/victory-shader/src/structure.rs (Lanes::exec_copies_at_joins):
    • Strips copies (s_mov, three-XOR swaps, constant-lane VGPR spills) on both EXEC and candidate SGPR pairs and solves coinductively across joins so loop-header EXEC shadows restored via s_mov exec, s or nested loops enter st.active.
    • Removes masks carrying inactive 1-bits from back-edge Bool::FALSE-resolved loop joins out of st.active.
  • crates/victory-shader/src/emit/lower.rs:
    • unchanged_mask_pair: evaluates phi webs whose live edges copy a single strictly-dominating mask pair directly to that pair's dwords (including inside divergent loops).
    • phi_mask_number & post_loop_inst_ballot: ballots wave-converged mask phis and post-loop inactive-preserving loop masks (s_or/s_xor/s_andn2 with active-subset masks, including multi-exit linear chains) via wide_ballot at the wave-converged join, refusing joins where skipped arms or back-edges alter inactive lanes' bits as "a lane mask holding lanes elsewhere read as data: a divergent join".
    • loop_local_mask_phi (fill_phis): lowers single-preheader, single-latch loop mask accumulators whose scalar values never escape the natural loop (except pure EXEC restores).
    • Wave32 s_movk_i32 / s_cmovk_i32: lowers in mask_number (restricting MaskData::Host to 0 and -1).
  • docs/native-host.md: documents the new shapes and refusal boundary.

Verification

  • cargo xtask policy
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings
  • cargo clippy --workspace --all-targets --all-features --locked --target x86_64-pc-windows-gnullvm -- -D warnings
  • cargo test -p victory-shader (mask_tests::lane_mask_phis_and_post_loop_ballots_lower_and_reject_unsound_divergent_joins)
  • Metal GPU value test: cargo test -p victory-gpu lane_mask_phis_post_loop_ballots_and_wave32_movk_masks_run_on_the_gpu (128-thread split-wave64 fast path + wave32 flag=0,1)
  • git merge-tree --write-tree clean against all open shader PRs (#433, #464, #512, #516, #523)

cc @⁠Olima34

**@⁠Sheffy007** on GitHub · 2026-11-28 01:32 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/537) `Sheffy007:feat/lane-mask-phi-data` → `main` · +1431 −34 · 5 files · 1 commits · open Closes #528 Refs #4, #258, #525 ## Problem 1. **`"a lane mask holding lanes elsewhere read as data: a program input"`** (93 shaders in the 28 November corpus, 32 in `#521`): `Lower::mask_number` searched only `p.blocks[b].insts` for masks outside `st.active`, so any lane-mask `Phi` node outside a `uniform_join` failed with `.ok_or(INPUT)`. 2. **Loop-carried `false`-resolved mask accumulators in `st.active`**: when `Lanes::join` resolved a loop-header mask phi to `Bool::FALSE` (which holds only in lanes still looping, not in lanes that exited on earlier iterations), downstream `s_or` accumulators (`s_next = s_phi | vcc`) entered `st.active` and were balloted inside the divergent loop instead of at `OEND` (refusing split wave64 with `DIVERGENT_EXCHANGE` or dropping earlier iterations' bits). 3. **`"written by a scalar instruction of the other width"`** (5 shaders in `#521`): wave32 `s_movk_i32` / `s_cmovk_i32` masks tracked in `Lanes::sop` missed the `_b32` suffix strip in `Lower::mask_number`. ## Changes - **`crates/victory-shader/src/structure.rs` (`Lanes::exec_copies_at_joins`)**: - Strips copies (`s_mov`, three-XOR swaps, constant-lane VGPR spills) on both `EXEC` and candidate SGPR pairs and solves coinductively across joins so loop-header `EXEC` shadows restored via `s_mov exec, s` or nested loops enter `st.active`. - Removes masks carrying inactive `1`-bits from back-edge `Bool::FALSE`-resolved loop joins out of `st.active`. - **`crates/victory-shader/src/emit/lower.rs`**: - **`unchanged_mask_pair`**: evaluates phi webs whose live edges copy a single strictly-dominating mask pair directly to that pair's dwords (including inside divergent loops). - **`phi_mask_number` & `post_loop_inst_ballot`**: ballots wave-converged mask phis and post-loop inactive-preserving loop masks (`s_or`/`s_xor`/`s_andn2` with active-subset masks, including multi-exit linear chains) via `wide_ballot` at the wave-converged join, refusing joins where skipped arms or back-edges alter inactive lanes' bits as `"a lane mask holding lanes elsewhere read as data: a divergent join"`. - **`loop_local_mask_phi` (`fill_phis`)**: lowers single-preheader, single-latch loop mask accumulators whose scalar values never escape the natural loop (except pure `EXEC` restores). - **Wave32 `s_movk_i32` / `s_cmovk_i32`**: lowers in `mask_number` (restricting `MaskData::Host` to `0` and `-1`). - **`docs/native-host.md`**: documents the new shapes and refusal boundary. ## Verification - `cargo xtask policy` - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings` - `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings` - `cargo clippy --workspace --all-targets --all-features --locked --target x86_64-pc-windows-gnullvm -- -D warnings` - `cargo test -p victory-shader` (`mask_tests::lane_mask_phis_and_post_loop_ballots_lower_and_reject_unsound_divergent_joins`) - Metal GPU value test: `cargo test -p victory-gpu lane_mask_phis_post_loop_ballots_and_wave32_movk_masks_run_on_the_gpu` (128-thread split-wave64 fast path + wave32 `flag=0,1`) - `git merge-tree --write-tree` clean against all open shader PRs (`#433`, `#464`, `#512`, `#516`, `#523`) cc @⁠Olima34
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 01:36:50 +00:00
Author
Owner

@⁠Olima34 on GitHub · 2026-11-28 03:52 UTC · original · requested changes

Thanks @⁠Sheffy007. This goes after one of the biggest refusal families we see, and the coinductive solve for loop-header EXEC shadows reads right to us. We swept a43bea1a over our boot corpora by output fingerprint (victory-shader's sweep example, -j 4, 120 s per shader), against main at a6a58361. There's been no translator change on main since. One thing needs fixing before it can merge.

Translation now times out on 28 compute shaders that main refuses quickly. In both corpora the tool stops them at its 120 s limit (timeout: no result after 120 s):

corpus shaders newly translated regressions output changed refused for another reason now timeouts (main: 0)
A (4,921, boot set) ok 4,251 → 4,252 1 (pixel) 0 13 (compute) 175 (compute) 6
B (4,129, refused set) ok 2,572 → 2,594 22 (pixel) 0 6 (compute) 230 (compute) 22

On main the A six were refused as "a lane-mask join of an untracked mask: a value the translation could not make" (3) or "…: data, at a join of several edges" (3). The 22 on B are all refused on main. Hashes: compute_064fdbe47a08a167, compute_09d594eb56c883c0, compute_11de67113e9eaaa0, compute_699291be9cef22ca, compute_786d6c676336f9ac, compute_e17e4da18a87461b (in both), plus compute_0fce298841f3b454, compute_14f5f388b65f9c2e, compute_15e5a72f41e40d8d, compute_17a4df8a5021087d, compute_1a9863eef9ac19fb, compute_1cdd0fa84d75a465, compute_2085b1b9df027b27, compute_216c04a7da821cca, compute_2588e499202c1588, compute_32fc68148d1bfb7f, compute_75ebd268f5a453d1, compute_870e3d265b593b4b, compute_9155c0be0cbc67fd, compute_9b9cfe1d5814f0fb, compute_c3a6e19d9b92885f, compute_cf6f7b3ef1905eff.

In a game run, a shader that takes minutes to translate holds a pipeline-compile thread. It also holds up the frame that needs it, so the title's 30 s watchdog would fire before it gets refused. We haven't profiled which part loops. The new fixed points (the cands retain loop and the exited_false propagation in exec_copies_at_joins) and the phi-web walks in unchanged_mask_pair / phi_mask_number look like the places to bound. A step limit that refuses ("… too many steps") would be fine; so would a cache, if the walks repeat work. A test that one of these shapes finishes quickly would pin it.

Also worth confirming when you update: the 13 + 6 changed outputs are all compute. We read them as programs that go through the new phi or post-loop ballot path instead of the old lowering; if that's right, a line in the PR saying so is enough. The 159 that now say "a divergent join" instead of "a program input" match your description.

The world corpus (21,600 shaders) sweep is still running; we'll add its numbers here when it finishes. CI is green on this head. No game run on our side.

**@⁠Olima34** on GitHub · 2026-11-28 03:52 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/537#pullrequestreview-6095580135) · **requested changes** Thanks @⁠Sheffy007. This goes after one of the biggest refusal families we see, and the coinductive solve for loop-header EXEC shadows reads right to us. We swept a43bea1a over our boot corpora by output fingerprint (`victory-shader`'s `sweep` example, `-j 4`, 120 s per shader), against main at a6a58361. There's been no translator change on main since. One thing needs fixing before it can merge. **Translation now times out on 28 compute shaders that main refuses quickly.** In both corpora the tool stops them at its 120 s limit (`timeout: no result after 120 s`): | corpus | shaders | newly translated | regressions | output changed | refused for another reason now | timeouts (main: 0) | |---|---|---|---|---|---|---| | A (4,921, boot set) | ok 4,251 → 4,252 | 1 (pixel) | 0 | 13 (compute) | 175 (compute) | 6 | | B (4,129, refused set) | ok 2,572 → 2,594 | 22 (pixel) | 0 | 6 (compute) | 230 (compute) | 22 | On main the A six were refused as "a lane-mask join of an untracked mask: a value the translation could not make" (3) or "…: data, at a join of several edges" (3). The 22 on B are all refused on main. Hashes: compute_064fdbe47a08a167, compute_09d594eb56c883c0, compute_11de67113e9eaaa0, compute_699291be9cef22ca, compute_786d6c676336f9ac, compute_e17e4da18a87461b (in both), plus compute_0fce298841f3b454, compute_14f5f388b65f9c2e, compute_15e5a72f41e40d8d, compute_17a4df8a5021087d, compute_1a9863eef9ac19fb, compute_1cdd0fa84d75a465, compute_2085b1b9df027b27, compute_216c04a7da821cca, compute_2588e499202c1588, compute_32fc68148d1bfb7f, compute_75ebd268f5a453d1, compute_870e3d265b593b4b, compute_9155c0be0cbc67fd, compute_9b9cfe1d5814f0fb, compute_c3a6e19d9b92885f, compute_cf6f7b3ef1905eff. In a game run, a shader that takes minutes to translate holds a pipeline-compile thread. It also holds up the frame that needs it, so the title's 30 s watchdog would fire before it gets refused. We haven't profiled which part loops. The new fixed points (the `cands` retain loop and the `exited_false` propagation in `exec_copies_at_joins`) and the phi-web walks in `unchanged_mask_pair` / `phi_mask_number` look like the places to bound. A step limit that refuses ("… too many steps") would be fine; so would a cache, if the walks repeat work. A test that one of these shapes finishes quickly would pin it. Also worth confirming when you update: the 13 + 6 changed outputs are all compute. We read them as programs that go through the new phi or post-loop ballot path instead of the old lowering; if that's right, a line in the PR saying so is enough. The 159 that now say "a divergent join" instead of "a program input" match your description. The world corpus (21,600 shaders) sweep is still running; we'll add its numbers here when it finishes. CI is green on this head. No game run on our side.
Author
Owner

@⁠alexballvideos-netizen on GitHub · 2026-11-28 04:56 UTC · original

Swept #541 (head a43bea1a, merged onto main 61f55a49) over a 21,579-shader world corpus (Series X, 1.0.2.1) with examples/sweep -j 4 (120 s per-shader limit), on an M3 Max.

main #541
translated 20,022 20,044
refused 1,557 1,502
timeout 0 33
  • Newly translated: 22 pixel shaders. On main they were refused for "a lane mask holding lanes elsewhere read as data": 14 for "not written by a scalar ALU instruction", 6 for "shifted on the host's lanes" and 2 for "a program input".
  • Lost: 0
  • Output changed: 15 (13 compute, 2 pixel)
  • Refused for another reason now: 207. 194 of them now stop at "a lane mask holding lanes elsewhere read as data: a divergent join", and 12 at "an image's dwords 5 to 7".

Compile-time regression: 33 compute shaders hit the 120 s limit. All 33 are refused on main within 2.4–4.6 s, 28 of them for "a lane-mask join of an untracked mask: data, at a join of several edges", 3 for "… a value the translation could not make" and 2 for "… a program input".

I reran 4 of them with a 15-minute limit. They don't hang: they finish, but take 40–50× as long, and end in the same refusal at the same address as on main:

shader main #541 result on both
compute_064fdbe47a08a167 3.7 s 168.8 s refused at 0x20b04
compute_09d594eb56c883c0 2.6 s 132.6 s refused at 0x16270
compute_0fce298841f3b454 2.9 s 121.5 s refused at 0x13dc0
compute_11de67113e9eaaa0 3.2 s 130.1 s refused at 0x198ac

(4 at a time; peak memory 525 MB.) These are large programs, with the refusal 80–130 KB into the code, so my guess is that the new fixed-point solve over joins in Lanes::exec_copies_at_joins grows much faster than linearly with block count on them. In game, that would stall pipeline creation for minutes for nothing, since they're refused anyway. Maybe an iteration cap, or bailing out early once a join is already untranslatable, would fix it?

All 33: compute_064fdbe47a08a167 compute_09d594eb56c883c0 compute_0fce298841f3b454 compute_11de67113e9eaaa0 compute_14f5f388b65f9c2e compute_15e5a72f41e40d8d compute_17a4df8a5021087d compute_1cdd0fa84d75a465 compute_2085b1b9df027b27 compute_216c04a7da821cca compute_32fc68148d1bfb7f compute_4a21d2a690e7db0a compute_56844698dd8fe19d compute_60997e6e9889a7d2 compute_699291be9cef22ca compute_75ebd268f5a453d1 compute_786d6c676336f9ac compute_870e3d265b593b4b compute_9155c0be0cbc67fd compute_9b9cfe1d5814f0fb compute_9dfa5e1db805f2fb compute_a562d1df29fe914e compute_ad5eae8c99a89f95 compute_c1966eda2faae302 compute_c3a6e19d9b92885f compute_cf6f7b3ef1905eff compute_d7360989b053cee0 compute_df8cffc3cf672be5 compute_e17e4da18a87461b compute_f016b01dc08e831c compute_f9a80955fd1cb648 compute_fb8d942443fe0592 compute_fd4b08d1534e1ec0

I can rerun any of them or time a fix.

**@⁠alexballvideos-netizen** on GitHub · 2026-11-28 04:56 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/537#issuecomment-7234349985) Swept #541 (head `a43bea1a`, merged onto main `61f55a49`) over a 21,579-shader world corpus (Series X, 1.0.2.1) with `examples/sweep -j 4` (120 s per-shader limit), on an M3 Max. | | main | #541 | |---|---|---| | translated | 20,022 | 20,044 | | refused | 1,557 | 1,502 | | timeout | 0 | 33 | - **Newly translated: 22 pixel shaders.** On main they were refused for "a lane mask holding lanes elsewhere read as data": 14 for "not written by a scalar ALU instruction", 6 for "shifted on the host's lanes" and 2 for "a program input". - **Lost:** 0 - **Output changed:** 15 (13 compute, 2 pixel) - **Refused for another reason now:** 207. 194 of them now stop at "a lane mask holding lanes elsewhere read as data: a divergent join", and 12 at "an image's dwords 5 to 7". **Compile-time regression: 33 compute shaders hit the 120 s limit.** All 33 are refused on main within 2.4–4.6 s, 28 of them for "a lane-mask join of an untracked mask: data, at a join of several edges", 3 for "… a value the translation could not make" and 2 for "… a program input". I reran 4 of them with a 15-minute limit. They don't hang: they finish, but take 40–50× as long, and end in **the same refusal at the same address** as on main: | shader | main | #541 | result on both | |---|---|---|---| | `compute_064fdbe47a08a167` | 3.7 s | 168.8 s | refused at 0x20b04 | | `compute_09d594eb56c883c0` | 2.6 s | 132.6 s | refused at 0x16270 | | `compute_0fce298841f3b454` | 2.9 s | 121.5 s | refused at 0x13dc0 | | `compute_11de67113e9eaaa0` | 3.2 s | 130.1 s | refused at 0x198ac | (4 at a time; peak memory 525 MB.) These are large programs, with the refusal 80–130 KB into the code, so my guess is that the new fixed-point solve over joins in `Lanes::exec_copies_at_joins` grows much faster than linearly with block count on them. In game, that would stall pipeline creation for minutes for nothing, since they're refused anyway. Maybe an iteration cap, or bailing out early once a join is already untranslatable, would fix it? All 33: compute_064fdbe47a08a167 compute_09d594eb56c883c0 compute_0fce298841f3b454 compute_11de67113e9eaaa0 compute_14f5f388b65f9c2e compute_15e5a72f41e40d8d compute_17a4df8a5021087d compute_1cdd0fa84d75a465 compute_2085b1b9df027b27 compute_216c04a7da821cca compute_32fc68148d1bfb7f compute_4a21d2a690e7db0a compute_56844698dd8fe19d compute_60997e6e9889a7d2 compute_699291be9cef22ca compute_75ebd268f5a453d1 compute_786d6c676336f9ac compute_870e3d265b593b4b compute_9155c0be0cbc67fd compute_9b9cfe1d5814f0fb compute_9dfa5e1db805f2fb compute_a562d1df29fe914e compute_ad5eae8c99a89f95 compute_c1966eda2faae302 compute_c3a6e19d9b92885f compute_cf6f7b3ef1905eff compute_d7360989b053cee0 compute_df8cffc3cf672be5 compute_e17e4da18a87461b compute_f016b01dc08e831c compute_f9a80955fd1cb648 compute_fb8d942443fe0592 compute_fd4b08d1534e1ec0 I can rerun any of them or time a fix.
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/541/head:github-bot/gh-537'
git switch 'github-bot/gh-537'

Merge

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