Skip to content

Recompiler: split direct compute programs that use guest LDS - #2299

Open
joeypercia wants to merge 8 commits into
xcl-dev:mainfrom
joeypercia:c5-lds-split
Open

joeypercia wants to merge 8 commits into
xcl-dev:mainfrom
joeypercia:c5-lds-split

Conversation

@joeypercia

@joeypercia joeypercia commented Nov 25, 2026 •

Copy link
Copy Markdown

Stacked on #2097; only the top commit belongs here (4de5261). Part of #2088 (campaign task C5, LDS part).

The direct-DXIL compute splitter (#2080, #2097) keeps every program that uses guest LDS whole. Its mutable-global check refuses xcl_lds, and its scan refuses LDS loads, stores and atomics, and guest s_barrier. This lets those programs split.

What is in it

  • crates/xcl/src/gpu/dxil/module/split.rs, Shader::split_compute / make_piece:
  • Same file, Module::dispatch_plan, which now takes uniform:
    • One console wave (wave32 32×1×1, split wave64 64×1×1) follows the guest's scalar control flow. Its threads diverge only in guarded per-lane accesses, which hold no barrier or return, so any cut keeps the guest barriers paired. These programs are cut as before.
    • A group of several console waves is cut only before a component that every thread enters exactly once: no earlier edge jumps past it, and no earlier block returns. Otherwise, a wave that returned or branched past a piece would wait at the piece exit while the others wait at a guest barrier inside it. Programs without such a cut stay whole.
    • In a group of several waves, a loop that reads the LDS (a load or an atomic) keeps the program whole. Another wave could be polling it until a write that a cut defers. This is the same idea as the loop rule in Recompiler: split direct compute programs that use global atomic adds #2123.
  • docs/wave64-on-wave32.md: the sentence saying LDS programs stay whole now describes the above.
  • Tests, in split.rs:
    • LDS fixture, GPU: the program writes the LDS and counts with an LDS atomic before a guest barrier. After several cuts it reads other threads' words (other halves and other waves), then writes and reads again across two more barriers. Lanes take different loop counts, and with several waves, odd and even waves take different branches. It runs in wave32 32×1×1 and split wave64 with 1, 2, 3 and 4 waves per group, 3 groups. The whole and split forms are each compared word by word with a CPU reference, plus 16 guard words.
    • Negative control: for 2–4 waves, an unrestricted plan (uniform: None) cuts where the group does not pass together, and the restricted plan never does. dispatch_chain_lds_cuts_before_a_guest_wave_returns covers wave 0 returning before later guest barriers. Unrestricted plans put one of those barriers in a piece that wave 0 still has to pass, and the restricted plan keeps everything from the return on in the last piece. Its split form also matches the CPU reference on the GPU.
    • dispatch_chain_lds_poll_loop_keeps_several_waves_whole, CPU only, polls with an atomic and with a plain load. The plain-load case fails without the load rule.

Tested

  • RTX 4070 Ti 12 GB (NVIDIA 621.40, 32-lane waves) and the AMD Radeon iGPU of a Ryzen 7 7800X3D (RDNA2, XCL_ADAPTER=Radeon). Windows 11 Pro 26200, Rust 1.100.0, DXC 1.8.2502.11, debug.

  • cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4 on 4de5261:

    • RTX 4070 Ti: 1255 passed, 2 failed, 46 ignored. Both failures, pso::shader_cache_tests::rerouted_disk_entries_follow_the_direct_translator and device_x::tests::pc_resource_desc_strips_uav_on_unsupported_formats_and_msaa, also fail on the base 8b2fa0e. Tests: two expectations that no longer match the code #2245 fixed them on main after this stack's base.
    • Radeon: 1253 passed, 4 failed, 46 ignored. The same two, plus fuzz_tests::fuzz_validate_and_gpu_1 and recomp::tests::gpu_image_get_resinfo_past_last_level. All four also fail on 8b2fa0e on the Radeon.
    • SKIPPED on the 4070 Ti (28): 21 wave64 cases (no native wave64), 3 per-lane f16 forms the per-lane lowering refuses, no heap windows, no D3D12 debug layer (2), PSO measurement without Developer Mode.
    • SKIPPED on the Radeon (17): 7 mesh-shader tests (no mesh shaders), 6 per-lane f16 forms, no heap windows, no D3D12 debug layer (2), PSO measurement without Developer Mode.
    • The 7 new tests ran without skips on both GPUs.
  • With the uniform rule switched off locally, the four tests with several waves fail on their plan assertions. They were not run on the GPU that way.

  • Census of the title's compute programs (xcl shaders <pack> --direct --sample 0 --max-bytes 0 --windows 260, XCL_DIRECT_DXIL=1, with a local logging patch):

    • Of 2,689 compute programs, 15 have guest LDS and are over the 12,500-instruction target. All 15 are one wave32 group (32×1×1).
    • 2 of them now split, into 2 pieces each.
    • The other 13 are still refused, at a UAV atomicBinOp (add) whose result is used. UAV atomics are another C5 item.
    • No other program changes.
  • Cold CreateComputePipelineState on the 4070 Ti. Each run is a fresh process under a new exe name (the driver cache is per exe name; Developer Mode is off). Pieces build in parallel, on the root signatures the runtime uses. 3 runs each:

    Program LDS_SIZE Whole Split (wall) Pieces (DXIL bytes)
    e9bcdee509dcebd9 CS_Primary_PrefilterAndIntegrateIrradianceSH 5 KB 0.755–0.780 s 0.537–0.554 s 110,444 + 88,500 (whole 140,696)
    2776b596fe6f0f1a CS_RaytraceShadows_Shared 2 KB 0.592–0.614 s 0.490–0.552 s 99,268 + 55,452 (whole 106,164)
  • 95cc13288a27a96e (CS_ScreenProbes_ActivateRays), the title's largest compute program, is not helped by this. 280,877 of its 291,811 instructions are in one strongly connected component (15,553 blocks), which a dispatch chain cannot cut. It also has a UAV atomic add. It stays whole.

  • GPU time, the new fixtures, 8192 groups, median of 20 timestamped dispatches on the 4070 Ti:

    Fixture Whole Split
    wave32, 3 pieces 0.049 ms 2.44 ms
    split wave64, 1 wave, 4 pieces 0.058 ms 4.04 ms
    2 waves, 4 pieces 0.075 ms 4.26 ms
    3 waves, 4 pieces 0.092 ms 4.45 ms
    4 waves, 4 pieces 0.106 ms 4.65 ms

    The cost is the LDS copy: each cut writes and reads back the whole 32 KB xcl_lds block of every group, about 1.3–1.4 ms per cut at 8192 groups. Direct DXIL: size a compute program's LDS block from its LDS_SIZE #2158 (open) sizes xcl_lds from LDS_SIZE, and this copy follows the array's size. For the two programs above, that is an 8 KB and a 4 KB block.

Regression run

scripts/smoke.ps1, the same retail title for 60 s, one after the other on the machine under Tested, release builds from clean trees.

main 1a0bbe3:

xcl-smoke v1
commit: 1a0bbe3a2ba91ea8f5b6fc29130a053868d3c9e6
gpu: NVIDIA GeForce RTX 4070 Ti
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1468 (PresentX 1468)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16696 MB

this PR, 4de5261:

xcl-smoke v1
commit: 4de52614fa58e20fb2b62896bd9a65212dcf9ec0
gpu: NVIDIA GeForce RTX 4070 Ti
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1387 (PresentX 1387)
presents per 2 s (last 3): 60 60 59
device removals: 0
crashes: 0
peak commit: 15996 MB

PR vs main: 1387 / 1468 frames (94 %), peak commit 15996 / 16696 MB (96 %). Device removals 0 and crashes 0 in both. An earlier pair on 5e60822, before the load rule, gave 1491 / 1548 frames.

Not tested

  • Whether the two programs that now split run in the 60 s smoke window. I did not check that, and their GPU time in the title is not measured: they need the title's resources bound, so I timed only the synthetic fixtures.
  • GPU output of the two split title programs, against their whole forms.
  • Native-wave64 GPUs (AMD RDNA3/4): chains are built only for 32-lane waves there.
  • Intel; cold build times on AMD.
  • Groups of several waves with guest LDS in the title: there are none, so that path runs only in the tests.

AI use

  • Claude Code with Claude Opus 5.5: wrote the change, the tests and this description, and ran the measurements and the test suites listed above.

Kalmarv and others added 7 commits November 25, 2026 06:46
Keep control-flow cycles in one pipeline, pass edge-live values through per-dispatch scratch and compile the pieces on the PSO workers. Direct dispatch records the chain with UAV ordering. Indirect dispatch builds the whole form on demand.

Assisted-by: OpenAI Codex (GPT-6)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The synthetic split fixture declared u2 twice with different coherence flags. Bind its existing memory window and validate the whole fixture before checking the cut.

Assisted-by: OpenAI Codex (GPT-6)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adjacent lanes previously accessed ef008c0f's continuation data 1,612 bytes apart. Store the tag and each live dword in a separate lane-contiguous plane; transport both halves of i64 values through their own planes.

Assisted-by: OpenAI Codex (GPT-6)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adopt WebIdentity1's fixture from xcl-dev#2080. Lanes return early, skip ahead
over a piece, or run different numbers of loop iterations. Check the
whole and split outputs against the CPU model and guard words on a
2 x 3 x 2 dispatch grid for native wave32 and split wave64.

Source: xcl-dev#2080 (comment)
Assisted-by: OpenAI Codex (GPT-6)
Co-authored-by: WebIdentity1 <212448219+WebIdentity1@users.noreply.github.com>
Compile and validate a partitionable CFG through the native-wave64 admission gate. On a wave64 adapter, run the whole pipeline and check its lane count and output. Identify the existing compare(64) case as two hardware waves.

Assisted-by: OpenAI Codex (GPT-6)
Use the workgroup's flat logical thread ID for the continuation of each
wave32 half. Keep each counter signal with its peer wait, and transfer
the per-half arrival counters and double-buffered exchange slots at a
group-wide rendezvous between pieces. Wave allocation starts afresh in
each piece. Leave guest LDS and partial guest waves on the whole path.

Exercise four wave64s with different exchange epochs across repeated
cuts and compare every output word to the whole shader and a CPU oracle.

Assisted-by: OpenAI Codex (GPT-6)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adopt WebIdentity1's four-wave fixture. Two guest waves return at
different points while the other waves keep exchanging. Compare the
whole shader and the dispatch chain to the CPU oracle across a 3D grid.

Source: xcl-dev#2097 (comment)
Assisted-by: OpenAI Codex (GPT-6)
Co-authored-by: WebIdentity1 <212448219+WebIdentity1@users.noreply.github.com>
The dispatch-chain splitter kept every program with guest LDS whole: its
mutable-global check refused xcl_lds, and its scan refused LDS loads,
stores and atomics and guest barriers.

Now the LDS (with the split form's exchange words at its top) is copied to
the per-group scratch at each piece exit and back at the next piece's
start, like the exchange slots of several split waves. Geps into it can
cross a cut as their index. In the split form the lane counter lives in
the LDS too, so a piece meets once more before restoring over it.

One console wave follows the guest's scalar control flow, so any cut keeps
its guest barriers paired. A group of several waves can branch and return
apart: a piece of such a program starts only at a component every thread
enters exactly once (no earlier edge jumps past it, no earlier block
returns), and a loop that reads the LDS (a load or an atomic), which
could poll for another wave's write past a cut, keeps the program whole.
@luckyteagirl

Copy link
Copy Markdown
Contributor

Independent focused test of exact PR head 5e608220fdb9c9d4d7c2fb19fabbf5ab7d68682d on a dedicated Radeon RX 6800M (RDNA2, driver 30.0.13002.13003), Windows 11 build 26200, Ryzen 9 5980HX, Rust 1.99.0 MSVC, and DXC/DXIL 1.9.2609.5. Clean detached worktree and isolated Cargo target.

XCL_ADAPTER=6800M XCL_REQUIRE_GPU=1 XCL_DIRECT_DXIL=1 cargo test --locked -p xcl --lib -j 2 dispatch_chain_lds -- --test-threads=1 --show-output: 7 passed, 0 failed, 0 ignored, with no SKIPPED line. The runner selects the adapter through XCL_ADAPTER; all six whole-versus-split GPU comparisons completed, including wave32, split wave64 with one through four guest waves, and the early-return case. The seventh test is the CPU-only LDS atomic-loop planning check. The five fixture logs report 3 or 4 pieces and matching output plus 16 guard words.

This adds a dedicated RX 6800M run to the author's RTX 4070 Ti and RDNA2 iGPU evidence. The synthetic wave64 cases explicitly use the split representation; they do not test native-wave64 chains. I did not run the full workspace suite, title smoke, title-program output comparison, or GPU timing on this head.

AI use: OpenAI Codex (GPT-6; exact variant not exposed in this session) ran the native Windows test, checked the fixture paths and clean exact head, and drafted this report. No game data was used.

@nnonno91

Copy link
Copy Markdown

Independent check of the updated head 4de52614fa58e20fb2b62896bd9a65212dcf9ec0 on Radeon integrated graphics and RTX 5090.

Tested

  • Ryzen 7 9800X3D, Windows 11 25H2 build 26200.9974, Rust 1.100.0 MSVC, Windows SDK DXC/DXIL 1.8.2502.11, unoptimized profile. AMD Radeon(TM) Graphics driver 32.0.21042.62 and GeForce RTX 5090 driver 32.0.16.1742.
  • Ran cargo test --locked -p xcl --lib dispatch_chain_lds -- --nocapture --test-threads=1 in separate processes with XCL_ADAPTER=AMD Radeon or XCL_ADAPTER=NVIDIA GeForce RTX 5090 (XCL_REQUIRE_GPU=wave64 on Radeon). Each gave 7 passed, 0 failed, 0 ignored and no skips.
  • The five logged LDS fixtures checked 2,016 output words plus 80 guard words against the CPU reference in both the whole and split forms on each GPU. The early-return GPU case and CPU polling-loop refusal case also passed.

Not tested

Retail smoke, GPU or compile timings, and the full workspace suite.

AI use

OpenAI Codex (GPT-6.2 Sol) ran the tests, checked the logs and wrote this report.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants