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

Close the remaining async PSO fallback, command-list reset, and pso_release lifetime gaps on top of main's pipeline generation pins (dcfbb49, 665ce02, 3f91865) and late_release::hold_pipeline (eb49926b) (XCL-BT-008). Part of #916. Part of #1488.

What main already covers vs. what this rebased PR keeps:

  • main's PipelineResolution, NativeGeneration recording/submission pins, and late_release::hold_pipeline already retain completed async builds through recording/GPU retirement and defer released backing/two-pass pipelines. Redundant Resolved / Pending::state tracking from the pre-rebase PR has been dropped.
  • Three orthogonal gaps remained on main: (1) real::pso_release called f(this) before forget_ready_compute / forget_pso / pso_async::released (address-reuse race even when XCL_LATE_RELEASE=0) and did not defer the adopted stand-in/PSO itself through late_release; (2) InitialFallback binds (unbuilt stand-ins with generation = None) and PC cl_reset (PreparedNativePipeline::record_generation leaving stale bind::State.resolution across resets, plus set_depth_bias_x/prepare_draw re-probing PENDING) left fallback/bound lifetime gaps; and (3) resolve_and_pin_if_enabled* gated one-shot pinning behind rebuild_recipes_enabled(). Rebased onto upstream/main (6bfb5c51), the diff is 5 files (+817/-102, mostly tests).

What is in it

  • Pin one-shot async builds unconditionally in pso_async::resolve_and_pin_if_enabled* regardless of XCL_REBUILD_RECIPES, align resolve_and_pin_mode / resolve_and_pin_pending with resolve_wait_budgets, and expose is_tracked and retain_com (crates/xcl/src/hle/d3d12x/pso_async.rs)
  • Retain fallback COM references (ListState::retained_fallbacks) in list_x whenever bind::select_native_choice selects an unbuilt stand-in (InitialFallback), propagate them across ExecuteBundle, mid-list splits, and KickoffX, release them via late_release::hold_pipeline (unadopted) or normal Drop (adopted) on reset/release, route set_depth_bias_x and prepare_draw through bind::resolve_bound_native_pipeline, and extend a_dispatch_with_a_pipeline_still_building_waits_at_the_submit to bind an adopted stand-in across mid-list splits (crates/xcl/src/hle/d3d12x/bind.rs, crates/xcl/src/hle/d3d12x/list_x.rs)
  • Commit PreparedNativePipeline in real::cl_reset so bind::State.resolution pins do not outlive PC list resets, probe final refs in real::pso_release (add(this) / f(this) == 1) so forget_ready_compute, forget_pso, and pso_async::released always run before final driver release (even with XCL_LATE_RELEASE=0), and defer adopted PSO release via late_release::hold_adopted_pipeline (orig_fn, avoiding re-entering pso_release) with unit tests in late_release and real::async_pso_lifetime_tests (crates/xcl/src/hle/d3d12x/late_release.rs, crates/xcl/src/hle/d3d12x/real.rs)

Tested

  • Hardware: NVIDIA GeForce RTX 3060 (driver 32.0.16.2140), AMD Ryzen 5 7500F 6-Core Processor, Windows 11 x64 (10.0.26200.0), rustc 1.100.0 (0ef1bc386 2026-11-09) (stable-x86_64-pc-windows-msvc), plus XCL_ADAPTER=warp; debug and release (6908ee6d6208b86e573187209c2ba719bd6ed751 on upstream/main 6bfb5c5153ccc23517daf30aa1071ddb0fadb53c)
  • cargo build -j 4 --workspace, cargo test -j 4 --workspace --no-run, and cargo build -j 4 --release -p xcl: exited 0, 0 new compiler warnings (36 pre-existing in xcl lib vs. 39 on upstream/main; 17 pre-existing in xcl lib tests)
  • Default RTX 3060 (--test-threads=1):
    • cargo test -j 4 -p xcl --lib late_release -- --test-threads=1: 9 passed, 0 failed, 0 ignored (0 SKIPPED)
    • cargo test -j 4 -p xcl --lib pso_async -- --test-threads=1: 193 passed, 0 failed, 0 ignored (0 SKIPPED)
    • cargo test -j 4 -p xcl --lib hle::d3d12x::bind -- --test-threads=1: 116 passed, 0 failed, 0 ignored (1 SKIPPED: two_pass_binds_set_the_shared_view_heap, opt-in XCL_HEAP_WINDOWS=1)
    • cargo test -j 4 -p xcl --lib hle::d3d12x::list_x -- --test-threads=1: 114 passed, 0 failed, 0 ignored (0 SKIPPED)
    • cargo test -j 4 -p xcl --lib hle::d3d12x::console_list -- --test-threads=1: 11 passed, 0 failed, 0 ignored (0 SKIPPED)
    • cargo test -j 4 -p xcl --lib hle::d3d12x::device_x -- --test-threads=1: 23 passed, 0 failed, 0 ignored (0 SKIPPED)
    • cargo test -j 4 -p xcl --lib hle::d3d12x::real -- --test-threads=1: 178 passed, 0 failed, 0 ignored (0 SKIPPED)
  • XCL_ADAPTER=warp (--test-threads=1):
    • late_release: 9 passed, 0 failed, 0 ignored; pso_async: 193 passed, 0 failed, 0 ignored; hle::d3d12x::bind: 116 passed, 0 failed, 0 ignored (1 SKIPPED: no heap windows); hle::d3d12x::list_x: 114 passed, 0 failed, 0 ignored; hle::d3d12x::console_list: 11 passed, 0 failed, 0 ignored; hle::d3d12x::device_x: 23 passed, 0 failed, 0 ignored; hle::d3d12x::real: 178 passed, 0 failed, 0 ignored (1 SKIPPED: gpu_image_load_of_a_stencil_view_gives_the_stencil, no wave64)

Regression run
main (6bfb5c5153ccc23517daf30aa1071ddb0fadb53c):

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

PR (6908ee6d6208b86e573187209c2ba719bd6ed751):

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

Not tested

  • Full cargo test --workspace execution (only --no-run and the 7 targeted hle::d3d12x test modules above ran on RTX 3060 and WARP)
  • AMD / Intel GPUs, native wave64 hardware, Linux / Wine without VKD3D_CONFIG=retain_psos, non-Windows targets (not built / not tested)
  • XCL_SAMPLE_* external shader packs (unset)

AI use

  • Antigravity (Gemini 4 Hydrogen): audited upstream/main generation pins (dcfbb49, 665ce02, 3f91865) and late_release::hold_pipeline, rebased fix/pso-async-lifetime-retention onto upstream/main 6bfb5c51 by dropping superseded retention logic and rebuilding the remaining InitialFallback / cl_reset / pso_release / one-shot-pin fixes, updated late_release and real::async_pso_lifetime_tests regression tests, and ran the builds, targeted RTX 3060 + WARP tests, and paired 60 s smoke runs.

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

@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

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

At head 5333a9b91290a0163e2368bc27e89907c5e4207a, the mid-list split now calls resolve_cached_for_bind(bound_pso, &bound_resolved) (list_x.rs:2855). For a still-tracked compute PSO, that calls resolve_for_bind_retained, which waits for the build (or runs an unclaimed job on the recording thread); the default XCL_PSO_WAIT_MS budget is unbounded. A normal SetPipelineState records the pending PSO in both bind and list_x, and bind::dispatch calls defer specifically so the build is waited for at submit. The split therefore blocks inside Dispatch before defer can return, losing the record-now/wait-at-submit behavior. Could the split use a retained nonwaiting lookup for the continuation's initial PSO, and extend a_dispatch_with_a_pipeline_still_building_waits_at_the_submit through the normal SetPipelineState path? That test currently initializes list_x::bound_pso to zero, so it misses this branch.

This is a source-derived timing review of the exact head; I did not run a native timing reproduction. AI use: OpenAI Codex (GPT-6.2 Sol) reviewed the source and drafted this point; I checked the call chain and existing test before posting.

rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
@fixgep
fixgep force-pushed the fix/pso-async-lifetime-retention branch from 5333a9b to 1a51cb9 Compare November 26, 2026 12:23
@fixgep

fixgep commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

@luckyteagirl Good catch, thanks! Changed list_x::split to use a non-blocking lookup (resolve_cached_if_pending) so it won't wait before submit, and updated a_dispatch_with_a_pipeline_still_building_waits_at_the_submit to cover this with a bound stand-in PSO (1a51cb95).

@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

@github-actions github-actions Bot added the stale No activity for 3 days; closed 4 days later unless something happens label Dec 1, 2026
@Foniass

Foniass commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Triage (#1607) – head 6908ee6

No open PR makes the same change. #2422 also changes real.rs:pso_release so that forget_pso runs before the last driver release, but only for the address-reuse race. Here forget_pso and pso_async::released run before the final driver release whether or not late release is enabled.
Main has since reworked this area: native pipeline generations are pinned in recordings (dcfbb49, 665ce02, 3f91865), and pso_release now hands the real pipeline to late_release::hold_pipeline. 6908ee6 is rebuilt on that rework and only closes the gaps left on top of it.
The diff is now +817/-102 across 5 files. The description argues it cannot be split, but the pso_release/late-release part and the list-side retention look separable.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

Upstream generation pins and `late_release::hold_pipeline` now retain
completed async builds across recording/submission and defer released
backing/two-pass pipelines until GPU queues pass their fences. Close the
remaining lifetime gaps on top of them:

- Pin one-shot async builds unconditionally in `resolve_and_pin_if_enabled*`
  (not only when recipe rebuilds are enabled), align wait budgets with
  `resolve_wait_budgets`, and commit `PreparedNativePipeline` in `cl_reset`
  so stale `PipelineResolution` pins are released on PC list resets.
- Track COM references (`retained_fallbacks`) in `ListState` whenever
  `InitialFallback` binds an unbuilt stand-in (`select_native_choice`),
  propagating through `ExecuteBundle`, mid-list splits, and `KickoffX` and
  releasing through `late_release::hold_pipeline` or `pso_release`.
- Route `set_depth_bias_x` and `prepare_draw` through
  `bind::resolve_bound_native_pipeline` instead of re-probing `PENDING`
  by raw stand-in address after release.
- Guard final release in `real::pso_release` with `res_release`-style
  probing so `forget_ready_compute`, `forget_pso`, and `pso_async::released`
  always run before final driver `Release` (even with `XCL_LATE_RELEASE=0`),
  and defer final adopted-PSO release via `late_release::hold_adopted_pipeline`
  using `orig_fn`.
- Add `late_release` and `real::async_pso_lifetime_tests` regression tests
  and extend `a_dispatch_with_a_pipeline_still_building_waits_at_the_submit`
  for real adopted stand-in binds across mid-list splits.

Part of xcl-dev#916
Part of xcl-dev#1488

Assisted-by: Antigravity (Gemini 4 Hydrogen)
@fixgep
fixgep force-pushed the fix/pso-async-lifetime-retention branch from 1a51cb9 to 6908ee6 Compare December 1, 2026 18:05
@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory 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) labels Dec 1, 2026
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: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) stale No activity for 3 days; closed 4 days later unless something happens

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants