Wave64 on 32-lane hosts: halves of a console wave meet inside per-lane branches the whole wave takes #34

Closed
64bitMango wants to merge 3 commits from upstream-pr/34 into main
64bitMango commented 2026-11-26 10:46:41 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by 64bitMango on 2026-11-26T10:46:41Z.


What. With wave32_host, a wave64 program whose group is one console wave was refused when a cross-half exchange or shared LDS sits in a per-lane branch or loop. Such programs are now made again with those branches taken by the whole wave, as the console's scalar unit takes them: each host wave asks its lanes (WaveActiveAnyTrue/AllTrue) and the halves exchange the answers through xchg; EXEC stays a guard inside. A check (scalar_parting) refuses the form where a scalar branch could still split the halves; wave_same/scalar_parting document which inputs are assumed uniform (user SGPRs and group ids, Sop results of uniform operands, Smem loads from uniform addresses, v_readlane but not v_readfirstlane).

Why. Apple's converter accepts only WaveSize(32).

Measured. On the Wine route (same limit, our own halves lowering): 148 of 153 bound wave64 programs convert (115 before); GPU time on a recorded frame rises 3.7 ms because the extra work now runs; it fixed blocky hair shadows and missing culled geometry. Through the native host's translation path, on a 19,105-shader capture: 50 refused programs now translate, none that translated before change by a byte (18,864 of 18,864 identical to main), and with VICTORY_WAVE_WALK=0 every shader is identical to main. Walks that succeed take 1 lowering (25), 2 (23) or 3 (2); none needs more than 3 of the 64 allowed.

Limits / not yet tested here. Only groups of exactly 64 threads are walked. The title's frame timings were not measured on the native host.

Off: VICTORY_WAVE_WALK=0. VICTORY_TRACE_WAVE_WALK=1 prints each walk and its lowerings.

Tests: programs where one half runs out of lanes first (a loop with trip count id/32+1, execz and vccz skips only the upper half takes) run on the GPU, and swapping Or/And in halves_decide, or breaking either side, fails them; a branch on a v_readfirstlane scalar is refused while the same branch on a root constant is made; 59 wave32 programs built with and without the walk give identical DXIL; a loop whose back-edge mask must stay untracked without the walk. victory-shader 227 passed, victory-gpu native/walk_tests.rs passed on the GPU; Windows clippy and xtask policy clean.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:6624950397 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/34). Originally posted by [64bitMango](https://github.com/64bitMango) on 2026-11-26T10:46:41Z. --- **What.** With `wave32_host`, a wave64 program whose group is one console wave was refused when a cross-half exchange or shared LDS sits in a per-lane branch or loop. Such programs are now made again with those branches taken by the whole wave, as the console's scalar unit takes them: each host wave asks its lanes (`WaveActiveAnyTrue`/`AllTrue`) and the halves exchange the answers through `xchg`; EXEC stays a guard inside. A check (`scalar_parting`) refuses the form where a scalar branch could still split the halves; `wave_same`/`scalar_parting` document which inputs are assumed uniform (user SGPRs and group ids, `Sop` results of uniform operands, `Smem` loads from uniform addresses, `v_readlane` but not `v_readfirstlane`). **Why.** Apple's converter accepts only `WaveSize(32)`. **Measured.** On the Wine route (same limit, our own halves lowering): 148 of 153 bound wave64 programs convert (115 before); GPU time on a recorded frame rises 3.7 ms because the extra work now runs; it fixed blocky hair shadows and missing culled geometry. Through the native host's translation path, on a 19,105-shader capture: 50 refused programs now translate, none that translated before change by a byte (18,864 of 18,864 identical to main), and with `VICTORY_WAVE_WALK=0` every shader is identical to main. Walks that succeed take 1 lowering (25), 2 (23) or 3 (2); none needs more than 3 of the 64 allowed. **Limits / not yet tested here.** Only groups of exactly 64 threads are walked. The title's frame timings were not measured on the native host. **Off:** `VICTORY_WAVE_WALK=0`. `VICTORY_TRACE_WAVE_WALK=1` prints each walk and its lowerings. **Tests:** programs where one half runs out of lanes first (a loop with trip count `id/32+1`, `execz` and `vccz` skips only the upper half takes) run on the GPU, and swapping `Or`/`And` in `halves_decide`, or breaking either side, fails them; a branch on a `v_readfirstlane` scalar is refused while the same branch on a root constant is made; 59 wave32 programs built with and without the walk give identical DXIL; a loop whose back-edge mask must stay untracked without the walk. victory-shader 227 passed, victory-gpu `native/walk_tests.rs` passed on the GPU; Windows clippy and `xtask policy` clean.
LakshanSivakumar commented 2026-11-26 11:00:07 +00:00 (Migrated from github.com)

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

Review: CHANGES_REQUESTED


Thanks, the structure is sound: barriers are only emitted in blocks that together_blocks proves are reached by both halves, and the halves exchange the wave-wide decisions first. The full suite, the GPU walk test, Windows clippy and policy all pass merged with current main. Three requests before merging:

  1. Add tests that can tell AnyTrue from AllTrue. Swapping Bin::Or and Bin::And in halves_decide (halves.rs) leaves walked_programs_give_the_console_wave_s_results_on_the_gpu green. The synthetic programs never leave one half out of lanes while the other is still going. Please add a loop where one half exits earlier than the other (a trip count depending on id / 32) and an execz/vccz skip where only one half has lanes.
  2. Document and test the uniformity assumption in wave_same/scalar_parting. This is the only thing keeping a barrier from landing in divergent code. If it is wrong at runtime, one half waits at a barrier the other never reaches, which hangs the GPU rather than failing cleanly. Please say which SGPR inputs and which Sop/Smem results are assumed uniform, and add a negative test where a per-thread-derived scalar must be refused.
  3. Strengthen the "programs that translated before are byte-identical" check. It currently covers one program. Compare the DXIL for the existing wave32/halves synthetic programs with no_wave_walk set and unset.

Smaller: NEEDS is a thread-local side channel between lower_graphics and widened, so returning it in the Err/Lowered result would be safer. Please also measure how many retry rounds widened takes on real programs. The performance and correctness figures in the description come from the Wine route; that's noted, so it's fine, but please say so in the commit message too.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6072948834 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/34#pullrequestreview-6072948834). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T11:00:07Z. **Review:** CHANGES_REQUESTED --- Thanks, the structure is sound: barriers are only emitted in blocks that `together_blocks` proves are reached by both halves, and the halves exchange the wave-wide decisions first. The full suite, the GPU walk test, Windows clippy and policy all pass merged with current main. Three requests before merging: 1. **Add tests that can tell `AnyTrue` from `AllTrue`.** Swapping `Bin::Or` and `Bin::And` in `halves_decide` (`halves.rs`) leaves `walked_programs_give_the_console_wave_s_results_on_the_gpu` green. The synthetic programs never leave one half out of lanes while the other is still going. Please add a loop where one half exits earlier than the other (a trip count depending on `id / 32`) and an `execz`/`vccz` skip where only one half has lanes. 2. **Document and test the uniformity assumption in `wave_same`/`scalar_parting`.** This is the only thing keeping a barrier from landing in divergent code. If it is wrong at runtime, one half waits at a barrier the other never reaches, which hangs the GPU rather than failing cleanly. Please say which SGPR inputs and which `Sop`/`Smem` results are assumed uniform, and add a negative test where a per-thread-derived scalar must be refused. 3. **Strengthen the "programs that translated before are byte-identical" check.** It currently covers one program. Compare the DXIL for the existing wave32/halves synthetic programs with `no_wave_walk` set and unset. Smaller: `NEEDS` is a thread-local side channel between `lower_graphics` and `widened`, so returning it in the `Err`/`Lowered` result would be safer. Please also measure how many retry rounds `widened` takes on real programs. The performance and correctness figures in the description come from the Wine route; that's noted, so it's fine, but please say so in the commit message too.
LakshanSivakumar commented 2026-11-26 11:22:21 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T11:22:21Z.

Review: CHANGES_REQUESTED


Two things since the last review:

  1. New blocker. wave_same marks every v_readlane_b32 result uniform (lower.rs:~13083). But the spill-restore lowering can forward the original scalar (~8215/~8275). If that scalar came from a per-half v_readfirstlane_b32, a later SCC branch can still split the halves and leave one waiting at a group barrier. Please make wave_same follow the original scalar for restored lane reads, and add a refusal test for spilling and restoring a per-half first-lane value.
  2. Still open from before:
    • Asymmetric Any/All GPU cases: the id % 4 + 1 loop gives both halves the same trip counts.
    • Documented SGPR and Sop/Smem assumptions.
    • A walk on/off DXIL comparison across the existing fixtures.
    • Retry-round measurements, and returning the retry sites in the result instead of the NEEDS thread-local.

Thanks for marking the Wine-route figures in the commit message.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6073282086 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/34#pullrequestreview-6073282086). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T11:22:21Z. **Review:** CHANGES_REQUESTED --- Two things since the last review: 1. **New blocker.** `wave_same` marks every `v_readlane_b32` result uniform (`lower.rs:~13083`). But the spill-restore lowering can forward the original scalar (`~8215`/`~8275`). If that scalar came from a per-half `v_readfirstlane_b32`, a later SCC branch can still split the halves and leave one waiting at a group barrier. Please make `wave_same` follow the original scalar for restored lane reads, and add a refusal test for spilling and restoring a per-half first-lane value. 2. **Still open from before:** - Asymmetric Any/All GPU cases: the `id % 4 + 1` loop gives both halves the same trip counts. - Documented SGPR and `Sop`/`Smem` assumptions. - A walk on/off DXIL comparison across the existing fixtures. - Retry-round measurements, and returning the retry sites in the result instead of the `NEEDS` thread-local. Thanks for marking the Wine-route figures in the commit message.
LakshanSivakumar commented 2026-11-26 12:01:53 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T12:01:53Z.

Review: CHANGES_REQUESTED


Thanks for adding the asymmetric loop and skip cases, the uniformity notes, and the DXIL comparison. I reproduced two inputs the walk still accepts before a barrier: a spilled and restored first-lane result (lower.rs ~13145 treats every v_readlane_b32 as uniform), and a lane read indexed by that per-half result (lower/halves.rs ~177). Please track the restored value, prove the index uniform, and add refusal tests for both. Please also give the eight-group test (walk_tests.rs ~399) separate output ranges and check all eight, and include retry counts from a representative corpus when available.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6073790121 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/34#pullrequestreview-6073790121). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T12:01:53Z. **Review:** CHANGES_REQUESTED --- Thanks for adding the asymmetric loop and skip cases, the uniformity notes, and the DXIL comparison. I reproduced two inputs the walk still accepts before a barrier: a spilled and restored first-lane result (`lower.rs` ~13145 treats every `v_readlane_b32` as uniform), and a lane read indexed by that per-half result (`lower/halves.rs` ~177). Please track the restored value, prove the index uniform, and add refusal tests for both. Please also give the eight-group test (`walk_tests.rs` ~399) separate output ranges and check all eight, and include retry counts from a representative corpus when available.
64bitMango commented 2026-11-26 12:36:45 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by 64bitMango on 2026-11-26T12:36:45Z.


Thanks. All three points plus the smaller ones:

  1. AnyTrue vs AllTrue: new programs where one half runs out of lanes while the other continues: a loop with trip count id/32+1, and execz and vccz skips where only the upper half has lanes. They run on the GPU, and swapping Bin::Or/Bin::And in halves_decide, or breaking either side alone, now fails them.
  2. Uniformity: wave_same/scalar_parting now list what is assumed uniform and why a wrong assumption would hang rather than fail: user SGPRs and group ids (the group-info SGPR and s_getreg are refused), SGPRs read before any write, masks read as numbers (made the console wave's ballot), Sop results of uniform operands, Smem loads from uniform addresses (s_memtime refused), and v_readlane but not v_readfirstlane. New test: a branch on a v_readfirstlane-derived scalar is refused, while the same branch on a root constant is made.
  3. Byte-identical: a new test builds 11 wave32 programs at 32/64/128 lanes with and without LDS, with and without no_wave_walk: all 59 that build without the walk give identical DXIL. I also checked against main on a 19,105-shader capture through the native host's path. That found a real leak: Lanes::phi_args() ran even with no branch taken wave-wide, changing 25 programs with the walk off. It now runs only for the walk, with a regression test. With the walk off, all 19,105 are now identical to main; with it on, all 18,864 that translated before are identical and 50 refused ones translate.

Smaller: NEEDS is gone. The blocks come back in Err(Refused { apart, .. }), and a failed walk reports its own last refusal. Rounds on that capture: walks that succeed take 1 lowering (25), 2 (23) or 3 (2); the 127 that still end refused stop within 3. VICTORY_TRACE_WAVE_WALK=1 logs them. The commit message says the performance and correctness figures in the description come from the Wine route. Squashed to one commit.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7192228318 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/34#issuecomment-7192228318). Originally posted by [64bitMango](https://github.com/64bitMango) on 2026-11-26T12:36:45Z. --- Thanks. All three points plus the smaller ones: 1. **AnyTrue vs AllTrue:** new programs where one half runs out of lanes while the other continues: a loop with trip count `id/32+1`, and `execz` and `vccz` skips where only the upper half has lanes. They run on the GPU, and swapping `Bin::Or`/`Bin::And` in `halves_decide`, or breaking either side alone, now fails them. 2. **Uniformity:** `wave_same`/`scalar_parting` now list what is assumed uniform and why a wrong assumption would hang rather than fail: user SGPRs and group ids (the group-info SGPR and `s_getreg` are refused), SGPRs read before any write, masks read as numbers (made the console wave's ballot), `Sop` results of uniform operands, `Smem` loads from uniform addresses (`s_memtime` refused), and `v_readlane` but not `v_readfirstlane`. New test: a branch on a `v_readfirstlane`-derived scalar is refused, while the same branch on a root constant is made. 3. **Byte-identical:** a new test builds 11 wave32 programs at 32/64/128 lanes with and without LDS, with and without `no_wave_walk`: all 59 that build without the walk give identical DXIL. I also checked against main on a 19,105-shader capture through the native host's path. That found a real leak: `Lanes::phi_args()` ran even with no branch taken wave-wide, changing 25 programs with the walk off. It now runs only for the walk, with a regression test. With the walk off, all 19,105 are now identical to main; with it on, all 18,864 that translated before are identical and 50 refused ones translate. **Smaller:** `NEEDS` is gone. The blocks come back in `Err(Refused { apart, .. })`, and a failed walk reports its own last refusal. **Rounds** on that capture: walks that succeed take 1 lowering (25), 2 (23) or 3 (2); the 127 that still end refused stop within 3. `VICTORY_TRACE_WAVE_WALK=1` logs them. The commit message says the performance and correctness figures in the description come from the Wine route. Squashed to one commit.
64bitMango commented 2026-11-26 12:38:46 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by 64bitMango on 2026-11-26T12:38:46Z.


@LakshanSivakumar ready for another look when you have time. The review points are addressed in the comment above, and the branch is squashed to one commit.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7192273033 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/34#issuecomment-7192273033). Originally posted by [64bitMango](https://github.com/64bitMango) on 2026-11-26T12:38:46Z. --- @LakshanSivakumar ready for another look when you have time. The review points are addressed in the comment above, and the branch is squashed to one commit.
LakshanSivakumar commented 2026-11-26 12:47:19 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T12:47:19Z.

Review: CHANGES_REQUESTED


Thanks for the asymmetric loop/skip programs, the uniformity notes, the on/off DXIL test and the retry counts; those look good. Three things from the 12:01 review are still open, and the first two reproduce on this head:

  1. wave_same (lower.rs ~13149) still treats every v_readlane_b32 result as uniform. A first-lane scalar spilled with v_writelane and read back (the st.restored path, ~8248) passes: v_readfirstlane s18,v0; v_writelane v5,s18,3; v_readlane s18,v5,3, then s_lshr s18,s18,5; s_cmp_lg s18,0; s_cbranch_scc1 before a barrier is translated rather than refused. Please follow restored back to the original scalar, and add a refusal test.
  2. The lane operand: v_readlane s18,v0,s18 with s18 from v_readfirstlane is accepted, though each half reads a different console lane (halves.rs ~177). Please require the lane operand to be uniform (a constant or in same) and add a refusal test.
  3. The eight-group GPU test (native/walk_tests.rs ~399) still has every group write the same dwords and reads back only the first group's, so a wrong later group is hidden. Please give each group its own range and check all eight.
    Since the walk is on by default, these are the GPU-hang cases we need closed before merging.
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6074371228 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/34#pullrequestreview-6074371228). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T12:47:19Z. **Review:** CHANGES_REQUESTED --- Thanks for the asymmetric loop/skip programs, the uniformity notes, the on/off DXIL test and the retry counts; those look good. Three things from the 12:01 review are still open, and the first two reproduce on this head: 1. `wave_same` (`lower.rs` ~13149) still treats every `v_readlane_b32` result as uniform. A first-lane scalar spilled with `v_writelane` and read back (the `st.restored` path, ~8248) passes: `v_readfirstlane s18,v0; v_writelane v5,s18,3; v_readlane s18,v5,3`, then `s_lshr s18,s18,5; s_cmp_lg s18,0; s_cbranch_scc1` before a barrier is translated rather than refused. Please follow `restored` back to the original scalar, and add a refusal test. 2. The lane operand: `v_readlane s18,v0,s18` with s18 from `v_readfirstlane` is accepted, though each half reads a different console lane (`halves.rs` ~177). Please require the lane operand to be uniform (a constant or in `same`) and add a refusal test. 3. The eight-group GPU test (`native/walk_tests.rs` ~399) still has every group write the same dwords and reads back only the first group's, so a wrong later group is hidden. Please give each group its own range and check all eight. Since the walk is on by default, these are the GPU-hang cases we need closed before merging.
64bitMango commented 2026-11-26 13:17:21 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by 64bitMango on 2026-11-26T13:17:21Z.


Closing this: I'm continuing this work on my fork, 64bitMango/Native-Victory-macOS, where it's merged with the other open PRs (#33–#37). Thanks for the thorough reviews; the fixes from your latest feedback are included there.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7193134516 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/34#issuecomment-7193134516). Originally posted by [64bitMango](https://github.com/64bitMango) on 2026-11-26T13:17:21Z. --- Closing this: I'm continuing this work on my fork, [64bitMango/Native-Victory-macOS](https://github.com/64bitMango/Native-Victory-macOS), where it's merged with the other open PRs (#33–#37). Thanks for the thorough reviews; the fixes from your latest feedback are included there.

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