Skip to content

Recompiler/D3D12.X: rebase #2353 (multi-wave/LDS dispatch chains) and split two-pass mesh producers - #3504

Closed
Kalmarv wants to merge 11 commits into
xcl-dev:mainfrom
Kalmarv:pr/10-2353-and-mesh-dispatch-chain
Closed

Kalmarv wants to merge 11 commits into
xcl-dev:mainfrom
Kalmarv:pr/10-2353-and-mesh-dispatch-chain

Conversation

@Kalmarv

@Kalmarv Kalmarv commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Rebases #2353 (by @zohaiblazuli, @joeypercia, @saintwolf — multi-wave & guest-LDS compute dispatch chains) cleanly onto current main and stacks two-pass mesh-producer DispatchChain splitting (using the early-exit-safe barrier) on top.

What is in it

  • Rebased commits from Recompiler: split single-wave compute groups of any shape #2353: split native wave32 compute groups beyond [32, 1, 1], carry wave64 partner exchanges across dispatch pieces, keep exited guest waves in dispatch checkpoints, split direct compute programs with guest LDS of any shape, and reconcile spin exchanges with the timeout path.
  • crates/xcl/src/gpu/dxil/module/split.rs: cut dispatch chains with the early-exit-safe barrier.
  • crates/xcl/src/hle/d3d12x/: build and run two-pass mesh producers as dispatch chains.

Tested

  • Hardware: NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.1074), AMD Ryzen 9 9950X, Windows 11, DXC 1.9.2609
  • Verified in full 24-thread cold archive precompile (2,162 split programs / 8,907 pieces, errors, refused) and 29-min live title run (695 split programs running 3,819 pieces / 95,737 chained dispatches, crashes).
  • scripts/smoke.ps1 on this exact head queued next.

Regression run

main:

xcl-smoke v1
commit: 91244db94d2f402237c6a8e428dbe5da07673c48
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 1514 (PresentX 1514)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 15133 MB

PR head:

xcl-smoke v1
commit: dac937862be3b5083765e05cef5719607e02bdcf
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 1717 (PresentX 1717)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 16681 MB

Not tested

  • AMD / Intel GPUs

AI use

@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:docs-ci Documentation, scripts, workflows, repo governance area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) needs-pr-check Failing the PR description check (CONTRIBUTING.md) needs-rebase Has merge conflicts with its base branch and removed needs-pr-check Failing the PR description check (CONTRIBUTING.md) labels Nov 30, 2026
@Kalmarv
Kalmarv force-pushed the pr/10-2353-and-mesh-dispatch-chain branch from 65b7be4 to ae6816b Compare November 30, 2026 04:14
@github-actions github-actions Bot removed the needs-rebase Has merge conflicts with its base branch label Nov 30, 2026
@Prime1997 Prime1997 added the test-only A maintainer reviewed the diff: tests only, no smoke run needed for this revision (CONTRIBUTING.md) label Nov 30, 2026
@Kalmarv
Kalmarv force-pushed the pr/10-2353-and-mesh-dispatch-chain branch from ae6816b to 3ee900b Compare November 30, 2026 04:23
@github-actions github-actions Bot added the needs-rebase Has merge conflicts with its base branch label Nov 30, 2026
@Kalmarv
Kalmarv force-pushed the pr/10-2353-and-mesh-dispatch-chain branch from 3ee900b to f8d879a Compare November 30, 2026 04:31
@github-actions github-actions Bot removed the needs-rebase Has merge conflicts with its base branch label Nov 30, 2026
saintwolf and others added 11 commits November 30, 2026 00:40
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)
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>
…rier

A program of several hardware waves whose guest s_barrier became the
early-exit-safe barrier (`Lw::safe_barrier_sync`: groupshared `xcl_bar`, a
live-wave count and an arrival/generation word, polled with atomics) stayed
whole: the planner refused the `xcl_bar` global, its atomics and fences. A
retail title's 253 KB mesh producer (128 threads, split wave64, no LDS) had
no other blocker.

The planner now lets the barrier through. Its two words are saved and
restored at each cut like the LDS, and a GEP into it is transported by its
index. Its group syncs are allowed only in `Block(0)` (its set-up), where
every thread starts; its polls use TGSM fences only. Cuts need not be where
the whole group passes: pieces follow the program's flow (components in
topological order) and keep a loop whole, so a wave polling at a barrier in
a piece waits only for waves that reach that barrier in that piece or have
already arrived.

Test: four hardware waves, three barriers between wave-divergent loops and
branches, cut into 14 pieces where the waves do not pass together; results
and the barrier words (four waves alive, generation 3) match the whole
program on an RTX 5070 Ti.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The compute pass of a two-pass mesh pipeline (the console mesh program
writing one record per group) was always one compute pipeline. A retail
title's 253 KB foliage producer took the NVIDIA driver 6.7 s cold, the
longest compile of the pipelines its world needs.

The direct translator now plans a chain for an `Entry::Mesh` (split wave64,
a multiple of 64 threads, no LDS but a single wave's) as it does for a
compute program, and the translation keeps it (`TwoPass::cs_chain`).
`finish_two_pass` builds the pieces with `dispatch_chain::build` when the
whole form is not ready from a cache (memory, disk or pipeline library); a
library being built keeps the whole. A direct DispatchMesh runs the chain;
an ExecuteIndirect runs the chain's whole form (`whole_ready`; skipped while
it is still being built), and XCL_TWO_PASS_BATCH=2 does not defer a chain.

Measured on an RTX 5070 Ti, 8 cold graphics/mesh recipes replayed with
`xcl shaders --graphics-records --threads 8`, translation warm, driver cache
off: wall 6.99 / 7.09 / 7.09 s before, 6.13 / 6.12 / 6.18 s after; peak
commit 1.07 - 1.13 GB before, 0.93 - 0.96 GB after. The foliage producer's
6.65 - 6.76 s became four pieces of 71 - 113 KB (longest 1.73 - 1.84 s), a
123 KB depth producer's 2.53 s two pieces (longest 1.17 - 1.26 s). The batch
is now bound by its 300 KB graphics pipelines (4.8 - 6.0 s).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@Kalmarv
Kalmarv force-pushed the pr/10-2353-and-mesh-dispatch-chain branch from 2bbfff6 to dac9378 Compare November 30, 2026 05:40
@ettehn

ettehn commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Independent Windows Release check of dac937862be3b5083765e05cef5719607e02bdcf merged cleanly into d52ff48caade1f5350d513bfffd370396dadfeb6. RTX 5070 Ti Laptop (621.24), Windows 11 25H2, Rust 1.97.1 MSVC, DXC 1.8.2502.11. With XCL_ADAPTER=NVIDIA and one test thread, the selected dispatch-chain, mesh and indirect tests gave 37 passed, 0 failed, 0 ignored, zero SKIPPED lines. The early-exit case compared 2,048 words and 16 guards over seven pieces. The safe-barrier case checked 384 words and 16 guards over 14 pieces. The native wave32 geometries and split wave64 LDS cases also ran.

The mesh fixture's pixel and record checks use an ordinary compute producer. Its direct-backend slice passes direct.dxil to the runner, leaving the newly chained two-pass producer outside that check. The indirect fixtures here cover argument scaling and record ownership. As noted in the mesh commit, indirect mesh uses the whole form; where a positive XCL_CS_PSO_WAIT_MS permits Whole::Late, the cold call skips both passes. That last point is source-traced. The local run was synthetic, and the smoke block in the PR currently names 2bbfff6.

OpenAI Codex (GPT-6.2 Sol) assisted with source review and Windows verification.

@Kalmarv

Kalmarv commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Thank you @ettehn for the independent RTX 5070 Ti verification on dac937862! I've updated the PR description's xcl-smoke v1 block to dac937862be3b5083765e05cef5719607e02bdcf (1717 frames, 0 device removals, 0 crashes, 16681 MB peak commit).

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

merge-check
base: d0832e6
head: dac9378
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2907 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: read the whole diff (split.rs, kernel.rs, lanes.rs, module.rs, pso.rs, bind.rs, real.rs, dispatch_chain.rs, docs). It changes the default path: large programs that stayed whole on main now run as dispatch chains (split wave64 groups of any multiple of 64 threads, the single-wave64 spin case, native wave32 groups of several waves or 2D/3D shapes, single-wave programs with LDS, two-pass mesh producers). Findings, most serious first: (1) early exits and the early-exit-safe barrier across cuts (likely, from reading; not reproduced). A wave that ends early branches to the shared exit block, the only place safe_barrier_exit drops it from XCL_BAR_ALIVE, and that block is in the last piece. So in a group where one wave exits before an s_barrier that sits in an earlier piece, the other waves poll that barrier until its budget runs out instead of seeing the wave leave. That costs a stall per group per barrier, possibly a GPU timeout. dispatch_chain_safe_barrier_crosses_cuts has no early exit; a variant with one would settle it. (2) Indirect two-pass draws are skipped until the whole form is built (bind.rs ~3683), and that build is the long compile the PR avoids, queued on the one whole-form worker (or on the title thread with cs_goes_on off). On main the compute pipeline was ready with the mesh one, so geometry can go missing for seconds; a smoke run won't show it. (3) kernel.rs ~367 only splits a wave64 program with LDS when the group is 64 threads (!uses_lds || total == 64), so the planner's multi-wave LDS rules and the dispatch_chain_lds_two/three/four_wave64s tests cover a path no title takes. (4) Every cut saves and restores all of LDS for every group, on by default, and no perf number is given; the PR's own peak commit is +10 % (15133 -> 16681 MB), unexplained. (5) Process: ~1246 lines and at least three logical changes with no reason given for not splitting; fixup commits not squashed (from 03d2e1b to dac9378 the tests don't compile, which breaks bisect); one subject uses DXIL:, not an existing area; Tested has no cargo test counts and blank numbers; AI use says "Claude Opus / Gemini" while the commits name other models too; a_split_wave64_compute_program_stays_whole now asserts that the program splits (rename it). Fine: credit and Co-authored-by lines from #2353 are kept, the scratch layout reuses slots consistently, the save/restore barriers and the lane-counter sync are right, returned threads still take part in the checkpoint, the chain's root signature matches the two-pass binding, and PSO release clears the chain entry.
performance: 60 s smoke of a retail title, main d0832e6 vs this merge (f8d48d1d): 1516 -> 1469 frames shown (97 %; 60 presents per 2 s in both), peak commit 18133 -> 15737 MB, no device removal, no crash. The title doesn't show whether it reaches dispatch chains, early exits before a cut, or indirect two-pass draws, so findings (1) and (2) are not exercised here.
verdict: not yet: early exits across cuts can stall the safe barrier (finding 1), indirect two-pass draws are dropped while the whole form builds (finding 2), and ~1246 lines with at least three changes and unsquashed fixups should be split
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

@brainhay5

Copy link
Copy Markdown

merge-check claim
head: dac9378

1 similar comment
@brainhay5

Copy link
Copy Markdown

merge-check claim
head: dac9378

@brainhay5

Copy link
Copy Markdown

merge-check
base: 7d86c5d
head: dac9378
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2912 passed, 1 failed, 51 ignored; 29 SKIPPED lines
failing: test_title_runs_and_game_folder_is_untouched
review: automated overnight check — diff inspected for safety only (no build/CI/toolchain/script changes, no process/network/runtime-loading code); no duplicate search performed; no line-by-line code review.
performance: not assessed beyond the suite.
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB, driver 610.88 (32.0.16.1088); Ryzen 7 5800X3D, 64 GB; Windows 11 22631; OpenCode agent, DeepSeek V4.1 Flash 1017

@Aniseto

Aniseto commented Dec 1, 2026

Copy link
Copy Markdown

Ran the gpu::dxil::module::split::tests module at dac93786 on an NVIDIA Blackwell desktop part with 16 GB of VRAM.

Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB, mesh shaders) driver 32.0.16.2140 (621.40), Intel Core i5-12400F, 64 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09), MSVC 14.44.35207, DXC 1.9.2609.5, debug build, XCL_ADAPTER=NVIDIA, detached worktree at the exact PR head, no local patches.

XCL_ADAPTER=NVIDIA cargo test -q -p xcl --lib gpu::dxil::module::split::tests -- --test-threads=1
28 passed; 0 failed; 0 ignored; 2754 filtered out      (exit 0)

All 28 tests in that module pass here, including the dispatch-chain cases of the description (dispatch_chain_carries_uav_add_result_to_later_load, dispatch_chain_safe_barrier_crosses_cuts, dispatch_chain_lds_cuts_before_a_guest_wave_returns, dispatch_chain_lds_poll_loop_keeps_several_waves_whole). This is a synthetic check of the recompiler module only.

Not tested: the full workspace suite, the 24-thread cold archive precompile, the 29-minute live title run, a retail title in Series X mode, native wave64 hosts, AMD and Intel GPUs, Wine, release profile, game data.

AI-assisted (OpenCode), model: MiMo-V2.6-Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.

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

Review of dac93786: 2 finding(s). 2 are inline.


These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.

// whole group passes. A loop that reads the LDS (a load or an atomic)
// may poll it until another wave writes past a cut, so such a loop
// keeps the program whole.
let plan = self.m.dispatch_plan(limit, lds.filter(|_| multi).map(|_| &reads))?;

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.

The rule that cuts only where the whole group meets is applied only to programs with guest LDS (lds.filter(|_| multi)). Multi-wave programs whose only shared state is xcl_bar (the early-exit-safe barrier) are planned with uniform = None, so a cut can fall where waves are on different paths to their next S_BARRIER. Take native wave32 [64,1,1], or split wave64 [128,1,1] with no LDS, where wave 0 reaches an s_barrier in block X and wave 1 one in block Y, which is legal on RDNA since any barrier counts. If X lands in piece k and Y in piece k+1, wave 0 polls xcl_bar in piece k while wave 1 has already gone to the checkpoint at the end of piece k. Wave 0 spins 2^20 iterations, takes the timeout path, decrements alive and stops counting, so later barriers don't wait for it. The result is wrong values and a large GPU stall per group. Applying the uniform-cut rule whenever the group has more than one wave, LDS or not, would avoid it.

return Ok(());
}
// (a compute pass cut into a chain runs its whole form: the group counts are the GPU's)
let whole = match super::real::dispatch_chain::whole_ready(tp.compute)? {

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.

Two-pass ExecuteIndirect of a chained mesh producer now needs the separately built whole form. While it's Late, the draw is skipped with an Err, and when cs_goes_on() is false the title thread compiles it synchronously. Before, finish_two_pass built one whole compute PSO that indirect mesh draws used. Now the pieces are built at PSO creation, and the first indirect draw queues a second compile of the whole program: the PR's own 253 KB producer takes 5.1 s on NVIDIA. Until then, every ExecuteIndirect(DispatchMesh) with that PSO logs "still being built" and is dropped, so geometry is missing for seconds. With cs_goes_on() off, the render thread stalls ~5 s, the stall this PR set out to remove, and driver work roughly doubles. Running the companion dispatch through dispatch_chain::execute_indirect (as compute indirect does), or not chaining producers that are only drawn indirectly, would avoid it.

@Kalmarv

Kalmarv commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Closing as superseded: all 11 commits from this PR landed on main via merged #3655 (d71578f85).

Thanks @bmjask for the two inline correctness findings (split.rs:228 uniform = None on non-LDS multi-wave xcl_bar programs, and bind.rs:3684 indirect mesh whole-form stall) — tracking both as follow-up fixes on main.

@Kalmarv Kalmarv closed this Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:docs-ci Documentation, scripts, workflows, repo governance area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 checks-disagree Merge-checks disagree (safe vs not yet); needs maintainer/3rd look gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) needs:amd-test Needs a test report or merge-check on an AMD GPU test-only A maintainer reviewed the diff: tests only, no smoke run needed for this revision (CONTRIBUTING.md)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants