shader: read the console wave's first active lane on split waves in one 2-barrier exchange (#254) #302
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/302"
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 brainbudt on 2026-11-27T10:01:30Z.
Refs #254
On wave64 compute shaders split into two 32-lane host waves,
v_readfirstlane_b32previously lowered towaveReadLaneFirst, returning each host half's own first running lane and ignoringEXEC. In the culling compute shaders this causes waves to read stale counts and overwrite each other's mesh records.What this changes
Lower::split_first_lane,halves.rs): whenEXECis a tracked lane function, each 32-lane host half computes its own first active lane locally (host_ballot+FirstbitLo+waveReadLaneAt) and exchanges(val, has_any)across the two halves in one LDS round-trip (2 barriers instead of 4, and without callingmask_dword(EXEC)/mask_number(EXEC)). Falls back tolockstep_first_lane+wide_read_laneonly ifEXECis untracked.lockstep_first_laneand fast path): checkshi != 0before picking the upper half so an emptyEXECselects lane0(per RDNA 2 ISA) rather than wrappingFirstbitLo(0) + 32to lane31(found by @evan-kolberg).wave_uniform(halves.rs): keeps provably wave-uniform values on the 0-barrier per-half path. Usesmemo+visiting(O(V + E)) and!bools.meet(&[(at_mask, true), (def_mask, false)])so uniform VALU values written under a widerEXEC(e.g. outside anif) stay accepted without an exchange, while rejecting narrowed-EXEC writes read afterEXECwidens, non-uniform scalar phis, and values defined in a cycle not containing the read block.lower.rs):first_lane_of_a_scalarchecks coveringEXECmasks before turning onconsole_lanes/halves, andfill_phiskeeps theall_or_none(0/-1) fast path enabled regardless ofconsole_lanes.split_scc):split_sccis left unchanged so mesh programs' per-half reads remain sound; behind a branch on a first-lane read, compute stays conservatively non-exchanging.Tests
cargo test -p victory-shader --locked: 334 passed, 0 failed (includes 2-barrier exchange, empty-EXEC, uniform VALU under wider EXEC, narrowed-EXEC negative after EXEC widens, and 4TheDoctor's branch form for lanes 8..9 and 40..41 in both 2-wave refusal and 1-wave lockstep).cargo clippy --no-deps -p victory-shader --all-targets --locked -- -D warnings: clean.cargo xtask policy: 370 files ok.Not run locally
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T10:32:37Z.
Thank you for taking #254, and for putting the empty-EXEC case in (evan-kolberg's check).
Before it can merge:
wave_uniformreturns true when it meets a cycle. Please say why a loop phi cannot make a value that differs between lanes look uniform, and add a test with a loop.split_scc) and the mask code of #261 and #271, so expect conflicts.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by brainbudt on 2026-11-27T11:15:29Z.
Updated in
1b8d4f5to address all four points:marcus-4's1d8fbb4that affect Sandile-0511's numbers:console_lanes/halvesare partially mitigated by allowingall_or_nonewhenconsole_lanesis set (lower.rs) and by broadeningfirst_lane_of_a_scalarto accept covering EXEC (at_mask => def_mask), avoiding turning onconsole_laneswhen the source VGPR was moved from a scalar under a wider EXEC.wave_uniformalso accepts VALU defs under a covering EXEC (at_mask => def_mask), which can narrow some of the 27 divergent-read refusals.v_readfirstlane_b32previously did a per-half read (now lowered to one 2-barrier exchange when EXEC is tracked).split_first_lane_reads_console_first_active_laneincrates/victory-gpu/src/native/split_wave_tests.rs(128 threads / 2 console waves,v3 = v0 + 100) checking exact output values for (a) only lanes 8 and 9 active (108/172), (b) only upper half lanes 40 and 41 active (140/204), and (c) empty EXEC (100/164, lane 0 of each console wave). Metal Shader Converter is not installed on this machine, so the GPU dispatch is skipped locally while translation on the split-wave fast path is asserted for all three cases; anyone with the converter can runcargo test -p victory-gpu --lib split_first_lane_reads_console_first_active_lane.wave_uniformcycles + loop test:Reg::V) require all non-self incoming values to be the exact same SSA value (args.iter().all(|&x| x == first)), which immediately rejects any loop-carried vector phiphi(init, updated). Scalar phis (Reg::S) first requireuniform_join(b, |_| true), rejecting divergent loops; on a uniform loop, returningtrueon a backedge computes the greatest fixed point so any non-cyclic divergent input feeding the cycle returnsfalseand failsargs.iter().all(...).trueinmemobefore an enclosing cycle finished checking a divergent edge.uniform_innow trackshit_cycleand only cachestrueonce no enclosing cycle is open (!res || !child_cycle || visiting.is_empty()).split_first_lane_loop_phi_accepts_uniform_and_rejects_divergentincrates/victory-shader/src/emit/wave32_tests.rscovering a uniform scalar loop (0 barriers), a divergent loop-carried VGPR (2-barrier exchange), and a divergent-iterations_cbranch_execnzloop (2-barrier exchange).git merge-treeagainst currentupstream/main; noted the overlap with #253, #261, and #271 and will rebase as those land.Verified locally on macOS ARM64:
cargo test -p victory-shader --lib(337 passed, 0 failed, 1 ignored),cargo clippy -p victory-shader --all-targets -- -D warningsclean, andcargo test -p victory-gpu --lib split_first_lane_reads_console_first_active_lanecompiles and passes translation.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T11:54:34Z.
Thank you for the four changes and for the memo bug you found while checking.
I ran every shader by output on
1b8d4f54(33,625 containers, against mainc1b95875):So 29 compute shaders that translate on main are refused with this change, and 253 give different output. Of the shaders the game binds in the world, 3 are lost and 45 change. Nothing is gained. I cannot merge it like this. Please say which of the changes is meant to change output (the first-lane read on split waves, I assume) and why 29 are now refused; if some of those refusals are on purpose because main's output was wrong, show one with a value test.
A value test that is skipped on your machine does not tell me much, so if you can, please ask someone with the converter to run
split_first_lane_reads_console_first_active_laneand post the result.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by brainbudt on 2026-11-27T12:39:19Z.
Rebased onto
origin/main(86786a7) and pushed4e70bb9with two fixes that directly address the 29 lost compute shaders from your corpus run:split_first_lanepreviously returned a custom refusal string instead oflower::DIVERGENT_EXCHANGE, soemit/mod.rs(matches!(what, lower::DIVERGENT_EXCHANGE | lower::SPLIT_LDS)) never triggered the lockstep retry.split_first_lanenow returnsself.exchange_site(self.cur_ir)?(DIVERGENT_EXCHANGE) directly.#253):Lowernow keepsbarrier_reads(p, st)andwave_uniformtreats those constant-address post-barrier LDS reads as wave-uniform, preserving#253's G-buffer culler behavior (a_barrier_block_behind_a_branch_on_an_lds_word_read_after_a_barrierpasses unchanged).v_readfirstlane_b32lowering changes output — onmain, each 32-lane host half read its own first running lane instead of the 64-lane EXEC's first active lane (#254). Remaining refusals after lockstep retry are multi-wave compute shaders whosev_readfirstlane_b32reads a lane-varying value inside divergent code where the two halves cannot meet at a barrier, wheremainsilently returned wrong per-half values.If anyone with Metal Shader Converter can run
cargo test -p victory-gpu --lib split_first_lane_reads_console_first_active_laneon4e70bb9and post the result, that would verify the Metal values end-to-end.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T16:01:30Z.
Leaving this open for now. I swept my full corpus (21,600 shaders) with this head (
d23c5c30) on top of the other shader PRs I'm landing tonight. Against the same tree without it, 17 compute shaders that translate now are refused with "a cross-lane operation between host waves in divergent code", and 353 outputs change (325 compute, 28 pixel). The Metal split-wave tests pass. It can go in once those losses are gone or explained.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by buddybot89 on 2026-11-28T15:26:00Z.
You asked for someone with the converter to run this, so here it is. At
d23c5c3, on an M2 Ultra (64 GB, macOS 26.7.1) with Apple's Metal Shader Converter 4.0.3:cargo test -p victory-gpu --lib split_first_lane_reads_console_first_active_lanepassed: 1 passed, 0 failed. It wasn't skipped: the log showsmetal: compute pipeline compiled: 46 msbefore the result.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.