D3D12.X: sweep completed PSO generation pins when nothing new is pinned #3185
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3185"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by afpruivo on 2026-11-28T16:59:30Z.
pso_async::retire_native_generationskeeps each pinnedNativeGeneration(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, andreleased()didn't sweep at all. A batch queued behind a pending fence therefore leaked its pins, and the pipeline'sTWO_PASSentry with them, whenever every later submission had already completed or no later submission came. Introduced in11613fb6(#2959). Fixes #3441.What is in it (one commit, on
mainc53e9696)pso_async.rs: sweep completed batches when retiring an already-complete receipt, and at the start ofreleased(). 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.rstests:a_completed_later_submission_retires_earlier_generations,releasing_a_standin_after_its_submission_completed_releases_the_pipeline, anda_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
XCL_D3D12_DIRset 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=4on6f263066: 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 e2ethen passed 3 of 3 on this head (and 5 of 5 onmain).cargo test -p xcl --test gpu_two_pass_cache_e2e -- --test-threads=1:mainc53e9696failed 3 of 6 (left: 1,right: 0at line 584);6f263066passed 6 of 6.cargo test -p xcl --lib -- --test-threads=4 hle::d3d12x::pso_async10 of 10 ok on6f263066(193 passed each). The race was ingraphics_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_idlefails without the worker's sweep (left: 1,right: 0) and passes with it.Regression run
main:
this PR:
Not tested
GetCompletedValueper 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 inreleased()at a level change that releases many pipelines. Not measured.smoke.ps1sends no input).AI use
🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by JJAutoCompare on 2026-11-28T17:26:02Z.
Tested
Independently reran the pinned XCL library test binary for
0cd75eae5062102abdb35fc2984c1d9f40a4ac73on 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.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, callingreleased()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.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 currentmainff0c364b3de011c13ed45865480c21918a79ec89(merge commit7e58b565d5503f6db3ddee50fa3f7223ebc11596).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, expected0). With the candidate below, it passes, along with the three existing retirement tests: 4 passed, 0 failed, 0 ignored, 0 skipped, run separately withXCL_LATE_RELEASE=0.git diff --checkpassed.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
AI use: Codex (GPT-6.2 Sol) prepared and tested the candidate; GPT-6.2 Astra checked the fence-completion lifecycle.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T09:42:12Z.
Triage (#1607) – head
0cd75eaNo open or merged PR makes the same change.
retire_native_generationsnow sweeps on an already-complete receipt andreleasedsweeps 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").releasednow 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.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T09:43:47Z.
Review (head
0cd75eae, diff read, not a merge-check; draft):released()(pso_async.rs~10979) now sweeps before every stand-in release. A sweep readsGetCompletedValueonce 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.RETIRING_TESTS. Other tests that reachsweep_native_generationsthroughreleased()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:
11613fb6/ #2959).sweep_retirementsdrops the retired generations outside its lock (~3744), so a Release that comes back throughstandin_released->released()-> sweep doesn't deadlock.two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobsloop (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.
Imported from ivall/xcl. Originally posted by cj-tomlin on 2026-12-01T20:54:12Z.
Test report, head
0cd75eae5062102abdb35fc2984c1d9f40a4ac73merged ontomainf07e426dade72aa7112cf6bfe08ca6f6ff5a9d5c(clean, mergead3d78b5).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.
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_blobsran (no SKIPPED line) and passed.cargo test -p xcl --test gpu_two_pass_cache_e2e -- --test-threads=1, alternating between the trees:mainf07e426dfailed 6 of 6, the merge passed 6 of 6. Onmainit is the #3441 assertion (left: 1, right: 0at line 584). So on this card it is not AMD-only.left: 1, right: 0) withmain'spso_async.rsput 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, afterthread '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:mainf07e426d10 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.0x4332is the fake pipeline ofgraphics_first_use_carries_the_exact_serialized_recipe_identity: itsubmit_lazys a job returning0x4332, then callsreleased(standin)without waiting. When a backlog worker has already started that job, the build is orphaned andcompletehands0x4332torelease, which drops it as a realID3D12PipelineState. Onmainreleasedusually drops the unstarted job first. My guess is that thesweep_native_generations()call this PR adds at the top ofreleasedwidens 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 beforereleased). 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.
Imported from ivall/xcl. Originally posted by afpruivo on 2026-12-02T23:15:42Z.
Rebased onto
mainc53e9696and updated (one commit, now6f263066, force-pushed; description updated). Thanks to everyone who tested and reviewed this:graphics_first_use_carries_the_exact_serialized_recipe_identity, whose job returned the fake pipeline0x4332. #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 on6f263066(RTX 3090).a_submission_completed_after_the_last_release_is_swept_while_idle. It fails without the worker's sweep (left: 1) and passes with it.RETIRING_TESTScomment: 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).Fixes #3441.#3441's test alone on the 3090:
mainc53e9696failed 3 of 6 (left: 1),6f263066passed 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.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T23:18:46Z.
Follow-up review of
6f263066, since0cd75ea(code reading only, not a merge-check) · no new findingsIn 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
RETIRING_TESTSdoc comment now says thatreleased()and the worker also sweep without the lock, and why the tests stay correct.GetCompletedValueonce 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_generationsstarts the worker only when it pushes a pending batch, so a title with no pinned in-flight work starts nothing new.start_threadis acall_once.sweep_retirementsdrops retired generations outside its lock, so a Release that comes back throughreleased()cannot deadlock the worker.a_submission_completed_after_the_last_release_is_swept_while_idlecompletes the fence after the release and waits up to 1 s for the pin to go, with no other submission or release.Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.
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 currentmain, 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):main395405e4: 3 of 15 runs failed (releasing the title PSOs releases their two-pass state, left 1, right 0)6f263066merged onto395405e4(clean merge): 0 of 15 failedWith a temporary trace on
mainI 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 thedisabledcase, 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.
Imported from ivall/xcl. Originally posted by pvfreis on 2026-12-03T15:45:30Z.
merge-check claim
head:
6f26306698View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.