Skip to content

D3D12.X: fast-lane cached whole PSOs and warm indirect split chains - #3754

Open
Decodere wants to merge 1 commit into
xcl-dev:mainfrom
Decodere:perf-dispatch-chain-fast-cached-whole
Open

Decodere wants to merge 1 commit into
xcl-dev:mainfrom
Decodere:perf-dispatch-chain-fast-cached-whole

Conversation

@Decodere

@Decodere Decodere commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Split compute programs whose whole form was compiled by Chain::whole() store their driver blob under the ChainRoot::DirectConstants root-signature namespace. On subsequent runs, two bottlenecks delayed whole-form promotion:

  1. translated_compute_pso_once only checked ComputeBuild::CachedWhole (the standard ABI root-signature namespace), missing cached DirectConstants blobs and falling back to building split pieces.
  2. When indirect dispatches queued whole-form promotion via queue_whole, already-cached blobs waited in the single xcl-pso-whole FIFO queue behind multi-second cold driver compiles and huge_compile_turn.

Changes (crates/xcl/src/hle/d3d12x/real.rs, crates/xcl/src/hle/d3d12x/real/dispatch_chain.rs, +363 / -18):

  • Add ComputeBuild::CachedDirectChain and dispatch_chain::try_cached_whole for cache-only lookup (pipeline library, in-memory blob cache, or disk driver cache) in the DirectConstants namespace without entering a cold compile or acquiring huge_compile_turn.
  • Route queue_whole through a lightweight xcl-pso-whole-cache worker (4 MiB stack) via dispatch_whole_lanes, installing cached blobs with WholeBuild::install_cached and forwarding only cache misses to xcl-pso-whole (run_cold_whole).
  • Eagerly warm split programs recorded in EARLIER_INDIRECT_USED during dispatch_chain::build (should_eagerly_warm_whole) so previously seen indirect chains promote before heavy frames instead of queueing at draw time.
  • Add unit and GPU tests in dispatch_chain::tests covering WholeBuild::install_cached, fast-lane promotion while the cold worker is blocked, should_eagerly_warm_whole, ChainRoot::DirectConstants namespace separation, and try_cached_whole / ComputeBuild::CachedDirectChain hit and miss paths.

Related: #3737 — #3737 targets amd-dev's split_builds / whole_direct path in shaders.rs, which does not exist on main. This PR operates on main's dispatch_chain / real.rs path so cached whole blobs promote without waiting on cold compiles or huge_compile_turn.

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: 22 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 5f0c226514e7eaa19def2dc7d609319fc235ac5e vs main 395405e4c0ed814afde0610a724dc96a3af329de):

Baseline (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 head (5f0c2265):

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

Not tested

  • AMD and Intel GPUs (tested on NVIDIA GeForce RTX 4060 8 GB wave32 only).
  • Linux / macOS builds and other retail titles beyond title 29640639.
  • amd-dev branch (#3737).

AI use

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

@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Dec 3, 2026
@Foniass

Foniass commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

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

In short: This PR does three things:

  • when a pipeline is created, it looks for a split program's cached whole form in the DirectConstants chain-root namespace, not only the ABI one;
  • it routes queue_whole through a new xcl-pso-whole-cache thread that only reads caches;
  • it queues the whole form when dispatch_chain::build sees a record listed in used-indirect-split.txt.

The lookup at creation looks right, but it has no test. The eager "warm" step queues cold compiles of the largest programs while the title loads, and that cost is unmeasured on AMD.

High

  1. The fix has no test.

    • The bug is that translated_compute_pso_once only checked the ABI namespace and missed whole forms cached under ChainRoot::DirectConstants.
    • The fix is the dispatch_chain::try_cached_whole fallback (real.rs ~6210), plus the ComputeBuild::CachedDirectChain handling in compute_container, which picks the chain-root name and returns on a miss or a refused blob without compiling (~6391, ~6407, ~6417).
    • The three new tests cover WholeBuild::install_cached, dispatch_whole_lanes with stub closures, and the should_eagerly_warm_whole predicate. None reaches this code.

    Fix: add a test that fails on main. A whole blob kept under the chain-root namespace should be picked up at creation without building pieces, and a miss in CachedDirectChain mode should return without calling create. The GPU tests in dispatch_chain::tests already build a PipelineBuilder and call skip_test without a GPU.

Medium

  1. The eager warm in build queues cold compiles, not cache warms.

    • build runs only after translated_compute_pso_once missed try_cached_whole, with the same DXIL, root signature, flags, node and mode. So the fast lane started from build (dispatch_chain.rs ~416) misses again and forwards the job to xcl-pso-whole.
    • Every journaled split program whose whole form is not cached gets a cold whole-form compile queued while the title loads. These are the biggest programs the driver compiles, and they run under with_late_build with only half the usual commit headroom.
    • On AMD the driver-blob disk cache is off by default, so this covers every journaled program.
    • The FIFO worker holds these compiles in load order, so a whole form an indirect dispatch needs right now can wait behind them, which is the delay this PR sets out to remove. The smoke run shows peak commit going from 16151 MB to 16702 MB, and there is no AMD run.

    Fix: have build queue only the cache lookup, or move this step to its own PR with an AMD measurement.

  2. The fast lane rarely finds anything after the creation-time lookup.

    • A chain reaches queue_whole only when the same cache-only lookup already missed at creation. The case in the description, a cached blob waiting in the FIFO behind cold compiles, now never creates a chain.
    • The fast lane can only hit when a blob appears after the chain was created. Meanwhile every queue_whole takes an extra hop through a second thread (whole_cache_worker ~239, queue_whole ~480).

    Fix: show a case where it hits, for example with a hit counter in log_counts, or drop it. The creation-time lookup can stand alone as one PR.

Checked and fine
  • CachedDirectChain reuses the cache-only exits of CachedWhole. With no blob it returns E_INVALIDARG before driver_compile_identified. A refused blob returns without the retry compile. With a blob, huge_compile_turn is never taken.
  • The whole form found under the chain root signature is registered with that signature (note_pso_rs). Root parameters 0-5 of dispatch_chain_root_signature match the ABI layout.
  • WholeSentGuard: a cache hit calls finish(), a miss moves the guard into run_cold_whole, and a failed send or a panic resets whole_sent.
  • install_cached racing a title-thread get_or_build is harmless: the first to set the OnceLock wins.
  • 235+/18-. Not a duplicate: Shaders: earlier-use preparation builds used split programs' chain-root whole #3737 changes amd-dev's preparation path.

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

Split compute programs whose whole form was compiled by `Chain::whole()`
persist their driver blob under the `DirectChain` root signature
namespace (`ChainRoot::DirectConstants`), which
`translated_compute_pso_once`'s `CachedWhole` lookup missed on later
runs. When indirect dispatches queued whole-form promotion, cached blobs
also waited behind multi-second cold driver compiles on `xcl-pso-whole`.

- Add `ComputeBuild::CachedDirectChain` and
  `dispatch_chain::try_cached_whole` so `translated_compute_pso_once`
  reuses `DirectChain`-cached whole PSOs before building split pieces.
- Route `queue_whole` through a lightweight `xcl-pso-whole-cache` fast
  lane that resolves cached blobs without blocking on `xcl-pso-whole` or
  `huge_compile_turn`, forwarding only misses to the cold worker.
- Eagerly warm chains listed in `EARLIER_INDIRECT_USED` during
  `dispatch_chain::build`.
- Add unit and GPU tests covering `ChainRoot::DirectConstants` namespace
  separation and `try_cached_whole` hit and miss paths.

AI-assisted: Antigravity (Gemini 4 Neon)
@Decodere
Decodere force-pushed the perf-dispatch-chain-fast-cached-whole branch from 9f39f73 to 5f0c226 Compare December 3, 2026 06:49
@Foniass

Foniass commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review of 5f0c2265, since 9f39f73a (code reading only, not a merge-check) · 1 medium

In short: Since 9f39f73a the only code change is two new tests in dispatch_chain::tests. One checks that the two namespaces differ. One GPU test covers a hit and a miss of try_cached_whole in CachedDirectChain mode. That fixes the missing test. A closer look shows the fast lane does find blobs, so I withdraw that earlier point. The eager warm in build is unchanged: it still queues cold whole-form compiles while the title loads, and peak commit in the new smoke run rises by about 1 GB, with no AMD run.

Medium

  1. The eager warm in build still queues cold compiles, not cache warms (still open).

    • build is reached only after translated_compute_pso_once missed both the ABI lookup and the try_cached_whole lookup (real.rs ~6203-6210). Its own lookup uses the same DXIL, chain root signature, flags and node. So the queue_whole it starts (dispatch_chain.rs ~416) misses on xcl-pso-whole-cache again and forwards to xcl-pso-whole.
    • The result is a cold whole-form compile, queued during load, for every split program in used-indirect-split.txt with no whole blob. These are the largest programs the driver compiles. On AMD the driver-blob disk cache is off by default, so this covers every journaled program.
    • The worker runs jobs in order, so a whole form that a live indirect dispatch asks for waits behind them.
    • main already builds the chain-root whole of journaled indirect programs in startup preparation (shaders.rs ~2597-2603). When it did, build is never reached; when it did not, the runtime warm is a cold compile.
    • Peak commit goes from 16544 MB to 17542 MB in the new smoke run. D3D12.X: predicate empty split indirect rounds and add whole-PSO pool #3763, stacked on this PR, adds priorities to the cold queue, but this PR has none if merged alone.

    Fix: have build queue only the cache lookup, or move the eager warm into its own PR with an AMD measurement.

Checked and fine
  • Earlier finding fixed: the creation-time lookup in the DirectConstants namespace had no test. try_cached_whole_hits_direct_chain_cache_and_skips_create_on_miss (~1362) checks that a miss returns None without calling create. With a seeded chain-root blob, it checks that the pipeline is created once, with a non-empty CachedPSO. cached_direct_chain_namespace_differs_from_abi_namespace covers the name split.
  • Earlier finding withdrawn: the fast lane does hit. Compute passes of translated graphics pipelines go into dispatch_chain::build (real.rs ~9617) after an ABI-only lookup (~9595), and their indirect draws call whole_ready (bind.rs ~3684). For those, a chain-root whole blob from an earlier run is found only by the cache lane. It also finds blobs written after the chain was created.
  • The test's cache key matches what compute_container computes. Its Drop removes both the disk file and the memory entry, and it calls skip_test without a GPU, DXC or a driver blob.
  • WholeSentGuard and the cache-only exits of CachedDirectChain are as before.
  • 363+/18-. D3D12.X: predicate empty split indirect rounds and add whole-PSO pool #3763 is stacked on this PR.

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

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

2 participants