Skip to content

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

Open
Kalmarv wants to merge 1 commit into
xcl-dev:mainfrom
Kalmarv:direct-split-atomic-add
Open

Kalmarv wants to merge 1 commit 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. #2080, the split this builds on, is merged; this PR is one commit on main afc5ee8, 655885e. It was 7f4b22d and before that bad5f04, stacked on #2080.

#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.

  • AMD Radeon RX 9070, regression pair by @Toons29 (comment), Ryzen 7 7800X3D, on d43468f (this branch before the latest rebase), 60 s of a title on the default route: main 568e7db 1566 frames and this PR 1635, peak commit 14592 / 14592 MB, no crash or device removal in either.

  • cargo test --workspace -- --test-threads=4 (debug) on 655885e: 1265 passed, 0 failed, 46 ignored. 25 SKIPPED notices: no native wave64 on this card, three per-lane FP16 forms the per-lane lowering refuses, and no heap windows. The split tests alone with the DXC 1.9 validator: 33 passed, 0 failed, 1 ignored, no skips.

  • RTX 3080 Ti, checked by @thehollowedone (comment) on 655885e, DXC 1.8: 1,265 passed, 0 failed, 46 ignored. Two extra controls of theirs pass with no skips: a contended 32-lane UAV add reaches 225 with all 32 expected old values in both forms, and a loop with a UAV read keeps the whole pipeline.

Regression run

The branch was rebased onto main afc5ee8, which has #2080, #2107 and #2126. The conflicts were in split.rs and the README, both with #2107. The planner now checks this PR's polling rule first, then #2107's four-times ceiling. Both PRs' tests are kept.

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

main afc5ee8 (this PR's base):

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

this PR, 655885e:

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

PR vs main: 1320 / 1287 frames (103 %), peak commit 29075 / 28897 MB (101 %); device removals 0 and crashes 0 on the PR run, 0 and 0 on main.

Both runs use XCL_DIRECT_DXIL=1 and start with the same private XCL pipeline cache, holding only the pipeline list; the driver's own cache was left alone. main now splits too, and logged compute split: 8 programs split, 42 pieces built, 52 chained dispatches issued at 120 s. This PR logged 24 programs split, 103 pieces built, 70 chained dispatches issued (0 chains by 60 s, 68 by 70 s), and neither run logged a piece ... refused warning. How far the title gets before it stops varies between runs, so the difference in split programs isn't all this change. Both runs present no frames in their last 6 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

@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.

@Kalmarv
Kalmarv force-pushed the direct-split-atomic-add branch 4 times, most recently from 66dd3e3 to d43468f Compare November 25, 2026 11:10
@Toons29

Toons29 commented Nov 25, 2026

Copy link
Copy Markdown

Regression run of d43468f3 on the retail title, for this PR's Regression run section. Both blocks are from scripts/smoke.ps1 as printed, not edited: main on 568e7db7, this PR on its head commit with no uncommitted changes, same title and time.

xcl-smoke v1
commit: 568e7db7729c8fa6c8f0f4b32d798faaf11462bb
gpu: AMD Radeon RX 9070
title: 34df7c50
seconds: 60
exit: 0x0
frames shown: 1566 (PresentX 1566)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14592 MB
xcl-smoke v1
commit: d43468f37d5e99c7c901ea0eec4974431be16323
gpu: AMD Radeon RX 9070
title: 34df7c50
seconds: 60
exit: 0x0
frames shown: 1635 (PresentX 1635)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14592 MB

Against the limits in CONTRIBUTING.md: 104 % of main's frames, 100 % of its peak commit, no crash, no device removal.

AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, cargo build --release -p xcl, 60 s, XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.

AI use: Claude Code (Claude Opus 5.5) built both trees and ran scripts/smoke.ps1; a script posted this right after the run, with both blocks exactly as printed.

@Kalmarv
Kalmarv force-pushed the direct-split-atomic-add branch 2 times, most recently from 1c341a2 to 7f4b22d Compare November 25, 2026 11:51
@thehollowedone

thehollowedone commented Nov 25, 2026 •

Copy link
Copy Markdown

Independent RTX 3080 Ti recheck of the clean 655885e rebase onto afc5ee8. Windows 11 build 26300, NVIDIA 621.35, Ryzen 7 9800X3D, Rust 1.99.1 MSVC and DXC 1.8.2502.11.

  • cargo build --offline --locked --workspace -j 6 passed. cargo test --offline --locked --workspace -j 6 --no-fail-fast -- --test-threads=4 --nocapture finished with 1,265 passed, 0 failed, 46 ignored. The pass count includes 26 runtime skips. Both stock atomic split tests passed.
  • The same two test-only controls from the earlier check also passed on this revision, 2/2 with zero skips. A 32-lane contended UAV add reached 225 in both the split and whole forms. Each form returned all 32 expected old values. A two-block loop with a scalar counter could split, while the control with a UAV read kept the whole shader. Command: cargo test --offline --locked -p xcl --lib -j 6 local_split_add -- --test-threads=1 --nocapture.

I also merged this head locally onto 0829441, which includes the new dispatch scratch sizing. The workspace built and reported 1,274 passed, 0 failed and 46 ignored, including 26 runtime skips. The dispatch-chain filter reported 11 passes including one native-wave64 skip. The atomic-add GPU readback and polling-loop guard both passed.

A separate test-only check called the runtime allocator on the RTX 3080 Ti. With an 8 MiB total target, three live allocations used 6, 2 and 2 MiB. The first recording reused its buffer, and after release the next recording got 4 MiB. Live scratch returned to zero once the test released all buffers. The 10 MiB peak includes the intentional 2 MiB minimum for a new recording. This was a serial allocation check, separate from the dispatch readback.

Synthetic tests only. No retail smoke or pipeline timing on this revision.

AI-assisted. Codex (GPT-6, exact variant unavailable) reran the tests and drafted this report.

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>
@Kalmarv
Kalmarv force-pushed the direct-split-atomic-add branch from 7f4b22d to 655885e Compare November 25, 2026 13:40
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.

8 participants