Skip to content

Recompiler: split single-wave compute groups of any shape - #2353

Open
zohaiblazuli wants to merge 5 commits into
xcl-dev:mainfrom
zohaiblazuli:split-single-wave-any-shape
Open

zohaiblazuli wants to merge 5 commits into
xcl-dev:mainfrom
zohaiblazuli:split-single-wave-any-shape

Conversation

@zohaiblazuli

@zohaiblazuli zohaiblazuli commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #2349, #2097 and #2299; only the top commit belongs here (a81f9d5). Part of #2088 (workstream 4, large-pipeline splitting).

Found independently: the 8×4×1 single-wave gate was described in #2088 (comment, 15:54 UTC) before either PR opened. #2349 covers the part without guest LDS, and this PR is reduced to the guest-LDS part on top of it.

#2349 splits native wave32 groups of any shape, but only without guest LDS. #2299 splits programs with guest LDS, but only in a [32, 1, 1] native wave32 group or a split-wave64 group whose translator gate admits it. So a program with guest LDS in a single 8×4×1 wave stays whole. In a census of the title's 30 largest compute programs (direct DXIL, default settings), 8 of the 13 that stay whole are exactly that: wave32 8×4×1 with guest LDS, 14.3 MB of plain DXIL, each a 66–217 s cold build on an RTX 3060. With this commit all 8 split, into 15–28 pieces each.

What is in it

  • crates/xcl/src/gpu/dxil/kernel.rs: a native wave32 group with guest LDS is offered to the splitter by its thread count (32, one wave) instead of [32, 1, 1]. A 64-thread split-wave64 group with guest LDS gets its split lane id, so each piece replays the lane allocation before restoring the LDS. Recompiler: split direct compute programs that use guest LDS #2299's description lists that case as cut, but its translator gate still kept it whole.
  • crates/xcl/src/gpu/dxil/module/split.rs: split_compute refuses a native group with guest LDS that is more than one wave and has no split lane id. Tests: Recompiler: split direct compute programs that use guest LDS #2299's LDS fixture takes a group shape and checks each thread's x/y/z, for wave32 8×4×1, 4×8×1 and 2×4×4 and split wave64 8×4×2. It also checks that single-wave native lane setup has no group barrier, and that an 8×8×1 wave32 group with LDS (two waves) is refused.
  • README.md: two lines on group shapes with guest LDS.

Tested

  • RTX 3060 12 GB (NVIDIA 617.42, 32-lane waves only), Intel Core i5-14600K, 32 GB, Windows 11 Pro 26300, Rust 1.94.0, DXC 1.8.2502.11. Tests in debug, smoke and timings in release.

  • cargo test --workspace --no-fail-fast -- --test-threads=4 on a81f9d5: 1288 passed, 0 failed, 46 ignored.

  • SKIPPED (25): 21 wave64 cases (no native wave64), 3 per-lane f16/f32 forms the per-lane lowering refuses, and no heap windows (1). The new LDS shape tests ran on the GPU without skips. Whole and split forms each match a CPU reference word for word over 3 groups, plus 16 guard words.

  • Census, translation only (XCL_DIRECT_DXIL=1, default split target, 4 windows): the 8 records split at a81f9d5 and stay whole at 5e8246b (the commit below): 219287eb2f6021fe 28 pieces, f839072880d49fb4 27, c963276f38285bf4 27, 52166c345576bded 19, 7b468aa4210b1810 16, 715e7a408a537ff5 17, f9d73adcc1ad69ef 16, df45a39c275d0db5 15.

  • Cold CreateComputePipelineState with xcl shaders <pack> --measure-pso and a local, not-included change that builds a chain's pieces in parallel. Implicit driver caches off, fresh process, no cached blob, 1 run each. These were measured on the earlier form of this change (7e92361, on Recompiler: split direct compute programs that use guest LDS #2299), which emits the same chains for these records:

    record pieces whole split (wall)
    219287eb2f6021fe 29 217.2 s 9.2 s
    7b468aa4210b1810 16 74.9 s 5.9 s
    df45a39c275d0db5 15 65.7 s 4.0 s

Regression run

  • scripts/smoke.ps1 -Game <title> -Seconds 100, both with XCL_DIRECT_DXIL=1, since the default HLSL path does not reach this code. 100 s because the title enters a texture-heavy phase near 60 s, and peak commit differs by ~4 GB between runs that end before it and runs that end after it.
xcl-smoke v1
commit: 6d12f58a229bc73889878a448c64dc3af25eeba0
gpu: NVIDIA GeForce RTX 3060
title: 6ca5cab7
seconds: 100
exit: 0x0
frames shown: 2770 (PresentX 2770)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13888 MB
xcl-smoke v1
commit: a81f9d536f1578e0b8393697320b185da97d573b
gpu: NVIDIA GeForce RTX 3060
title: 6ca5cab7
seconds: 100
exit: 0x0
frames shown: 2756 (PresentX 2756)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13925 MB

Not tested

AI use

  • Claude Code (Claude Opus 5.5) planned the work, reviewed the diff and the safety argument, ran the smoke runs, and wrote this description.
  • OpenAI Codex (GPT-6.2 Sol) wrote the code and tests, resolved the rebase conflicts, ran the test suite, and made the census and the driver timings.

🤖 Generated with Claude Code

Single-wave 2D/3D native wave32 compute groups (y * z > 1, total <= 32) no longer allocate @xcl_wt or emit the wave-index atomic and barriers, since tid equals WaveGetLaneIndex(). Multi-wave 2D/3D groups also skip the trailing barrier unless sharing xcl_lds[8191].

Extend direct DXIL compute dispatch splitting to all full-wave native wave32 threadgroup shapes without guest LDS (total >= 32, total % 32 == 0): size per-group scratch by total threads, preserve @xcl_wt only as the wave-ID prefix for multi-wave 2D/3D groups while gating the wave64 exchange state machine on xcl_xs, select FlattenedThreadIdInGroup() for multi-wave 1D groups, and recompute Feature::WaveOps per piece so pieces without wave ops validate.

Part of xcl-dev#1269, xcl-dev#2088.

Assisted-by: Antigravity (Gemini 4 Neon)
@throny

throny commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Two contributors checked independently and found that #2349 solves the same problem (for #2088) in a different way: #1607, group D85. You may want to compare them with the other author and agree on one, or say in the PR why both are needed.

This is a hint from the community triage in #1607, not a maintainer decision.

AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

  • cargo test -p xcl --lib: 2 real failures, deterministic (also fail --test-threads=1):
gpu::recomp::pso::shader_cache_tests::rerouted_disk_entries_follow_the_direct_translator
  assertion failed (pso.rs:1439)
hle::d3d12x::device_x::tests::pc_resource_desc_strips_uav_on_unsupported_formats_and_msaa
  assertion failed: format 85 kept — left: 28, right: 85 (device_x.rs:1376)

Same pair of failures seen across #2229/#2231/#2234/#2235-#2247 — shared feature area, needs fixes before merge.

— Devin

@zohaiblazuli

Copy link
Copy Markdown
Contributor Author

Thanks, @throny. #2349 and this PR overlap: both drop the [32, 1, 1] gate and use the lane index for one-wave 2-D/3-D groups. #2349 is based on main and also covers groups of several wave32 waves; this one covers groups that use guest LDS (on top of #2299), which #2349 keeps whole. The 8 programs measured here all use LDS. I'll rebase this PR onto #2349 + #2299 and reduce it to the LDS part, so the two don't compete.

@DavidM1911: both failures also fail on this stack's base 4de5261 without this commit; #2245 fixed them on main, and they go away when #2299 is rebased.

AI use: Claude Code (Claude Opus 5.5).

Kalmarv and others added 4 commits November 26, 2026 00:14
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.
Large direct DXIL compute shaders with guest LDS stayed whole when a
single native wave32 was laid out across multiple group dimensions, or
when a full guest wave64 used two hardware wave32 halves.

Admit native wave32 LDS groups by their 32-thread count. Pass the flat
split lane ID for a 64-thread LDS group so each piece can replay lane
allocation before restoring LDS. Exercise three wave32 shapes and an
8x4x2 split wave64 group, and reject a two-wave native LDS group.

Earlier measurements on an RTX 3060 with cold caches compared whole
pipeline builds with pieces built in parallel:
219287eb2f6021fe 217.2 s -> 9.2 s
7b468aa4210b1810 74.9 s -> 5.9 s
df45a39c275d0db5 65.7 s -> 4.0 s

Assisted-by: OpenAI Codex (GPT-6.2 Sol)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@zohaiblazuli
zohaiblazuli force-pushed the split-single-wave-any-shape branch from 7e92361 to a81f9d5 Compare November 25, 2026 20:07
@zohaiblazuli
zohaiblazuli marked this pull request as ready for review November 25, 2026 20:07

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No confirmed source-level correctness defect found, but this is not merge-ready. It substantially overlaps #2349; the author notes that it must be rebased onto #2349 plus #2299 and reduced to the LDS-specific portion. Please do that before review/merge, since the current +940/-43 diff obscures the boundary. Also, the strong synthetic GPU coverage is not a substitute for current real-title smoke/regression evidence for these LDS programs. After rebasing, please provide a fresh Windows GPU/smoke comparison, particularly because snapshotting full LDS around cuts can grow generated DXIL.

@emirduran707

Copy link
Copy Markdown
Contributor

Independent AMD RDNA4 (native wave64) test report on exact head a81f9d536f1578e0b8393697320b185da97d573b (clean detached checkout, no local changes).

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64, driver 32.0.31044.16), Ryzen 5 5600, 32 GB RAM, Windows 11 Pro 26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2602.17; tests debug, smoke release.
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4: 1286 passed, 2 failed, 46 ignored; 8 SKIPPED (6 in lower_dxil::tests::{f16,f32}_programs_on_the_gpu refused by per-lane form; heap_window_out_of_memory_falls_back_to_the_switch_form; pso_measurement_compiles_an_exact_synthetic_record). All native wave64 GPU tests ran and passed.
    • All 4 new gpu::dxil::module::split::tests passed (no skips): dispatch_chain_four_wave64s_preserves_partner_epochs, dispatch_chain_exited_waves_preserve_other_waves_3d, single_wave_2d_3d_omits_xcl_wt_and_guest_barrier_declines_split, and dispatch_chain_native_wave32_group_shapes_match_whole.
    • The 2 failures (gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 seed 722 and fuzz_validate_and_gpu_3 seed 1599) are pre-existing on unmodified main on this GPU.

Regression run (60 s retail-title smoke, XCL_NETWORK=0, release)

xcl-smoke v1
commit: a81f9d536f1578e0b8393697320b185da97d573b
gpu: AMD Radeon RX 9060 XT
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1593 (PresentX 1593)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 13955 MB

(Matched main 68a284a baseline on the same machine today: 1573 frames, 14420 MB peak, 0 device removals, 0 crashes.)

Not tested

  • D3D12 debug layer; Intel GPUs.

AI use

  • Antigravity with Gemini 4 Neon ran the build, test suite, and smoke run and drafted 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.

8 participants