Skip to content

Recompiler: XCL_WAVE64_SPIN=0 gives direct DXIL one-wave groups the group barrier - #3625

Open
BBareth wants to merge 1 commit into
xcl-dev:mainfrom
BBareth:recompiler/direct-wave64-spin-switch
Open

BBareth wants to merge 1 commit into
xcl-dev:mainfrom
BBareth:recompiler/direct-wave64-spin-switch

Conversation

@BBareth

@BBareth BBareth commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

On a GPU with 32-lane waves the two halves of a console wave64 exchange words. The HLSL path meets the halves of a one-wave group at a group barrier unless XCL_WAVE64_SPIN asks for the arrival counters; the direct DXIL translator has used the counters for compute and mesh groups since #1741 (a guess at the hang of #1727) and did not read the switch, although the switch is in the cache keys. This PR makes XCL_WAVE64_SPIN=0 give those groups the group barrier in the direct translator too. The default does not change.

Why: in a retail title on an RTX 5070 Ti one such compute program (a particle update, numthreads(64,1,1), 191 exchanges, 370 KB of DXIL) takes almost exactly 50 ms at every dispatch, about 57 dispatches a frame: one half polls its partner's counter to the limit of 1 << 20 and gives up. That is 2.8 s of a 4.2 s frame in the intro cutscene after the title screen. Part of #1833.

the particle program, this title, RTX 5070 Ti ms per call ms per frame
main (counters, limit 1 << 20) about 50 2822 / 2891
counters, limit 16,384 for this program only (local experiment) 0.9 94
group barrier for this program only (local experiment) 0.1 9.7
this PR with XCL_WAVE64_SPIN=0 (every one-wave compute and mesh group) 0.1 6.9 / 8.2

What the wait is not (each tested with a local build that changed this one program): the mask plan (all masks exchanged: no change), a half that left the program (an exit mark its partner sees: no change), the memory fences around the exchange (taken out: no change), short lane counts (both halves count whole waves of 32). At the timed-out wait the lower half has added (k + 1) * 32, its partner's counter is exactly one exchange short, and k is 32 or more. A read of the translated DXIL found the exchange number and the counters consistent on every path. So the counters do not work for this program on this driver, and I do not know why; the group barrier does.

What is in it

  • crates/xcl/src/gpu/dxil/kernel.rs: one_wave_spin (the switch, as ComputePolicyKey::wave64_spin reads it) and its use where Lw::new picks Partner::Present or Partner::Spin for a group of 33 to 64 threads; a test override that goes along into the translator's thread. Groups of several console waves keep the counters.
  • crates/xcl/src/gpu/dxil/core_tests.rs, a_single_split_wave_of_a_compute_group_exchanges_without_a_group_barrier: also checks the switch's values, that a 64-thread group without the counters has group barriers at the exchange and no compare-exchange, and that a 128-thread group keeps the counters.
  • crates/xcl/src/gpu/dxil/mask_exchange.rs, gpu_split_wave64_compare_batch_preserves_both_words: runs its 64-thread compute program on the GPU through the group barrier too and expects the same memory.
  • docs/wave64-on-wave32.md: two sentences that said the direct translator always uses the counters for compute and mesh.

Tested

  • RTX 5070 Ti, driver 32.0.16.2124; i7-12700K; Windows 11 Pro 26200; rustc 1.95.0; debug suite, release runs.
  • cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4 on 334564a (on main f07e426): 2904 passed, 0 failed, 51 ignored.
  • SKIPPED on this adapter: 28: 22 no wave64; 2 no heap windows; 2 no d3d12SDKLayers.dll; 1 no D3D12 debug layer; 1 cannot disable the driver cache (no Developer Mode). Both tests this PR changes ran, the GPU one on wave32.
  • The retail title, 360 s runs, the start prompt pressed at 70 s, XCL_TEXTURE_LEVEL_PAGES=1 XCL_GPU_TIMES=6,200, one compute program left out in every run (XCL_SKIP_CS, the compact-form removal of Recompiler: programs whose compact table needs more than 12,288 words take the plain form again #3516), builds of this branch, interleaved, each setting after a warm-up run of its own:
presents in minute 5 GPU first to last stamp per frame device removals, crashes
switch unset, run 1 11 about 4.2 s 0, 0
XCL_WAVE64_SPIN=0, run 1 72 about 1.4 s 0, 0
switch unset, run 2 11 about 4.3 s 0, 0
XCL_WAVE64_SPIN=0, run 2 65 about 1.4 s 0, 0
  • Five runs with XCL_WAVE64_SPIN=0 in all (two warm-ups, the two above, one with frame dumps): no device removal, no crash, no hang.
  • The picture with the switch on (every 10th frame of one run looked at): the night sky with its particles, a light with its lens flare, the credit texts and one credit card are drawn; most other frames of the cutscene are black, as on main. The run with the switch unset gave no frames to compare (every dump timed out), so this says the picture is not broken by the switch, not that it is better.

Regression run

xcl-smoke v1
commit: f07e426dade72aa7112cf6bfe08ca6f6ff5a9d5c
gpu: NVIDIA GeForce RTX 5070 Ti
title: 9cc6a39e
seconds: 120
exit: 0x0
frames shown: 3044 (PresentX 3044)
presents per 2 s (last 3): 40 10 20
device removals: 0
crashes: 0
peak commit: 34749 MB
xcl-smoke v1
commit: 334564ab841dce9f88c915a0c49401670a3a1931
gpu: NVIDIA GeForce RTX 5070 Ti
title: 9cc6a39e
seconds: 120
exit: 0x0
frames shown: 3062 (PresentX 3062)
presents per 2 s (last 3): 16 22 22
device removals: 0
crashes: 0
peak commit: 34870 MB

Both without the switch: the smoke runs check that the default is unchanged. Each follows a warm-up run of the same build; the start prompt is pressed once at 70 s. In this session the title lost the D3D12 device (0x887a0006) near 120 s in 1 of 3 runs of main f07e426 and in 1 of 3 runs of this head; the blocks are a clean run of each.

Not tested

  • The hang of Direct DXIL: split wave64 uses a group barrier for 1-wave groups – GPU hangs in parallel test runs on NVIDIA (RTX 5070) #1727 (group barriers in parallel test runs on an RTX 5070): five title runs without one is a small sample, and the lib tests were not run in parallel with the switch set. That is why this is a switch and not a new default.
  • The open world: the runs above end in the intro cutscene. Other titles, other NVIDIA generations, Intel.
  • AMD: wave64 is native there and nothing splits, so the switch does nothing.
  • The first runs with the switch set compile the programs it changes again (its cache identity is its own): 22 to 100 driver compiles without a stored blob after 200 s in those runs.
  • Whether the particle program's output is right in either form was not compared against a reference.

AI use

  • Claude Code, Claude Fable 5.2: found the wait with timing experiments in the shader, wrote the change, the tests and this description, and ran the suite and the runs. Gemini 4 Neon (agy) read the translated DXIL for consistency; I did not re-verify that reading line by line.

🤖 Generated with Claude Code

…roup barrier

On a GPU with 32-lane waves, the two halves of a console wave64 exchange
words. In the direct DXIL translator the halves of a compute or mesh
group of one console wave meet through bounded arrival counters since
xcl-dev#1741 (a guess at the hang of xcl-dev#1727); the HLSL path meets them at a
group barrier unless XCL_WAVE64_SPIN asks for the counters. The direct
translator did not read the switch, although it is in the cache keys.

In a retail title on an RTX 5070 Ti one such compute program (a particle
update, 191 exchanges, numthreads(64,1,1)) takes 50 ms at every
dispatch: one half polls its partner's counter to the limit of 1 << 20
and gives up, about 57 times a frame, 2.8 s of a 4.2 s frame. With the
poll limit cut to 16,384 for that program a call takes 0.9 ms, with the
group barrier 0.1 ms. The translated program is consistent (the
exchange number and the counters agree on every path), a half that
leaves the program was ruled out, and so were the mask plan and the
memory fences: the counters do not work for this program on this
driver, the barrier does.

XCL_WAVE64_SPIN=0 now gives one-wave compute and mesh groups the group
barrier in the direct translator too. The default stays the counters.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@github-actions github-actions Bot added area:docs-ci Documentation, scripts, workflows, repo governance area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:tests Unit, integration, e2e tests, or testtitle gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Dec 1, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Review (head 334564a, diff read, not a merge-check):

  • The switch also brings back dispatch chains for these programs. In gpu/dxil/kernel.rs, only Partner::Spin keeps a split 64-thread program whole (~887). With XCL_WAVE64_SPIN=0 the program becomes Partner::Present (~852), so one without LDS over XCL_DIRECT_SPLIT_INSTRUCTIONS (12,500 by default) goes to split_compute (~897) and can be cut into several dispatches. Since 0f2fa3e no test runs that chain path at 64 threads (module/split.rs ~971 now asserts the program stays whole), the PR's tests do not cover it, and the description does not mention this second effect.
  • The doc paragraph is still wrong about the HLSL default. docs/wave64-on-wave32.md ~75 still says "Both translators use this variant [the counters] by default for one console wave per group", but x64_spin_for (recomp/emit.rs ~6554) gives the HLSL path's one-wave groups the group barrier by default, as the description says; the rewritten sentence after it still reads as if both default to the counters.

Fine: opt-in with the default unchanged; one_wave_spin_wanted is only checked for compute and mesh groups of 33 to 64 threads; the test override reaches the translator thread; the switch is already in the compute and pipeline cache keys (ComputePolicyKey::wave64_spin, semantic_pipeline_setting, cache_allowed); multi-wave groups keep the counters, and the test checks it.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

@i7Gamer

i7Gamer commented Dec 2, 2026

Copy link
Copy Markdown

Independent NVIDIA validation: RTX 5090, driver 616.56, Windows 11. The DXIL structure test and synthetic GPU readback test passed without skips on base 1c8b5514, PR head 334564ab, and integration ab09d222. The four-thread integration suite also passed: 2,909 passed, 0 failed, 51 ignored.

This covers the tested wave32 compute case. The larger dispatch-chain path, native wave64, mesh-stage execution, and retail titles were not tested. Would a separate synthetic compiler test for the larger dispatch chain be useful?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:docs-ci Documentation, scripts, workflows, repo governance area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:tests Unit, integration, e2e tests, or testtitle gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants