Repository navigation
wave64_emulate_opt: a guarded s_barrier keeps only the tail in the round scheduler (SHADER-W64-STRUCTURED-SBARRIER-TAIL) - #2102
Conversation
…und scheduler (SHADER-W64-STRUCTURED-SBARRIER-TAIL) plan_structured_emulation gave no plan for any multi-wave program with an s_barrier under a guard or in a loop, which every mesh program has (NGG epilogue). The tail scheduler used from an early s_endpgm on now takes over from that s_barrier on, and what comes before is emitted structured. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@OreoFR asked on Discord which library programs move out of the rounds form. These 34 ( 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
left a comment
There was a problem hiding this comment.
Approving 84816055. I verified it independently on main 747809e (merged cleanly).
- Reading: the removed guard returned
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. - Own tests:
tests/semantic/test_wave64_emulate_opt.pyandtest_loop_ballot_barrier.pyare OK. - Bite check: with
main'stools/wave64_emulate_opt.pythey fail (2 + 2). - Whole translator suite: 491 files, 6,313 tests, 0 files failed.
- Emulation fuzzing with this branch's translator on llvmpipe:
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).
|
Thanks for the list. I ran it: only |
|
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 Tests
Safety
Suggestions (non-blocking)
Not covered by this review
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) |
|
I integrated this change into |
|
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 a73a57e, and identical with this PR merged onto that main (including cs_w64x_sbarrier, cs_w64x_chain_barrier, and the three cs_barrier_* fixtures). |
|
Merging.
Optional follow-ups from @MoonEyes's review: a 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) |
…ojectLeonida#2102) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Gt9hwNPurxyJ9LAfUbNiYr
Claimed in the coordination issue as: SHADER-W64-STRUCTURED-SBARRIER-TAIL (#1608 (comment))
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