wave64_emulate_opt: a guarded s_barrier keeps only the tail in the round scheduler (SHADER-W64-STRUCTURED-SBARRIER-TAIL) #2102
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!2102
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2102"
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?
@DadaCap on GitHub · 2026-11-25 20:45 UTC · original
DadaCap:mesh-epilogue-tail→main· +52 −18 · 4 files · 1 commits · merged 2026-11-26 21:42 UTCClaimed in the coordination issue as: SHADER-W64-STRUCTURED-SBARRIER-TAIL (#1608)
Depends on: nothing
What and why
Under
--wave64-emulate,plan_structured_emulationgives no plan for a multi-wave program (more than 64 threads) as soon as ones_barriersits under a guard or in a loop. The NGG mesh epilogue has one (s_cbranch_vccnzover ans_barrier), so every mesh program of 1.0.2.1 runs whole in the round scheduler.The planner already has a step for a tail that must stay in rounds (
tail_scheduler, used from an earlys_endpgmon). This change uses it from the first guardeds_barrieron as well, and emits what comes before in the structured form.Why it is sound:
s_barrierand runs to the end of the program, so every suchs_barrier, and every one after it, stays in the rounds. Waves on different paths still meet at different sites there (cs_barrier_divergent).s_barriers in top-level blocks, which the whole workgroup reaches, and nos_endpgm.Counts over 1.0.2.1 (translator only)
spirv-valfailuresAll of them translate before and after. The compute programs were run through main's translator again for the "before" column (none is structured). For mesh, main's translator gives the same bytes as the old folder for three programs I checked. Other stages cannot reach this code.
Measured in the game
Two runs of the same executable (a local tree of
db1a22d29with other open work, GPU timer on), the only difference being the mesh modules. Median GPU time of the sampled indirect draws, for the 17 mesh programs sampled at the same group count in both; the sample counts are small for some:MS_VS_TransformD_c5fd36bbMS_VS_OctaSLOD_5fd19871MSNC_VS_TransformSkinD_9e3a1555MS_VS_TransformD_c5fd36bb~153MSNC_VS_PropFoliageSkinDeferred_4352f5e1~8MSNC_VS_TransformSkinD_9e3a1555~50The other 11 are between 0.13 and 0.64.
Not shown by these runs:
Tested
tests/semantic/test_wave64_emulate_opt.py:test_multiwave_divergent_sbarrier_falls_back_to_roundsasserted the old fallback; it now asserts that boths_barrierarms are in the tail, and the same memory result in both invocation orders. New: a mesh-epilogue shape (guardeds_barrier, skipped and taken, 128 threads, both orders).tests/semantic/test_loop_ballot_barrier.py: two tests asserted the rounds form for ans_barrierin a loop; they now expect the structured form, and their memory results (including the wave that ends early) are unchanged.tests/test_translate.py: 706 pass, 2 fail (cs_dpp_cmp.asm: my olderllvm-mcrefuses the DPP form ofv_cmp); both fail the same way on plainmainhere.python -I -m compileall -q tools tests,tests/test_docs_*.py,scripts/check_no_game_data.pyon the changed files.GPUs tested: NVIDIA GeForce RTX 5080, driver 621.24, Windows 11 (the game runs above; the hand-written GPU tests were not run)
AI-assisted: yes (Claude Code, Claude Opus 5.5 wrote the change, the tests and this text)
Checklist
mainand merges cleanly.docs/design.md, with how it was confirmed.🤖 Generated with Claude Code
@DadaCap on GitHub · 2026-11-25 20:52 UTC · original
@OreoFR asked on Discord which library programs move out of the rounds form. These 34 (
lib_cs_numbers of the 1.0.2.1 listing here):00848, 00959, 00960, 00962, 00963, 01009, 01010, 01054, 01055, 01058, 01059, 01060, 01061, 01180, 01182, 01454, 01456, 01459, 01461, 01532, 01610, 02003, 02060, 02079, 02923, 02931, 02935, 02936, 03108, 03114, 03118, 03134, 03135, 03138
Of your five: 00959 is in the list. 01851 stays in rounds with this change. 01468 and 01855 were already structured before it, and 00906 is not emulated wave64, so this change does not touch those three. The new compute modules have not been run in the game here.
AI-assisted (Claude Code, Claude Opus 5.5).
@xel1uz on GitHub · 2026-11-25 21:13 UTC · original · approved these changes
Approving
84816055. I verified it independently onmain747809e7(merged cleanly).Nonefor the whole program at any guarded or loopeds_barrier. The new condition hands off at the first such top-level item, so every guardeds_barrierand everything after it stays in the rounds. Before that point only whole-workgroup top-level blocks can hold ans_barrier, and the tail step and its dirty-memory barrier are unchanged.tests/semantic/test_wave64_emulate_opt.pyandtest_loop_ballot_barrier.pyare OK.main'stools/wave64_emulate_opt.pythey fail (2 + 2).tools/lds_fuzz.py --wave 64 --emulate(seed 55501) 300/300 match;tools/crosslane_fuzz.py --wave 64 --modes emulate --no-maskdata(seed 55502) 300/300 match.run_gpu_tests.pywithLEONIDA_W64_EMULATE=1 --filter cs_: 99/130 passed, the same asmain.cs_barrier_divergentandcs_barrier_early_endpass with the expected127 126 ... 120.cs_barrier_loopskips on llvmpipe, which can't pin 32 lanes. The one failure,cs_imgatomic_ext, also fails onmainand is #1518.All runs: Ubuntu 26.04, Python 3.14, LLVM 21.1.8 / 19.1.7, SPIRV-Tools 2026.1, Mesa 26.0.8 llvmpipe. I did not measure the in-game speedup.
AI-assisted review, CPU only (llvmpipe).
@OreoFR on GitHub · 2026-11-25 22:11 UTC · original
Thanks for the list. I ran it: only
lib_cs_00959swapped for your translation (main's translator reproduces my installed module byte for byte), main +mesh-indirect-on-main, RTX 4070 Laptop 621.40. The device was still lost at ~197 s. Aftermath showslib_cs_00959(new hash) at the loop head of the round-scheduler tail that stays after the guardeds_barrier. So for this hang the remaining tail is enough. Next run: all 16,762 mesh programs (9,282 + 7,480fspx_gfx) translated with this PR.@MoonEyes on GitHub · 2026-11-25 22:39 UTC · original
Verdict: ready to merge. This agrees with xel1uz's approval and adds a second mutation, a coverage note and a mesh sample. Two suggestions below, neither blocking.
Setup: PR head
84816055don its basedb1a22d29. Main is nowd3b8251bc, 176 commits later; none of them touches the 4 changed files ortools/rdna2spirv.py, and the two touched test files give the same result on the PR merged with it (34/34 and 15/15). Windows 11, Python 3.14. The tests below run on the CPU SPIR-V interpreter, so no GPU was involved. I ran nothing in the game.Tests
test_wave64_emulate_opt33/33,test_loop_ballot_barrier15/15.tools/wave64_emulate_opt.py: 4 fail, all on thecontrol_flowassertion (rounds!=structured). That is 2 intest_wave64_emulate_optand 2 intest_loop_ballot_barrier.or (...)clause removed attools/wave64_emulate_opt.py:1792: onlytest_multiwave_guarded_sbarrier_epilogue_keeps_body_structuredfails. See the first suggestion.test_lds_src2, 63 failures). It fails the same way on main: myllvm-mcruns through WSL and cannot see the Windows temp path. This is unrelated to the PR, and #1733 fixes it. xel1uz's Linux run has 0 files failed.scripts/check_no_game_data.pyon the 4 changed files: clean.--wave64-emulate):spirv-val-valid: 1,032/1,032 with main and 1,032/1,032 with the PR;emulated wave64 roundstoemulated wave64 structured;Safety
tools/wave64_emulate_opt.py:1792runs before the sync-free and mini-scheduler paths (:1801-1822). It uses_blocks_in_tree(:1058-1068), which descends into both guards and loops. So any top-level guard or loop that contains ans_barrier, however deeply nested, starts the tail, and the tail runs to the end (:1795-1796).s_barrieronly in top-level blocks (:1782-1788).check_sync_freealso rejects anys_barrier(:1750). Folds cannot hide one: the fold rules excludes_barrier(:14), andsb_has_sbarrierscans every block of a chain (:1594-1615).s_endpgmstill starts the tail throughhas_end(:1781,:1792). The flattening stops after it (:1719-1742), so a guardeds_barrierbehind an earlys_endpgmalso ends up in the tail.tools/rdna2spirv.py:16598-16609).s_barriersites. Main never produced that, because the old early return covered all offlat_top.test_multiwave_divergent_sbarrier_stays_in_tail_rounds(tests/semantic/test_wave64_emulate_opt.py:1433) checks it in both invocation orders.s_barrier. Planinline_block, inline_sync_free, inline_block, tail_scheduler, and the memory result was correct in both orders.Suggestions (non-blocking)
:1433), each arm ends ins_endpgm, sohas_endalready sends it to the tail. In the epilogue test (:1461),vccis the same for both waves. As a result, no PR test pins a wave-divergent guardeds_barrierthat rejoins with nos_endpgm(for example an if/else with ans_barrierin each arm). I tried that shape locally: on the PR the plan isinline_block, tail_schedulerand the memory is correct in both orders. With mutation 2 the two arms become two separate mini-schedulers, and the CPU interpreter still returns the correct memory. So the test needs atail_blocksassertion; the memory check alone does not catch it. Mutation 2 also passestest_loop_ballot_barrierunchanged, because those loops go to a mini-scheduler.tail_blocksassertions attests/semantic/test_loop_ballot_barrier.py:1395and:1468would pin the new clause there too.tools/wave64_emulate_opt.py:1517still says a divergents_barrierreturnsNone. The comment at:1793only mentionss_endpgm. Both could say "or a guarded/loopeds_barrier".Not covered by this review
tests/test_translate.pyor the hand-written GPU tests.docs/design.mdrow, so whichever PR lands second will need a trivial merge.AI-assisted: yes (Claude Code, Claude Fable 5.2, ran the tests and wrote this; a second agent re-ran the mutations and checked this text)
@ZroIsHere on GitHub · 2026-11-25 23:56 UTC · original
I integrated this change into
ZroIsHere/leonidaonintegration/world-frame-blockersasad86d5ebd. It applies cleanly over the current integration branch. The existing PR remains the review path for this topic.@ammonium231 on GitHub · 2026-11-26 08:54 UTC · original
RTX 3090 / 621.40, LEONIDA_W64_EMULATE=1: handwritten wave64 GPU tests (run_gpu_tests.py --filter w64 and --filter cs_barrier) are 28/29 pass + 1 skip and 3/3 pass on current main
a73a57e13, and identical with this PR merged onto that main (including cs_w64x_sbarrier, cs_w64x_chain_barrier, and the three cs_barrier_* fixtures).@aslan2142 on GitHub · 2026-11-26 21:42 UTC · original
Merging.
s_barriernow keeps only the code from it onward in the rounds scheduler, instead of sending the whole program there. Nothing changes without--wave64-emulate.mainfac8b4bb9+ this PR (84816055d):main's planner (4 of 49) and pass here.test_ci_registration.py, the docs tests,compileall,make_game.py --helpandcheck_no_game_data.pypass.main's output.--wave64-emulate, 154 of those 450 move from rounds to structured (150 mesh, 2 compute, 2 library), 27 stay in rounds, and all 450 passspirv-valwith both translators.cs_dpp_cmpunder CI'sllvm-mc, an uncalled test intest_feature_scan.py, and a missing define invk_null_descriptor_test.cpp. None is in the four files changed here.Optional follow-ups from @MoonEyes's review: a
tail_blocksassertion in the loop tests, and the docstring atwave64_emulate_opt.py:1516.Thanks @DadaCap, and @xel1uz, @MoonEyes, @ammonium231 and @OreoFR for the reviews and runs.
AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2)