shader: preserve complete wave reductions for pixel lane reads #328

Closed
theappartment wants to merge 1 commit from upstream-pr/328 into main
theappartment commented 2026-11-27 11:44:28 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by theappartment on 2026-11-27T11:44:28Z.


Refs #258 and the requested validation.

Change

Keep track of which lanes hold a complete whole-wave reduction in a pixel shader, including when EXEC allows only some lanes to write the last step. A later constant-lane read in the same block can use the complete reduction when the selected lane is proven to hold it. The negative case exercises a lane outside the proven write mask. This also handles the ordinary scalar shifts and subtraction used inside this whole-wave section.

Validation

  • The synthetic Metal test runs with GPU validation enabled. It computes the minimum of lane values 32 through 63, allows only the upper 16 lanes to write the final step, restores EXEC, and reads lane 31. Every channel of every texel in the 8×8 output is exactly 32. The same test on upstream main (ce2b7860) stops at the unsupported constant-lane read.
  • The translator test also checks the read inside a later whole-wave section and verifies that a lane without a proven complete reduction is refused. The shader suite passed 332 tests, with 3 ignored.
  • Using the sweep and comparison tool from #286 (76f1757f), I compared all 16,420 entries on upstream main and this branch. The number translated went from 9,740 to 9,755. All 15 additions are pixel shaders. The tool reported zero changes to previously translated output hashes, zero regressions, and 137 pixel shaders that now reach a later refusal on 16-bit input.
  • All nine hashes listed in the issue, including 5cfd461606ae6eaa, went from refused to translated in a targeted sweep. Two are already in the 16,420-entry corpus. These checks cover translation and the synthetic GPU fixture. Gameplay rendering and Windows CI are pending.
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5526053672 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/328). Originally posted by [theappartment](https://github.com/theappartment) on 2026-11-27T11:44:28Z. --- Refs #258 and the [requested validation](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/258#issuecomment-7215997401). ## Change Keep track of which lanes hold a complete whole-wave reduction in a pixel shader, including when EXEC allows only some lanes to write the last step. A later constant-lane read in the same block can use the complete reduction when the selected lane is proven to hold it. The negative case exercises a lane outside the proven write mask. This also handles the ordinary scalar shifts and subtraction used inside this whole-wave section. ## Validation - The synthetic Metal test runs with GPU validation enabled. It computes the minimum of lane values 32 through 63, allows only the upper 16 lanes to write the final step, restores EXEC, and reads lane 31. Every channel of every texel in the 8×8 output is exactly 32. The same test on upstream main (ce2b7860) stops at the unsupported constant-lane read. - The translator test also checks the read inside a later whole-wave section and verifies that a lane without a proven complete reduction is refused. The shader suite passed 332 tests, with 3 ignored. - Using the sweep and comparison tool from #286 (76f1757f), I compared all 16,420 entries on upstream main and this branch. The number translated went from 9,740 to 9,755. All 15 additions are pixel shaders. The tool reported zero changes to previously translated output hashes, zero regressions, and 137 pixel shaders that now reach a later refusal on 16-bit input. - All nine hashes [listed in the issue](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/258#issuecomment-7215523685), including 5cfd461606ae6eaa, went from refused to translated in a targeted sweep. Two are already in the 16,420-entry corpus. These checks cover translation and the synthetic GPU fixture. Gameplay rendering and Windows CI are pending.
Olima34 commented 2026-11-27 12:26:50 +00:00 (Migrated from github.com)

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


Sweep of this PR on our boot-time shader set (M5 Pro, Series S; 4,921 containers the prewarm translated in 40 s, plus 4,129 refused ones), main against main + #328, by outcome and output fingerprint:

Stage Gained Lost Changed
Pixel 23 0 0
Vertex 0 0 0
Compute 0 0 0

These are counts only. We haven't run it in game yet.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7218252823 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/328#issuecomment-7218252823). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-27T12:26:50Z. --- Sweep of this PR on our boot-time shader set (M5 Pro, Series S; 4,921 containers the prewarm translated in 40 s, plus 4,129 refused ones), main against main + #328, by outcome and output fingerprint: | Stage | Gained | Lost | Changed | |---|---|---|---| | Pixel | 23 | 0 | 0 | | Vertex | 0 | 0 | 0 | | Compute | 0 | 0 | 0 | These are counts only. We haven't run it in game yet.
Olima34 commented 2026-11-27 12:38:06 +00:00 (Migrated from github.com)

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


Follow-up with the larger set: the 4,129 containers refused at boot, eb5b8f79 merged onto 465db23b, native host options, no panics.

  • Pixel: 737 gained, 0 lost, 0 changed; 179 move on to a later refusal. Compute and vertex are unchanged.
  • The 819 v_readlane 31/63 shapes: 818 pixel and 1 vertex. 683 of the 818 pixel ones now translate. The other 135 reach a later refusal: descriptor read only as data (40), lane mask read as data (30), image base address (24), lane mask holding lanes elsewhere (14), buffer dword 1 (10), lane-mask join (7), others. The vertex one is unchanged, since this PR is pixel only.
  • Also gained: 52 of the 96 "whole-wave step … no reduction or prefix" refusals, and 2 "s_lshl_b32".

Not run in game yet.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7218490011 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/328#issuecomment-7218490011). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-27T12:38:06Z. --- Follow-up with the larger set: the 4,129 containers refused at boot, `eb5b8f79` merged onto 465db23b, native host options, no panics. - **Pixel:** 737 gained, 0 lost, 0 changed; 179 move on to a later refusal. Compute and vertex are unchanged. - **The 819 `v_readlane` 31/63 shapes:** 818 pixel and 1 vertex. 683 of the 818 pixel ones now translate. The other 135 reach a later refusal: descriptor read only as data (40), lane mask read as data (30), image base address (24), lane mask holding lanes elsewhere (14), buffer dword 1 (10), lane-mask join (7), others. The vertex one is unchanged, since this PR is pixel only. - **Also gained:** 52 of the 96 "whole-wave step … no reduction or prefix" refusals, and 2 "s_lshl_b32". Not run in game yet.
Olima34 commented 2026-11-27 12:55:01 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-27T12:55:01Z.


Check report: eb5b8f79 merged onto main c5d7f4d0 (after #304), on an M5 Pro 48 GB.

  • cargo test -p victory-hle -p victory -p victory-gpu -p xtask (arm64, with the converter): all pass, victory-gpu 329 passed (main 328).
  • cargo test -p victory-shader: 360 passed.
  • cargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings: clean. cargo xtask policy: ok.
  • By-output sweep, native host options, main vs main + #328:
Set Stage Gained Lost Changed
boot-time set (4,921) pixel 23 0 0
refused at boot (4,129) pixel 737 0 0
both vertex, compute 0 0 0

180 pixel shaders move on to a later refusal. Among the 179 in the refused set: "a descriptor read only as data" 68, "an image's base address (dword 0)" 34, "a lane mask read as data" 30, "a lane mask holding lanes elsewhere: a program input" 14, "the first half of an interpolation" 12, "a buffer's dword 1" 10, "lane-mask join of an untracked mask" 7, v_readlane_b32 of a constant lane 4.

Result: passes. Merging. Not run in game.

@theappartment, thanks. If you want a next one, the largest class these shaders now reach is "a descriptor read only as data" (68 here). Please check #4 and the work board #338 for claims, and /claim before starting. When you have numbers, mention @Olima34 on the PR with a by-output sweep (gained / lost / changed per stage).

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7218831589 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/328#issuecomment-7218831589). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-27T12:55:01Z. --- Check report: `eb5b8f79` merged onto main `c5d7f4d0` (after #304), on an M5 Pro 48 GB. - `cargo test -p victory-hle -p victory -p victory-gpu -p xtask` (arm64, with the converter): all pass, victory-gpu 329 passed (main 328). - `cargo test -p victory-shader`: 360 passed. - `cargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings`: clean. `cargo xtask policy`: ok. - By-output sweep, native host options, main vs main + #328: | Set | Stage | Gained | Lost | Changed | |---|---|---|---|---| | boot-time set (4,921) | pixel | 23 | 0 | 0 | | refused at boot (4,129) | pixel | 737 | 0 | 0 | | both | vertex, compute | 0 | 0 | 0 | 180 pixel shaders move on to a later refusal. Among the 179 in the refused set: "a descriptor read only as data" 68, "an image's base address (dword 0)" 34, "a lane mask read as data" 30, "a lane mask holding lanes elsewhere: a program input" 14, "the first half of an interpolation" 12, "a buffer's dword 1" 10, "lane-mask join of an untracked mask" 7, `v_readlane_b32` of a constant lane 4. Result: passes. Merging. Not run in game. @theappartment, thanks. If you want a next one, the largest class these shaders now reach is "a descriptor read only as data" (68 here). Please check #4 and the work board #338 for claims, and `/claim` before starting. When you have numbers, mention @Olima34 on the PR with a by-output sweep (gained / lost / changed per stage).
Olima34 commented 2026-11-27 12:55:14 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-27T12:55:14Z.


Correction: GitHub won't merge it yet, because the branch has to be up to date with main (c5d7f4d0 now). @theappartment, could you update it on main (a merge or a rebase; our check above was already of this PR merged onto c5d7f4d0, with no conflict)? I'll merge once CI is green on the new head.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7218836008 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/328#issuecomment-7218836008). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-27T12:55:14Z. --- Correction: GitHub won't merge it yet, because the branch has to be up to date with main (`c5d7f4d0` now). @theappartment, could you update it on main (a merge or a rebase; our check above was already of this PR merged onto `c5d7f4d0`, with no conflict)? I'll merge once CI is green on the new head.
Olima34 commented 2026-11-27 13:09:29 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-27T13:09:29Z.


Update: main has moved again (d35ba927: #262 is in, and it changes the same parts of emit/lower.rs and emit/wave.rs), so this now conflicts. @theappartment, when you rebase it, mention @Olima34 and I'll re-sweep the new head and merge if nothing is lost or changed.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7219129528 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/328#issuecomment-7219129528). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-27T13:09:29Z. --- Update: main has moved again (`d35ba927`: #262 is in, and it changes the same parts of `emit/lower.rs` and `emit/wave.rs`), so this now conflicts. @theappartment, when you rebase it, mention @Olima34 and I'll re-sweep the new head and merge if nothing is lost or changed.
AnastasisKon commented 2026-11-27 13:26:56 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-27T13:26:56Z.


Verified by running the branch: full cargo test -p victory-shader green (332 passed, 3 ignored, x86_64-unknown-linux-gnu, rustc 1.98.1). Traced the logic: the lane-reduction groups are built only from per-lane symbols whose uniform shape is Shape::Active(..) (so lanes holding stale intermediates land in a different group or no group), reads take the result only when the selected lane's bit is in the group's mask, section_lane_result additionally requires the source defined in the current block, and the negative test exercises exactly the unproven-lane case. The uniform_scalar_alu addition is semantically right (SALU is EXEC-independent) and conservatively limited to three opcodes, pixel-only. For a lane ≥ the wave width the mask never contains the bit, so it degrades to refusal rather than a wrong value. The corpus numbers are the strongest part — 15 new translations, zero output changes to previously-translated shaders, zero regressions, and the issue's nine named hashes all flipped to translated. LGTM from my side.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7219489741 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/328#issuecomment-7219489741). Originally posted by [AnastasisKon](https://github.com/AnastasisKon) on 2026-11-27T13:26:56Z. --- Verified by running the branch: full cargo test -p victory-shader green (332 passed, 3 ignored, x86_64-unknown-linux-gnu, rustc 1.98.1). Traced the logic: the lane-reduction groups are built only from per-lane symbols whose uniform shape is Shape::Active(..) (so lanes holding stale intermediates land in a different group or no group), reads take the result only when the selected lane's bit is in the group's mask, section_lane_result additionally requires the source defined in the current block, and the negative test exercises exactly the unproven-lane case. The uniform_scalar_alu addition is semantically right (SALU is EXEC-independent) and conservatively limited to three opcodes, pixel-only. For a lane ≥ the wave width the mask never contains the bit, so it degrades to refusal rather than a wrong value. The corpus numbers are the strongest part — 15 new translations, zero output changes to previously-translated shaders, zero regressions, and the issue's nine named hashes all flipped to translated. LGTM from my side.
Olima34 commented 2026-11-27 13:39:00 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-27T13:39:00Z.


We re-ran the sweep on current main (60baf130), against d35ba927, over the 4,129 containers refused at boot. Main alone now translates all 737 pixel shaders this PR gained: 1,157 pixel and 80 vertex shaders newly translate, with 0 lost and 0 changed outputs. 793 of the 819 v_readlane 31/63 shapes pass. That's the maintainer's "half-wave reduction lane reads" fix (053e5993). So on this corpus #328 adds nothing on top of main any more. @theappartment, thanks for this one: it surfaced the class.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7219760054 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/328#issuecomment-7219760054). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-27T13:39:00Z. --- We re-ran the sweep on current main (60baf130), against d35ba927, over the 4,129 containers refused at boot. Main alone now translates all 737 pixel shaders this PR gained: 1,157 pixel and 80 vertex shaders newly translate, with 0 lost and 0 changed outputs. 793 of the 819 `v_readlane` 31/63 shapes pass. That's the maintainer's "half-wave reduction lane reads" fix (053e5993). So on this corpus #328 adds nothing on top of main any more. @theappartment, thanks for this one: it surfaced the class.
theappartment commented 2026-11-27 13:42:21 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by theappartment on 2026-11-27T13:42:21Z.


@Olima34 Thanks for re-running the sweep. I reproduced the result on main at 60baf130 with the original synthetic regression cases copied over. The shader translation test passed, including the unfinished lane that must still be refused. The native Metal test passed with API validation enabled and returned the expected minimum (32.0).

I also re-ran the local cases that had previously gone from refused to accepted with #328. All 28 now translate on main (15 pixel, 10 vertex, 3 compute). With that result and your larger sweep, the half-wave fix from #262 covers the cases we checked and supersedes the rebase request.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7219839963 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/328#issuecomment-7219839963). Originally posted by [theappartment](https://github.com/theappartment) on 2026-11-27T13:42:21Z. --- @Olima34 Thanks for re-running the sweep. I reproduced the result on `main` at `60baf130` with the original synthetic regression cases copied over. The shader translation test passed, including the unfinished lane that must still be refused. The native Metal test passed with API validation enabled and returned the expected minimum (`32.0`). I also re-ran the local cases that had previously gone from refused to accepted with #328. All 28 now translate on `main` (15 pixel, 10 vertex, 3 compute). With that result and your larger sweep, the half-wave fix from #262 covers the cases we checked and supersedes the rebase request.
Olima34 commented 2026-11-27 14:43:04 +00:00 (Migrated from github.com)

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


For the record: a by-output sweep of main 60baf130 against d35ba927 on our 4,129 containers refused at boot shows that main alone now translates all 737 of this PR's gains (793 of the 819 v_readlane 31/63 shapes), with 0 lost and 0 changed. That matches what you found, @theappartment, so this PR is superseded by the maintainer's 053e5993. Closing it is your call. Thanks for the work and the test cases.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7221137818 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/328#issuecomment-7221137818). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-27T14:43:04Z. --- For the record: a by-output sweep of main `60baf130` against `d35ba927` on our 4,129 containers refused at boot shows that main alone now translates all 737 of this PR's gains (793 of the 819 `v_readlane` 31/63 shapes), with 0 lost and 0 changed. That matches what you found, @theappartment, so this PR is superseded by the maintainer's `053e5993`. Closing it is your call. Thanks for the work and the test cases.
LakshanSivakumar commented 2026-11-27 16:01:18 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T16:01:18Z.


Closing this as superseded: main's half-wave reduction fix (053e5993) already translates every shader this one gained, as the sweeps above show. Thanks for the work and the test cases, they helped find the class.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7222760427 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/328#issuecomment-7222760427). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T16:01:18Z. --- Closing this as superseded: main's half-wave reduction fix (053e5993) already translates every shader this one gained, as the sweeps above show. Thanks for the work and the test cases, they helped find the class.

Pull request closed

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!328
No description provided.