Wave64 on 32-lane hosts: halves of a console wave meet inside per-lane branches the whole wave takes #34
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/34"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 throughxchg; EXEC stays a guard inside. A check (scalar_parting) refuses the form where a scalar branch could still split the halves;wave_same/scalar_partingdocument which inputs are assumed uniform (user SGPRs and group ids,Sopresults of uniform operands,Smemloads from uniform addresses,v_readlanebut notv_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=0every 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=1prints each walk and its lowerings.Tests: programs where one half runs out of lanes first (a loop with trip count
id/32+1,execzandvcczskips only the upper half takes) run on the GPU, and swappingOr/Andinhalves_decide, or breaking either side, fails them; a branch on av_readfirstlanescalar 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-gpunative/walk_tests.rspassed on the GPU; Windows clippy andxtask policyclean.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_blocksproves 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:AnyTruefromAllTrue. SwappingBin::OrandBin::Andinhalves_decide(halves.rs) leaveswalked_programs_give_the_console_wave_s_results_on_the_gpugreen. 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 onid / 32) and anexecz/vcczskip where only one half has lanes.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 whichSop/Smemresults are assumed uniform, and add a negative test where a per-thread-derived scalar must be refused.no_wave_walkset and unset.Smaller:
NEEDSis a thread-local side channel betweenlower_graphicsandwidened, so returning it in theErr/Loweredresult would be safer. Please also measure how many retry roundswidenedtakes 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.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:
wave_samemarks everyv_readlane_b32result uniform (lower.rs:~13083). But the spill-restore lowering can forward the original scalar (~8215/~8275). If that scalar came from a per-halfv_readfirstlane_b32, a later SCC branch can still split the halves and leave one waiting at a group barrier. Please makewave_samefollow the original scalar for restored lane reads, and add a refusal test for spilling and restoring a per-half first-lane value.id % 4 + 1loop gives both halves the same trip counts.Sop/Smemassumptions.NEEDSthread-local.Thanks for marking the Wine-route figures in the commit message.
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 everyv_readlane_b32as 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.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by 64bitMango on 2026-11-26T12:36:45Z.
Thanks. All three points plus the smaller ones:
id/32+1, andexeczandvcczskips where only the upper half has lanes. They run on the GPU, and swappingBin::Or/Bin::Andinhalves_decide, or breaking either side alone, now fails them.wave_same/scalar_partingnow list what is assumed uniform and why a wrong assumption would hang rather than fail: user SGPRs and group ids (the group-info SGPR ands_getregare refused), SGPRs read before any write, masks read as numbers (made the console wave's ballot),Sopresults of uniform operands,Smemloads from uniform addresses (s_memtimerefused), andv_readlanebut notv_readfirstlane. New test: a branch on av_readfirstlane-derived scalar is refused, while the same branch on a root constant is made.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:
NEEDSis gone. The blocks come back inErr(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=1logs them. The commit message says the performance and correctness figures in the description come from the Wine route. Squashed to one commit.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.
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:
wave_same(lower.rs~13149) still treats everyv_readlane_b32result as uniform. A first-lane scalar spilled withv_writelaneand read back (thest.restoredpath, ~8248) passes:v_readfirstlane s18,v0; v_writelane v5,s18,3; v_readlane s18,v5,3, thens_lshr s18,s18,5; s_cmp_lg s18,0; s_cbranch_scc1before a barrier is translated rather than refused. Please followrestoredback to the original scalar, and add a refusal test.v_readlane s18,v0,s18with s18 fromv_readfirstlaneis accepted, though each half reads a different console lane (halves.rs~177). Please require the lane operand to be uniform (a constant or insame) and add a refusal 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.
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.
Pull request closed