Skip to content

D3D12.X: retain resolved async pipelines until reset and retirement - #2417

Open
fixgep wants to merge 1 commit into
xcl-dev:mainfrom
fixgep:fix/pso-async-lifetime-retention
Open

fixgep wants to merge 1 commit into
xcl-dev:mainfrom
fixgep:fix/pso-async-lifetime-retention

Conversation

@fixgep

@fixgep fixgep commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Retain resolved async pipeline COM references across command list recording, reset, and GPU queue retirement so background-built pipelines cannot be freed while bound or in flight (XCL-BT-008). Part of #1488.

What is in it

  • Synchronize Pending completion, state updates, and unstarted/adopted stand-in release under Pending::state (Pending::finish_release), return COM-retaining Resolved handles (resolve_wait_retained, resolve_for_bind_retained, resolve_if_pending, resolve_cached_*) with settled fast-path tracking, and gate adopted stand-in release via try_release_standin (pso_async.rs)
  • Retain resolved ID3D12PipelineState references on command lists (list_x::ListState::retained_psos, console_list::ListState::retained_psos, and bound-pipeline tracking in bind/list_x) across creation, Reset, ClearState, SetPipelineState, Draw*/Dispatch/ExecuteIndirect, RSSetDepthBiasX restore/prepare, KickoffX, mid-list split, and console_list::close until reset or release
  • Route final adopted PSO release (only when add(this) == 2 proves the caller released the actual last ref, removing the else if f(this) == 1 branch so 2 -> 1 releases stay non-final) and unadopted COM pipeline releases through non-spinning late_release::hold_deferred, dispatch unadopted COM objects via vtable slot 2 in late_release::drain_known, and clone queue COM references safely under QUEUES (present::known_queue_refs) while purging retired test queues from Held::fences (real.rs, late_release.rs, present.rs, pso_async.rs)
  • Add synthetic COM stress race (UnstartedReal RAII guard), GPU queue retirement (late_release + stalled queue), standin::shell command-list lifetime, and pending stand-in bind/retain -> title Release (2 -> 1) -> list Reset (1 -> 0) regression tests (with XCL_ADAPTER=warp / agility::create_device fallback and clean skip when no D3D12 adapter is present) in pso_async.rs, late_release.rs, and real.rs

Tested

  • Hardware: NVIDIA GeForce RTX 3060 (driver 32.0.15.9144), Windows 11 x64, rustc 1.100.0 (0ef1bc386 2026-11-09), debug and release (rebased onto upstream/main 6d12f58a229b, head 5333a9b91290a0163e2368bc27e89907c5e4207a)
  • cargo build --workspace: exited 0 with 0 new compiler warnings
  • cargo test -p xcl --lib hle::d3d12x -- --test-threads=4 (default RTX 3060): 259 passed, 0 failed, 2 ignored (0 SKIPPED GPU tests)
  • XCL_ADAPTER=warp cargo test -p xcl --lib hle::d3d12x -- --test-threads=1: 259 passed, 0 failed, 2 ignored (0 SKIPPED GPU tests; under --test-threads=4 on WARP, pre-existing hle::d3d12x::alloc_pool::tests::a_recording_outlives_the_reset_of_the_titles_allocator failed with -2147024809 from concurrent alloc_pool state sharing and passed alone and single-threaded)
  • cargo test --workspace -- --test-threads=4: 1303 passed, 1 failed, 26 ignored (unrelated pre-existing failure in gpu::recomp::tests::gpu_clamp_and_omod_per_instruction on RTX 3060)

Regression run
main (3ceb5507a05355719ff1d7b5c29bc52aff142000):

xcl-smoke v1
commit: 3ceb5507a05355719ff1d7b5c29bc52aff142000
gpu: NVIDIA GeForce RTX 3060
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 831 (PresentX 832)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14851 MB

PR (5333a9b91290a0163e2368bc27e89907c5e4207a):

xcl-smoke v1
commit: 5333a9b91290a0163e2368bc27e89907c5e4207a
gpu: NVIDIA GeForce RTX 3060
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 912 (PresentX 913)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14617 MB

Not tested

  • ShaderCacheControl / wave64 GPU paths and non-Windows targets (not built / not tested)
  • XCL_SAMPLE_* external shader packs (unset)
  • Full clean .\scripts\test.ps1 pass (unrelated pre-existing gpu::recomp::tests::gpu_clamp_and_omod_per_instruction failure on RTX 3060)

AI use

  • Antigravity (Gemini 4 Hydrogen): verified XCL-BT-008 unclaimed via GitHub REST API, authored failing-first and multi-threaded COM lifetime tests, implemented COM reference retention, late_release synchronization, and WARP/no-GPU test guards across d3d12x, addressed @bmjask review feedback (pso_release add(this) == 2 check and pending stand-in 2 -> 1 -> 0 reset regression), rebased onto upstream/main 6d12f58a229b, and ran hle::d3d12x tests, workspace tests, and 60 s smoke check

@Aniseto

Aniseto commented Nov 25, 2026

Copy link
Copy Markdown

Ran the async-pipeline lifetime tests at 8142aa1:

Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, wave32 only, 16 GB) driver 32.0.16.2124, 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.

Results

  • cargo test -p xcl --lib async_pso -- --test-threads=4: 3 passed, 0 failed (exit 0)
  • cargo test -p xcl --lib pso_async -- --test-threads=4: 12 passed, 0 failed (exit 0)
  • cargo test -p xcl --lib late_release -- --test-threads=4: 3 passed, 0 failed (exit 0)
  • cargo test -p xcl --lib list_x -- --test-threads=4: 34 passed, 0 failed (exit 0)

The new lifetime tests (async_pso_stays_alive_through_command_list_reset_and_gpu_retirement, concurrent_resolve_retained_and_release_never_exposes_freed_pipeline and the late_release queue-retirement case) pass here on a real D3D12 device and command list.

What this adds: the author ran these filters on an Ampere RTX 3060; this is a Blackwell wave32 part. No test report from another machine exists in the thread yet.

Not tested: the whole xcl --lib run (the description lists a pre-existing gpu_clamp_and_omod_per_instruction failure), a paired 60 s smoke run, AMD and Intel GPUs, Wine, release profile, title data.

AI-assisted (OpenCode), model: DeepSeek V4.1 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.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: 1 real failure, deterministic (also fails --test-threads=1, 1219/1):
gpu::recomp::lower_dxil::tests::a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier
  assertion failed: group barriers in the program (lower_dxil.rs:1155)

The lowered program is missing an expected group barrier (or emits one where none is expected). Needs a fix before merge.

— Devin

@emirduran707

Copy link
Copy Markdown
Contributor

Independent AMD RDNA4 (native wave64) test report on exact head 75726f769e996fdeae51c37f1a6beb26371f9e98 (clean detached checkout, no local changes).

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64, driver 32.0.31044.16), Ryzen 5 5600, 32 GB RAM, Windows 11 Pro 26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2602.17; tests debug, smoke release.
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4: 1349 passed, 3 failed, 46 ignored; 8 SKIPPED (6 in lower_dxil::tests::{f16,f32}_programs_on_the_gpu refused by per-lane form; heap_window_out_of_memory_falls_back_to_the_switch_form; pso_measurement_compiles_an_exact_synthetic_record). All native wave64 GPU tests ran and passed.

Regression run (60 s retail-title smoke, XCL_NETWORK=0, release)

xcl-smoke v1
commit: 75726f769e996fdeae51c37f1a6beb26371f9e98
gpu: AMD Radeon RX 9060 XT
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1575 (PresentX 1575)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16128 MB

(Matched main 68a284a baseline on the same machine today: 1573 frames, 14420 MB peak, 0 device removals, 0 crashes.)

Not tested

  • D3D12 debug layer; Intel GPUs.

AI use

  • Antigravity with Gemini 4 Neon ran the build, test suite, and smoke run and drafted this report.

@fixgep
fixgep force-pushed the fix/pso-async-lifetime-retention branch from 75726f7 to 1029a82 Compare November 25, 2026 20:07

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

P1: pso_release can misclassify a normal 2->1 release as final and double-release a retained pending stand-in. With late release enabled, real.rs:1721-1734 treats f(this)==1 as final, removes async state, and queues a deferred raw Release. But this PR intentionally AddRefs a bound pending stand-in via Resolved/retained_psos, so title Release commonly changes title+list retention from 2 to 1. The branch then reports zero/forgets state and schedules release of the list-owned ref; when the list resets and drops its retained ID3D12PipelineState, it releases that same ref again. Please retain a separate deferred ref only after proving the caller released the actual last ref, and add a bind/retain -> title Release -> list reset regression.

`pso_async::resolve`, `resolve_wait`, and `resolve_for_bind` previously returned unretained raw `ID3D12PipelineState` addresses while `released()` could synchronously drop `real` outside any shared lock with callers or before command list reset and GPU retirement.

Synchronize pending pipeline completion, resolution, and stand-in release under `Pending::state`, introduce `Resolved` COM-owning handles across command list creation, reset, binding, draw/dispatch, KickoffX, and `console_list` replay, keep bound resolved pipelines on `bind`/`list_x` state so released stand-ins are not re-dereferenced, and route final stand-in/real COM release (including unadopted COM objects and `pso_release` only when `add(this) == 2` proves the caller released the actual last ref) through `late_release::hold_deferred` until GPU queues pass their fences.

Drop unstarted orphaned jobs immediately across `Pending::finish_release` and `drop_unstarted_job`, guard pre-allocated test pipelines against early-orphan drops and worker saturation in `pso_async::used_tests`, clone `present` queue COM references under `QUEUES` in `late_release::drain_known` while purging retired test queue fences, and add bind/retain -> title Release -> list Reset regression coverage in `async_pso_lifetime_tests` (selecting WARP via `XCL_ADAPTER` / `agility::create_device` fallback).

Part of xcl-dev#1488

Assisted-by: Antigravity (Gemini 4 Hydrogen)
@fixgep
fixgep force-pushed the fix/pso-async-lifetime-retention branch from 1029a82 to 5333a9b Compare November 25, 2026 20:49
@fixgep

fixgep commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for catching this! Removed the else if f(this) == 1 branch in pso_release (crates/xcl/src/hle/d3d12x/real.rs) so it now matches res_release and pso_async::release: a separate deferred ref is held in late_release::hold_deferred only when add(this) == 2 proves the caller is releasing the actual last ref (1 -> 0), and any add(this) > 2 call immediately drops its speculative ref via f(this) and runs the caller's release let n = f(this) with held = false. Also added async_pso_lifetime_tests::pending_standin_retained_on_command_list_survives_title_release_until_reset covering pending stand-in bind/retain (1 -> 2) → title Release() (2 -> 1) → command list Reset() (1 -> 0) and GPU retirement, rebased onto upstream/main, and refreshed the hle::d3d12x test and 60 s smoke runs.

@itsSio

itsSio commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Two points from reading the diff against main 08db802:

I checked pso_release (real.rs, the hunk at 1716): the else if f(this) == 1 branch from @bmjask's review is gone. The last reference is now held for late_release::hold_deferred only when add(this) == 2.

AI use:
Ran via Samaritan:

  • OpenCode (Claude Opus 5.5): read the diff and the threads, checked each point above against the code and wrote this comment.
  • OpenCode (Claude Opus 5.5), a helper session: read the diff and the threads.

The points were checked by the account owner as well (edited to complete this AI use line).

@DavidM1911

Copy link
Copy Markdown
Contributor

Re-verification on RTX 3060 Ti (Windows 11), new head merged with current main:

Thanks!

— Devin

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.

6 participants