Proposal: if-conversion for compute groups of several console waves (extending lockstep to multi-wave groups) #376
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 Hayyan612 on 2026-11-27T14:42:50Z.
Proposal, not claimed. For discussion before anyone builds it.
Gap
Lockstep (
emit/lockstep.rs, native-host.md "Lockstep") translates a refused wave64 compute program whose group is one console wave: every host thread follows the console wave's program counter, so both host waves always reach the group barriers of cross-half exchanges. Groups of several console waves are not covered. The offline measurement in native-host.md lists 74 such refused programs (64 not for a descriptor).The roadmap's remaining shape, "cross-lane operations and LDS shared between the two host waves… inside real per-lane branches (needs if-conversion…)", is this case. Metal has no barrier scoped to the two simdgroups of one console wave, so console waves that branch differently inside one threadgroup would wait on each other's barriers.
Idea
Make control flow uniform across the whole group by predication, so every host thread executes the same instruction stream and every barrier is reached by all:
if/elsebecomes both arms executed under per-lane masks (stores, LDS writes and exports masked; values selected at the join);xchgexchange unchanged, since barriers are uniform;Costs and risks
Both arms run (slower for unbalanced branches); one extra barrier per group-uniform loop test; memory side effects in inactive arms must be masked exactly (atomics, LDS, image stores). Code that relies on a lane not executing an arm for correctness (a fault-avoiding guard) needs its loads masked too.
Testability
Hand-assembled GFX10 tests in the style of
gfx_refusal_tests.rsandsplit_wave_tests(two console waves that branch opposite ways around a cross-half read; a per-lane loop with LDS across halves), plus the corpus sweep (#282) to count the 74 and check for regressions.Open questions
structure::lockstep, or a separate predication pass after structuring?Refs #4, #258.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-27T16:19:17Z.
https://github.com/LakshanSivakumar/Native-Victory-macOS/compare/main...AnastasisKon:Native-Victory-macOS:vibe/if-conversion-design-376-567a86
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by marcus-4 on 2026-11-27T18:09:38Z.
/claim
I'm taking this one. It is the design @Olima34 asked about on #258 for
eee76bf6265f33bb(25 indirect records of the ray-traced passes) and the 27 compute shaders refused as "a cross-lane operation between host waves in divergent code" in groups of several console waves. AnastasisKon's linked branch has no commits on main, so I take it as free; say so if not.Plan
victory-gpu, Metal): synthetic wave64 programs in groups of 2 and 4 console waves with the shapes in Olima34's note, each failing or refused on main: a ballot read as a number in a block only some waves enter; whole-wave sections behind a branch ons_and_b64 mask, exec; a loop whose trip count differs per wave with a cross-half exchange inside.lockstep::fits), so a program that translates now keeps its exact output. Each console wave keeps lockstep's reading of its own branches (its mask as a number, from its two halves). Every branch is then made uniform across the group: a block runs while any wave of the group takes it (one LDS "any" and a group barrier per branch), and a wave that would not take it runs it predicated off: vector work guarded as lockstep guards it now, scalar writes kept at their old value, memory and LDS writes skipped, the exchanges' barriers still reached. Loops run while any wave still loops.wip/relay-eee76bf6, 69b22e24) as the first commit if they still apply, credited.Limits I already see: extra barriers per branch in those programs (only in programs refused today); a console
s_barrierreached by only some waves would hang the console too, so it is not modelled. Corpus: I have none, so the comparison by output needs someone with one before this leaves draft. A draft PR with the failing tests will follow within the day.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by github-actions[bot] on 2026-11-27T18:09:47Z.
Claimed by @marcus-4. Open a draft pull request with
Refs #376in its description within 24 hours, or the claim expires.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by gagarinyury on 2026-11-27T20:07:22Z.
Prior art that may save work here: the Windows fork TaynanGT/Vice-Tay runs each console wave of 64 in one host wave of 32 ("paired lanes"). Each host thread lowers two console lanes, so wave-wide sums, first-lane reads and LDS within the console wave are exact without group barriers, at twice the VALU work (
crates/victory-shader/src/emit/paired.rs;docs/this-fork.md, "Wave64 programs on a 32-lane card"). It credits ByFxbian's #1397 and #1419 on fxceless/victory-fork. 29 programs take that form by default (DEFAULT_WAVE_PAIRS_HASHESinemit/mod.rs): the tiled shadow mask, the water's transmission volumetrics and tile generation, and the atmospheric diffusion with its depth scan, the ones whose other forms left the picture wrong. As I read it, with one host wave per console wave, a group's barriers are reached exactly as on the console, so it may also cover groups of several console waves, at the cost of the doubled vector work. I have not tried it on Metal.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by marcus-4 on 2026-11-27T20:14:54Z.
Thanks, @gagarinyury. I hadn't looked at Vice-Tay's paired lanes, and it's a real alternative. Here's how it compares with what #438 does now.
#438 (lockstep per console wave, pair barriers). Each console wave follows its own program counter in lockstep, as one-wave lockstep already does. Only the exchange barriers changed: they wait for the wave's own two host waves through a counter in group-shared memory, not for the whole group. Vector work stays at 1x. The costs are two pair barriers per cross-half exchange (a fence, an atomic add and a short poll each) and one assumption: that one SIMD group keeps running while its partner polls. Metal doesn't document that, but it held in all eight Metal tests here, in groups of 96, 128 and 256.
Paired lanes (Vice-Tay
emit/paired.rs). Each host thread carries two console lanes, so wave-wide operations, first-lane reads and LDS within a console wave are exact with no barrier at all, and group barriers line up as on the console. It needs no forward-progress assumption. The costs are twice the vector work, and a second lowering of every instruction class it supports: its LDS path takes reads, writes,read2/write2and returnless atomics, and the rest is refused.My take: they cover overlapping but different sets. Paired lanes is exact where it applies and doesn't depend on Metal's scheduling. #438 is cheaper per instruction and takes whatever one-wave lockstep already takes. The corpus sweep requested on #438 would show which of the 27 "a cross-lane operation between host waves in divergent code" shaders each gains. If #438 gains
eee76bf6and most of the class, paired lanes could still be the fallback for what remains, or for any shader where the pair barrier shows a timeout in a game run. Both are GPL-3.0, so portingpaired.rswith credit would be fine. I'd keep that as a separate PR, so neither blocks the other.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by marcus-4 on 2026-11-28T08:19:20Z.
/release
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by github-actions[bot] on 2026-11-28T08:19:31Z.
Released. This issue is free to claim.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-28T15:39:19Z.
Status of this proposal on fork
AnastasisKon/Native-Victory-macOSmain: implemented, behindVICTORY_PAIRED_WAVES=1(Options::paired_waves,emit/lower/paired.rs), and the question left is whether it should be the default. This is the evidence for that decision, as it stands without a run.Shapes pinned end to end on the GPU in the paired form (
victory-gpusplit_wave_tests, all active):a_vote_used_as_a_branch_follows_each_console_wave_in_the_paired_forms_bcnt1vote branched on by SCC, waves voting differentlya_lane_read_in_a_group_of_two_waves_reads_each_waves_own_lanev_readlane35 with a different EXEC per wavea_lane_read_in_a_group_of_four_waves_reads_each_waves_own_lanea_ballot_in_a_block_one_wave_of_the_group_skips_counts_only_its_wavea_per_lane_loop_sharing_lds_in_each_wave_of_a_group_runs_each_waves_tripsa_whole_wave_prefix_sum_behind_a_branch_each_wave_takes_differentlya_whole_wave_prefix_sum_behind_a_branch_on_a_mask_anded_with_exec_in_four_waveseee76bf6's shape (#258), four wavesa_lane_count_of_vcc_under_an_exec_skip_branched_on_by_scc_counts_each_console_wave_wholes_bcnt1under an EXEC skip, branched by SCCa_mask_anded_with_exec_into_vcc_under_an_exec_skip_skips_only_waves_without_a_lanes_and_b64 vcc, exec, mask+s_cbranch_vcczunder an EXEC skipa_lane_mask_join_read_as_data_answers_per_wave_in_the_paired_forma_wave_maximum_read_at_lane_0_answers_the_wave_in_the_paired_formEach asserts the console's per-wave answer, not merely that it translates.
What the switch changes: nothing the fast path already translates.
lockstep::retryruns only after a refusal (fits/fits_refused), so the risk is confined to shapes that are dropped today. WhenVICTORY_PAIRED_WAVES=1 cargo test -p victory-gputranslates a program the default refuses, twelve refusal pins insplit_wave_testsstop failing on their assertion (they name the default path throughdefaults(), so the suite itself is green either way).How to decide it on a real run, without running the title twice:
translates every container earlier runs kept (
shaders::keep) twice - as the defaults do, and with the paired form and the strictvcczrefusal on - and prints: translated both ways, recovered by the switches, lost by them (translates today, refused with them), refused both ways, the shaders in each changed group with the refusal that changed, and a histogram of the reasons still refused (warm::switch_delta).Proposal: make the paired form the default once a tester's kept containers show
lost 0with a meaningfulrecovered, leavingVICTORY_PAIRED_WAVES=0to opt out. Until then the switch stays off: a shape this form translates that no test pins would be a guess drawn on the screen rather than a refusal, which is the trade this project does not take by default.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-28T15:39:58Z.
Correction to one sentence above: the twelve refusal pins in
split_wave_testsno longer fail when the suite runs withVICTORY_PAIRED_WAVES=1. They name the default translation throughdefaults()(both switches off, whatever the environment says), socargo test -p victory-gpuis green with the switches set and unset - 493 passed, 10 ignored, both ways. What the switch changes for them is only which translation the host makes, not what they assert.