shader: lockstep for compute groups of several console waves (#376) #438
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/438"
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 marcus-4 on 2026-11-27T18:22:26Z.
What this changes
Refs #376
Lockstep (
emit/lockstep.rs) for wave64 compute groups of several console waves, off by default behindVICTORY_LOCKSTEP_WAVES=1(Options::lockstep_waves, so it is part of the shader cache key). It runs only as the retry after the fast path refuses, as lockstep does today, so a program that translates now keeps its exact output, whether the switch is on or off.Why no predication is needed. Lockstep's reading is per console wave already: each wave's branches test its own ballot, so every thread of one console wave follows that wave's program counter, and other waves follow theirs. What broke with several waves was only the exchange's group barrier (and lockstep's LDS barriers), which waited for waves that took another way. With several console waves those barriers become a barrier of the console wave's own two host waves (
Lower::pair_barrier,lower/halves.rs):pairs), zeroed at entry, followed by one group barrier there;(old / n + 1) * n), then a fence. No thread adds for the next barrier before allnhave added for this one;s_barrierkeeps the group barrier, and is accepted only in a block every thread reaches once (once_blocks). Anywhere else the program is refused ("an s_barrier the console waves of a lockstep group may reach unevenly").A ballot's exchange now splits the DXIL block, because the wait is a loop. So in this mode lane masks are made numbers right after the instruction that writes them (
Lower::ballot_masks_written), and masks on entry in the entry block. An exchange that would still land in an earlier block is refused, not emitted.Guess, marked in the code and docs: SIMD groups of one threadgroup make progress while another spins. Metal doesn't document this. The poll is capped at 2^20, so a host that didn't schedule the other SIMD group would give wrong values instead of hanging the GPU. All the Metal tests below ran without a timeout.
Documented in
docs/native-host.md, "Lockstep per console wave in groups of several". The earlier #376 design note (predication) is kept for the shapes this does not take.How it was tested
M1 Pro, macOS 27.2.1, Xcode 27.2, MSC 4.0.3.
New Metal tests in
split_wave_tests, each with a different EXEC or trip count per console wave:a_lane_read_in_a_group_of_two_waves_reads_each_waves_own_lane(wave 0 reads 1035, wave 1 reads 1099)a_lane_read_in_a_group_of_four_waves_reads_each_waves_own_lane(including wave 3 reading a lane that is off)a_per_lane_loop_sharing_lds_in_each_wave_of_a_group_runs_each_waves_trips(wave 0 loops at most once, wave 1 twice; LDS shared within each wave without barriers, checked against a model of the console)a_whole_wave_prefix_sum_behind_a_branch_each_wave_takes_differentlya_title_barrier_in_a_loop_the_waves_of_a_group_run_differently_is_refusedseveral_waves_branching_differently_are_refused_today(switch off), anda_ballot_in_a_block_one_wave_of_the_group_skips_counts_only_its_wave(a shape the fast path already takes)Results:
-p victory-hle -p victory -p victory-gpu -p xtask -p victory-shader -p victory-metal -p victory-platform -p victory-loader -p victory-formats -p victory-backend -p victory-core): 1159 passed, 0 failedcargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory: 390 passed, 1 failed under parallel load. The failure wasdsp::tests::dump_captures_the_titles_ir_blocks_and_output, untouched here; it passes 3 of 3 times when run alone.cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings: clean.cargo xtask policy: okNeeded before this leaves draft: a corpus comparison by output with
VICTORY_LOCKSTEP_WAVES=1. That would show how many of the 27 compute shaders refused as "a cross-lane operation between host waves in divergent code" (includingeee76bf6265f33bb, #258) it gains, and whether any other refusal reason now hits them. I have no corpus. With the switch off, output cannot change by construction; a sweep can confirm it.Checklist
VICTORY_*variable and documented (VICTORY_LOCKSTEP_WAVES)Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by marcus-4 on 2026-11-27T18:49:08Z.
The implementation is in (
2cc4e9f4), and I'm asking for a corpus sweep, since I have no corpus here.@LakshanSivakumar @Sandile-0511, you both ran corpus comparisons on #254. Could one of you sweep this head with
VICTORY_LOCKSTEP_WAVES=1against main? The sweep example builds its options the way the native host does, so set the variable in its environment, or flipOptions::lockstep_wavesthere.What I expect, and what would show it wrong:
eee76bf6265f33bbfrom #258), plus whatever LDS or lane-mask refusals lockstep already lifts for one-wave groups. Nothing that translates today should change, because the retry runs only after a refusal.A list of the shaders gained, with their hashes, would let me write value tests for the shapes that matter, starting with
eee76bf6. One more thing to watch in a game run with the switch on: a GPU timeout or wrong output in a gained shader. The pair barrier assumes one SIMD group keeps running while its partner spins. That held in every Metal test here, but Metal doesn't document it.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-27T23:29:21Z.
A data point for #438 from an M5 Pro 48 GB (Series S), on preview
b3c1a1b0plus #438 and a few other open PRs.lockstep_waves,eee76bf6265f33bband22bac47e3a8446f9now translate.898d9c1a5605ad81(the Series X culler) is still refused, now as "an s_barrier the console waves of a lockstep group may reach unevenly" at 0x694.VICTORY_LOCKSTEP_WAVES=1:eee76bf6is first bound at frame 2290 (+95 s). The first GPU time-out comes at +117.4 s, with 3 command buffers never reported (the first for 16.8 s) and one OutOfMemory report at +124 s. The GPU drained afterwards.This is one run each way, so not proof. What we don't know yet is whether the stuck pass is
eee76bf6itself (the lockstep poll: can a SIMD group spin while another one in the same threadgroup isn't being scheduled?), or the four ray-traced dispatches it feeds, which now get real group counts for the first time (0af6bb55,52f01bcb,67662685,caa50df7). A run with a per-pass command-buffer trace will name it, and we'll post the result here.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-27T23:49:12Z.
@marcus-4 an offline sweep of #438's switch (
VICTORY_LOCKSTEP_WAVES), on against off, same binary, by output fingerprint (examples/sweep+tools/corpus/compare.sh):eee76bf6265f33bbis among them. It is the one we care most about: it writes the[0, 1, 1]init of the dispatch records of the ray-traced passes (0af6bb55,52f01bcb,67662685,caa50df7). While it is refused they run zero groups, the per-tile light mask stays empty, and interiors are dark (chain on #258). The other newly translated:00fc302d8e70d1b6,08b62ac5ce40cceb,22bac47e3a8446f9,67a13ba4cde171c6,e265a8356ad6125c, and on B also17d6c48bac0751f3,61a6c35cf9a06a5a,d3ada4dfc4a06127.One refusal becomes a panic with the switch on:
compute_ab95b63f73b77253panics in the translator with "forward reference outside a phi"; with the switch off it is a plain refusal. Worth a look before this lands.Where the rest of the class goes with the switch on (B): 9 "an s_barrier the console waves of a lockstep group may reach unevenly" (
898d9c1a5605ad81, the Series X culler, is one), 6 "an exchange between host waves in an earlier block, in lockstep of several console waves a group", 2 "ds_append or ds_consume in a console wave the host splits".Not covered: a game run on current main (
86cefd22). Our earlier in-game run with the switch on stopped about 12 s aftereee76bf6first ran; we'll re-run on the new main and post what we see.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by marcus-4 on 2026-11-27T23:55:16Z.
Thank you, @Olima34, that run answered it. The time-out is almost certainly the pair barrier itself, not the ray-traced passes. I reproduced it without the game (
5bf340b8, two measurement tests, ignored by default):So once the GPU has more groups than it runs at once, a SIMD group spinning in a threadgroup does not let its partner run, and the 2^20-poll bound doesn't rescue it. The small Metal tests passed only because a handful of groups always run together. Every world dispatch is past that size.
898d9c1abeing refused at 0x694 is the uneven-barrier rule working as meant, but it doesn't matter now.What this means for #438: the switch must stay off. It already is by default, and I've written the result into
docs/native-host.md. Please don't spend more runs on it. The spin-wait is not a sound barrier on Apple GPUs, so the pair-barrier mode can't be fixed by tuning.What I think it needs instead: a barrier-free form for these programs. That's Vice-Tay's paired lanes (gagarinyury's pointer on #376): one host wave per console wave, each thread two console lanes, so a group's barriers line up as on the console and nothing waits on a partner. I'd like to try that next, as a separate PR, and either rework or close #438 depending on what the maintainer prefers.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-27T23:58:22Z.
Thanks @marcus-4, that's a clear answer, and it matches what we saw: right in small tests, a hang about 12 s into the world. We've stopped all runs with the switch on. Paired lanes sounds right to us. When the PR is up, we'll sweep it over our corpora and run it in game on an M5 Pro, watching
eee76bf6and the four ray-traced passes' records (0af6bb55,52f01bcb,67662685,caa50df7). Those records should then hold real group counts, and the per-tile light mask of the interior should stop being empty.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by marcus-4 on 2026-11-28T02:10:29Z.
Closed in favour of #541 (paired lanes: one host wave per console wave, no barrier of our own), which replaces the spinning pair barrier that hung the GPU here.
Pull request closed