Skip to content

D3D12.X: promote direct split chains to whole and vectorize LDS scratch - #3774

Open
Decodere wants to merge 1 commit into
xcl-dev:mainfrom
Decodere:perf-dxil-split-chain-whole-and-vec-scratch
Open

Decodere wants to merge 1 commit into
xcl-dev:mainfrom
Decodere:perf-dxil-split-chain-whole-and-vec-scratch

Conversation

@Decodere

@Decodere Decodere commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Speed up direct split compute chains without changing the DispatchChain disk-cache format or conflicting with indirect promotion (crates/xcl/src/gpu/dxil/module/split.rs, crates/xcl/src/gpu/recomp/{pso.rs,runner.rs}, crates/xcl/src/hle/d3d12x/real/dispatch_chain.rs, +370 / -67):

  • Direct whole reuse without queuing cold builds (dispatch_chain::dispatch): When chain.whole is already compiled/ready, bind it directly and issue a single Dispatch with zero scratch, slabs, or barriers; direct dispatches never call queue_whole, so skipped indirect/mesh builds are never delayed behind direct dispatches. Promoted/fallback whole PSOs and their chain remain retained in RECORDINGS[allocator] (scratch: None) until allocator_reset so GPU lifetime is preserved.
  • 128-bit vectorized and LDS-trimmed split scratch (module/split.rs): Transfer shared-memory spill/reload slices as v4i32 rawBufferLoad/rawBufferStore quads (with scalar tail) and trim xcl_lds spill/reload to provably accessed (start, count) dword intervals, failing closed to the full 8192-dword array on unbounded indices.
  • Targeted scratch UAV barriers (pso.rs, dispatch_chain.rs, runner.rs): Emit UAV(Some(scratch)) on slab/chain reuse boundaries (i == 0) and after pieces whose SFI0/PSV0 prove no non-scratch UAV access, keeping global UAV(None) after pieces that bind guest UAVs or resource-heap indexing.

Testing

Tested

  • NVIDIA GeForce RTX 4060 8 GB (driver 621.40, wave32), Intel Core i5-11400F, 32 GB, Windows 11 build 26200, release build.
  • cargo test -p xcl --lib dispatch_chain::tests: 18 passed, 0 failed; cargo test -p xcl --lib split::tests: 29 passed, 0 failed (baseline main 395405e4 full workspace: 3012 passed, 0 failed, 56 ignored, 28 SKIPPED).
  • Local retail title smoke (title 29640639, 60 s via scripts/smoke.ps1, clean worktree at e58ea256397e26e53f9d6872eefffa1341fb494f vs main 395405e4c0ed814afde0610a724dc96a3af329de):

Regression run

main (395405e4):

xcl-smoke v1
commit: 395405e4c0ed814afde0610a724dc96a3af329de
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1593 (PresentX 1593)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16544 MB

PR (e58ea256):

xcl-smoke v1
commit: e58ea256397e26e53f9d6872eefffa1341fb494f
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1647 (PresentX 1647)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 15558 MB

Not tested

  • AMD (wave64) and Intel GPUs, Linux / macOS builds.
  • Other retail titles beyond title 29640639.

AI use

  • Antigravity (Gemini 4 Neon) wrote the implementation, unit tests, and this PR description. All unit tests and xcl-smoke v1 runs are executed directly on local hardware.

@Foniass

Foniass commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

Review of c6c9ca9f (code reading only, not a merge-check) · 2 high, 2 medium, 1 nit

In short: The PR makes three changes to split compute chains:

  • direct dispatches switch to the whole form once it is built, and their first split dispatch queues that build;
  • LDS spill and reload move 128-bit quads and only the LDS ranges the program can reach;
  • most UAV barriers inside a chain cover only the scratch buffer.

The LDS range analysis and the narrower barriers look sound. Two things block it: the new build queue delays dispatches that are skipped until their whole form exists, and no reported test run covers the recompiler change.

High

  1. Direct dispatches now fill the single whole-form worker queue.

    • dispatch_chain::dispatch (dispatch_chain.rs ~570) now calls queue_whole for every split program the first time it is dispatched directly. Before, only indirect and mesh dispatches did.
    • whole_worker (~212) is one FIFO thread, and each whole compile can take seconds (real.rs ~9596 mentions 5.1 s).
    • Some dispatches are skipped until their whole form is ready: the mesh two-pass path (bind.rs ~3687) and the ExecuteIndirect path that is not Dispatch-only (bind.rs ~3878). Their builds now wait behind one build for every split program the title dispatches directly, so their work stays dropped for longer.

    Fix: leave the direct path's builds out of this PR, or queue them below builds a skipped dispatch waits on. Show how long skipped dispatches wait on a title with many split programs.

  2. No reported test run covers the recompiler change. Tested lists dispatch_chain::tests and slab_tests at the head, plus a full-workspace count on main only. The filter does not match gpu::dxil::module::split::tests::*, so neither the new dispatch_chain_lds_vectorized_and_trimmed_ranges nor the existing GPU tests comparing split and whole output were run. Yet transfer_shared is rewritten for every split program with LDS. Run cargo test --workspace -- --test-threads=4 at c6c9ca9f and report the counts and skips.

Medium

  1. Three separate changes in one PR. Whole-form promotion (dispatch_chain.rs), LDS quad transfer and trimming (split.rs), and scratch-only barriers (pso.rs, runner.rs) are independent and can each break in their own way. Split them so a regression can be traced.
  2. Conflicts with D3D12.X: fast-lane cached whole PSOs and warm indirect split chains #3754 and D3D12.X: predicate empty split indirect rounds and add whole-PSO pool #3763. It does not merge cleanly with D3D12.X: fast-lane cached whole PSOs and warm indirect split chains #3754 (dispatch_chain.rs) or D3D12.X: predicate empty split indirect rounds and add whole-PSO pool #3763 (pso.rs, runner.rs, dispatch_chain.rs). D3D12.X: predicate empty split indirect rounds and add whole-PSO pool #3763 changes the barriers in record_dispatch_chain_indirect differently: it skips the round-0 barrier and keeps a global UAV(None) between pieces of a round. It also gives queue_whole a priority argument. Decide which barrier scheme goes in, and stack or rebase accordingly.

Nit

  1. The log wording does not match the counters. log_counts (~85) prints "N chained dispatches (M promoted to whole)", but a promoted dispatch returns at ~549 before DISPATCHES is counted, so M is not part of N. Write "N chained dispatches, M promoted to whole".
Checked and fine
  • u32_range gives sound bounds in every case: Add, Mul and Shl give up on overflow, Sub needs la >= hb, the shifts need hb < 32, and phis, loads and signed ops fall back to the full range.
  • shared_ranges: a direct non-GEP use, a pointer through a select, phi or nested GEP, or an index that can be out of bounds all fall back to the full range.
  • transfer_shared: quads plus the scalar tail cover each word of a range exactly once, and the highest scratch offset stays inside the space reserved for it.
  • piece_has_non_scratch_uav: the PSV0 and SFI0 reads are bounds-checked and fail closed. A piece that only reads through a declared UAV still counts as a writer.
  • Piece 0 of a slab, round or repeat depends on scratch only through other groups or chains. The slicer's UNORDERED_ACCESS → INDIRECT_ARGUMENT transition still orders commands before ExecuteIndirect.
  • A promoted direct dispatch binds the whole form the same way the no-scratch fallback does, and a failed whole build stays on the chain.
  • Changes under gpu/dxil change XCL_DIRECT_DXIL_SOURCE_ID, so old cached pieces are not reused.

Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.

@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory 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) labels Dec 3, 2026

@vasanex vasanex left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review of c6c9ca9 (code reading and the tests named below, not a merge-check) - 1 finding, 1 addition to an open point

In short: this adds to Foniass's review of the same head and does not repeat it. Two things from it can be answered with data: the whole suite and the new split test were run here on a merge (below), and the new GPU parity test does notice a wrong transfer. One point is new: a promoted direct dispatch keeps nothing alive for the list it was recorded on. I agree with their point 1 (the build queue) and add one detail to it.

Measured (RTX 3080, wave32, Windows 11, merge of c6c9ca9 onto main 16c2fd0 = bae972b6):

  • cargo build --workspace: ok. cargo test --workspace --no-fail-fast -- --test-threads=4 (debug): 3015 passed, 0 failed, 56 ignored; 25 SKIPPED, the same tests as on main (main: 3012 / 0 / 56). The three new tests ran and passed, dispatch_chain_lds_vectorized_and_trimmed_ranges with its GPU part (not skipped on this card).
  • Does that test notice a wrong result? Four deliberate breaks of split.rs, one at a time, each restored:
    • the recorded span cut to one word ((lo, lo + 1)): fails, at the size assertion;
    • spans from index 4000 up accepted but not recorded (three accessed words left out of the transfer): fails, split and whole outputs differ on the GPU;
    • quads restored four words off: fails, outputs differ on the GPU;
    • the bound of waveGetLaneIndex set to 15 instead of 31: still passes. The test's indices come from the thread id, so that arm of u32_range has no test.
  • scripts/smoke.ps1, 60 s, offline, release: 1692 frames (main 1696), no device removal, no crash, peak commit 17831 MB (main 18885 MB; two runs of the same runtime code differed by 4 % here tonight). The smoke run does not get to the world, so it says little about the promoted path or the queued whole builds.

Findings (each in its own thread):

  1. Low to medium, read: a promoted dispatch records no Recording, so the whole pipeline bound on the list is owned by the Chain alone and goes with the title's final Release of the pipeline, also while the list is still in flight. The split path is safe against that on main (Recording.first).
  2. Addition to Foniass's point 1, read: after an out-of-memory whole build the direct path queues a job for every dispatch and retries the compile every 10 s for as long as the program is dispatched.

Checked and fine, beyond what is already listed there: the transfer layout is contiguous per range (quad q at 16q, tail word t at 4 * (tail_start + t) from the range's slot), a chain is cached as a unit with its dwords_per_group, LDS words that only the replayed prefix touches need no restore, and piece_has_non_scratch_uav reads the offsets XCL's own writer produces (ResourceHeapIndexing is set for every createHandleFromHeap).

Not checked: a title run into the world (plain main does not get there on this card), so neither the promoted path nor the cost of the queued whole builds was measured; AMD and wave64; which barriers are recorded on a real list; the conflicts with #3754 and #3763.

Review by Claude Code (Claude Fable 5.2), with an independent second read by a subagent (Claude Fable 5.2) whose points were checked before use, posted without a human check of each point. An automated PR review workflow is running at the request of the user.

return Ok(())
};
if grid.contains(&0) { return Ok(()); }
if let Some(Ok(whole)) = chain.whole.ready() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Low to medium, read (not measured).

The split path below pushes a Recording { first, chain, .. } for the allocator ("Keep the title-visible first piece alive while this recording may still execute"), and it goes at allocator_reset. This early return records nothing: the whole pipeline bound on the list has one owner, Chain.whole.

Scenario: the title records a promoted Dispatch, then does its final Release of the pipeline before that list has run on the GPU. pso_release sees the count reach zero, forget_pso -> dispatch_chain::forget drops the Chain, and with it the last reference to the whole pipeline, while a recorded or submitted list has it bound. On main the same sequence is harmless on this path: Recording.first holds a reference to the title's pipeline, the title's Release does not reach zero, and forget runs only after the allocator is reset.

Whether a title does this I cannot say from the code. late_release.rs exists because a retail title's final Release did arrive with work in flight, and pso_release already hands the real pipeline of a late-built one to late_release::hold_pipeline for that reason. The same gap is on main in the no-scratch fallback a few lines down; this change makes it the usual path instead of a rare one.

Suggested fix: keep the chain for the recording here too (an entry in RECORDINGS for the allocator, without scratch), or let the Chain's whole pipeline go through late_release::hold_pipeline when the chain is dropped.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fixed in e58ea25. Read in the delta from c6c9ca9 (one file): the promoted dispatch and the no-scratch fallback now push a Recording { scratch: None, first: whole, chain, .. } for the allocator, so the whole pipeline and its chain stay until allocator_reset, also after the title's final Release.

Measured on a merge of e58ea25 onto main 16c2fd0 (RTX 3080, debug): cargo test -p xcl --lib dispatch_chain::tests -- --test-threads=4: 18 passed, 0 failed. With the new push taken out of the promoted path, direct_dispatch_promotes_to_ready_whole_without_queuing_cold_whole fails at its "keeps whole PSO alive until allocator reset" check.

What is left, as on main: with allocator == 0 nothing is kept. The whole suite and the smoke run were not repeated for this follow-up.

Follow-up by Claude Code (Claude Fable 5.2), posted without a human check of each point. An automated PR review workflow is running at the request of the user.

list.Dispatch(x, y, z);
return Ok(());
};
if chain.whole.ready().is_none() && !chain.whole_code.is_empty() { let _ = queue_whole(&chain); }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Addition to Foniass's point 1, read (not measured).

When a whole build ends in E_OUTOFMEMORY, WholeBuild keeps no result and WholeSentGuard clears whole_sent. ready() is then still None, so with this line every later direct dispatch of the program queues a new job: until WHOLE_RETRY has passed each one returns at once, after it the next one runs the whole compile again, and that repeats every 10 s for as long as the title dispatches the program. On main only indirect dispatches did that.

Scenario: a machine short of commit and a title that dispatches a few large split programs every frame: the one worker keeps taking the same giant compiles in turn, each waiting for its headroom and failing again, and the builds that skipped draws wait on (your point 1) sit behind them.

If the direct path keeps queueing whole builds, a cap on retries for builds no dispatch waits on (or no retry at all for them) would bound it.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fixed in e58ea25: the direct path no longer queues a whole build (the line is gone, and the renamed test asserts !chain2.whole_sent), so a direct dispatch is promoted only when the whole form was built for another reason, and the retry after an out-of-memory build is back to what main does for indirect dispatches. Same run as in the other thread: 18 passed, 0 failed.

Follow-up by Claude Code (Claude Fable 5.2), posted without a human check of each point. An automated PR review workflow is running at the request of the user.

Speed up direct split compute chains without changing the DispatchChain
disk-cache format or conflicting with indirect promotion:

- Direct whole reuse (`dispatch_chain::dispatch`): when `chain.whole` is
  already compiled, bind it directly, issue a single Dispatch with zero
  scratch, slabs, or barriers, and retain the promoted PSO on the
  allocator's recordings until reset. Direct dispatches never queue cold
  whole compiles so skipped indirect/mesh builds are never delayed.
- 128-bit vectorized and LDS-trimmed split scratch (`module/split.rs`):
  transfer shared-memory spill/reload slices as `v4i32`
  `rawBufferLoad`/`rawBufferStore` quads (with scalar tail) and trim
  `xcl_lds` spill/reload to provably accessed `(start, count)` dword
  intervals, failing closed to the full 8192-dword array on unbounded
  indices.
- Targeted scratch UAV barriers (`pso.rs`, `dispatch_chain.rs`,
  `runner.rs`): emit `UAV(Some(scratch))` on slab/chain reuse boundaries
  (`i == 0`) and after pieces whose SFI0/PSV0 prove no non-scratch UAV
  access, keeping global `UAV(None)` after pieces that bind guest UAVs
  or resource-heap indexing.

AI-assisted: Antigravity (Gemini 4 Neon)
@Decodere
Decodere force-pushed the perf-dxil-split-chain-whole-and-vec-scratch branch from c6c9ca9 to e58ea25 Compare December 3, 2026 08:09
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: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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants