D3D12.X: sweep completed PSO generation pins when nothing new is pinned #3185

Open
afpruivo wants to merge 1 commit from upstream-pr/3185 into main
afpruivo commented 2026-11-28 16:59:30 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by afpruivo on 2026-11-28T16:59:30Z.


pso_async::retire_native_generations keeps each pinned NativeGeneration (an extra reference on the real PSO) until its submission's receipt completes. Completed batches were swept only when a new pending batch was queued. Retiring an already-complete receipt returned early, and released() didn't sweep at all. A batch queued behind a pending fence therefore leaked its pins, and the pipeline's TWO_PASS entry with them, whenever every later submission had already completed or no later submission came. Introduced in 11613fb6 (#2959). Fixes #3441.

What is in it (one commit, on main c53e9696)

  • pso_async.rs: sweep completed batches when retiring an already-complete receipt, and at the start of released(). Queuing an in-flight pinned receipt starts the late-release worker.
  • late_release.rs: the worker sweeps the completed pins on each tick, so a fence that completes after the title's last submission and release is still looked at (thehollowedone's case and fix from the review below).
  • list_x.rs tests: a_completed_later_submission_retires_earlier_generations, releasing_a_standin_after_its_submission_completed_releases_the_pipeline, and a_submission_completed_after_the_last_release_is_swept_while_idle (thehollowedone's test). Each fails without its part of the fix. The tests that use the retirement queue take a shared lock (RETIRING_TESTS); its comment now says which other sweeps run without it.

Tested

  • NVIDIA GeForce RTX 3090 24 GB, driver 621.40, i5-13600K, Windows 11 Pro 26300, Rust 1.100.1, debug; Windows' own D3D12 (XCL_D3D12_DIR set to an empty folder: with the Agility SDK 1.620 the lib test binary stops on this machine, #3488).
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on 6f263066: 3007 passed, 0 failed, 52 ignored; SKIPPED: 26 (22 no wave64 on this 32-lane GPU, 2 no xgameruntime.dll, 2 no heap windows). An earlier run of the same head had 3006 passed and 1 failed: the e2e test title's "a texture in title memory follows CPU writes" check, the intermittent failure of #3382; cargo test -p xcl --test e2e then passed 3 of 3 on this head (and 5 of 5 on main).
  • #3441's test alone, cargo test -p xcl --test gpu_two_pass_cache_e2e -- --test-threads=1: main c53e9696 failed 3 of 6 (left: 1, right: 0 at line 584); 6f263066 passed 6 of 6.
  • cj-tomlin's abort (below): cargo test -p xcl --lib -- --test-threads=4 hle::d3d12x::pso_async 10 of 10 ok on 6f263066 (193 passed each). The race was in graphics_first_use_carries_the_exact_serialized_recipe_identity, whose job returned a fake pipeline; #3493 (merged) made it return none, and this branch is now on top of it.
  • a_submission_completed_after_the_last_release_is_swept_while_idle fails without the worker's sweep (left: 1, right: 0) and passes with it.

Regression run

main:

xcl-smoke v1
commit: c53e96960265a82477a9c98677afb0402e98d486
gpu: NVIDIA GeForce RTX 3090
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1573 (PresentX 1573)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15794 MB

this PR:

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

Not tested

  • AMD and wave64 hardware here (YousefElghanam's results on a discrete AMD card for the earlier head are on #3441).
  • No measured gain in play: a running title keeps submitting, so pins usually clear at the next pending submission.
  • The cost of the worker's sweep: one GetCompletedValue per distinct fence among the pending batches on every 4 ms tick while any are pending (a lock and an empty check when none are). And of the sweep in released() at a level change that releases many pipelines. Not measured.
  • The smoke runs stay on "press A to start" (smoke.ps1 sends no input).
  • Nothing in HANDOFF.md or docs/specs becomes wrong, as far as I can tell.

AI use

  • Claude Code, Claude Opus 5.5: found the cause, wrote the fix and tests, ran the tests and smoke runs, and drafted this description. The idle-completion fix and its test are thehollowedone's (posted in review here). The rebase, that addition and this update were made and posted by Claude Code while I was away, under the standing approval I gave it for this session.

🤖 Generated with Claude Code

<!-- greyfinch-sync:ivall/xcl:issue:5542540877 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3185). Originally posted by [afpruivo](https://github.com/afpruivo) on 2026-11-28T16:59:30Z. --- `pso_async::retire_native_generations` keeps each pinned `NativeGeneration` (an extra reference on the real PSO) until its submission's receipt completes. Completed batches were swept only when a new pending batch was queued. Retiring an already-complete receipt returned early, and `released()` didn't sweep at all. A batch queued behind a pending fence therefore leaked its pins, and the pipeline's `TWO_PASS` entry with them, whenever every later submission had already completed or no later submission came. Introduced in 11613fb6 (#2959). Fixes #3441. **What is in it** (one commit, on `main` `c53e9696`) - `pso_async.rs`: sweep completed batches when retiring an already-complete receipt, and at the start of `released()`. Queuing an in-flight pinned receipt starts the late-release worker. - `late_release.rs`: the worker sweeps the completed pins on each tick, so a fence that completes after the title's last submission and release is still looked at (thehollowedone's case and fix from the review below). - `list_x.rs` tests: `a_completed_later_submission_retires_earlier_generations`, `releasing_a_standin_after_its_submission_completed_releases_the_pipeline`, and `a_submission_completed_after_the_last_release_is_swept_while_idle` (thehollowedone's test). Each fails without its part of the fix. The tests that use the retirement queue take a shared lock (`RETIRING_TESTS`); its comment now says which other sweeps run without it. **Tested** - NVIDIA GeForce RTX 3090 24 GB, driver 621.40, i5-13600K, Windows 11 Pro 26300, Rust 1.100.1, debug; Windows' own D3D12 (`XCL_D3D12_DIR` set to an empty folder: with the Agility SDK 1.620 the lib test binary stops on this machine, #3488). - `cargo test --workspace --no-fail-fast -- --test-threads=4` on `6f263066`: 3007 passed, 0 failed, 52 ignored; SKIPPED: 26 (22 no wave64 on this 32-lane GPU, 2 no xgameruntime.dll, 2 no heap windows). An earlier run of the same head had 3006 passed and 1 failed: the e2e test title's "a texture in title memory follows CPU writes" check, the intermittent failure of #3382; `cargo test -p xcl --test e2e` then passed 3 of 3 on this head (and 5 of 5 on `main`). - #3441's test alone, `cargo test -p xcl --test gpu_two_pass_cache_e2e -- --test-threads=1`: `main` `c53e9696` failed 3 of 6 (`left: 1`, `right: 0` at line 584); `6f263066` passed 6 of 6. - cj-tomlin's abort (below): `cargo test -p xcl --lib -- --test-threads=4 hle::d3d12x::pso_async` 10 of 10 ok on `6f263066` (193 passed each). The race was in `graphics_first_use_carries_the_exact_serialized_recipe_identity`, whose job returned a fake pipeline; #3493 (merged) made it return none, and this branch is now on top of it. - `a_submission_completed_after_the_last_release_is_swept_while_idle` fails without the worker's sweep (`left: 1`, `right: 0`) and passes with it. **Regression run** main: ``` xcl-smoke v1 commit: c53e96960265a82477a9c98677afb0402e98d486 gpu: NVIDIA GeForce RTX 3090 title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 1573 (PresentX 1573) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15794 MB ``` this PR: ``` xcl-smoke v1 commit: 6f263066986fb0212b9e41b40c92c201d7a71449 gpu: NVIDIA GeForce RTX 3090 title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 1575 (PresentX 1575) presents per 2 s (last 3): 61 60 60 device removals: 0 crashes: 0 peak commit: 16796 MB ``` **Not tested** - AMD and wave64 hardware here (YousefElghanam's results on a discrete AMD card for the earlier head are on #3441). - No measured gain in play: a running title keeps submitting, so pins usually clear at the next pending submission. - The cost of the worker's sweep: one `GetCompletedValue` per distinct fence among the pending batches on every 4 ms tick while any are pending (a lock and an empty check when none are). And of the sweep in `released()` at a level change that releases many pipelines. Not measured. - The smoke runs stay on "press A to start" (`smoke.ps1` sends no input). - Nothing in HANDOFF.md or docs/specs becomes wrong, as far as I can tell. **AI use** - Claude Code, Claude Opus 5.5: found the cause, wrote the fix and tests, ran the tests and smoke runs, and drafted this description. The idle-completion fix and its test are thehollowedone's (posted in review here). The rebase, that addition and this update were made and posted by Claude Code while I was away, under the standing approval I gave it for this session. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
JJAutoCompare commented 2026-11-28 17:26:02 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by JJAutoCompare on 2026-11-28T17:26:02Z.


Tested

Independently reran the pinned XCL library test binary for 0cd75eae5062102abdb35fc2984c1d9f40a4ac73 on Windows 11 x64 build 26200.9974 with a Ryzen 7 3800X. The binary was built with Rust 1.100.1 (x86_64 MSVC) from the exact-head source plus one private fixture in the existing test module.

xcl-8941870b96d3eddf.exe hle::d3d12x::list_x::tests::a_retirement_sweep_releases_only_completed_receipts --exact --nocapture --test-threads=1
xcl-8941870b96d3eddf.exe hle::d3d12x::list_x::tests::releasing_a_standin_after_its_submission_completed_releases_the_pipeline --exact --nocapture --test-threads=1

Both native processes exited 0. Total was 2 passed, 0 failed, 0 ignored, 0 skipped. The fixture asserted that three synthetic pipelines went from refcounts [2,2,2] to [1,1,1] after dropping the title owners. An already-complete submission carrying no new pin swept only the completed middle receipt, leaving [1,0,1]. After the other two receipts completed, calling released() on a distinct absent stand-in swept the remaining pins, leaving [0,0,0]. Updating the completion counters alone left refcounts unchanged before each sweep. The stock control passed separately.

Not tested

Real D3D12 queues and fences, live COM objects, GPU, retail titles, leak rates, and the workspace suite.

AI use

T3 Code through Codex (gpt-6.2-sol, high) prepared the fixture, verified the source and binary, independently reran the tests, and drafted this report.

<!-- greyfinch-sync:ivall/xcl:comment:7243012428 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3185#issuecomment-7243012428). Originally posted by [JJAutoCompare](https://github.com/JJAutoCompare) on 2026-11-28T17:26:02Z. --- **Tested** Independently reran the pinned XCL library test binary for `0cd75eae5062102abdb35fc2984c1d9f40a4ac73` on Windows 11 x64 build 26200.9974 with a Ryzen 7 3800X. The binary was built with Rust 1.100.1 (x86_64 MSVC) from the exact-head source plus one private fixture in the existing test module. ```text xcl-8941870b96d3eddf.exe hle::d3d12x::list_x::tests::a_retirement_sweep_releases_only_completed_receipts --exact --nocapture --test-threads=1 xcl-8941870b96d3eddf.exe hle::d3d12x::list_x::tests::releasing_a_standin_after_its_submission_completed_releases_the_pipeline --exact --nocapture --test-threads=1 ``` Both native processes exited 0. Total was 2 passed, 0 failed, 0 ignored, 0 skipped. The fixture asserted that three synthetic pipelines went from refcounts `[2,2,2]` to `[1,1,1]` after dropping the title owners. An already-complete submission carrying no new pin swept only the completed middle receipt, leaving `[1,0,1]`. After the other two receipts completed, calling `released()` on a distinct absent stand-in swept the remaining pins, leaving `[0,0,0]`. Updating the completion counters alone left refcounts unchanged before each sweep. The stock control passed separately. **Not tested** Real D3D12 queues and fences, live COM objects, GPU, retail titles, leak rates, and the workspace suite. **AI use** T3 Code through Codex (`gpt-6.2-sol`, high) prepared the fixture, verified the source and binary, independently reran the tests, and drafted this report.
thehollowedone commented 2026-11-30 19:36:47 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-30T19:36:47Z.


Follow-up on PR #3185 at head 0cd75eae5062102abdb35fc2984c1d9f40a4ac73, merged cleanly onto current main ff0c364b3de011c13ed45865480c21918a79ec89 (merge commit 7e58b565d5503f6db3ddee50fa3f7223ebc11596).

One lifecycle ordering still retains a pipeline: the title releases its last stand-in while the submission receipt is pending, then the fence completes after the PR's release-time sweep. If no later submission or PSO release occurs, nothing is guaranteed to sweep the receipt again. The native pipeline reference therefore remains retained after GPU use has ended. The related observed failure is tracked in #3441.

I added this schedule as a synthetic regression. With the regression test added but before the runtime candidate, it failed after the fake fence advanced (left: 1, expected 0). With the candidate below, it passes, along with the three existing retirement tests: 4 passed, 0 failed, 0 ignored, 0 skipped, run separately with XCL_LATE_RELEASE=0. git diff --check passed.

The candidate starts XCL's existing late-release worker after queuing an incomplete pinned receipt, then sweeps these receipts on worker ticks. This uses one existing worker and does not poll fences synchronously on each submission. This is focused CPU evidence only; I did not run the workspace suite, live D3D12 fence checks, GPU tests, or title smoke. The PR remains a draft, so this is not a merge check.

Candidate fix and regression test
diff --git a/crates/xcl/src/hle/d3d12x/late_release.rs b/crates/xcl/src/hle/d3d12x/late_release.rs
@@ -254,11 +254,16 @@ fn start_thread() {
         let _ = std::thread::Builder::new().name("xcl-late-release".into()).spawn(|| loop {
             std::thread::sleep(TICK);
+            super::pso_async::sweep_native_generations();
             unsafe { drain_known(false) };
         });
     });
 }
 
+pub(super) fn start_native_generation_worker() {
+    start_thread();
+}
+
 /// A pipeline state XCL owns (raw pointer, 0 = none) is let go: the compute pass of a two-pass
diff --git a/crates/xcl/src/hle/d3d12x/pso_async.rs b/crates/xcl/src/hle/d3d12x/pso_async.rs
@@ -3758,7 +3758,7 @@ fn dedup_generations<G>(pins: impl Iterator<Item = G>, identity: impl Fn(&G) -> usize) -> Vec<G> {
-fn sweep_native_generations() {
+pub(super) fn sweep_native_generations() {
@@ -3788,6 +3788,7 @@ pub(super) fn retire_native_generations<'a>(
     }
     RETIRING_GENERATIONS.lock().unwrap().push(receipt, pins);
+    super::late_release::start_native_generation_worker();
     sweep_native_generations();
 }
diff --git a/crates/xcl/src/hle/d3d12x/list_x.rs b/crates/xcl/src/hle/d3d12x/list_x.rs
@@ -7563,6 +7563,24 @@ fn releasing_a_standin_after_its_submission_completed_releases_the_pipeline() {
     assert_eq!(native.refs.load(Ordering::Relaxed), 0, "a completed submission kept the released pipeline");
 }
 
+/// A completion after the title's last release needs a background sweep even when no later
+/// submission or PSO release arrives to trigger one.
+#[test]
+fn release_before_receipt_completion_is_reaped_while_idle() {
+    let _serial = RETIRING_TESTS.lock().unwrap_or_else(|e| e.into_inner());
+    let standin = 0x7E57_B02Busize;
+    let (native, completed) = pinned_in_flight(standin);
+    super::super::pso_async::release(super::super::pso_async::released(standin));
+    assert_eq!(native.refs.load(Ordering::Relaxed), 1, "in-flight receipt released its generation");
+
+    completed.store(1, Ordering::Release);
+    let deadline = Instant::now() + Duration::from_secs(1);
+    while native.refs.load(Ordering::Relaxed) != 0 && Instant::now() < deadline {
+        std::thread::sleep(Duration::from_millis(1));
+    }
+    assert_eq!(native.refs.load(Ordering::Relaxed), 0, "idle completion worker did not retire the generation");
+}

AI use: Codex (GPT-6.2 Sol) prepared and tested the candidate; GPT-6.2 Astra checked the fence-completion lifecycle.

<!-- greyfinch-sync:ivall/xcl:comment:7289672106 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3185#issuecomment-7289672106). Originally posted by [thehollowedone](https://github.com/thehollowedone) on 2026-11-30T19:36:47Z. --- Follow-up on [PR #3185](https://github.com/xcl-dev/xcl/pull/3185) at head `0cd75eae5062102abdb35fc2984c1d9f40a4ac73`, merged cleanly onto current `main` `ff0c364b3de011c13ed45865480c21918a79ec89` (merge commit `7e58b565d5503f6db3ddee50fa3f7223ebc11596`). One lifecycle ordering still retains a pipeline: the title releases its last stand-in while the submission receipt is pending, then the fence completes after the PR's release-time sweep. If no later submission or PSO release occurs, nothing is guaranteed to sweep the receipt again. The native pipeline reference therefore remains retained after GPU use has ended. The related observed failure is tracked in [#3441](https://github.com/xcl-dev/xcl/issues/3441). I added this schedule as a synthetic regression. With the regression test added but before the runtime candidate, it failed after the fake fence advanced (`left: 1`, expected `0`). With the candidate below, it passes, along with the three existing retirement tests: **4 passed, 0 failed, 0 ignored, 0 skipped**, run separately with `XCL_LATE_RELEASE=0`. `git diff --check` passed. The candidate starts XCL's existing late-release worker after queuing an incomplete pinned receipt, then sweeps these receipts on worker ticks. This uses one existing worker and does not poll fences synchronously on each submission. This is focused CPU evidence only; I did not run the workspace suite, live D3D12 fence checks, GPU tests, or title smoke. The PR remains a draft, so this is not a merge check. <details> <summary>Candidate fix and regression test</summary> ```diff diff --git a/crates/xcl/src/hle/d3d12x/late_release.rs b/crates/xcl/src/hle/d3d12x/late_release.rs @@ -254,11 +254,16 @@ fn start_thread() { let _ = std::thread::Builder::new().name("xcl-late-release".into()).spawn(|| loop { std::thread::sleep(TICK); + super::pso_async::sweep_native_generations(); unsafe { drain_known(false) }; }); }); } +pub(super) fn start_native_generation_worker() { + start_thread(); +} + /// A pipeline state XCL owns (raw pointer, 0 = none) is let go: the compute pass of a two-pass diff --git a/crates/xcl/src/hle/d3d12x/pso_async.rs b/crates/xcl/src/hle/d3d12x/pso_async.rs @@ -3758,7 +3758,7 @@ fn dedup_generations<G>(pins: impl Iterator<Item = G>, identity: impl Fn(&G) -> usize) -> Vec<G> { -fn sweep_native_generations() { +pub(super) fn sweep_native_generations() { @@ -3788,6 +3788,7 @@ pub(super) fn retire_native_generations<'a>( } RETIRING_GENERATIONS.lock().unwrap().push(receipt, pins); + super::late_release::start_native_generation_worker(); sweep_native_generations(); } diff --git a/crates/xcl/src/hle/d3d12x/list_x.rs b/crates/xcl/src/hle/d3d12x/list_x.rs @@ -7563,6 +7563,24 @@ fn releasing_a_standin_after_its_submission_completed_releases_the_pipeline() { assert_eq!(native.refs.load(Ordering::Relaxed), 0, "a completed submission kept the released pipeline"); } +/// A completion after the title's last release needs a background sweep even when no later +/// submission or PSO release arrives to trigger one. +#[test] +fn release_before_receipt_completion_is_reaped_while_idle() { + let _serial = RETIRING_TESTS.lock().unwrap_or_else(|e| e.into_inner()); + let standin = 0x7E57_B02Busize; + let (native, completed) = pinned_in_flight(standin); + super::super::pso_async::release(super::super::pso_async::released(standin)); + assert_eq!(native.refs.load(Ordering::Relaxed), 1, "in-flight receipt released its generation"); + + completed.store(1, Ordering::Release); + let deadline = Instant::now() + Duration::from_secs(1); + while native.refs.load(Ordering::Relaxed) != 0 && Instant::now() < deadline { + std::thread::sleep(Duration::from_millis(1)); + } + assert_eq!(native.refs.load(Ordering::Relaxed), 0, "idle completion worker did not retire the generation"); +} ``` </details> AI use: Codex (GPT-6.2 Sol) prepared and tested the candidate; GPT-6.2 Astra checked the fence-completion lifecycle.
Foniass commented 2026-12-01 09:42:12 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T09:42:12Z.


Triage (#1607) – head 0cd75ea

No open or merged PR makes the same change.
retire_native_generations now sweeps on an already-complete receipt and released sweeps before removing the pending entry; the two new tests cover both paths. An incomplete receipt with no pins still returns before sweeping, so that case keeps the old behaviour despite the title ("when nothing new is pinned"). released now polls the retiring fences on every title PSO release; cheap when the list is empty, but not measured.
Recommendation: keep open.

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

<!-- greyfinch-sync:ivall/xcl:comment:7307081912 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3185#issuecomment-7307081912). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T09:42:12Z. --- **Triage (#1607)** – head 0cd75ea No open or merged PR makes the same change. `retire_native_generations` now sweeps on an already-complete receipt and `released` sweeps before removing the pending entry; the two new tests cover both paths. An incomplete receipt with no pins still returns before sweeping, so that case keeps the old behaviour despite the title ("when nothing new is pinned"). `released` now polls the retiring fences on every title PSO release; cheap when the list is empty, but not measured. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Foniass commented 2026-12-01 09:43:47 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T09:43:47Z.


Review (head 0cd75eae, diff read, not a merge-check; draft):

  • No blocking finding. released() (pso_async.rs ~10979) now sweeps before every stand-in release. A sweep reads GetCompletedValue once per distinct fence among the pending batches, so a title that releases thousands of pipelines at a level change pays that many sweeps. Small, but unmeasured.
  • The tests take RETIRING_TESTS. Other tests that reach sweep_native_generations through released() without that lock (any test releasing a stand-in) can still drop another test's pin early. The description's 30/30 suggests it's fine in practice; it's worth a word in the lock's doc comment.

Fine:

  • Sweeping when an already-complete receipt is retired fixes the case where every later submission had completed and earlier pins stayed for good (11613fb6 / #2959).
  • sweep_retirements drops the retired generations outside its lock (~3744), so a Release that comes back through standin_released -> released() -> sweep doesn't deadlock.
  • Both new tests fail without the fix, and the flaky two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs loop (30 % -> 30/30) points at the same leak.

Once it's out of draft, a suite run and smoke pair on current main would make it ready.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7307119985 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3185#issuecomment-7307119985). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T09:43:47Z. --- Review (head 0cd75eae, diff read, not a merge-check; draft): - No blocking finding. `released()` (`pso_async.rs` ~10979) now sweeps before every stand-in release. A sweep reads `GetCompletedValue` once per distinct fence among the pending batches, so a title that releases thousands of pipelines at a level change pays that many sweeps. Small, but unmeasured. - The tests take `RETIRING_TESTS`. Other tests that reach `sweep_native_generations` through `released()` without that lock (any test releasing a stand-in) can still drop another test's pin early. The description's 30/30 suggests it's fine in practice; it's worth a word in the lock's doc comment. Fine: - Sweeping when an already-complete receipt is retired fixes the case where every later submission had completed and earlier pins stayed for good (11613fb6 / #2959). - `sweep_retirements` drops the retired generations outside its lock (~3744), so a Release that comes back through `standin_released` -> `released()` -> sweep doesn't deadlock. - Both new tests fail without the fix, and the flaky `two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs` loop (30 % -> 30/30) points at the same leak. Once it's out of draft, a suite run and smoke pair on current main would make it ready. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
cj-tomlin commented 2026-12-01 20:54:12 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by cj-tomlin on 2026-12-01T20:54:12Z.


Test report, head 0cd75eae5062102abdb35fc2984c1d9f40a4ac73 merged onto main f07e426dade72aa7112cf6bfe08ca6f6ff5a9d5c (clean, merge ad3d78b5).

Edit: the lib test binary aborts in about 3 of 10 runs with this PR; see below. This report does not count as a clean run.

  • Hardware: NVIDIA GeForce RTX 3080 10 GB, driver 621.40, AMD Ryzen 7 7800X3D, Windows 11 build 26300, debug build.
  • cargo build --workspace: ok.
  • cargo test --workspace --no-fail-fast -- --test-threads=4, first run: 2906 passed, 0 failed, 51 ignored; SKIPPED: 27 (22 no wave64, 2 no heap windows, 3 no D3D12 debug layer / d3d12SDKLayers.dll). two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs ran (no SKIPPED line) and passed.
  • #3441 on NVIDIA: cargo test -p xcl --test gpu_two_pass_cache_e2e -- --test-threads=1, alternating between the trees: main f07e426d failed 6 of 6, the merge passed 6 of 6. On main it is the #3441 assertion (left: 1, right: 0 at line 584). So on this card it is not AMD-only.
  • The two new tests pass, and both fail (left: 1, right: 0) with main's pso_async.rs put back into the merged tree.

New abort. A second full-suite run, on this merge plus #1249 (which only touches xaudio2.rs), lost the whole lib test binary: exit code: 0xc0000409, after thread 'xcl-pso-ahead-2' panicked at windows-core-0.62.2\src\interface.rs:41:18: misaligned pointer dereference: address must be a multiple of 0x8 but is 0x4332. cargo test -p xcl --lib -- --test-threads=4 hle::d3d12x::pso_async, alternating between the trees: main f07e426d 10 of 10 ok, the merged tree aborted 3 of 10, the same way each time. Backtrace: pso_async::release ← pso_async::complete ← run_build ← spawn_backlog_worker.

0x4332 is the fake pipeline of graphics_first_use_carries_the_exact_serialized_recipe_identity: it submit_lazys a job returning 0x4332, then calls released(standin) without waiting. When a backlog worker has already started that job, the build is orphaned and complete hands 0x4332 to release, which drops it as a real ID3D12PipelineState. On main released usually drops the unstarted job first. My guess is that the sweep_native_generations() call this PR adds at the top of released widens that window, but I have not proven it. The race is in the test, so the fix may belong in the test (for example a job returning 0, or waiting for the build before released). Either way, with this PR the lib binary aborts about 30 % of the time on this machine.

Not run: a title (no smoke run), AMD / wave64.

Tool and model: Claude Code (Claude Opus 5.5) merged, built, ran the tests and drafted this; I checked it.

<!-- greyfinch-sync:ivall/xcl:comment:7325446682 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3185#issuecomment-7325446682). Originally posted by [cj-tomlin](https://github.com/cj-tomlin) on 2026-12-01T20:54:12Z. --- Test report, head `0cd75eae5062102abdb35fc2984c1d9f40a4ac73` merged onto `main` `f07e426dade72aa7112cf6bfe08ca6f6ff5a9d5c` (clean, merge `ad3d78b5`). **Edit: the lib test binary aborts in about 3 of 10 runs with this PR; see below. This report does not count as a clean run.** - Hardware: NVIDIA GeForce RTX 3080 10 GB, driver 621.40, AMD Ryzen 7 7800X3D, Windows 11 build 26300, debug build. - `cargo build --workspace`: ok. - `cargo test --workspace --no-fail-fast -- --test-threads=4`, first run: 2906 passed, 0 failed, 51 ignored; SKIPPED: 27 (22 no wave64, 2 no heap windows, 3 no D3D12 debug layer / d3d12SDKLayers.dll). `two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs` ran (no SKIPPED line) and passed. - #3441 on NVIDIA: `cargo test -p xcl --test gpu_two_pass_cache_e2e -- --test-threads=1`, alternating between the trees: `main` `f07e426d` failed 6 of 6, the merge passed 6 of 6. On `main` it is the #3441 assertion (`left: 1, right: 0` at line 584). So on this card it is not AMD-only. - The two new tests pass, and both fail (`left: 1, right: 0`) with `main`'s `pso_async.rs` put back into the merged tree. **New abort.** A second full-suite run, on this merge plus #1249 (which only touches `xaudio2.rs`), lost the whole lib test binary: `exit code: 0xc0000409`, after `thread 'xcl-pso-ahead-2' panicked at windows-core-0.62.2\src\interface.rs:41:18: misaligned pointer dereference: address must be a multiple of 0x8 but is 0x4332`. `cargo test -p xcl --lib -- --test-threads=4 hle::d3d12x::pso_async`, alternating between the trees: `main` `f07e426d` 10 of 10 ok, the merged tree aborted 3 of 10, the same way each time. Backtrace: `pso_async::release` ← `pso_async::complete` ← `run_build` ← `spawn_backlog_worker`. `0x4332` is the fake pipeline of `graphics_first_use_carries_the_exact_serialized_recipe_identity`: it `submit_lazy`s a job returning `0x4332`, then calls `released(standin)` without waiting. When a backlog worker has already started that job, the build is orphaned and `complete` hands `0x4332` to `release`, which drops it as a real `ID3D12PipelineState`. On `main` `released` usually drops the unstarted job first. My guess is that the `sweep_native_generations()` call this PR adds at the top of `released` widens that window, but I have not proven it. The race is in the test, so the fix may belong in the test (for example a job returning 0, or waiting for the build before `released`). Either way, with this PR the lib binary aborts about 30 % of the time on this machine. Not run: a title (no smoke run), AMD / wave64. Tool and model: Claude Code (Claude Opus 5.5) merged, built, ran the tests and drafted this; I checked it.
afpruivo commented 2026-12-02 23:15:42 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by afpruivo on 2026-12-02T23:15:42Z.


Rebased onto main c53e9696 and updated (one commit, now 6f263066, force-pushed; description updated). Thanks to everyone who tested and reviewed this:

  • @cj-tomlin, the lib binary abort: your reading was right; the race was in graphics_first_use_carries_the_exact_serialized_recipe_identity, whose job returned the fake pipeline 0x4332. #3493 (merged since) makes that job return none, and this branch is now on top of it. cargo test -p xcl --lib -- --test-threads=4 hle::d3d12x::pso_async: 10 of 10 ok on 6f263066 (RTX 3090).
  • @thehollowedone, the release-before-completion case: right, and taken in as you proposed, with credit in the commit and description: queuing an in-flight pinned receipt starts the late-release worker, whose tick now sweeps the completed pins; your test is in as a_submission_completed_after_the_last_release_is_swept_while_idle. It fails without the worker's sweep (left: 1) and passes with it.
  • @Foniass, the RETIRING_TESTS comment: it now says which sweeps run without the lock. The cost of a sweep per release and per tick is listed under Not tested (not measured).
  • @YousefElghanam, thank you for the AMD runs on #3441; I added Fixes #3441.

#3441's test alone on the 3090: main c53e9696 failed 3 of 6 (left: 1), 6f263066 passed 6 of 6. Full suite and smoke pair are in the description. Marking ready for review.

AI use: Claude Code (Claude Opus 5.5) rebased, added the fix, ran the tests and wrote this while I was away; posted with my standing approval for this session.

<!-- greyfinch-sync:ivall/xcl:comment:7361767599 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3185#issuecomment-7361767599). Originally posted by [afpruivo](https://github.com/afpruivo) on 2026-12-02T23:15:42Z. --- Rebased onto `main` `c53e9696` and updated (one commit, now `6f263066`, force-pushed; description updated). Thanks to everyone who tested and reviewed this: - @cj-tomlin, **the lib binary abort**: your reading was right; the race was in `graphics_first_use_carries_the_exact_serialized_recipe_identity`, whose job returned the fake pipeline `0x4332`. #3493 (merged since) makes that job return none, and this branch is now on top of it. `cargo test -p xcl --lib -- --test-threads=4 hle::d3d12x::pso_async`: 10 of 10 ok on `6f263066` (RTX 3090). - @thehollowedone, **the release-before-completion case**: right, and taken in as you proposed, with credit in the commit and description: queuing an in-flight pinned receipt starts the late-release worker, whose tick now sweeps the completed pins; your test is in as `a_submission_completed_after_the_last_release_is_swept_while_idle`. It fails without the worker's sweep (`left: 1`) and passes with it. - @Foniass, **the `RETIRING_TESTS` comment**: it now says which sweeps run without the lock. The cost of a sweep per release and per tick is listed under **Not tested** (not measured). - @YousefElghanam, thank you for the AMD runs on #3441; I added `Fixes #3441`. #3441's test alone on the 3090: `main` `c53e9696` failed 3 of 6 (`left: 1`), `6f263066` passed 6 of 6. Full suite and smoke pair are in the description. Marking ready for review. AI use: Claude Code (Claude Opus 5.5) rebased, added the fix, ran the tests and wrote this while I was away; posted with my standing approval for this session.
Foniass commented 2026-12-02 23:18:46 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T23:18:46Z.


Follow-up review of 6f263066, since 0cd75ea (code reading only, not a merge-check) · no new findings

In short: This push adds a third sweep point. The late-release worker now sweeps completed pipeline pins on each tick, and it is started when a pinned submission is still in flight. A fence that completes after the title's last submission and release is now seen too. The lock doc comment now says which other sweeps run without it, and a third unit test covers the idle case. Nothing blocks it.

Checked and fine
  • Earlier finding fixed: the RETIRING_TESTS doc comment now says that released() and the worker also sweep without the lock, and why the tests stay correct.
  • Earlier point, still unmeasured but small: a sweep per stand-in release reads GetCompletedValue once per distinct pending fence. The worker's sweep adds the same every 4 ms (TICK). With nothing pending, it takes the lock twice and builds an empty map.
  • retire_native_generations starts the worker only when it pushes a pending batch, so a title with no pinned in-flight work starts nothing new. start_thread is a call_once.
  • sweep_retirements drops retired generations outside its lock, so a Release that comes back through released() cannot deadlock the worker.
  • a_submission_completed_after_the_last_release_is_swept_while_idle completes the fence after the release and waits up to 1 s for the pin to go, with no other submission or release.
  • The commit message credits the case and the worker sweep to the reviewer on #3185, and links #3441.

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

<!-- greyfinch-sync:ivall/xcl:comment:7361833107 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3185#issuecomment-7361833107). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T23:18:46Z. --- **Follow-up review** of `6f263066`, since `0cd75ea` (code reading only, not a merge-check) · no new findings **In short:** This push adds a third sweep point. The late-release worker now sweeps completed pipeline pins on each tick, and it is started when a pinned submission is still in flight. A fence that completes after the title's last submission and release is now seen too. The lock doc comment now says which other sweeps run without it, and a third unit test covers the idle case. Nothing blocks it. <details><summary>Checked and fine</summary> - Earlier finding fixed: the `RETIRING_TESTS` doc comment now says that `released()` and the worker also sweep without the lock, and why the tests stay correct. - Earlier point, still unmeasured but small: a sweep per stand-in release reads `GetCompletedValue` once per distinct pending fence. The worker's sweep adds the same every 4 ms (`TICK`). With nothing pending, it takes the lock twice and builds an empty map. - `retire_native_generations` starts the worker only when it pushes a pending batch, so a title with no pinned in-flight work starts nothing new. `start_thread` is a `call_once`. - `sweep_retirements` drops retired generations outside its lock, so a Release that comes back through `released()` cannot deadlock the worker. - `a_submission_completed_after_the_last_release_is_swept_while_idle` completes the fence after the release and waits up to 1 s for the pin to go, with no other submission or release. - The commit message credits the case and the worker sweep to the reviewer on #3185, and links #3441. </details> <sub>Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.</sub>
afpruivo commented 2026-12-03 05:13:13 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by afpruivo on 2026-12-03T05:13:13Z.


The flaky two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs (#3441) on current main, and with this PR, same machine and command (cargo test -p xcl --test gpu_two_pass_cache_e2e, run 15 times in a row, RTX 3090, inbox D3D12):

  • main 395405e4: 3 of 15 runs failed (releasing the title PSOs releases their two-pass state, left 1, right 0)
  • 6f263066 merged onto 395405e4 (clean merge): 0 of 15 failed

With a temporary trace on main I saw the cause this PR fixes. In each failing run, the stand-in of the leaked pipeline was released while its real pipeline still had 2 references (the others had 1). Late release then dropped its reference, and the count never reached 0. Which pipeline leaked changed from run to run (the first MS, the second MS, or the GS). It also failed in the disabled case, so the disk cache is not involved.

Other PRs' test reports count this test's two failures against the PR (for example on #3676), so this PR also cleans up their counts.

AI use: Claude Code (Claude Opus 5.5) ran the tests and traced the references; I posted it.

<!-- greyfinch-sync:ivall/xcl:comment:7368503805 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3185#issuecomment-7368503805). Originally posted by [afpruivo](https://github.com/afpruivo) on 2026-12-03T05:13:13Z. --- The flaky `two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs` (#3441) on current `main`, and with this PR, same machine and command (`cargo test -p xcl --test gpu_two_pass_cache_e2e`, run 15 times in a row, RTX 3090, inbox D3D12): - `main` 395405e4: 3 of 15 runs failed (`releasing the title PSOs releases their two-pass state`, left 1, right 0) - 6f263066 merged onto 395405e4 (clean merge): 0 of 15 failed With a temporary trace on `main` I saw the cause this PR fixes. In each failing run, the stand-in of the leaked pipeline was released while its real pipeline still had 2 references (the others had 1). Late release then dropped its reference, and the count never reached 0. Which pipeline leaked changed from run to run (the first MS, the second MS, or the GS). It also failed in the `disabled` case, so the disk cache is not involved. Other PRs' test reports count this test's two failures against the PR (for example on #3676), so this PR also cleans up their counts. AI use: Claude Code (Claude Opus 5.5) ran the tests and traced the references; I posted it.
pvfreis commented 2026-12-03 15:45:30 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by pvfreis on 2026-12-03T15:45:30Z.


merge-check claim
head: 6f26306698

<!-- greyfinch-sync:ivall/xcl:comment:7383682559 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3185#issuecomment-7383682559). Originally posted by [pvfreis](https://github.com/pvfreis) on 2026-12-03T15:45:30Z. --- merge-check claim head: 6f263066986fb0212b9e41b40c92c201d7a71449
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3185:upstream-pr/3185'
git switch 'upstream-pr/3185'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3185'
git switch 'upstream-pr/3185'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3185'
git switch 'upstream-pr/3185'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3185'
git switch 'main'
git merge --squash 'upstream-pr/3185'
git switch 'main'
git merge --ff-only 'upstream-pr/3185'
git switch 'main'
git merge 'upstream-pr/3185'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!3185
No description provided.