Skip to content

Recompiler: split direct compute programs that use global atomic adds - #2123

Open
Kalmarv wants to merge 6 commits into
xcl-dev:mainfrom
Kalmarv:direct-split-atomic-add
Open

Kalmarv wants to merge 6 commits into
xcl-dev:mainfrom
Kalmarv:direct-split-atomic-add

Conversation

@Kalmarv

@Kalmarv Kalmarv commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Part of #1269. Stacked on #2080: only the last commit, bad5f04, is new here.

#2080 splits a program with atomics only when they are 32-bit AND or OR whose old value is unused (the sub-dword stores). It declines every other atomic. For a global (UAV) 32-bit add that is safe to cut around. The add still runs exactly once per lane, in the piece where it stands. The UAV barrier between dispatches orders it before every later piece. Its old value is a live value like any other. The title's meshlet-cull program 1ada490879c33c0e (48,191 DXIL instructions; two guest add sites, which become eight DXIL atomic adds across its heap windows) was declined for this alone. With this change it splits into 4 pieces and builds cold in 0.86 s instead of 1.93 s.

What is in it

  • crates/xcl/src/gpu/dxil/module/split.rs: dx.op.atomicBinOp.i32 with ADD is now admitted. Each add stays at its original site and runs once whenever control reaches it, as before. Its old value goes to later pieces in an existing continuation slot when it is live there. The rule against polling is conservative. If a program has an add and any loop (including a self-loop) contains an atomic or a raw-buffer, typed-buffer or texture load, it keeps the whole pipeline, because such a loop could poll memory the add changes. It doesn't try to prove that the load aliases the add or decides the loop's exit.
  • Tests: a GPU test where each lane does an add, uses its old value, and then reads the counter back 24 times in later pieces. All 64 words match the whole shader and a CPU reference: 32 counters incremented exactly once and 32 outputs that consume the old value. A CPU test checks the refusal for a program that could poll.

Tested

  • Ryzen 9 9950X, RTX 5070 Ti (NVIDIA 610.74), Windows 11 build 26200, release, DXC 1.9.2609.

  • Cold pipeline build of 1ada490879c33c0e as the title emits it (the whole binary is byte-identical to the title's cache, and so are its samplers), fresh process, implicit caches off, split pieces on 16 threads:

    Form Wall Pieces Slowest piece Sum of pieces
    Whole 1.93 s 1
    Split 0.86 s 4 0.86 s 3.09 s

    2.2× faster. All 4 pieces pass the DXC 1.9 validator, and the chain uses 7,488 scratch dwords per group.

  • cargo test --release --offline --workspace -- --test-threads=4 on e3c50c1, the same change before Recompiler: split large direct compute pipelines at CFG edges #2080's README-only rebase onto main f5c5bdf: 1160 passed, 0 failed, 46 ignored, with 25 skip notices across 15 tests (no native wave64, unsupported per-lane forms, no heap windows). All five dispatch_chain GPU tests ran. Four passed with their output read back: the new dispatch_chain_carries_uav_add_result_to_later_load, plus wave32_live_loops, divergent_forward_edges_3d and wave64_live_loops_and_exchange. native_wave64_builds_whole skipped its GPU part as expected on this card. The CPU refusal test passed. On bad5f04 the six dispatch_chain tests pass again.

  • AMD Radeon (native wave64) and RTX 5090, measured by @nnonno91 (comment) on bad5f04 with DXC 1.8.2502: the six dispatch_chain tests pass on both. On the Radeon none skip, and the native-wave64 test checks its GPU output. On both GPUs the new atomic-add test matches all 64 expected words for the whole shader and the split chain.

  • AMD RDNA4, measured by @bielfreedom (comment), RX 9070 XT, on bad5f04: on that adapter this change splits only 2 more of the title's 2,689 compute programs (462 → 464), both about 125 KB in 2 pieces, 2.7 → 2.1 s for the pair. 1ada490879c33c0e is not among them there; why hasn't been checked. The dispatch_chain and split::tests tests pass, 6 of 6, with no skips.

Regression run

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

main cbc296a (the same code as this PR's base f5c5bdf, which changed only the README and its images):

xcl-smoke v1
commit: cbc296ab65a2661a61e3e2da109134bcd5319f60
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 120
exit: 0x0
frames shown: 1310 (PresentX 1310)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 29215 MB

this PR, bad5f04:

xcl-smoke v1
commit: bad5f04f2a5291c2c911cbd3368e13db204094ee
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 120
exit: 0x0
frames shown: 1309 (PresentX 1309)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 30162 MB

PR vs main: 1309 / 1310 frames (100 %), peak commit 30162 / 29215 MB (103 %); device removals 0 and crashes 0 on the PR run, 0 and 0 on main.

Both runs use XCL_DIRECT_DXIL=1 (the split applies only on the direct route) and start with the same private XCL pipeline cache, holding only the pipeline list; the driver's own cache was left alone. The PR run logged compute split: 37 programs split, 149 pieces built, 204 chained dispatches issued at 120 s, all chains issued between 60 s and 70 s. Both runs stop presenting at about 64 s for a reason this change doesn't touch. The log doesn't say whether 1ada490879c33c0e was among the split programs, so this run checks for regressions but doesn't show the build gain.

Not tested

  • 1ada490879c33c0e's output on the GPU with title inputs: there is no seeded input for it.
  • GPU time of the split form.
  • 64-bit atomics, and 32-bit atomics other than add (and the unused-result AND/OR Recompiler: split large direct compute pipelines at CFG edges #2080 already takes): they still keep the whole pipeline.
  • AMD, native wave64 on hardware, Linux.

AI use

OpenAI Codex (GPT-6) wrote the change and the tests. Claude Code (Claude Opus 5.5) helpers ran the driver timings, and Claude Code wrote this description and opened the PR.

🤖 Generated with Claude Code

Kalmarv and others added 6 commits November 25, 2026 00:00
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)
Keep each integer UAV add in its original block. If its old value is
live on a crossing edge, save and restore it through the existing
scalar continuation slot. The inter-dispatch UAV barrier orders later
reads. Keep programs with a potentially polling loop on one pipeline.

Exercise a returned add value and dependent reads against whole-pipeline
and CPU results, and cover the polling-loop refusal separately.

Assisted-by: OpenAI Codex (GPT-6)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nnonno91

Copy link
Copy Markdown

Independent Radeon and RTX 5090 verification of exact PR head bad5f04f2a5291c2c911cbd3368e13db204094ee.

Tested

  • Ryzen 7 9800X3D, Windows 11 25H2 build 26200.9974, Rust 1.100.0 MSVC, Windows SDK DXC/DXIL 1.8.2502.11, unoptimized test profile.
  • Ran cargo test --locked -p xcl --lib dispatch_chain -- --nocapture --test-threads=1 in separate processes with XCL_ADAPTER=AMD Radeon and XCL_ADAPTER=NVIDIA GeForce RTX 5090. The dispatch-chain test log confirmed both adapter selections.
  • Radeon(TM) Graphics (32.0.21042.62, XCL_REQUIRE_GPU=wave64): 6 passed, 0 failed, 0 ignored and no skips. The native-wave64 test kept its shader whole and checked its GPU output.
  • GeForce RTX 5090 (32.0.16.1742): 6 passed, 0 failed and 0 ignored, with one explicit GPU skip in that pass count. dispatch_chain_native_wave64_builds_whole skipped GPU execution with no wave64.
  • On both GPUs, the new atomic-add test matched all 64 CPU-expected words with both the whole shader and the split chain: 32 counters incremented once, and 32 outputs carried each old counter value into later dispatches. The CPU test also confirmed that the splitter declines the potential polling loop.

Not tested

Retail inputs, title smoke, compile-time or GPU timing, and the full workspace suite in this run.

AI use

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

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

@bielfreedom

Copy link
Copy Markdown

AMD RDNA4 data for #2123. On the RX 9070 XT this change splits 2 more retail compute programs (462 → 464 of 2,689). Both are about 125 KB of direct DXIL, in 2 pieces each, and build 1.3× faster split (2.7 s → 2.1 s for the pair). The PR's tests pass on this card.

Setup

Method

  • XCL_DIRECT_DXIL=1, default split target, XCL_PSO_DISK_CACHE=0.
  • A fresh exe name per round, since the AMD driver cache is keyed on it.
  • 2 rounds.

Results (mean of 2 rounds)

direct DXIL pieces whole split faster sum of pieces
123 KB 2 1.3 s 1.0 s 1.24× 1.3 s
127 KB 2 1.4 s 1.0 s 1.38× 1.4 s
  • All 4 whole builds and 8 piece builds succeeded.
  • Only two programs gain the split here. The description's meshlet-cull program and the larger atomic-add programs may stay whole on this adapter for another reason, or carry a polling loop. I did not check which.

Tests on this card (XCL_REQUIRE_GPU=1, XCL_ADAPTER=9070)

  • cargo test --release -p xcl --lib -- dispatch_chain split::tests --test-threads=1: 6 passed, 0 failed, no SKIPPED notices.
  • That includes dispatch_chain_carries_uav_add_result_to_later_load and dispatch_chain_declines_uav_add_with_a_polling_loop.

Not tested

  • The split programs' output on title inputs.
  • A title run.
  • RDNA2 and RDNA3.

AI use: Claude Code (Claude Opus 5.5) ran the census, timings and tests and drafted this. Counts and timings only, no game data.

@JJAutoCompare

Copy link
Copy Markdown

Tested

  • Clean detached bad5f04f2a5291c2c911cbd3368e13db204094ee on Intel Arc A770 (driver 32.0.101.9175), Ryzen 7 3800X, Windows 11 25H2 (26200.9974). Rust/Cargo 1.100.0 x64 MSVC and DXC/DXIL 1.9.2609.5. Unoptimized test build, debuginfo and incremental compilation disabled.
  • Prebuilt with cargo test --locked -p xcl --lib -j 2 --no-run --message-format=json. With XCL_ADAPTER=A770, ran the Cargo-reported test executable under the Arc mutex using & $fixtureExe --exact gpu::dxil::module::split::tests::dispatch_chain_carries_uav_add_result_to_later_load --nocapture --test-threads=1. Its SHA-256 matched before and after lock acquisition and after exit.
  • 1 passed, 0 failed, 0 ignored, 0 GPU skips, 1129 filtered out, 1.83 s. The whole direct-DXIL shader and the split dispatch chain each matched all 64 CPU-expected words on one wave32 group. The 32 counters each incremented by 7 and the 32 outputs included the old counter value plus the sum of 24 later loads.

Not tested

Polling-loop refusal, other GPUs or wave modes, workspace suite, retail inputs, title smoke, and performance.

AI use

T3 Code / Codex (gpt-6.2-sol) ran the fixture, verified 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

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants