shader: two lane-mask joins in loops (the 'program input' refusal, and an execz skip's edge): 28 compute shaders translate #304

Merged
Olima34 merged 2 commits from upstream-pr/304 into main 2026-11-27 12:38:39 +00:00
Olima34 commented 2026-11-27 10:30:46 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-27T10:30:46Z.


Refs #4, #258.

The misleading refusal. "a lane mask holding lanes elsewhere read as data: a program input" is not about a program input. In every case we have, it is a structurized loop's "lanes still looping" register:

  • a copy of EXEC before the loop;
  • s_andn2_b64 s, s, exec at the head (its SCC asks whether any lane loops on);
  • s_andn2_wrexec_b64 s, s at the back edge, which writes the same result to both the register and EXEC.

Where the structuriser couldn't prove that every lane arriving at the head has its bit set, the head's SCC needed that join as a number. The join has no defining instruction, so mask_number read it as an input and refused. An outer loop whose lanes break out is what makes the arrivals unprovable.

Fix. On every edge, that join takes EXEC's own incoming value: either a copy, or the same _wrexec result. It is therefore EXEC at the head. Lanes::exec_copies_at_joins gives it EXEC's mask there and counts it as active, so a ballot at the head gives it. A join counts only if every edge's argument is provably EXEC's own incoming value on that edge (the same SSA value read by an s_mov, or written by the _wrexec).

Test. mask_tests::a_loop_register_that_is_exec_on_every_edge_is_exec_at_the_head uses a hand-assembled synthetic program of two nested loops of that shape, and fails without the fix. One loop, or no break, was already resolved.

Where it shows. Lighting compute 9e5a12054881a74d is the only writer of a 1280x720 R11G11B10 target that the host never writes in the world ("draws 0 clears 0"), so the target keeps title memory, including Inf/NaN patterns (#258). With this fix that program passes this refusal and stops at its next one: a loop's break accumulator read back through copies ("a lane-mask join of an untracked mask: data whose high dword is not known"). We're on that next.

Sweep, and a request. We dumped 4,129 refused containers at boot. All 15 "program input" refusals among them are such joins, and only the compute one changes outcome. Accepted shaders weren't in that corpus, so we can't check that their outputs stay unchanged. @Sandile-0511, could you run your fingerprint sweep on this branch?

Checks: victory-shader 331 and victory-gpu 316 tests pass. Windows clippy is clean with -D warnings, cargo xtask policy passes, and there's a doc line in docs/native-host.md.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5525102415 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/304). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-27T10:30:46Z. --- Refs #4, #258. **The misleading refusal.** "a lane mask holding lanes elsewhere read as data: a program input" is not about a program input. In every case we have, it is a structurized loop's "lanes still looping" register: - a copy of EXEC before the loop; - `s_andn2_b64 s, s, exec` at the head (its SCC asks whether any lane loops on); - `s_andn2_wrexec_b64 s, s` at the back edge, which writes the same result to both the register and EXEC. Where the structuriser couldn't prove that every lane arriving at the head has its bit set, the head's SCC needed that join as a number. The join has no defining instruction, so `mask_number` read it as an input and refused. An outer loop whose lanes break out is what makes the arrivals unprovable. **Fix.** On every edge, that join takes EXEC's own incoming value: either a copy, or the same `_wrexec` result. It is therefore EXEC at the head. `Lanes::exec_copies_at_joins` gives it EXEC's mask there and counts it as active, so a ballot at the head gives it. A join counts only if every edge's argument is provably EXEC's own incoming value on that edge (the same SSA value read by an `s_mov`, or written by the `_wrexec`). **Test.** `mask_tests::a_loop_register_that_is_exec_on_every_edge_is_exec_at_the_head` uses a hand-assembled synthetic program of two nested loops of that shape, and fails without the fix. One loop, or no break, was already resolved. **Where it shows.** Lighting compute `9e5a12054881a74d` is the only writer of a 1280x720 R11G11B10 target that the host never writes in the world ("draws 0 clears 0"), so the target keeps title memory, including Inf/NaN patterns (#258). With this fix that program passes this refusal and stops at its next one: a loop's break accumulator read back through copies ("a lane-mask join of an untracked mask: data whose high dword is not known"). We're on that next. **Sweep, and a request.** We dumped 4,129 refused containers at boot. All 15 "program input" refusals among them are such joins, and only the compute one changes outcome. Accepted shaders weren't in that corpus, so we can't check that their outputs stay unchanged. @Sandile-0511, could you run your fingerprint sweep on this branch? **Checks:** victory-shader 331 and victory-gpu 316 tests pass. Windows clippy is clean with `-D warnings`, `cargo xtask policy` passes, and there's a doc line in `docs/native-host.md`.
Olima34 commented 2026-11-27 10:43:50 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-27T10:43:50Z.


Second commit (78cd3fed): the next refusal of 9e5a12054881a74d, at 0x76c, "a lane-mask join of an untracked mask: data whose high dword is not known".

What the refusal was. It looked like the loop's break accumulator, but it is a join where one edge is an execz skip over the outer loop. On that edge the register still holds data, descriptor dwords with an unknown high half. Its only read is s_and_b64 s40, s50, exec, and on that edge EXEC is empty: it is exactly what the execz tested. So the edge's value is never needed. Two gaps let it through:

  1. unneeded_edges didn't see that a taken execz edge (lowered as s_cmp_eq_u64 exec, 0 / s_cbranch_scc1) brings an empty EXEC to a join read only together with EXEC.
  2. In the join, the uniform "number" case came before the "unneeded edge" case, so it refused even when the edge was unneeded.

Both are now handled exactly: such an edge needs nothing, and an unneeded edge accepts any value, as a number too.

Test. gfx_refusal_tests::a_join_read_only_with_exec_needs_nothing_from_an_exec_skip, a synthetic program, fails without the change. A v_readlane in the skipped arm forces lockstep, so the join is uniform and the skip is the s_cmp_eq_u64 exec, 0 form.

Sweep over the 4,129 refused containers dumped at boot, with both commits: 28 compute shaders now translate, 2 move on to a later refusal, and nothing else changes, pixel shaders included. The 28 include:

  • 9e5a12054881a74d, the R11G11B10 writer;
  • 2fcb1ef0e54c7df4, which writes a 1280x720 fmt 26 HDR target;
  • 113a4779d954d6d2, a81f1b5bb0d7ba01 and dd1d8e07445421e6, candidate writers of the cullers' 640x360 inputs.

Metal, pipeline creation only (no dispatch): 21 of the 28 compute pipelines are created with no error, including all five above. The other 7 are refused by the host with "needs view addresses or write marks" (an existing host refusal, not a Metal error): 00bc6a9b, fcd8ef10, c3873dc0, a2d0209f, 550d92da, 48828947 and 0c748826.

Checks: victory-shader 332 and victory-gpu 316 tests pass. Windows clippy is clean with -D warnings, cargo xtask policy passes, and docs/native-host.md is updated. As with the first commit, the shaders that translate today weren't in our corpus, so a fingerprint sweep on a full corpus would still be welcome. We haven't measured it in game yet: our runs are paused.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7216235431 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/304#issuecomment-7216235431). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-27T10:43:50Z. --- Second commit (78cd3fed): the next refusal of `9e5a12054881a74d`, at 0x76c, "a lane-mask join of an untracked mask: data whose high dword is not known". **What the refusal was.** It looked like the loop's break accumulator, but it is a join where one edge is an `execz` skip over the outer loop. On that edge the register still holds data, descriptor dwords with an unknown high half. Its only read is `s_and_b64 s40, s50, exec`, and on that edge EXEC is empty: it is exactly what the `execz` tested. So the edge's value is never needed. Two gaps let it through: 1. `unneeded_edges` didn't see that a taken `execz` edge (lowered as `s_cmp_eq_u64 exec, 0` / `s_cbranch_scc1`) brings an empty EXEC to a join read only together with EXEC. 2. In the join, the uniform "number" case came before the "unneeded edge" case, so it refused even when the edge was unneeded. Both are now handled exactly: such an edge needs nothing, and an unneeded edge accepts any value, as a number too. **Test.** `gfx_refusal_tests::a_join_read_only_with_exec_needs_nothing_from_an_exec_skip`, a synthetic program, fails without the change. A `v_readlane` in the skipped arm forces lockstep, so the join is uniform and the skip is the `s_cmp_eq_u64 exec, 0` form. **Sweep** over the 4,129 refused containers dumped at boot, with both commits: 28 compute shaders now translate, 2 move on to a later refusal, and nothing else changes, pixel shaders included. The 28 include: - `9e5a12054881a74d`, the R11G11B10 writer; - `2fcb1ef0e54c7df4`, which writes a 1280x720 fmt 26 HDR target; - `113a4779d954d6d2`, `a81f1b5bb0d7ba01` and `dd1d8e07445421e6`, candidate writers of the cullers' 640x360 inputs. **Metal, pipeline creation only (no dispatch):** 21 of the 28 compute pipelines are created with no error, including all five above. The other 7 are refused by the host with "needs view addresses or write marks" (an existing host refusal, not a Metal error): `00bc6a9b`, `fcd8ef10`, `c3873dc0`, `a2d0209f`, `550d92da`, `48828947` and `0c748826`. **Checks:** victory-shader 332 and victory-gpu 316 tests pass. Windows clippy is clean with `-D warnings`, `cargo xtask policy` passes, and `docs/native-host.md` is updated. As with the first commit, the shaders that translate today weren't in our corpus, so a fingerprint sweep on a full corpus would still be welcome. We haven't measured it in game yet: our runs are paused.
LakshanSivakumar commented 2026-11-27 11:54:07 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T11:54:07Z.


Thank you for the careful write-up and the numbers.

I ran every shader by output on 78cd3fed (33,625 containers, against main c1b95875):

stage gained lost changed hangs
pixel 0 0 0 0
vertex 0 0 0 0
compute 28 0 50 0

So your 28 are confirmed and nothing is lost. But 50 compute shaders that already translate now give different output, and 8 of them are in my list of shaders the game binds in the world. I expect that is the reordered match arm (an unneeded edge now gives false where it gave the number). Please check a few of the 50 and say why the new output means the same.

Before I merge I also need tests for what must stay refused: a join where one edge is not EXEC, an execz skip whose taken edge is the non-empty one, and the s_cmp_eq_u32 form in a wave64 program (that compares only the low half of EXEC; can it happen there?). A test that runs a loop on the GPU and checks the lanes' values would be better than "it translates".

I have not run this in the game.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7217606261 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/304#issuecomment-7217606261). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T11:54:07Z. --- Thank you for the careful write-up and the numbers. I ran every shader by output on 78cd3fed (33,625 containers, against main c1b95875): | stage | gained | lost | changed | hangs | |---|---|---|---|---| | pixel | 0 | 0 | 0 | 0 | | vertex | 0 | 0 | 0 | 0 | | compute | 28 | 0 | 50 | 0 | So your 28 are confirmed and nothing is lost. But 50 compute shaders that already translate now give different output, and 8 of them are in my list of shaders the game binds in the world. I expect that is the reordered match arm (an unneeded edge now gives `false` where it gave the number). Please check a few of the 50 and say why the new output means the same. Before I merge I also need tests for what must stay refused: a join where one edge is not EXEC, an `execz` skip whose taken edge is the non-empty one, and the `s_cmp_eq_u32` form in a wave64 program (that compares only the low half of EXEC; can it happen there?). A test that runs a loop on the GPU and checks the lanes' values would be better than "it translates". I have not run this in the game.
LakshanSivakumar commented 2026-11-27 12:38:39 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T12:38:39Z.


Merged, with one commit of mine on top.

I checked the 50 shaders whose output changed: with the old order of the match arms all 50 are byte-identical to main, so the reordered arm is the only cause, and on an edge in unneeded_edges old and new give the same result (I traced four through the converter's output). All 28 gains are kept, ca62cc7380fe92df among them.

The s_cmp_eq_u32 form was a real hole in wave64 programs (it compares only the low half of EXEC, and a test showed it was accepted). No shader in my dump hits it; the _u32 compare now counts only in wave32 programs. I also added Metal value tests for both rules (lane values checked) and tests for what must stay refused: an execnz branch into the join, the wave64 _u32 form, and a loop register that is not EXEC on one edge.

One gap is left and is not new: the skip rule looks at the low half of EXEC only, so a write to exec_hi alone between the skip and the AND would escape it. Not run in the game yet. Thank you @Olima34.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7218501066 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/304#issuecomment-7218501066). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T12:38:39Z. --- Merged, with one commit of mine on top. I checked the 50 shaders whose output changed: with the old order of the match arms all 50 are byte-identical to main, so the reordered arm is the only cause, and on an edge in `unneeded_edges` old and new give the same result (I traced four through the converter's output). All 28 gains are kept, `ca62cc7380fe92df` among them. The `s_cmp_eq_u32` form was a real hole in wave64 programs (it compares only the low half of EXEC, and a test showed it was accepted). No shader in my dump hits it; the `_u32` compare now counts only in wave32 programs. I also added Metal value tests for both rules (lane values checked) and tests for what must stay refused: an `execnz` branch into the join, the wave64 `_u32` form, and a loop register that is not EXEC on one edge. One gap is left and is not new: the skip rule looks at the low half of EXEC only, so a write to `exec_hi` alone between the skip and the AND would escape it. Not run in the game yet. Thank you @Olima34.
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
LakshanSivakumar/Native-Victory-macOS!304
No description provided.