Skip to content

D3D12.X: keep caller allocator for untracked lists and retain whole PSOs in dispatch_chain - #2333

Open
Decodere wants to merge 1 commit into
xcl-dev:mainfrom
Decodere:fix-2080-dispatch-chain-allocator-lifetime
Open

Decodere wants to merge 1 commit into
xcl-dev:mainfrom
Decodere:fix-2080-dispatch-chain-allocator-lifetime

Conversation

@Decodere

@Decodere Decodere commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What is in it

Follow-up to #2080 (Part of #2088, Part of #1269) fixing two runtime allocator/lifetime bugs in crates/xcl/src/hle/d3d12x/real/dispatch_chain.rs and crates/xcl/src/hle/d3d12x/bind.rs:

  1. Preserve caller allocator for lists not tracked by alloc_pool: Extracted resolve_allocator (resolve_allocator_with) so when alloc_pool::enabled() is true and alloc_pool::recording_backing(list) returns None (as for console command lists created via dev_create_command_list_x and bundles), dispatch_chain falls back to the caller's allocator instead of 0. Previously, zeroing the allocator forced every console-list split compute dispatch onto the synchronous unsplit chain.whole() fallback.
  2. Retain Arc<Chain> (and its bound whole PSO) until allocator_reset: Changed Recording::{scratch, first} to Option<Arc<Scratch>> / Option<ID3D12PipelineState>, updated dispatch_chain::whole(list, pso, allocator) (and its bind.rs:318 ExecuteIndirect callsite), and added retain_whole(allocator, chain) on both the dispatch() whole fallback and ExecuteIndirect's whole() path. Whenever allocator != 0, Arc<Chain> is retained in RECORDINGS[allocator] (deduplicated per allocator, dropping any duplicate Arc<Chain> outside RECORDINGS.lock()) so forget(pso) while the command list is still in flight does not destroy the bound whole ID3D12PipelineState before allocator_reset(allocator).

(Rebased onto origin/main 08294413 to integrate cleanly with e9ddf17/0829441 slabbed bounded scratch (Option<Arc<Scratch>> + SLABS + record_dispatch_chain). Also updated the dispatch() fallback test fixture to use a D3D12_COMMAND_LIST_TYPE_BUNDLE list with SetComputeRootSignature(&rs) and [1, 1, 1] groups so it deterministically exercises the whole fallback regardless of VRAM size and avoids debug-layer ID 952/1296 messages noted by @fromthemoonx.)

Tested

  • Pre-fix reproduction (cargo test --release -p xcl --lib hle::d3d12x::real::dispatch_chain::tests:: -- --test-threads=1 --nocapture): confirmed unmodified dispatch() whole fallback failed whole_fallback_retains_chain_until_allocator_reset_preflight (0 passed; 1 failed — Chain and its whole PSO dropped immediately on forget(pso)).
  • Post-fix cargo test --release -p xcl --lib hle::d3d12x::real::dispatch_chain::tests:: -- --test-threads=1 --nocapture on NVIDIA GeForce RTX 4060 (0.23 s) and under XCL_ADAPTER="Microsoft Basic Render Driver" (0.19 s): 3 passed, 0 failed, 0 ignored (0 skipped), including a_chains_scratch_is_bounded_by_what_all_recordings_hold and:
    • untracked_list_keeps_caller_allocator_when_alloc_pool_is_enabled (pure CPU): verifies untracked lists retain caller allocator when alloc_pool is enabled, tracked lists still resolve their recording_backing, and disabled pool uses caller allocator.
    • whole_fallback_and_indirect_retain_chain_until_allocator_reset (D3D12, skip_test-guarded): exercises both dispatch()'s whole fallback (on a real bundle with root signature set and [1, 1, 1] groups) and repeated ExecuteIndirect whole() calls on a real DIRECT command list, verifying Arc<Chain> stays alive across forget(pso) without duplicate RECORDINGS entries, releases cleanly on allocator_reset, and closes cleanly.
  • Full release workspace (cargo test --release --workspace --no-fail-fast -- --test-threads=4 --nocapture on RTX 4060): 23 test binaries, 1274 passed, 0 failed, 46 ignored (28 pre-existing hardware/debug-layer SKIPPED: 21 no wave64 on 32-lane GPU, 3 wave32 per-lane refused, 2 missing D3D12 debug layer, 1 driver cache toggle, 1 no heap windows; 0 skipped in dispatch_chain).

Regression run

Paired 60 s scripts/smoke.ps1 runs on the same RTX 4060 host against origin/main (082944135cd2b96288470a595861fa608eee08dc) and PR head (e406771b8ad3e1aff1525ca03dbd146edd157b8c):

Baseline (origin/main):

xcl-smoke v1
commit: 082944135cd2b96288470a595861fa608eee08dc
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1553 (PresentX 1554)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14022 MB

PR head:

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

Not tested

  • Retail title run with XCL_CONSOLE_LISTS=1 or D3D12 debug-layer execution (d3d12SDKLayers.dll is not installed on this host; allocator fallback and whole PSO lifetime retention are verified directly by the unit/D3D12 tests).
  • AMD/Intel GPUs and native wave64 hardware (this host has an NVIDIA RTX 4060).

AI use

Implemented and verified with Google Antigravity (Gemini 4 Neon).

Part of #2088
Part of #1269

@nnonno91

Copy link
Copy Markdown

Independent Radeon and RTX 5090 verification of af0b6672d1ed51a7d8855c61050262ad9c470464.

Tested

  • Windows 11 25H2 build 26200.9974, Ryzen 7 9800X3D, Rust 1.100.0 MSVC, unoptimized profile. AMD Radeon(TM) Graphics driver 32.0.21042.62 and RTX 5090 driver 32.0.16.1742.
  • cargo test --locked -p xcl --lib hle::d3d12x::real::dispatch_chain::tests:: -- --nocapture --test-threads=1 with each adapter selected by XCL_ADAPTER. The checked-in GPU fixture uses the default device, so I temporarily changed only its adapter lookup and printed the selected device. Both runs gave 2 passed, 0 failed, 0 ignored and no skips.
  • The CPU test checked caller and tracked allocator selection. On both devices, the whole-fallback and indirect fixture retained the chain across forget(pso), deduplicated repeated recording, then released it on allocator reset. The adapter selection edit was restored.

Not tested

Submitted in-flight work outside the unit fixture, the parent, retail smoke and the full workspace suite.

AI use

OpenAI Codex (GPT-6.2 Sol) adapted the test's adapter lookup, ran the tests and wrote this report.

@fromthemoonx

Copy link
Copy Markdown

Passes on NVIDIA with the D3D12 debug layer installed. The e2e debug-layer messages are the same as on main. With the layer on, the new D3D12 test records two messages from its own fixture (below).

Tested: RTX 3060 12 GB (driver 610.88), Ryzen 7 5700X, Windows 11 Pro 26300, Rust 1.100.0 MSVC, debug, Graphics Tools (D3D12 debug layer) installed. Head af0b667, which already contains main 06c9f55.

result
cargo test --workspace --no-fail-fast -- --test-threads=4 1267 passed, 0 failed, 46 ignored; 25 SKIPPED lines (no wave64 and the refused per-lane forms); test_title_draws_with_a_root_signature_under_the_debug_layer ran and passed
hle::d3d12x::real::dispatch_chain::tests::, 30 runs (--test-threads=4) 2 passed each time, 30 of 30
e2e title's debug-layer messages in xcl.log, PR vs 06c9f55 identical: 3× error id 93, 1× error id 1046, 1× warning id 820, 8× id 0 (live objects at exit)

whole_fallback_and_indirect_retain_chain_until_allocator_reset makes its own device through agility::create_device, so XCL_D3D12_DEBUG does not reach it. With a scratch EnableDebugLayer() before that call, it still passes, and the device's info queue then holds:

  • error, id 952: ID3D12CommandList::Dispatch: No Root Signature has been set so calling Dispatch can lead to unexpected behavior.
  • warning, id 1296: ID3D12CommandList::Dispatch: At least one of {ThreadGroupCountX, ...} (4294967295, 1, 1) exceeds the maximum threadgroup count of 65535.

Both come from the fixture: dispatch(&list, p1, a1, [u32::MAX, 1, 1]) on a list with no root signature set. The list is closed and never executed, so nothing breaks today. A SetComputeRootSignature(&rs) and a group count of 65 535 or less would keep the test clean if it is ever submitted or run under the layer.

The e2e title does not reach dispatch_chain's split path, so the e2e comparison only shows that nothing else changed. The new tests cover the two fixes.

Not tested: a title with XCL_CONSOLE_LISTS=1, a release build, AMD / Intel, the new test failing without the fix (it uses the new 3-argument whole(), so it does not build against main's file).

AI use: Claude Code (Claude Opus 5.5) ran the tests and the scratch debug-layer check, and wrote this report.

…SOs in dispatch_chain

Two runtime lifetime fixes in `real/dispatch_chain.rs` (follow-up to xcl-dev#2080):

1. When `alloc_pool::enabled()` is true and `alloc_pool::recording_backing(list)`
   returns `None` (e.g., console command lists and bundles not registered in
   `alloc_pool`), fall back to the caller's `allocator` instead of `0` so
   console-list split compute dispatches do not unconditionally degrade to the
   synchronous unsplit `chain.whole()` fallback.
2. Retain `Arc<Chain>` in `RECORDINGS[allocator]` whenever `allocator != 0` on
   both the `dispatch()` `whole` fallback and `ExecuteIndirect`'s
   `dispatch_chain::whole(list, pso, allocator)` path (deduplicating per
   allocator and dropping any duplicate `Arc<Chain>` outside `RECORDINGS.lock()`),
   so releasing the PSO (`forget(pso)`) while the command list is still in flight
   does not destroy the bound `whole` `ID3D12PipelineState` before
   `allocator_reset(allocator)`.

Part of xcl-dev#2088
Part of xcl-dev#1269
Assisted-by: Google Antigravity (Gemini 4 Neon)
@luckyteagirl

Copy link
Copy Markdown
Contributor

Independent RX 6800M check on exact head af0b6672d1ed51a7d8855c61050262ad9c470464.

Tested

  • Windows 11 build 26200, discrete AMD Radeon RX 6800M (driver 30.0.13002.13003), Rust 1.99 MSVC, DXC/DXIL 1.9.2609.5.
  • Clean checkout: cargo test --locked -p xcl --lib hle::d3d12x::real::dispatch_chain::tests:: -- --test-threads=1 --show-output: 2 passed, 0 failed, 0 ignored, 0 explicit skips. The checked-in fixture uses the default D3D12 device, so this run alone does not identify the adapter.
  • Local test-only change to the GPU fixture selected via XCL_ADAPTER=6800M and printed dispatch_chain test adapter: AMD Radeon RX 6800M. With XCL_REQUIRE_GPU=wave64, the same filter gave 2 passed, 0 failed, 0 ignored, 0 explicit skips. The GPU fixture exercised both dispatch() whole fallback and repeated whole() calls, including retention across forget(pso), deduplication, and release at allocator reset. The selector change was restored; the checkout is clean.

This adds a discrete RDNA2 and older AMD driver to the existing Radeon/NVIDIA checks. I did not run the full workspace suite or a retail-title smoke comparison for this PR, and these focused tests do not cover an in-flight console command list.

AI use: OpenAI Codex (GPT-6) ran the checks and prepared this report.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 25, 2026
…#2296, xcl-dev#2297, xcl-dev#2320, xcl-dev#2323, xcl-dev#2329, xcl-dev#2333

Integrates shader heap-base addresses (xcl-dev#1803), fenced superseded texture unmaps (xcl-dev#2270), cross-queue VRAM heap reclamation fencing (xcl-dev#2275, using create_raw_fence under Wine), PcCall frame clamping and orphan PSO drop (xcl-dev#2296), PSO pointer guards (xcl-dev#2297), KickoffX idle spare list switching (xcl-dev#2320, preserving UnadoptGuard), console-list descriptor heap binding (xcl-dev#2323), ClearUnorderedAccessView PC handles (xcl-dev#2329), and dispatch_chain PSO retention (xcl-dev#2333).
@Decodere
Decodere force-pushed the fix-2080-dispatch-chain-allocator-lifetime branch from af0b667 to e406771 Compare November 25, 2026 15:50
@Decodere

Copy link
Copy Markdown
Contributor Author

Thank you @nnonno91, @fromthemoonx, and @luckyteagirl for testing across RTX 5090, RX 7900 XTX / Arc A770, and RX 6800M!

Rebased #2333 cleanly onto origin/main (08294413 -> e406771b) to integrate with e9ddf17/0829441 slabbed bounded scratch:

  • Adapted Recording::scratch to Option<Arc<Scratch>> while keeping the SLABS / scratch_for / record_dispatch_chain design and a_chains_scratch_is_bounded_by_what_all_recordings_hold intact.
  • Updated whole_fallback_and_indirect_retain_chain_until_allocator_reset so the dispatch() whole fallback test uses a D3D12_COMMAND_LIST_TYPE_BUNDLE command list with SetComputeRootSignature and [1, 1, 1] groups (deterministically hitting the fallback without huge grid args, addressing @fromthemoonx's note about D3D12 debug layer ID 952/1296).
  • Re-verified dispatch_chain::tests (3 passed, 0 failed on both RTX 4060 and WARP), full release workspace (1274 passed, 0 failed), and paired 60 s smoke (1553 -> 1624, 0 device removals/crashes).

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.

4 participants