Skip to content

D3D12.X: predicate empty split indirect rounds and add whole-PSO pool - #3763

Open
Decodere wants to merge 2 commits into
xcl-dev:mainfrom
Decodere:perf-dispatch-chain-predicate-empty-rounds-and-parallel-whole
Open

Decodere wants to merge 2 commits into
xcl-dev:mainfrom
Decodere:perf-dispatch-chain-predicate-empty-rounds-and-parallel-whole

Conversation

@Decodere

@Decodere Decodere commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #3754 (Depends on #3754, 5f0c226514e7); only the top commit belongs here.

Summary

Reduce split indirect compute overhead while whole forms compile and allow opt-in parallel whole-form builds (README.md, crates/xcl/src/gpu/recomp/pso.rs, runner.rs, crates/xcl/src/hle/d3d12x/list_x.rs, pso_async.rs, real.rs, real/dispatch_chain.rs, +566 / -84):

  • Slicer predicate & SetPredication (pso.rs, runner.rs, list_x.rs, real.rs): Write an 8-byte-aligned u64 active flag (CHAIN_PREDICATE_AT = 48) inside each 256-byte INDIRECT_SLICER round record (sharing D3D12_RESOURCE_STATE_PREDICATION == D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT, zero extra buffer bytes or state transitions). Predicate rounds r >= 1 in record_dispatch_chain_indirect with D3D12_PREDICATION_OP_EQUAL_ZERO whenever the list has no active title predication, clearing predication unconditionally via an RAII drop guard. Hook native console SetPredication (slot 31 -> PC slot 55) so list_x::has_active_predication tracks both native SetPredication and SetPredicationBufferX and never overwrites or clears title predication.
  • Barrier narrowing (pso.rs): Skip the redundant barrier before round 0 piece 0 (already flushed by record_indirect_slicer), narrow inter-round boundaries (r >= 1 && i == 0) to UAV(Some(scratch)) (disjoint slabs share only scratch), and keep global UAV(None) between split pieces of the same round (i != 0) so intra-round UMA/descriptor-heap UAV hazards remain sound on multi-round dispatches.
  • Bounded priority WholeColdPool (dispatch_chain.rs, pso_async.rs, README.md): Replace the single FIFO xcl-pso-whole thread with a bounded priority pool (xcl-pso-whole-*, default 1 worker so default peak commit stays flat, opt-in XCL_WHOLE_WORKERS=2..4 or auto with 1.5 GiB commit headroom gating, documented in README.md). Live skipped dispatches (whole_ready, high = true) and live indirect dispatches compile at high priority ahead of speculative eager warms while preserving the xcl-pso-whole-cache fast lane from D3D12.X: fast-lane cached whole PSOs and warm indirect split chains #3754.
  • Tests: Unit and GPU tests covering predicate alignment/state, RAII guard unwinding, native SetPredication + SetPredicationBufferX tracking, GPU-written slicer predicates, priority ordering, commit-headroom throttling, and panic survival.

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 slab_tests: 6 passed, 0 failed; dispatch_chain::tests: 25 passed, 0 failed; set_predication_buffer_state_transitions_and_lifecycle: 1 passed, 0 failed (baseline main 395405e4 full workspace: 3012 passed, 0 failed, 56 ignored, 28 SKIPPED).
  • Combined-stack telemetry on title 29640639 (XCL_WHOLE_WORKERS=4): promoted up to 625 split indirect chains to whole, collapsing Wave32 Top-60 GPU time 25x–49x (zero Wave32-EI split chains remaining in Top-25); standalone c301c1e6 default-config (XCL_WHOLE_WORKERS=1) 60 s smoke via scripts/smoke.ps1 below.

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 (c301c1e6):

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

Not tested

  • XCL_WHOLE_WORKERS=2..4 / auto is opt-in and was not enabled in the default scripts/smoke.ps1 regression run above (default runs with 1 worker; multi-worker pool behavior was exercised in unit tests and combined-stack runs).
  • AMD (wave64) and Intel GPUs, Linux / macOS builds, and other retail titles beyond title 29640639.

AI use

  • Antigravity (Gemini 4 Neon) wrote the implementation, review fixes, 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 51b4b7a3 (code reading only, not a merge-check) · 1 high, 3 medium, 1 nit

In short: Stacked on #3754 (its first commit is #3754's head); only the top commit 51b4b7a3 is new. It does two things for split indirect chains: rounds after the first are predicated on a flag the slicer writes, and the single whole-PSO thread becomes a priority pool of up to 4 workers, limited by free commit. One bug: a title's own SetPredication is not seen, so a split ExecuteIndirect overwrites it and then clears it. The pool's priority order also puts the jobs whose dispatches are skipped last, and two unrelated changes share one commit.

High

  1. A title's native SetPredication is overwritten, then cleared.

    • has_active_predication (list_x.rs ~5254) only sees predication set through SetPredicationBufferX. The console slot for plain SetPredication (31 → PC 55, console_remap in real.rs ~1495) has no hook in the command-list table (~1670-1690), so the call goes straight to the driver and is never recorded in LISTS.
    • On a list where the title set predication that way, execute_indirect (dispatch_chain.rs ~925) passes predicate_empty = true. record_dispatch_chain_indirect (pso.rs ~2033) then replaces the title's predicate for rounds ≥ 1, and the guard (~2026) calls SetPredication(None) at the end.
    • Everything the title records after that on the list runs unpredicated, and round 0 and the later rounds follow different predicates. Before this PR the chain path did not touch predication.

    Fix: track the native call (hook the slot and record its state in LISTS), or drop the predication part, since an empty round already dispatches zero groups.

Medium

  1. The priority order puts skipped dispatches last.

    • Only whole_ready queues at normal priority (dispatch_chain.rs ~612). Both its callers are indirect paths: the two-pass mesh compute pass (bind.rs ~3684), and an ExecuteIndirect the chain cannot take (~3875). While their form is Late, their dispatches are skipped.
    • The high-priority jobs (~570 eager warm, ~907) belong to chains that already run correctly through the split form, and the eager warm queues every EARLIER_INDIRECT_USED chain as high at PSO creation. So the skipped work waits behind all of them, where before the queue was FIFO.
    • This only matters with XCL_CS_PSO_WAIT_MS set. No caller queues the "non-indirect chains" the description mentions.

    Fix: pass true from whole_ready, or rank first the jobs whose dispatches are left out.

  2. Two unrelated changes in one commit, over the size limit. The commit is +483/-70. It combines the GPU recording change (predicate slot, guard and barrier narrowing in pso.rs / list_x.rs) with the CPU worker pool in dispatch_chain.rs. Split them so each can be reviewed and measured.

  3. Neither part is measured on its own, and the pool is on by default. The 25x-49x figure is for the whole stack with D3D12.X: fast-lane cached whole PSOs and warm indirect split chains #3754. This PR's smoke runs show 1635 → 1610 frames and peak commit 16151 → 17813 MB (+1.6 GB), with nothing showing which part costs that. Up to 4 workers start by default, and only XCL_WHOLE_WORKERS=1 goes back to one. Measure each part, or start the pool at one worker until it is measured.

Nit

  1. Stale comments. dispatch_chain.rs ~596 and ~602 still say the whole form goes to "the single xcl-pso-whole worker", and ~219, ~237 and pso_async.rs ~334, ~367 still name a single thread. XCL_WHOLE_WORKERS is not in README.md.
Checked and fine
  • D3D12.X: fix two-pass batch cap starvation, wait-backoff stampede, and chain deferral #3753 and D3D12.X: keep two-pass batch deferral active across cap shrinks and tight budgets #3764 only touch bind.rs, so they do not overlap this PR.
  • Record layout: the predicate at bytes 48..56 sits after the Dispatch arguments and inside the 256-byte record. The tail record is still written with Store3 only.
  • D3D12_RESOURCE_STATE_PREDICATION equals INDIRECT_ARGUMENT (const-asserted). Predication is cleared before restore_indirect_commands moves commands back to UAV.
  • The active flag is 0 only when some dimension is 0, so a predicated-off round would have dispatched nothing anyway.
  • Dropping the barrier before round 0, piece 0 is covered by record_indirect_slicer's barrier and transition. Narrowing the barrier between rounds to scratch is safe, since rounds are disjoint group slabs.
  • With SetPredicationBufferX active, the path is unchanged.
  • Pool: active is counted under the lock and released by a drop guard, and the first job is always admitted when nothing is running.
  • The widened one-thread assertion (1..=4) matches the intended change. The GPU test checks each round's predicate against its groups.

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
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)
Reduce split indirect compute overhead while whole forms compile and
allow opt-in parallel whole-form builds:

- Write an 8-byte-aligned u64 active flag (`CHAIN_PREDICATE_AT = 48`)
  inside each 256-byte `INDIRECT_SLICER` round record (sharing
  `D3D12_RESOURCE_STATE_PREDICATION ==
  D3D12_RESOURCE_STATE_INDIRECT_ARGUMENT`, zero extra buffer bytes or
  state transitions).
- Predicate rounds `r >= 1` in `record_dispatch_chain_indirect` with
  `D3D12_PREDICATION_OP_EQUAL_ZERO` whenever the command list has no
  active title predication, clearing predication unconditionally via an
  RAII drop guard.
- Hook native console `SetPredication` (slot 31 -> PC slot 55) in
  `real.rs` / `list_x.rs` so `list_x::has_active_predication` tracks
  both native `SetPredication` and `SetPredicationBufferX` and never
  overwrites or clears title predication.
- Skip the redundant barrier before round 0 piece 0 (already flushed by
  `record_indirect_slicer`), narrow inter-round boundaries
  (`r >= 1 && i == 0`) to `UAV(Some(scratch))`, and keep global
  `UAV(None)` between split pieces of the same round (`i != 0`).
- Replace the single FIFO `xcl-pso-whole` thread with a bounded priority
  `WholeColdPool` (`xcl-pso-whole-*`, default `1` worker so peak commit
  stays flat, opt-in `XCL_WHOLE_WORKERS=2..4` or `auto` with 1.5 GiB
  commit headroom gating, documented in `README.md`). Live skipped
  (`whole_ready`) and live indirect dispatches compile at high priority
  ahead of speculative eager warms.

AI-assisted: Antigravity (Gemini 4 Neon)
@Decodere
Decodere force-pushed the perf-dispatch-chain-predicate-empty-rounds-and-parallel-whole branch from 51b4b7a to c301c1e Compare December 3, 2026 06:49
@Decodere Decodere changed the title D3D12.X: predicate empty split indirect rounds and parallelize whole-PSO pool D3D12.X: predicate empty split indirect rounds and add whole-PSO pool Dec 3, 2026
@github-actions github-actions Bot added area:docs-ci Documentation, scripts, workflows, repo governance area:shaders Shader cache, PSO compilation, pipeline libraries, precompilation labels Dec 3, 2026
@Foniass

Foniass commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review of c301c1e6, since 51b4b7a3 (code reading only, not a merge-check) · 3 medium

In short: Stacked on #3754 (reviewed there); only the top commit c301c1e6 belongs here. Since 51b4b7a3:

  • it hooks the console's native SetPredication (slot 31) and tracks it, so split rounds no longer overwrite or clear a title's predicate;
  • skipped live dispatches now queue at high priority;
  • the pool defaults to one worker, and XCL_WHOLE_WORKERS is in README.md.

The new hook adds a small regression for a title that switches between native SetPredication and SetPredicationBufferX. It also overlaps #1349 on the same slot, and the commit still holds two unrelated changes.

Medium

  1. Native SetPredication hides an earlier SetPredicationBufferX from the disarm step.

    • set_predication_x (list_x.rs ~5285) sets s.predication = None, while apply_predication_copy (~5344) decides whether to disarm only from s.predication.is_some().
    • For SetPredicationBufferX(A), then native SetPredication(B), then SetPredicationBufferX(C): before this PR, the stale predication made the third call disarm first. Now it does not, so the CopyBufferRegion into the predication buffer runs under the title's predicate B. If B fails, the copy is skipped, and C's draws follow a stale value.

    Fix: use s.predication.is_some() || s.native_predication there, and extend the (g2) test with this sequence.

  2. Overlaps D3D12.X: console list #31 SetPredication gets its placement delta and survives kickoffs #1349 on the same slot. D3D12.X: console list #31 SetPredication gets its placement delta and survives kickoffs #1349 also adds set_predication_x at console slot 31 and keeps the call in Bindings.predication, adding buffer_delta to the offset for placed buffers. It also restores the predicate after KickoffX and mid-list splits, and disarms before the SetPredicationBufferX copy. The two conflict as written. Build has_active_predication on D3D12.X: console list #31 SetPredication gets its placement delta and survives kickoffs #1349's tracking, or keep only one hook.

  3. Two unrelated changes in one commit, over the size limit (still open). The commit is now +566/-84. It combines the GPU recording change (round predicate, guard, barrier narrowing, the slot 31 hook) with the CPU worker pool in dispatch_chain.rs. The predication part has no measurement of its own: the 25x-49x figure is for the whole stack with D3D12.X: fast-lane cached whole PSOs and warm indirect split chains #3754 and XCL_WHOLE_WORKERS=4. Split it.

Checked and fine
  • Earlier finding fixed: a title's native SetPredication was overwritten and cleared. Slot 31 is hooked, and has_active_predication checks native_predication. Reset, on_pc_reset, ClearState, clear_segment_state and a null SetPredicationBufferX all clear it, and the (g2) test covers set, null, reset and clear-state.
  • Earlier finding fixed: skipped dispatches queued last. whole_ready now queues at high priority, the eager warm at normal (dispatch_chain.rs ~576, ~617).
  • Earlier finding fixed: the pool was on by default. whole_worker_count_for returns 1 unless XCL_WHOLE_WORKERS is set, with a test. The default run (1637 frames, 17512 MB) is flat against D3D12.X: fast-lane cached whole PSOs and warm indirect split chains #3754's head, so the +1 GB over main comes from D3D12.X: fast-lane cached whole PSOs and warm indirect split chains #3754.
  • Earlier finding fixed: the comments name xcl-pso-whole-*, and README documents XCL_WHOLE_WORKERS.
  • Slot 31 is console SetPredication (console_remap 28..=31 → 52..=55), next to the existing hooks at 28-30, and forwards the title's offset unchanged.
  • After a KickoffX or mid-list split the native predicate is not carried to the new PC list, and has_active_predication reads false there too, so the chain matches what the GPU has.
  • pso.rs and runner.rs are unchanged since 51b4b7a3.

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 area:docs-ci Documentation, scripts, workflows, repo governance area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:shaders Shader cache, PSO compilation, pipeline libraries, precompilation 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