Cross-lane compute: a wave vote used as a branch is refused (16 lighting programs); needs if-conversion #527
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 LakshanSivakumar on 2026-11-28T01:02:23Z.
What you see
Lighting and shadow work is skipped because a family of compute shaders is refused with
a cross-lane operation between host waves in divergent code. In my runs 22 compute programs are refused this way per frame.What I know
16 of the 22 are large (4,000 to 29,000 instructions, 128 or 256 threads). They are dispatched together, next to the computes that write the screen lighting targets. All 16 refuse at one of two shapes, a vote over the whole console wave that is then used as a branch:
s_bcnt1 sN, vccthens_cbranch_scc0s_and vcc, exec, maskthens_cbranch_vcczThe Mac's GPU runs a 64-lane console wave as two 32-lane host waves, so each half sees only its own lanes' vote.
Why the easy fixes are wrong:
The fix I believe is correct is if-conversion as in design note #393: run both arms predicated, keep loops going while any wave of the group still wants to, and exchange votes at points every thread reaches. The other route is paired lanes (one host thread does two console lanes), which needs no barriers but touches every vector lowering.
Not in this family, although they are often listed with it: the shadow traces
534b3645dd344ab2,d50c03da6d935d87andffd9788ba9fec033have 32-thread groups and refuse withlane-mask join of an untracked mask(#434, #466).What would help
Related
#376, #393, #302 (regresses 17 compute shaders), #438 (unsound), #512.
How to see it
Branch
lit-world/base-3(commit9a0d811d). It is #437 with fixes on top: #518, the cross-page loads, texture fixes, the page table for described pipelines and the image null-view test. It is not main, and one upstream test fails on it by design (wave32_tests::a_branch_on_a_first_lane_read_is_not_uniform_across_the_halves).Apple Silicon Mac with 48 GB, Series S profile. The world shows about 4.5 minutes after start on a cold shader cache.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by marcus-4 on 2026-11-28T01:47:36Z.
/claim
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by github-actions[bot] on 2026-11-28T01:47:54Z.
Claimed by @Sheffy007. Open a draft pull request with
Refs #527in its description within 24 hours, or the claim expires.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by marcus-4 on 2026-11-28T02:55:25Z.
@Sheffy007, a question so we don't overlap. My
/claimhere (01:47:36 UTC) came 18 s before the bot assigned this issue to you, and I don't see a comment of yours on it, so I think the bot may have mixed up two claims that arrived at about the same time. Your/claimon #538 went in at 01:48:04.I already have a PR for this issue, #541. It adds paired lanes behind
VICTORY_PAIRED_WAVES=1, the route this issue names besides if-conversion, with GPU tests for both of the vote shapes listed above.Are you working on #527, perhaps the if-conversion route? If not, could you
/releaseit so the claim matches the PR? If you are, I'll keep #541 to #376 and stay off yours.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-28T03:05:54Z.
/release
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by github-actions[bot] on 2026-11-28T03:06:04Z.
Released. This issue is free to claim.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by marcus-4 on 2026-11-28T03:06:47Z.
/claim
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by github-actions[bot] on 2026-11-28T03:06:57Z.
Claimed by @marcus-4. Open a draft pull request with
Refs #527in its description within 24 hours, or the claim expires.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by marcus-4 on 2026-11-28T08:19:16Z.
/release
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by marcus-4 on 2026-11-28T08:23:36Z.
/release
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by github-actions[bot] on 2026-11-28T08:23:48Z.
Released. This issue is free to claim.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-28T11:25:16Z.
/claim
Taking the narrow first step this issue asks for: if-conversion for only the two vote shapes (
s_bcnt1 sN, vccthens_cbranch_scc0, ands_and vcc, exec, maskthens_cbranch_vccz) used as a branch, everything else refused as today. Testable without the game via hand-assembled GFX10 in the refusal tests, plus a two-host-wave case where the halves vote differently. I'll read design note #393 and the related #376/#438/#512/#302 first and say in the PR what I took from them. Draft PR from my fork's vibe/ branch to follow.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by github-actions[bot] on 2026-11-28T11:25:31Z.
Claimed by @AnastasisKon. Open a draft pull request with
Refs #527in its description within 24 hours, or the claim expires.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-28T12:27:18Z.
Following up on my claim above, and closing it out honestly.
The narrow first step (the two vote shapes) already exists as @marcus-4's paired-lanes work in #541, which was closed as already in the private tree. It is not in the public tree, so I have carried it forward in my fork: https://github.com/AnastasisKon/Native-Victory-macOS/pull/2
VICTORY_PAIRED_WAVES=1, off by default and part of the shader cache key.main69146296. On an M3 Pro: 422 shader tests, 60 Metalsplit_wavetests (both vote shapes included), clippy forx86_64-pc-windows-gnullvmwith-D warnings, andcargo xtask policyall pass.I am not writing a second implementation of the same fix. As with the rest of the public tree, upstream is frozen, so this lives in the fork rather than here. The one thing left, and the reason to care: with the switch on,
eee76bf6runs, and alexballvideos-netizen measured the four ray-traced passes filling in (0.0000 to 0.6958 non-zero on the 1280x720 target they all write). That needs a game run on a Mac with the title to confirm, which I have not done.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-28T13:03:54Z.
Pinned both shapes with synthetic programs (
emit/wave32_tests.rs, in my fork'smainat20254252). Two findings, the second one changes the scope.1. The
s_bcnt1shape reproduces as described.v_cmp/s_cbranch_execzover the body /v_cmp/s_bcnt1_i32_b64 s6, vcc/s_cbranch_scc0, plus av_readlane_b32of a lane in the upper half:a cross-lane operation between host waves in divergent code.One detail worth recording:
s_and_saveexec_b64masking on its own does not make a site divergent. Every thread still visits the block once, so the exchange stays legal there and the vote lowers. What makes these sites divergent is a real branch (ans_cbranch_execzregion, an if/else) around the vote - which matches "these sites sit under EXEC skips" only if the skip is a branch, not a bare EXEC mask.2.
s_and vcc, exec, maskthens_cbranch_vcczis not refused at all. It translates at every group size, with no exchange and no barriers, because each half branches on its own 32 bits ofvcc. Where the halves agree onvccthat is fine; where they differ it is not the console's answer - the console takes the branch for the wave as a whole, so lanes that hold EXEC but no mask bit still run the body, while here their half skips it. So this shape is a wrong answer rather than a refusal, and if the title's sites are this shape then the if-conversion has to replace the lowering, not only stop refusing it, and "16 refused programs" undercounts how much lighting is currently going wrong.Caveat, so nobody builds on a guess: these are synthetic programs, not the title's shaders. The game files here are still downloading (no
game_scarlett_master.exeyet), so I have no corpus sweep and no in-game counts.docs/metal-backend.mdnow records both behaviours as the boundary an if-conversion has to widen.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-28T13:11:21Z.
Update, and it may make the if-conversion unnecessary for this shape: the paired form already handles it.
a_vote_used_as_a_branch_follows_each_console_wave_in_the_paired_form(crates/victory-gpu/src/native/split_wave_tests.rs, my fork'smainat367ce23e) is the GPU test you asked for - a group of two console waves whose halves vote differently:v_cmp_lt_u32 vcc, 64, v0leaves wave 0 whole (threads 0..63) and wave 1 empty;s_bcnt1_i32_b64 s6, vcccounts 64 there and 0 here;s_cbranch_scc0skips av_mov, so the two waves take different arms. (s_bcnt1leaves SCC set when the count is zero, so wave 0's branch is taken and wave 1's is not.)The fast path refuses the program with
a cross-lane operation between host waves in divergent code, which is the refusal this issue is about. Translated withpaired_waves(VICTORY_PAIRED_WAVES=1,lower/paired.rs), it runs on Metal and the read-back values are per wave: 1 in threads 0..63, 2 in 64..127. Nothing crosses a host wave there - one host wave per console wave, two console lanes a thread - so the vote is the wave's own and the waves may differ, as on the console.So for this shape the fix looks like running these programs in the paired form, not if-conversion:
lockstep::fitsalready allows groups of several waves whenpaired_wavesis set, and the switch is what decides it today (victory-gpu/src/native/shaders.rs).What this does not settle: my program is the vote-and-branch shape only, not the body of the 16 lighting computes, so their whole bodies are still unproven in the paired form, and nothing here is measured in game - the game files on this machine are still downloading, so there is no corpus sweep and no before/after log. The useful next step is a run with
VICTORY_PAIRED_WAVES=1to count what translates and what the picture does. If that holds, #527 turns from "needs a compiler feature" into "validate the paired form and decide the default".Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-28T13:28:37Z.
Second shape, measured on the GPU: it is not only refused-or-fine - the fast path answers it per lane, and that answer is wrong. Pinned by
a_vccz_branch_where_the_lanes_disagree_answers_for_the_wave(crates/victory-gpu/src/native/split_wave_tests.rs, my fork'smainate8cebe57), marked#[ignore]with the observed values until the lowering is fixed.Program, a group of 128 threads (two console waves):
On the console
exec & vccis non-zero for both waves, so both run the body with EXEC as it was and every lane stores 7. On the GPU the fast path stores 0 in lanes 0..32 and 7 in lanes 33..127: the branch is testing each lane's ownvccbit, not the wave's 64-bit mask.Why this matters beyond the refusal count: this shape does not refuse. It translates and draws the wrong lighting wherever the lanes of a wave disagree about the mask, so if the title's light-list programs take this path, part of the black/interior lighting is a wrong answer rather than a dropped draw - which the refusal counts in #527 and #526 would not show.
Confirmed not to be a harness artefact: the same store pattern reads back the lane id 0..127 in order (
v_mov_b32_e32 v2, v0), so the mapping is identity and the values above are what the shader computed.Route out, same as the first shape: the paired form answers per wave (
a_vote_used_as_a_branch_follows_each_console_wave_in_the_paired_form), so running these programs withVICTORY_PAIRED_WAVES=1should both translate them and answer correctly. Second best, if that does not hold for their bodies: refuse this shape instead of translating it, so the draw is dropped and counted rather than drawn wrong.Still synthetic - no title shaders, no in-game numbers, no corpus sweep until the game files here finish downloading.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-28T13:34:18Z.
Correction to what I said above about the second shape, now that I have measured it rather than reasoned about it: the paired form does not answer it either, and the reason is structural.
run_grouptranslates withOptions::paired_waves, but lockstep (and so the paired form) is only tried after the fast path has refused a program - it isemit's retry onUnsupported. Fors_and vcc, exec, maskthens_cbranch_vcczthe fast path accepts the program and answers per lane, so the retry never happens and the paired lowering is never reached. Same program, same per-lane values (0 in lanes 0..32, 7 in the rest) whether the option is set or not:a_vccz_branch_where_the_lanes_disagree_answers_for_the_wave- fast path, wrong answer, ignored;a_vccz_branch_where_the_lanes_disagree_answers_for_the_wave_in_the_paired_form- asserts the fast path refuses first, then the per-wave answer, ignored.So the fix for this shape is not "flip the default": it is to make the fast path refuse a
vccz/vccnzbranch whosevccis a per-lane mask the structuriser cannot test wave-wide - it already refuses other cross-half reads that way - so that the retry runs. Lockstep'sbranchesthen rewrites the branch tos_cmp_eq_u64 vcc, 0and a scalars_cbranch_scc1, which is the wave's answer, and the paired form carries it for groups of several waves. The ignored test names the answer to expect afterwards (all 128 lanes 7).Why I have not made that change yet: it is in the structuriser's
branch(), and the size of the coverage change is unknown without a corpus - somevcczbranches are uniform in practice and are right today, so refusing too widely would drop draws that currently draw correctly. That number needs a run, and a run needs the game files, which are still downloading here.(The first shape, the
s_bcnt1vote, does go through the retry and is answered per wave in the paired form - that result stands.)Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-28T13:42:51Z.
Second shape of this issue fixed behind a switch:
VICTORY_STRICT_VCCZ_BRANCH=1(off by default) on forkAnastasisKon/Native-Victory-macOSmain, commite26b2a9d.What was wrong.
v_cmp_lt_u32 vcc, 32, v0; s_and_b64 vcc, exec, vcc; s_cbranch_vcczasks about the whole wave's mask, butstructure::branch()modelsvcczasvcc & execfor the lane, so the fast path answers per lane. Measured on the GPU (split_wave_tests::a_vccz_branch_where_the_lanes_disagree_answers_for_the_wave, still#[ignore]d as a pin): lanes 0..32 store 0, 33..127 store 7, console is 7 in all 128. The structurer'sBoolsare per-lane booleans, so there is no correct lowering in that form — the answer has to be lockstep, wherebranches()rewrites the branch tos_cmp_eq_u64 vcc, 0+s_cbranch_scc1and it becomes the wave's.What the switch does.
structure::structure_with(program, strict)refuses avccz/vccnzbranch whosevccis not a uniform mask ("a vccz branch on a lane mask the two halves of a console wave can see differently"), andemit::translate_nativehands that refusal tolockstep::retryinstead of reporting it, so the program runs in the paired form with the branch answered per wave. The flag isOptions::strict_vccz_branch, filled from the environment by the native host, and added toTRANSLATION_SWITCHES— without that, a warm cache would keep serving the per-lane translations.Measured end to end (
split_wave_tests::a_vccz_branch_where_the_lanes_disagree_answers_for_the_wave_with_the_strict_switch, 128 threads, two console waves): all 128 lanes store 7,refusals() == 0. Pins:structure::tests::a_vccz_branch_on_a_split_mask_is_refused_only_in_the_strict_form(refusal fires only in the strict form).To measure it yourself:
VICTORY_STRICT_VCCZ_BRANCH=1 VICTORY_PAIRED_WAVES=1on a run, then compare dump translations offline (guess). Off by default, so nothing changes until the switch is set; the shapes it moves to lockstep are the ones to count before making it the default.