Recompiler: split-wave64 one-wave groups can meet at a group barrier (opt-in, XCL_WAVE64_BARRIER=1) #2377
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!2377
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@grahamster2 on GitHub · 2026-11-25 17:24 UTC · original
grahamster2:wave64-barrier-default→main· +155 −17 · 4 files · 1 commits · openIn 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).
@DarkPanda69 on GitHub · 2026-11-25 17:32 UTC · original · edited 2026-11-26 06:55 UTC
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.
@emirduran707 on GitHub · 2026-11-25 17:44 UTC · original
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
@jordi-vancuijlenborg-vinci on GitHub · 2026-11-25 17:50 UTC · original
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.
@DavidM1911 on GitHub · 2026-11-25 19:01 UTC · original
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!
Recompiler: split-wave64 one-wave groups meet at a group barrier by defaultto Recompiler: split-wave64 one-wave groups can meet at a group barrier (opt-in, XCL_WAVE64_BARRIER=1)6ee3743c78to0c44653368@grahamster2 on GitHub · 2026-11-26 06:46 UTC · original
@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.
@bmjask on GitHub · 2026-11-25 20:23 UTC · original · reviewed
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.
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.