Recompiler: split-wave64 one-wave groups can meet at a group barrier (opt-in, XCL_WAVE64_BARRIER=1) #2367
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2377"
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 ivall/xcl. Originally posted by grahamster2 on 2026-11-25T17:24:05Z.
In the HLSL split-wave64 form, a group of one console wave (64 threads or fewer) is just the two 32-lane halves of that wave. They meet through the bounded counter spin (
XCL_X_SPIN 1) by default since #798, which costs about 2.3x the group barrier per exchange on Ampere (see #1244: RTX 3080 and RTX 3070 numbers). This PR adds an opt-in for the cheaper group barrier on one-wave groups, as the direct DXIL translator already does for 33-64-thread groups (Partner::Present, #1426). The default does not change: the counter spin stays, and the barrier needsXCL_WAVE64_BARRIER=1.An earlier head of this PR made the barrier the default. bmjask's review (P1) pointed out that the barrier is unbounded: a pair that desynchronises (a plain non-GLC
s_loadthat sees two values, hazard 1 indocs/wave64-on-wave32.md) would hang the dispatch until a TDR, where the counters give up after a bounded wait and give wrong output instead. So the barrier is now something you ask for.Design discussion: #1244 (last comments).
What is in it
crates/xcl/src/gpu/recomp/emit.rs:x64_spin_for(threads, spin, barrier)picks the meet form, andx64_spincalls it withXCL_WAVE64_SPINandXCL_WAVE64_BARRIER. The rule:XCL_WAVE64_SPINset to0(trimmed) gives the barrier, as onmain; set to anything else, including empty (as onmain), it forces the counters. WithXCL_WAVE64_SPINunset,XCL_WAVE64_BARRIERset to anything but empty or0gives the barrier; otherwise the counters (the default).XCL_WAVE64_SPINkeeps its current meaning exactly,XCL_WAVE64_BARRIER=1is a second way to the same barrier, andXCL_WAVE64_SPIN=1wins overXCL_WAVE64_BARRIER=1.crates/xcl/src/gpu/recomp/pso.rs:XCL_WAVE64_BARRIERjoins the variables that bypass the shader cache (cache_allowed, and its test). Without it a cached counter-form shader would be served with the variable set, or the reverse.docs/wave64-on-wave32.md("Synchronisation"): says the barrier for one console wave is opt-in, why, and how the two variables interact.crates/xcl/src/gpu/recomp/tests.rs:split_wave64_meet_form_by_group_size(unit test):x64_spin_forfor 16, 32, 40 and 64 threads with every combination ofXCL_WAVE64_SPIN(unset,0,0, empty,1) andXCL_WAVE64_BARRIER(unset, empty,0,1,1) that the rule distinguishes, and for 65 to 1024 threads; the emitted#define XCL_X_SPIN 1for 64x1x1, 8x8x1, 4x4x4, 40, 32, 16, 256 and 8x8x4 groups (hard-coded, so checked in any environment for several-wave groups and when neither variable is set for the rest); and that a half without a partner leavesxcl_x_meetbefore either form.gpu_split_wave64_one_wave_groups_end_early(GPU test): 64-, 48- and 40-thread groups make an exchange, then odd groups end early on a scalar branch and even ones exchange again and store. It checks the form it expects (the counters, or the barrier whenXCL_WAVE64_BARRIERasks for it) and that no half is left waiting. With the default settings it covers the counter form; the barrier form runs when the variable is set (see Tested).gpu_split_wave64_waves_divergeexpects the counters unless a variable asks for the barrier in the 64-thread case.bench_split_wave64labels its rows with the formx64_spin_forpicks.Why the barrier holds in a one-wave group, and when it does not (checked in the code at
main0829441; this part has not been touched since)s_endpgmbecomesFlow::End, which lowers topc = 0xFFFFFFFFu;(recomp/mod.rs,Flow::Endarm). That is a jump to the end of the program, not areturn, so no hardware wave leavesmainearly.xcl_budget:LOOP_GUARDis a per-lane counter that both halves start at the same value and decrement once per loop iteration. Branches are on SGPRs, SCC, VCCZ or EXECZ.x64_maskstreats any whole read of a mask as needing the exchange; lane reads and GLC/DLC scalar loads are exchanged. So the halves branch the same way and spend their budgets equally, as long as the SGPRs they branch on are the same.s_load, which is not exchanged: each half loads on its own. A one-wave group whose halves can see two different values (a group that writes memory and reads it back with a plains_load, or one that polls memory another group writes, then branches on the result) can split its halves. With the barrier that hangs the dispatch (TDR); with the counters it gives bounded wrong output. That is why the barrier is opt-in. On the console such a load is not coherent either, so a title that relies on it is already racing.xcl_xnis 0 in the only hardware wave, andxcl_x_meetreturns before the#if XCL_X_SPIN, so neither form meets. In a 33-64-thread group both halves havexcl_xn > 0and both meet.xcl_xn = 32in both halves, the GS phasexcl_xn = 0(no meets).Tested
0c44653(rebased onmainb49be183),cargo test -p xcl --lib: 1311 passed, 0 failed, 27 ignored, 24 SKIPPED lines (theno wave64GPU cases and three direct DXIL refusals of f16 or f32-to-f16 forms).cargo test -p xcl --lib gpu::recomp::tests: 169 passed, 0 failed, 17 ignored withXCL_WAVE64_SPINandXCL_WAVE64_BARRIERunset, withXCL_WAVE64_BARRIER=1(the barrier form everywhere it applies, including the early-end test), withXCL_WAVE64_SPIN=1and withXCL_WAVE64_SPIN=0.XCL_WAVE64_BARRIER=1orXCL_WAVE64_SPIN=1set: 1310 passed, 1 failed in each,pso::shader_cache_tests::console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk. That is the shader cache being bypassed by the variable on purpose (the same for the existingXCL_WAVE64_SPIN), not a recompiler failure.a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier(left: 3, right: 1) on the previous head, which was based on amainfrom before #2420 changed that test. It passes on this head, rebased on currentmain, in every run above. I did not rerun the old head to confirm it was that test's staleness and not the barrier default; the head is rebased and the default is gone either way.bench_split_wave64(cargo test --release -p xcl --lib bench_split_wave64 -- --ignored --nocapture, 2^18 threads x 32768 iterations, GPU timestamps, median of 9). It ran onmain0829441and on this PR's earlier head 34d2583, which selected the barrier for one-wave groups; the barrier code path is the oneXCL_WAVE64_BARRIER=1selects now, but I did not rerun the bench on this head.main, 64-thread groups (counters)main, 256-thread groupsOne run each. 256-thread groups always spin, as intended.
Regression run
The smoke run is with the default settings, which give the same recompiler output as
main(the counters). A run withXCL_WAVE64_BARRIER=1on this head showed 1634 frames, no device removal, no crash, peak commit 14849 MB (not a second block, one 60 s run).main:
PR:
One 60 s run each, so a gap of a few frames is not meaningful.
Not tested
cargo test --workspace): only thexcllib tests ran.XCL_WAVE64_BARRIER=1makes the retail title's one-wave split programs faster in frame time.s_load(the hazard above): no test builds one, so there is no regression test that the default does not hang on it, only the argument that the counters are bounded.bench_split_wave64runs, no bench on this head, and no run with the 32 KB LDS block.AI use
AI-assisted (Claude Code).
Imported from ivall/xcl. Originally posted by DarkPanda69 on 2026-11-25T17:32:30Z.
Update for head
0c44653(now opt-in): rerun onmainb49be18, in both modes.XCL_WAVE64_BARRIERunset): pairedgpu::runs, RTX 3060 710 → 712 passed, 0 failed; RX 9070 XT withXCL_SPLIT_WAVE64=1708 → 710 passed, 2 failed (#2115, the same onmain). The only result changes aregpu_split_wave64_one_wave_groups_end_earlyandsplit_wave64_meet_form_by_group_size, both ok, with no new skips. Soak on the RTX 3060:split_wave64×10 = 120 test runs, 0 failed.XCL_WAVE64_BARRIER=1:split_wave64×5 on the RTX 3060 = 60 test runs, 0 failed. ×2 on the RX 9070 XT withXCL_SPLIT_WAVE64=1= 24 test runs, 0 failed.gpu_split_wave64_one_wave_groups_end_earlyok there, with no SKIPPED.An NVIDIA soak of the split-wave64 GPU tests (listed as untested), on an Ampere RTX 3060, plus the change on an AMD driver with the split form forced. No failures.
Head
6ee3743applied onmain68a284a, debug, Windows 11 Pro 26200.Soak, RTX 3060 (driver 32.0.16.1088, 32-lane waves, so the split form by default):
cargo test -p xcl --lib -- split_wave64 --test-threads=4, 10 runs back to back = 120 test runs, 0 failed (12 tests per run,gpu_split_wave64_one_wave_groups_end_earlyamong them).Paired against
main, wholegpu::filter (cargo test -p xcl --lib -- gpu:: --test-threads=4):mainXCL_SPLIT_WAVE64=1On both cards the only differences are the 2 new tests (
gpu_split_wave64_one_wave_groups_end_early,split_wave64_meet_form_by_group_size, both ok); no existing test changes result or skip state. The failures are all onmainwithout this PR:a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrieron both (since #2074's merge, see there) and, on the RX 9070 XT, the #2115 fuzz seeds. So the group-barrier meet also holds on an AMD driver when it runs the split form.Not tested: the whole workspace suite, frame time in a title, a soak longer than 10 runs.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.
Imported from ivall/xcl. Originally posted by emirduran707 on 2026-11-25T17:44:43Z.
Independent AMD RDNA4 (native wave64) full workspace + retail-title smoke report on exact head
6ee3743c788bb7485f1a372adf95bd98ea3eabe9(clean detached checkout, no local changes).Tested
stable-x86_64-pc-windows-msvc), DXC 1.9.2602.17; tests debug, smoke release.cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4: 1272 passed, 2 failed, 46 ignored; 8 SKIPPED (6 inlower_dxil::tests::{f16,f32}_programs_on_the_gpurefused by per-lane form;heap_window_out_of_memory_falls_back_to_the_switch_form;pso_measurement_compiles_an_exact_synthetic_record).gpu::recomp::tests::split_wave64_meet_form_by_group_sizeandgpu::recomp::tests::gpu_split_wave64_one_wave_groups_end_early.gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1seed 722 andfuzz_validate_and_gpu_3seed 1599) are pre-existing on unmodifiedmainon this GPU.Regression run (60 s retail-title smoke,
XCL_NETWORK=0, release; note this GPU runs native wave64 in the title rather than split wave64)(Matched
main68a284abaseline on the same machine today: 1573 frames, 14420 MB peak, 0 device removals, 0 crashes.)Not tested
AI use
Imported from ivall/xcl. Originally posted by jordi-vancuijlenborg-vinci on 2026-11-25T17:50:24Z.
On an RTX 3080 10 GB with NVIDIA driver 621.01, I reproduced the single-wave speedup on the current PR head
6ee3743c788bb7485f1a372adf95bd98ea3eabe9.Tested
Windows 11, i7-9700F, Rust 1.100.0 MSVC, release, DXC 1.9.2609.5. I used the same executable for both modes. A used the default group barrier for 64-thread groups. B forced the counters with
XCL_WAVE64_SPIN=1. Run order was A, B, B, A. Each value is the median of nine GPU timestamp measurements frombench_split_wave64.The 256-thread case used counters in both configurations. Nine focused correctness tests also passed with
XCL_WAVE64_SPINunset, set to1, and set to0. This includes the 40-, 48-, and 64-thread early-exit case. Per setting, 9 passed, 0 failed, 0 ignored, 0 skipped. The benchmark passed in each of the four runs.Commands
Built with
cargo test --locked --offline --release -p xcl --lib --no-run -j 3, then invoked the resulting test executable withXCL_ADAPTER=3080and these arguments:Not tested
Game frame rate, other adapters and the full workspace suite.
OpenAI Codex (GPT-6.2 Astra Extra High) ran the tests and drafted this report.
upstream-sync referenced this pull request2026-11-25 19:07:20 +00:00
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T19:01:02Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)Thanks!
Imported from ivall/xcl. Originally posted by bmjask on 2026-11-25T20:23:04Z.
Review: COMMENTED
P1: this makes a known split-wave64 divergence hazard a default GPU hang. For <=64-thread groups, emit.rs:5975-5985 selects unbounded GroupMemoryBarrierWithGroupSync in xcl_x_meet. A plain non-GLC s_load is not exchanged and can produce different scalar values in the two emulated halves; the PR description acknowledges this. The prior counter form eventually abandoned the exchange, but the new default can deadlock the dispatch/TDR. XCL_WAVE64_SPIN=1 is an opt-in escape hatch, not a safe default, and tests cover only synchronized early scalar end. Keep the bounded form by default or gate the barrier on proof/feature support, with a non-hanging regression or rejection test. The current Windows build/test check also fails and needs repair/re-run.
[PR #2377] Recompiler: split-wave64 one-wave groups meet at a group barrier by defaultto [PR #2377] Recompiler: split-wave64 one-wave groups can meet at a group barrier (opt-in, XCL_WAVE64_BARRIER=1)Imported from ivall/xcl. Originally posted by grahamster2 on 2026-11-26T06:46:34Z.
@bmjask thanks, you were right and I took the first option: the barrier is no longer the default. Head is now
0c44653, rebased on currentmain.s_load) gives the old bounded wrong output again.XCL_WAVE64_BARRIER=1turns the barrier on for groups of 64 threads or fewer.XCL_WAVE64_SPINkeeps its current meaning:0still selects the barrier, any other value still forces the counters, andXCL_WAVE64_SPIN=1wins overXCL_WAVE64_BARRIER=1. Groups of several console waves always use the counters.XCL_WAVE64_BARRIERalso bypasses the shader cache, likeXCL_WAVE64_SPIN(pso.rs, with its test), so a cached shader of the other form is never served.docs/wave64-on-wave32.mdnow says the barrier is opt-in and why.XCL_WAVE64_BARRIER=1. Thegpu::recomp::testsfilter passes unset, withXCL_WAVE64_BARRIER=1,XCL_WAVE64_SPIN=1andXCL_WAVE64_SPIN=0.What I did not add: a test for the hang itself. No test builds a program whose halves split through a plain
s_load, so "the default does not hang on it" rests on the counters being bounded, not on a regression test. The description says so.The failing "Build and test" run was
a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier(left: 3, right: 1) on the old head, based on amainfrom before #2420 changed that test. It passes on this head in every run I did, but I did not rerun the old head, so I cannot say whether the barrier default also played a part.Smoke pair on the new head (default settings, 60 s): 1640 frames against 1642 on
main, no device removal, no crash. The title and description are updated.AI use: Claude Code (Claude Sonnet 5.5) wrote this reply.
Imported from ivall/xcl. Originally posted by Decodere on 2026-11-27T03:58:36Z.
Independent desktop NVIDIA verification of PR #2377 at head
0c446533681f07cf43e91479a7abf869e2aab28e(1commit; exact parent & merge-base:b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7, pre-#2555ancestor ofmain).Environment
7956 MiBreported by D3D12, Wave32-only Ada), driver32.0.16.2114(NVIDIA621.14, WDDM 3.2)31.9 GiBusable), Windows 11 Home26200(Developer Mode off)rustc 1.100.0 (0ef1bc386 2026-11-09)MSVC, DXC1.9.2609.5,--releaseTargeted release tests & build (
0c446533)cargo test --release -p xcl --lib split_wave64_meet_form_by_group_size -- --nocapture(default env, 3 runs)1 passed; 0 failed; 0 ignored; 1337 filtered out× 3 (0.00s× 3,0skipped)cargo test --release -p xcl --lib gpu_split_wave64_one_wave_groups_end_early -- --nocapture(default env, 3 runs)1 passed; 0 failed; 0 ignored; 1337 filtered out× 3 (0.32s,0.29s,0.27s,0skipped; live RTX 4060 counter-spin path)cargo test --release -p xcl --lib gpu::recomp::pso::(default env, 3 runs)27 passed; 0 failed; 1 ignored; 1310 filtered out× 3 (0.08s× 3,0skipped; includesshader_cache_bypasses_debug_overridescoveringXCL_WAVE64_BARRIERandconsole_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk)XCL_WAVE64_BARRIER=1 cargo test --release -p xcl --lib gpu_split_wave64_one_wave_groups_end_early -- --nocapture(opt-in barrier, 3 runs)1 passed; 0 failed; 0 ignored; 1337 filtered out× 3 (0.29s,0.25s,0.25s,0skipped; live RTX 4060 group-barrier path)XCL_WAVE64_BARRIER=1 cargo test --release -p xcl --lib gpu::recomp:: -- --test-threads=4(opt-in barrier, 3 runs)402 passed; 1 failed; 20 ignored; 915 filtered out× 3 (6.49s,6.13s,6.17s;23SKIPPEDnotices across13distinct tests —no wave64on Wave32-only Ada and#1426per-lane refusals;0GPU execution failures; see cache-bypass test note below)cargo build --release -p xcl1m 09s, exit0,0new warnings)Observation on
gpu::recomp::with process-wideXCL_WAVE64_BARRIER=1: All402other tests ingpu::recomp::(including every split-wave64 GPU test) passed3/3underXCL_WAVE64_BARRIER=1. The sole failure (3/3) wasgpu::recomp::pso::shader_cache_tests::console_mesh_caches_hlsl_compute_pass_in_memory_and_on_diskatcrates/xcl/src/gpu/recomp/pso.rs:1970:9(assert_eq!(cache.lock().unwrap().entries.len(), 1)observed0). That directly confirms PR #2377's intentional addition of"XCL_WAVE64_BARRIER"to the shader-cache debug-override bypass list (pso.rs:908); the same test passes3/3in the default environment (gpu::recomp::pso::27/27). (Minor test-ergonomics note: unlike line1979'sXCL_TRANSLATED_CACHEguard, line1970does not skip when a debug-override env var disables caching.)Paired quiet 60 s retail smoke (
title: 29640639)Exact parent & merge-base (
b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7, cached baseline on the same machine):PR #2377 (
0c446533681f07cf43e91479a7abf869e2aab28e, default flags — counter spin):PR #2377 (
0c446533681f07cf43e91479a7abf869e2aab28e, opt-inXCL_WAVE64_BARRIER=1):Runtime log observations (
xcl.log&report.json)9222lines and0[ERROR]/ device-removal / panic lines, with228background pipelines (0failures) and1024+translated compute dispatches (0skipped).XCL_WAVE64_BARRIERunset):D3D12.X: compute PSO with the translated console CS (98748 B DXIL, 1 ms, the driver's blob of an earlier build);dxil_cache:460hits,0misses,0compilations;19489 draws with translated pipelines (0 skipped, 0 with PC pipelines), 1024 dispatches (0 skipped); last memory sample13986 MB committed by the process; video memory 6115 MB local, 4651 MB non-local.XCL_WAVE64_BARRIER=1run:D3D12.X: compute PSO with the translated console CS (92296 B DXIL, 968 ms)— DXIL shrank from98748 Bto92296 B(-6452 B,-6.5%), compiling cleanly fresh (dxil_cache:459hits,1miss,1compilation,0compilation failures), confirming live barrier emission and shader-cache bypass on a retail compute shader with0hangs or timeouts across1024+dispatches (0skipped) and19615+draws (0skipped); last memory sample14032 MB committed by the process; video memory 6115 MB local, 4683 MB non-local.Limits of coverage
XCL_WAVE64_BARRIER=1one-wave group-barrier paths were directly exercised on desktop RTX 4060 in unit/GPU tests (3/3) and paired 60 s retail smokes (0hangs,0device removals,0crashes).bench_split_wave64microbenchmark was not run.XCL_WAVE64_BARRIER=1stays opt-in because a desynchronized scalar-load pair could still hang an unbounded barrier in shaders not exercised during this 60 s retail window; Wave64-onlygpu::recomp::tests self-skipped on Wave32-only Ada.AI disclosure: test execution and report drafting assisted by Google Antigravity (Gemini 4 Neon).
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T06:16:59Z.
Review (head
0c446533, diff read, not a merge-check; it conflicts with main, so not built or run):4701a874("Recompiler: use barriers for one-wave split wave64 groups", bmjask, via #2959), adapted from this PR's earlier head6ee3743c. On main, one-wave split groups already meet at the group barrier by default (emit.rs~6546: unset gives the barrier,XCL_WAVE64_SPIN=1the counters), and thex64_spin_forunit test andgpu_split_wave64_one_wave_groups_end_earlyare on main too. Rebasing this head would turn main's default back to the counters, the opposite of an opt-in. If the TDR concern from the earlier review should change main's default, that's a new small PR against main'sx64_spin_for(which now takesx64_hw_threads).docs/wave64-on-wave32.md(~55-58, ~75-78) still describes the counters as the default, which no longer matches the code.Fine: the analysis of why the barrier holds for one-wave groups and when it doesn't. Recommendation: close as superseded by
4701a874.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by throny on 2026-12-01T12:52:22Z.
Closing as superseded: this change is already on
main(4701a874). main4701a874(bmjask, adapted from grahamster2's6ee3743c) uses group barriers for one-wave split wave64 groups by default, XCL_WAVE64_SPIN=1 forces counters; PR's opt-in XCL_WAVE64_BARRIER is mootTwo independent checks found this: Foniass's close list on #1607 and ours against current
main. If something here is still missing onmain, say so and reopen it, or ask and I will.AI use: Claude Code (Claude Opus 5.5); the per-PR comparison was done by Claude Sonnet 5.5 sub-agents.
Pull request closed