Recompiler: bound spin waits of programs without a loop at 2^12 polls #3668
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3668"
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 Prime1997 on 2026-12-02T05:54:20Z.
Requested by Prime
In a split wave64 program, a half waits for its partner at each exchange, and a wave at the bounded
s_barrierwaits for the others, up to 2^20 LDS atomic polls before it gives up. In a program without a loop every wait is straight-line code and should end within microseconds, so a wait that runs out has missed its arrival and only burns time. On an RTX 3060 Ti 8 GB (wave32), two character-skinning mesh programs of a game title have no loop (15 exchanges between the halves and twos_barrierat the end) and took 133 ms for 4 groups and 228 ms for 19 groups per call, 16 calls a frame. 2^20 polls are about 40 to 100 ms on that GPU, the order of the measured times. A program without a loop now waits at most 2^12 polls (about 0.1 to 0.3 ms), in both translators (HLSL preludes and direct DXIL). A program with a loop, or with a jump the forward walk does not follow, keeps 2^20, since there a wave can rightly wait for another wave's loop.Related: #3652 (open) also lowers the direct DXIL bounds, for every program: an exit bit for a departed half, then 2^12 polls for the spin exchange and 2^16 for the bounded barrier. This one keeps 2^20 where a program has a loop, also covers the HLSL preludes, and adds no exit bit. Both change the same two lines in
dxil/lanes.rs, so whichever lands second needs a rebase. #3562 (open, opt-inXCL_WAVE64_FOLD=1) folds a wave64 compute program into one 32-lane wave, which removes the exchange and its wait for the programs it folds; it tries compute programs only, so the mesh programs here keep the split form and this bound.What is in it
crates/xcl/src/gpu/recomp/emit.rs:program_shape(a forward walk: no back edge, no call or indirect jump; it also reports whether every path passes each reachables_barrier,barriers_on_every_path, which the tests check and nothing here uses yet), the spin bound (spin_log2: 2^12 without a loop, 2^20 with one,XCL_WAVE64_SPIN_LOG2overrides), and the HLSL preludes of the spin exchange and the bounded barrier take that bound. Three tests.crates/xcl/src/gpu/dxil/kernel.rs,lower.rs,lanes.rs: the direct DXIL spin exchange and bounded barrier use the same bound.crates/xcl/src/gpu/recomp/pso.rs: a setXCL_WAVE64_SPIN_LOG2is part of the translated cache's identity, in both translators. One test.docs/wave64-on-wave32.md: the new bound and the switch.Tested
1c8b5514):cargo check -p xcl --lib --tests --target x86_64-pc-windows-gnupasses. The test suite was not run on this exact branch.Regression run
Not tested
scripts/smoke.ps1on this branch; AMD.Switches
XCL_WAVE64_SPIN_LOG2=<8..24>: unset by default (2^12 polls without a loop, 2^20 with one). A value sets the bound for every program;XCL_WAVE64_SPIN_LOG2=20gives the behaviour before this change. Values outside 8 to 24 are ignored.AI use
🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T09:12:38Z.
Review (head
d70c1ca2, diff read, not a merge-check; checks red):emit.rs ~5981). When the budget runs out, the exchange marks the pair failed and every later exchange reads 0 (lanes.rs ~545-620,xcl_x_meet). At the barrier, the timed-out wave forces the generation forward for all the waves still waiting and drops out of every later barrier (lanes.rs ~703-720,xcl_s_barrier). The result is silent wrong output, and nothing logs it.safe_barrieris used by every compute or mesh group of more than one hardware wave that hass_barrier(emit.rs ~707,kernel.rs ~832). That includes native wave64 on AMD and console wave32 programs. A straight-line program that loads to LDS, runss_barrier, then reads LDS (a common pattern) now gives up after 4096 polls on every vendor. Nothing measures how long waves arrive apart there.spin_log2_for, the string replacement in the preludes,program_shapeand the cache identity. Nothing checks that a translated program (HLSL or direct DXIL) actually carries the 2^12 bound. No GPU test shows that a live but late partner is not cut off. Two of the tests checkbarriers_on_every_path, which nothing uses (new logic with no caller).xcl-smokeblocks (main and headd70c1ca235). The suite was not run either (onlycargo check). AI use names the tool but not the model.lanes.rs(~539, ~703) with a different policy: every program, plus an exit bit, 2^12 for the exchange and 2^16 for the barrier. Only one policy can land, and this PR's barrier bound (2^12) is the lower one. #3655 moves both loops intomodule.rshelpers, sospin_log2would have to be passed through them.pso.rsconflicts textually with #3669 (identity lines next to each other); there is no functional overlap with #3669 or #3667.Fine: by reading,
program_shapeis conservative for the console code: any back edge, call, swappc, setpc without a resolved far target, or target that is not an instruction start keeps 2^20, and unreachable data after the lasts_endpgmis skipped. The default change invalidates both caches through the source hashes (emit.rsis inTRANSLATOR_SOURCES, anddxil/is hashed). The env override has its own identity in both translators.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 Foniass on 2026-12-02T09:37:25Z.
Test report (not a merge-check:
PR descriptionred)base:
1c8b551475head:
d70c1ca235merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2913 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: read by one reviewer at this same head; the review is at https://github.com/xcl-dev/xcl/pull/3668#issuecomment-7340543521 and its findings stand. Most serious: the 2^12 bound cuts partners that are late but still running, and the barrier bound is on by default for every multi-wave group on every vendor.
performance: 60 s smoke of a retail title, main
1c8b5514vs this merge (d70c1ca2): 1652 -> 1596 frames shown (96 %; last presents per 2 s: 60 60 60), peak commit 18228 -> 16915 MB, 0 device removals, 0 crashes.assessment: merges, builds and passes the whole suite on current main, and the smoke run is clean; the blocking point is in the review: the 2^12 bound cuts partners that are late but still running, and the barrier bound is on by default for every multi-wave group on every vendor
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
AI-written and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T20:36:27Z.
Code review location:
crates/xcl/src/gpu/recomp/emit.rs; line 5045High: The bounded
s_barriergets the same 2^12 poll budget as a single exchange, but a wave at the barrier has to outwait every other wave's whole path, which can include up to 15 exchanges with their own 2^12 budgets plus memory latency. In the PR's own mesh shape (15 exchanges, then two s_barriers), wave A reaches the barrier early while wave B is still in exchange 10, waiting legitimately on its partner. A spends 4096 polls, takes the timeout branch, lowers XCL_BAR_ALIVE, forces the generation forward and setsxcl_bar_alive = false, then runs past the barrier and reads LDS that B hasn't written yet. The DXIL path (lanes.rs:703) does the same. Giving barriers a budget that covers the exchanges before them (or keeping 2^20 for barriers) would avoid it.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T20:36:27Z.
Code review location:
crates/xcl/src/gpu/recomp/emit.rs; line 6738Medium: Not certain about this one, because it depends on real GPU timing: SPIN_LOG2_STRAIGHT = 12 counts polls, not time, and 'no loop' doesn't mean 'microseconds', so a slow but legitimate partner can now be timed out and marked failed, which changes output. Take a loop-free mesh skinning program that does dependent loads from UMA memory (system memory over PCIe, ~1–2 µs per miss) on a busy GPU. The partner half can take more than 4096 LDS-atomic polls to reach the next exchange (~20–40 µs on a fast GPU). The waiter then CASes XCL_X_FAIL into the partner's counter, both halves set
xcl_x_deadand stop early, and geometry is dropped or corrupted, where before the program completed within 2^20 polls. A time-based bound, or signalling a departed half (#3652's exit bit) and keeping 2^20 as the safety net, would avoid cutting off slow partners.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T20:36:27Z.
Review: COMMENTED
Review of
d70c1ca2: 2 finding(s) (1 high, 1 medium), most severe first.crates/xcl/src/gpu/recomp/emit.rs:5045: The boundeds_barriergets the same 2^12 poll budget as a single exchange, but a wave at the barrier has to outwait every other wave's whole path, which can include up to 15 exchanges with their own 2^12 budgets plus memory latency. (inline)crates/xcl/src/gpu/recomp/emit.rs:6738: Not certain about this one, because it depends on real GPU timing: SPIN_LOG2_STRAIGHT = 12 counts polls, not time, and 'no loop' doesn't mean 'microseconds', so a slow but legitimate partner can now be timed out and marked failed, which .... (inline)These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.