Recompiler: split wave64 spin loops poll with a compare-exchange, not an add of 0 (#847) #1244
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!1244
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1244"
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?
@upipibi on GitHub · 2026-11-24 13:40 UTC · original
upipibi:fix/spin-poll-cas→main· +34 −3 · 2 files · 1 commits · openThe split wave64 form's spin loops poll the other half's arrival counter with
InterlockedAdd(x, 0u, c). On RADV, Mesa's NIR lowers that to a plain load of shared memory and hoists it out of the loop. SzczepanGrela showed this in the RDNA4 ISA on #847: oneds_load_b32before the loop, none inside it. So a half that arrives a few polls late is never seen, and the waiting half always runs out its 2^20 polls and gives up. Under async compute load the split tests fail 66 of 80 times there, and pass 80 of 80 withXCL_WAVE64_SPIN=0. This PR makes the three polls compare-exchanges that never change the word. NIR keeps those inside the loop (checked on #847 with DXC 1.9 and Mesa 26.2.5).Part of #847 (the RADV failures). Related to #772 (the same
gpu_split_wave64_*failures under RADV).With #2377 (one-wave groups meet at a group barrier by default): the two merge cleanly in either order (
git merge-tree, 2026-11-25), and this PR still applies there. Groups of more than 64 threads, and one-wave groups withXCL_WAVE64_SPINset to anything but0, keep the spin counters whose polls this changes.What is in it
gpu/recomp/emit.rs:xcl_x_meet()polls withInterlockedCompareExchange(XCL_XC(...), 0u, 0u, c), andxcl_s_barrier()pollsXCL_BAR_STATEandXCL_BAR_ALIVEthe same way. A compare-exchange of 0 with 0 returns the word like the add of 0 did, and leaves it as it was (when the word is 0 it writes 0). Nothing else changes: the bound, the dead-pair path and the counters.gpu/recomp/tests.rs:split_wave64_spin_polls_are_not_adds_of_zerotranslates a 128-thread split program withs_barrierand av_readfirstlane. It checks that the three polls are compare-exchanges and that noInterlockedAdd(…, 0u, …)is left, and compiles the HLSL with DXC. It fails onmainand passes here. It needs no GPU.Tested
cargo build --workspace+cargo test --workspace --no-fail-fast -- --test-threads=4:71d3a38): 742 passed, 0 failed, 41 ignored;main47efa2e: 741 passed, 0 failed, 41 ignored.gpu_geometry_wave32_prefix_count_over_a_maskandgpu_wave32_program_in_wave64_hardware. Allgpu_split_wave64_*andgpu_safe_s_barrier_*tests pass.bench_split_wave64's loop (one exchange per iteration) with its shape changed locally (64 threads,Dispatch(4,1,1), as on #505). GPU timestamps, median of 9:mainThe poll costs the same when the halves meet. A timed-out meet is about 20 % longer (about 42 ns per poll instead of 36), and that path is taken at most once per wave.
Regression run
From Kalmarv's run (https://github.com/ivall/xcl/pull/1244#issuecomment-7136905555), thanks:
main:
PR:
That is Kalmarv's first pair (the PR at 87 % of
main's frames). Their second pair, about 10 minutes later on the same machine, has the PR at 103 % (1360 / 1317 frames). In every run the title slows to a few frames per 2 s at 44–48 s, and how long that phase lasts decides the total.Not tested
gpu_split_wave64_*andgpu_geometry_wave32_prefix_count_over_a_mask, defaultXCL_WAVE64_SPIN) on this head?AI use
🤖 Generated with Claude Code
@dcastell1 on GitHub · 2026-11-24 13:45 UTC · original
Verified on Windows 11 10.0.26300, NVIDIA GeForce RTX 5090 (driver 621.24), Rust 1.100.0 MSVC 14.44.35207, debug build, on
main@930e8b4(baseline 751 passed, 0 failed, 41 ignored on this box):One more passing test than the baseline; the split wave64 spin-loop polling change ships its case and runs green.
Tree restored afterwards (full diff against a clean checkout), hardware adapter, no Wine, no game data. AI-assisted (opencode): applied the patch to a built tree, ran the suite, reverted it.
@SzczepanGrela on GitHub · 2026-11-24 13:57 UTC · original
Verified on Linux / Mesa RADV +
vkd3d-protonat PR head71d3a38: every failure from #847 and #772 is gone (0 / 146 failed under async compute load; 0 / 185 total including idle runs and the new unit test, vs 86 / 105 failed onmain1ec4c98under the same async loads), andRADV_DEBUG=shadersconfirmsds_cmpstore_rtn_b32stays inside the spin loop.Machine and build. AMD Radeon RX 9070 (RDNA4 /
GFX1201, native wave64, 15.81 GiB VRAM), Ryzen 7 7700, 31.4 GiB RAM. CachyOS, kernel7.3.0-5-cachyos, Mesa26.2.5-arch3.1(radv, Vulkan1.4.354),GE-Proton11-12(Wine Staging 11.0 +ntsync),vkd3d-protonv3.1-1-g8293130eb, DXC/DXIL1.9.2602.17. Built withrustc 1.97.1crossx86_64-pc-windows-gnu, release (cargo test -p xcl --lib --target x86_64-pc-windows-gnu --release --no-run). DefaultXCL_WAVE64_SPIN(unset),XCL_NETWORK=0, solo--exact --test-threads=1 --nocapture, no skips.gpu_geometry_wave32_prefix_count_over_a_mask(XCL_REQUIRE_GPU=wave64):main1ec4c9871d3a38asynccompute (6.5 ms dispatches, 32 KiB LDS, 1 GiB VRAM)async+gfx~83 ms dispatches, 32 KiB LDS, 12 GiB VRAM)gpu_split_wave64_*andgpu_safe_s_barrier(XCL_SPLIT_WAVE64=1):main1ec4c98(idle / async)71d3a38(idle / async)gpu_split_wave64_waves_divergegpu_split_wave64_local_and_exchanged_masks_in_diverging_wavesgpu_split_wave64_masks_read_whole_after_partial_writesgpu_split_wave64_cross_half_operationsgpu_split_wave64_lane_local_masksgpu_safe_s_barrier_multi_warp_and_early_endpgmRADV_DEBUG=llvmunder the same 6.5 msasyncload:cross_half_operations3/3,waves_diverge3/3 (cross_half_operationswas 0/3 idle onmain).split_wave64_spin_polls_are_not_adds_of_zero: 1/1 passed (0.03s).RDNA4 ISA check (
RADV_DEBUG=shadersongpu_geometry_wave32_prefix_count_over_a_mask):ds_cmpstore_rtn_b32stays inside the0xfffffloop body:Not tested: full workspace suite on this branch, native Windows AMD, RX 7900 XT (RDNA3), or
xcl-smoke(no local retail title).AI use: Antigravity (Gemini 4 Neon) cross-compiled
71d3a38, ran the Linux/RADV test matrix andRADV_DEBUG=shaderscheck on my machine, and drafted this comment; I reviewed the results before posting.@DavidM1911 on GitHub · 2026-11-24 14:01 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:Thanks!
@IvyNotFound on GitHub · 2026-11-24 14:23 UTC · original
Retail run on an RTX 5080 (32-lane waves):
71d3a38merged ontomain930e8b4– no regression into world loading; the #505 GPU-wait stalls are still there, about as onmainTested
main930e8b4+ this PR's head71d3a38(clean merge, local commit458ba4d). Retail title of #505,scripts/smoke.ps1 -Seconds 140,XCL_PRESS_A_AT=15,XCL_PSO_WAIT_MS=50(so it gets past the firstListX #101into world loading),XCL_FRAME_DUMP=2. Two runs of the PR (the first also rebuilt the changed split-wave64 programs), one ofmain.main930e8b4GPU queue.Wait … did not complete within 5000 msSo on this title the split-wave64 programs with the compare-exchange polls run into world loading as before. The stalls of #505 are not changed by it beyond run-to-run noise: one
mainrun is not enough to read the 19 / 10 / 14 as a trend, and the frames after loading stay black, as onmain.main:this PR merged onto it (run 2):
Not tested
AI use
@Kalmarv on GitHub · 2026-11-24 15:57 UTC · original
Two regression pairs for
71d3a38againstmain47efa2e(this PR's base), for the Regression run section. Both pairs pass: no device removal, no crash. The first PR run was low (87 % ofmain's frames); the second pair, run right after to check it, has the PR at 103 %, so the drop did not repeat.Tested
scripts/smoke.ps1, the same retail title for 60 s each:mainat47efa2e(this PR's base) first, then this PR's head, one after the other on the same machine; then the same pair again about 10 minutes later.Pair 1,
main47efa2e:Pair 1, this PR,
71d3a38:Pair 2,
main47efa2e:Pair 2, this PR,
71d3a38:Presents per 2 s over the whole run (from the
activity (2 s)lines):main: 0 30 59 50 27 60 60 60 60 60 60 60 60 60 59 46 54 60 60 60 45 56 23 6 2 25 10 19 45 48main: 0 31 60 51 31 60 60 60 60 60 60 60 60 60 59 46 51 60 60 60 46 49 15 1 8 5 33 35 53 23All four runs slow down to a few frames per 2 s at about 44-48 s; three of them pick up again before 60 s. When that phase starts and how long it lasts is what decides each total: in pair 1 it lasted to the end of the PR's run (65 frames in the last 16 s, against 178 on
main), and in pair 2 it started later in the PR's run.For #505. The program at 100 % before the device removal on this machine is the BVH builder's refit,
cs b6043104de672057. It is a wave32 program (xcl shaders --recomp: "wave32: 1"), so it doesn't run in the split form, and this PR's poll loop doesn't touch it.Not tested
AI use: Claude Code (Claude Opus 5.5)
@ExoCalibra on GitHub · 2026-11-24 16:17 UTC · original
Tested exact head
71d3a38(clean merge ontomainb7aa9f3).Tested
610.88(32.0.16.1088), Ryzen 7 7800X3D, 63.1 GB RAM, Windows 11 Pro10.0.26200,rustc 1.100.0, DXC1.8.2502.11..\scripts\test.ps1(debug): 742 passed, 0 failed, 41 ignored. SKIPPED (no wave64):gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware. Passed:split_wave64_spin_polls_are_not_adds_of_zero,gpu_safe_s_barrier_multi_warp_and_early_endpgm, and all 5gpu_split_wave64_*tests.cargo build --release -p xcl+ 60 sscripts/smoke.ps1(XCL_NETWORK=0, compared against basemain47efa2e; identical6529 MBlocal VRAM,3577 MBtarget pages,0skipped draws/dispatches once past startup):main(47efa2e, warm cache):PR
#1244(71d3a38, run 2 — cold re-hashed split-wave64 PSO compiles of 24.0 s / 40.3 s + 12.3 s startup delay, then steady 60 presents/2 s):(Run 1 on
71d3a38:710frames,58 59 60presents/2 s,15705 MBpeak commit,0device removals,0crashes; 11.6 s cold compute PSO compile.)Notes
crates/xcl/src/gpu/recomp/emit.rs: noInterlockedAdd(..., 0u, ...)spin polls remain.Not tested
AI use
@SlopTart on GitHub · 2026-11-24 21:14 UTC · original
RDNA3 confirmation, as requested on #847: PR head
71d3a38on RX 7900 XT (RADV NAVI31) - the wholegpu_split_wave64_*family goes green in forced split mode (XCL_SPLIT_WAVE64=1), every test solo, 2 runs each:gpu_split_wave64_cross_half_operations: ok, ok (was FAILED solo 2/2 on main, and was the polluter that flippedwaves_divergered in family runs)gpu_split_wave64_masks_read_whole_after_partial_writes: ok, ok (was deterministic FAILED 3/3 solo)gpu_split_wave64_local_and_exchanged_masks_in_diverging_waves: ok, ok (was self-flaky 2/3 FAILED,157vs164delta)gpu_split_wave64_waves_diverge: ok, okgpu_split_wave64_lane_local_masks: ok, okgpu_geometry_wave32_prefix_count_over_a_mask: ok, ok (the #772 side of the root cause)12/12 runs green. My #847 floor comments' failing set is exactly this PR's fixed set: all four single-test failures and the cross-test leak are gone on RDNA3 too. Consistent with SzczepanGrela's NIR-hoisting root cause: the Mesa-side spin-loop poll elimination explains my mask-semantics symptoms on RDNA3 as well, Windows-native-AMD staying clean included.
Machine. RX 7900 XT (RADV NAVI31), Mesa 26.2.5, Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, DXC 1.9.2609.5, release profile, target
x86_64-pc-windows-gnu,XCL_NETWORK=0,--exact --test-threads=1.Counts only, no game data.
AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.
@grahamster2 on GitHub · 2026-11-25 04:34 UTC · original
A measurement for the split-wave64 meet in one-wave groups (64-thread groups: the two 32-lane halves are the whole group). Main
cbc296a, RTX 3080 10 GB (driver 610.88), thebench_split_wave64loop: 2^18 threads, one v_readfirstlane exchange per iteration, GPU timestamps, median of 7 to 9 dispatches.XCL_X_SPIN 1, default since #798)XCL_WAVE64_SPIN=0)With the 32 KB LDS block (any program that touches LDS), the same loop with an LDS store + load per iteration takes 41.9 ms spin vs 13.9 ms barrier. 256-thread groups always spin: 12.6 ms vs 3.4 ms native.
That makes a meet about 2.3x to 3x more expensive with the counter spin than with the barrier in one-wave groups. 257 of the 374 split compute programs in the title I looked at use 64-thread groups, and their exchanges are mostly v_cmp masks, 25.4k static exchanges in total. This is only a number for whoever touches the meet form. I'm not proposing to drop #798's guard. In a one-wave group both halves reach every meet together unless they desync, and the barrier form has no bound for that case. A cheaper poll (#1244) or a barrier fast path with a bounded fallback would be the places to win it back.
AI-assisted (Claude Code, Claude Opus 5.5); numbers from runs on my machine.
@upipibi on GitHub · 2026-11-25 06:23 UTC · original
Thanks grahamster2. The same
bench_split_wave64on an RTX 3070 (Ampere, driver 616.56), release build, 2^18 threads x 32768 iterations,main6ea813aand this PR's71d3a38, with one exchange per iteration (v_cmp + v_cndmask + v_readfirstlane):main, counter spin (default)main,XCL_WAVE64_SPIN=0XCL_WAVE64_SPIN=0Without an exchange, all four are within 1.0-1.15x of wave32.
On Ampere too, then, the counter spin in one-wave groups costs about 2.3x the barrier, matching your 3080 numbers. This PR doesn't change that: the compare-exchange poll runs at the same speed as the add of 0. Its point is the correctness of the poll (#847), not speed. Using the barrier for one-wave groups would be a separate change.
AI-assisted (Claude Code). Synthetic benchmark only.
@grahamster2 on GitHub · 2026-11-25 06:34 UTC · original
A design question before I write anything: could the HLSL split-wave64 form go back to a group barrier for the meet in one-wave groups (≤ 64 threads), as the direct DXIL translator does?
Why ask. In a group of one console wave, the two 32-lane halves are the whole group. #798 made the bounded counter spin the default there too, as a guard against a half that exits early, runs out of
xcl_budget, or desyncs. On an RTX 3080, a meet costs:bench_split_wave64loop, 64-thread groups, 1 exchange / iterationXCL_WAVE64_SPIN=0)257 of the 374 split compute programs in the title I checked use 64-thread groups. Most of their 25k static exchanges are
v_cmpmasks (#1597).Why I think the barrier is safe there (please correct me):
s_endpgmbefore the end jumps to the program's end (pc = 0xFFFFFFFF/ END), so no hardware wave leavesmainearly. The branch is on scalar state, which both halves hold identically after the exchanges.xcl_budget: both halves run the same loop iterations, because every branch they take is on exchanged, wave-uniform state. So their budgets stay equal.xcl_xn == 0, 32 threads or fewer) never meets in either form.Partner::Present). #1727 first blamed that barrier for NVIDIA hangs. The bisection there showed the cause was the sparse VRAM test (#614): a local patch giving direct DXIL the spin form hung exactly as often (9/15 vs 9/15).What the spin still buys is a bound if the translator ever desyncs the halves (a bug). That shows up as wrong output instead of a TDR. As upipibi noted on #798, the wrong output is silent.
Question: would you take a change that emits the barrier meet (
XCL_X_SPIN 0) for groups of at most one console wave, withXCL_WAVE64_SPIN=1forcing the spin back? Multi-wave groups keep the counter spin. Or do you want the spin kept as the default there for the desync case, and the cost won back on the poll side instead (#1244)? I can do either, withbench_split_wave64numbers and an NVIDIA soak of the GPU tests.AI-assisted (Claude Code, Claude Opus 5.5); measurements from runs on my machine.
@upipibi on GitHub · 2026-11-25 06:58 UTC · original · edited 2026-11-25 07:02 UTC
@grahamster2 From #1244's side, a separate PR for that fits; whether the barrier becomes the default there is the maintainers' call. It doesn't conflict with this PR: #1244 only changes what the spin polls with (
InterlockedCompareExchangeinstead of an add of 0), and the barrier meet has no poll. #1244 still matters for multi-wave groups and forXCL_WAVE64_SPIN=1.Your RTX 3080 numbers match the 3070 run I posted above: in 64-thread groups, spin is 3.6x wave32 and the barrier 1.55x.
On safety, I checked only the early-exit point.
s_endpgmbecomesFlow::End(recomp/emit.rs:1263onmain), which lowers topc = 0xFFFFFFFFu;(recomp/mod.rs:1174): a jump to the program's end, not a return, so no hardware wave leavesmainearly. I did not check thexcl_budgetpoint or the partial-group case. The cost you named still applies: if a translator bug desyncs the halves, a half misses the barrier and the dispatch hangs (TDR) instead of giving wrong output. KeepingXCL_WAVE64_SPIN=1as the way back covers debugging that.I can run the NVIDIA GPU-test soak on the 3070 (Ampere) at your head once it's up.
@DavidM1911 on GitHub · 2026-11-26 04:32 UTC · original
Re-verification on RTX 3060 Ti (Windows 11), new head merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.Thanks!
— Devin
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.