Repository navigation
Conversation
|
Thanks for the quick fix! I'm the original reporter of #1668. I have an RTX 3090 available and can independently validate this PR using the original synthetic regression, concurrent stress, endurance, and GPU data integrity tests. I'll post the results here for comparison. Independent validation — PASSTested commit The original failure from #1668 no longer reproduces. All 12 additional stress runs passed using unchanged synthetic test binaries. One additional observation: during the endurance test, the device reference count was 112, 131, 142, and 161 at rounds 128, 256, 384, and 512 respectively. The final Live Producer refcount was 155. These snapshots were taken under concurrent load, so this is not conclusive evidence of a remaining leak, but may be worth investigating separately. The original queue exhaustion regression is confirmed fixed in my test environment. Thanks for the fix! |
|
Tested on an RTX 3070 (driver 616.56, Windows 11) at
One race this PR opens. Before it, a queue in
Interleaving: the reader snapshots → the title's last Suggested fix: take the references while the list is locked. diff --git a/crates/xcl/src/hle/d3d12x/late_release.rs b/crates/xcl/src/hle/d3d12x/late_release.rs
index c3fd9b3..eca1ca9 100644
--- a/crates/xcl/src/hle/d3d12x/late_release.rs
+++ b/crates/xcl/src/hle/d3d12x/late_release.rs
@@ -136,13 +136,7 @@ pub unsafe fn drain_known(seal_now: bool) {
if HELD.lock().unwrap().as_ref().is_none_or(Held::is_empty) {
return;
}
- let mut queues: Vec<ID3D12CommandQueue> = Vec::new();
- for raw in super::present::known_queues() {
- let raw = raw as *mut c_void;
- if let Some(q) = ID3D12CommandQueue::from_raw_borrowed(&raw) {
- queues.push(q.clone());
- }
- }
+ let mut queues: Vec<ID3D12CommandQueue> = super::present::known_queues_held();
queues.extend(super::sparse::queue());
queues.extend(super::title_textures::upload_queues());
let gone = match HELD.lock().unwrap().as_mut() {
diff --git a/crates/xcl/src/hle/d3d12x/present.rs b/crates/xcl/src/hle/d3d12x/present.rs
index 81bf546..3138566 100644
--- a/crates/xcl/src/hle/d3d12x/present.rs
+++ b/crates/xcl/src/hle/d3d12x/present.rs
@@ -247,6 +247,19 @@ pub fn known_queues() -> Vec<usize> {
QUEUES.lock().unwrap().clone()
}
+/// The queues the title submitted work to, each with a reference of the caller's, taken while
+/// they are listed: since #1668 a queue the title lets go is released by `q_release`, so a raw
+/// pointer from [`known_queues`] may be freed before it is used.
+pub fn known_queues_held() -> Vec<ID3D12CommandQueue> {
+ let q = QUEUES.lock().unwrap();
+ q.iter()
+ .filter_map(|&raw| {
+ let raw = raw as *mut c_void;
+ unsafe { ID3D12CommandQueue::from_raw_borrowed(&raw) }.cloned()
+ })
+ .collect()
+}
+
/// `queue` is down to the one reference `note_execute` took to keep it valid for `late_release`:
/// the title is done with it. Forget it – and any use of it here – so the caller can let that
/// reference go: otherwise every queue a title ever submitted to (and the driver memory behind
diff --git a/crates/xcl/src/hle/d3d12x/real.rs b/crates/xcl/src/hle/d3d12x/real.rs
index 9e894e6..60227d0 100644
--- a/crates/xcl/src/hle/d3d12x/real.rs
+++ b/crates/xcl/src/hle/d3d12x/real.rs
@@ -5434,7 +5434,6 @@ pub fn drain_gpu() {
// a fence per queue (they finish in any order)
let mut fences = Vec::new();
- for q in super::present::known_queues() {
- let qr = q as *mut c_void;
- let Some(q) = ID3D12CommandQueue::from_raw_borrowed(&qr) else { continue };
+ for q in super::present::known_queues_held() {
+ let q = &q;
let submit = || {
let f: ID3D12Fence = dev.CreateFence(0, D3D12_FENCE_FLAG_NONE)With this on top (and #1523): A side effect on the new test: it asserts AI-assisted (Claude Code). No game files; synthetic tests only. |
|
@upipibi I independently validated your exact suggested patch on top of Synthetic regression and stress tests:
Regarding the refcount assertion: I added an isolated test that explicitly retains an owned queue snapshot during the title's release. All five runs produced: This confirms your observation about the exact refcount assertion. One additional nuance: checking registry membership immediately after the title's release can also be unreliable while a snapshot remains alive. Checking membership after the temporary owner is dropped passed consistently. Regarding #1523: I tested all four combinations of the original PR, your ownership patch, and #1523 ( All eight serial suite runs passed. Four parallel runs also passed, but a subsequent parallel run with both patches encountered DXGI_ERROR_DEVICE_REMOVED / DXGI_ERROR_DEVICE_HUNG, accompanied by an NVIDIA driver event 153. I stopped the remaining runs after the device loss. I did not reproduce the fake-fence access violation, and I cannot attribute the device loss to either patch. Your ownership patch preserves the original queue exhaustion fix in my synthetic workloads. Thanks for the review! |
|
Thanks, DEViANCEVxXXxM, for the runs and the membership nuance. The device loss in the parallel run with both patches matches #1727. There, |
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
|
@upipibi Thanks for pointing me to #1727 and #614. I ran additional validation on upstream Both parallel runs completed with:
One limitation: this subset does not include Synthetic tests only. AI-assisted test planning and log analysis using ChatGPT (GPT-6.2). |
present::note_execute AddRef'd every queue a title submitted work to and never dropped that reference, so the queue's own Release never reached zero, q_release never ran, and every queue (and the driver memory behind it) lived on for the rest of the process. In the loop of xcl-dev#1668 - create, submit, synchronise, release, 128 times - CreateCommandQueue failed with E_OUTOFMEMORY on the 64th queue, while the same loop without a submit (the path that takes no reference) passed all 128. Drop the reference when a Release brings the count down to it (n == 1), clear the present candidate that names the queue, and drop the fence late_release keeps for it. The presenter now holds its own reference to the queue it makes a swap chain for, so that pointer cannot dangle once the title lets its queues go. A tracked queue can now be freed, so its readers no longer take raw pointers out of the list: late_release's drain and drain_gpu get their references from known_queues_held(), which takes them while the list is locked. A reader's reference either lands before the queue leaves the list - its release is then the one that lets the queue go - or the reader does not see the queue at all (review of xcl-dev#1691). Assisted-by: OpenCode (Claude Fable 5.2)
1de417c to
81f6397
Compare
|
@upipibi you are right, and thanks @DEViANCEVxXXxM for running it. Before this PR nothing in Pushed
Both tests fail with the handoff disabled (0 passed, 2 failed) and pass with it. Full suite on this head: 977 passed, 0 failed, 45 ignored; smoke blocks for What this does not have is a test that fails on the previous head for the race itself: as you found, a freed queue does not reliably fault. That is stated under Not tested. The device refcount growing during the endurance run (112 → 161) is not addressed here. I have not looked into it. AI use: OpenCode, Claude Fable 5.2 made the change, ran the tests and wrote this comment. |
|
Tested exact head Tested
Not tested
AI use |
|
Tested
Not tested
AI use OpenAI Codex (GPT-6, exact variant not exposed in this session) inspected the test and queue-lifetime paths, ran the AMD-machine tests and build, reviewed the logs, and drafted this report. |
XCL PR #1691 verificationTested clean detached head Tested
Workspace failures and skips The library had 24 GPU failures. Twenty reported Not tested Matched main run, retail title smoke comparison, issue #1668's 128-queue loop, and AMD/NVIDIA GPUs. No AI use T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high) ran the build and verification. Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against |
|
Independent validation update for #1691 and its interaction with #1945. Tested revisions:
Both PRs merge individually with the tested main revision, but combining them requires resolving a conflict in The resolution preserves #1691's submit-tracking reference removal and calls both Combined validation results:
The four production configurations (main, #1691, #1945, combined) also completed 120-second idle retail-title runs at 30 FPS and exited cleanly. The existing retail-title crash remains reproducible in all four configurations with an identical exception signature. This does not appear to be a new regression introduced by #1691. The combined lifecycle results are encouraging, although they do not establish the absence of all concurrent lifetime races. No changes were made to upstream main. AI assistance: ChatGPT (GPT-6.2) assisted with source review, test implementation and analysis. All reported test executions were performed on actual Windows hardware (RTX 3090). |
|
Test report for
AI use: Claude Code (Claude Opus 5.5, with a Claude Sonnet subagent, exact version unknown) ran the tests and wrote this report. |
|
Update: this compared the PR at its old base with a newer An Ampere data point for the device loss PracticalStudios reported with parallel
So the failure isn't specific to the 3090: with two test threads, this PR loses the device or runs out of memory in 2 of 3 runs here, and AI-assisted (Claude Code). Synthetic tests only. |
|
Follow-up to my run above. That one compared this PR at its old base with a newer
So the failure isn't only an artefact of the old base: with this PR merged onto current AI-assisted (Claude Code). Synthetic tests only. Caveat (added later): the same test hangs without this PR. With tiagonleal's filter on #2057 ( |
81f6397 to
1759519
Compare
|
@upipibi thank you for the controlled rerun — that is what made the device loss visible as this PR's and not the base's. You are right that the queue has to outlive what was submitted to it, and that is a real hole in what I had: the reference went the moment the title's last release arrived, so a queue with work in flight could be freed under the GPU. Pushed
Suite on this head: 1157 passed, 0 failed, 46 ignored. Smoke blocks for If you still have the 3070, a rerun of the same six-run alternation against this head would be the check that matters — I am not claiming it fixes your 1-in-6 without it. AI use: OpenCode, Claude Fable 5.2 made the change, ran the tests and wrote this comment. |
present::note_execute AddRef'd every queue a title submitted work to and never dropped that reference, so the queue's own Release never reached zero, q_release never ran, and every queue (and the driver memory behind it) lived on for the rest of the process. In the loop of xcl-dev#1668 - create, submit, synchronise, release, 128 times - CreateCommandQueue failed with E_OUTOFMEMORY on the 64th queue, while the same loop without a submit (the path that takes no reference) passed all 128. Drop the reference when a Release brings the count down to it (n == 1), clear the present candidate that names the queue, and drop the fence late_release keeps for it. The presenter now holds its own reference to the queue it makes a swap chain for, so that pointer cannot dangle once the title lets its queues go. A tracked queue can now be freed, so its readers no longer take raw pointers out of the list: late_release's drain and drain_gpu get their references from known_queues_held(), which takes them while the list is locked. A reader's reference either lands before the queue leaves the list - its release is then the one that lets the queue go - or the reader does not see the queue at all (review of xcl-dev#1691). A queue must outlive the work submitted to it, though: letting the reference go the moment the title does would free a queue the GPU is still executing, which ends in a device removal (0x887A0005, one run of six with this change merged onto main). The reference now goes to late_release, which signals a value on the queue's fence and drops it once every earlier submission has passed it - as it already does for a resource's last release. Assisted-by: OpenCode (Claude Fable 5.2)
present::note_execute AddRef'd every queue a title submitted work to and never dropped that reference, so the queue's own Release never reached zero, q_release never ran, and every queue (and the driver memory behind it) lived on for the rest of the process. In the loop of xcl-dev#1668 - create, submit, synchronise, release, 128 times - CreateCommandQueue failed with E_OUTOFMEMORY on the 64th queue, while the same loop without a submit (the path that takes no reference) passed all 128. Drop the reference when a Release brings the count down to it (n == 1), clear the present candidate that names the queue, and drop the fence late_release keeps for it. The presenter now holds its own reference to the queue it makes a swap chain for, so that pointer cannot dangle once the title lets its queues go. A tracked queue can now be freed, so its readers no longer take raw pointers out of the list: late_release's drain and drain_gpu get their references from known_queues_held(), which takes them while the list is locked. A reader's reference either lands before the queue leaves the list - its release is then the one that lets the queue go - or the reader does not see the queue at all (review of xcl-dev#1691). A queue must outlive the work submitted to it, though: letting the reference go the moment the title does would free a queue the GPU is still executing, which ends in a device removal (0x887A0005, one run of six with this change merged onto main). The reference now goes to late_release, which signals a value on the queue's fence and drops it once every earlier submission has passed it - as it already does for a resource's last release. Assisted-by: OpenCode (Claude Fable 5.2) The late-release thread that lets a held resource or a released queue go is started once (`ensure_thread`), from either path: a title that does both must not start two.
1759519 to
f71cf21
Compare
|
Rebased onto Head |
Fixes #1668.
present::note_executetook a reference to every command queue a title submitted work to (solate_releasecan fence what it holds), and never dropped it. The queue's own lastReleasetherefore only brought the count to 1,q_releasenever saw 0, and every queue a title ever submitted to — with the driver memory behind it — stayed allocated for the rest of the process.That is the asymmetry in the issue: "create and release unused queues" passes 128/128 (no submit, so no reference is taken), while "create, submit, synchronize and release" fails on the 64th queue with
E_OUTOFMEMORY.This drops the reference when a release brings the count down to it (
n == 1): the queue is forgotten by the submit tracking (and the present candidate that names it), the fencelate_releasekeeps for that queue is dropped, and the reference goes. The presenter now also holds its own reference to the queue it makes a swap chain for, so that pointer cannot dangle once the title lets its queues go.Since the review (@upipibi's race, validated by @DEViANCEVxXXxM on an RTX 3090): a tracked queue can now be freed, so the two readers of the list no longer take raw pointers out of it.
late_release::drain_knownandreal::drain_gpuget their references frompresent::known_queues_held(), which takes them while the list is locked.And the device loss from the follow-up runs: a queue has to outlive the work submitted to it. Dropping the reference as soon as the title's last release arrived could free a queue the GPU was still executing —
0x887A0005in 1 of 6 runs on @upipibi's RTX 3070 with this change merged ontomain. The released queue's reference now goes tolate_release, which signals a value on that queue's fence and lets the reference go once every earlier submission has passed it, exactly as it already holds a resource's last release.list_x's queue list is cleared when that reference finally goes, not before.What is in it
crates/xcl/src/hle/d3d12x/real.rs: inq_release, when the count reaches the one reference the submit tracking holds, hand the queue back (present::forget_queue) and pass the reference tolate_release::hold_queue;drain_gpusignals queues it holds a reference to. GPU testsa_queue_the_title_releases_is_not_kept_alive_by_the_submit_tracking,a_tracked_queue_a_reader_holds_outlives_the_titles_releaseanda_released_queue_is_held_until_its_submitted_work_is_done.crates/xcl/src/hle/d3d12x/present.rs:forget_queueuntracks a released queue and drops the present candidate naming it;known_queues_heldreturns the tracked queues with references taken under the lock;new_presenterholds its own reference to the queue andPresenter::dropreleases it.crates/xcl/src/hle/d3d12x/late_release.rs:forget_queuedrops the fence kept for a queue that is gone (a sealed batch keeps its own clone);hold_queuefences a released queue and drops its reference once the fence passes;take_released_queuesindrain_known; oneensure_threadstarts the drain thread for both paths (holdandhold_queue), so a title that does both does not run two.Tested
stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1).\scripts\test.ps1(cargo build --workspace+cargo test --workspace -- --test-threads=4): 1246 passed, 0 failed, 46 ignored (SKIPPED: the wave64 / direct-DXIL per-lane tests that need 64-lane hardware or a semantics mode this adapter refuses,no heap windows, andcannot disable the driver cache (Windows Developer Mode is required))cargo test -p xcl --lib -- a_released_queue_is_held: 1 passed. With the deferral taken out: 0 passed, 1 failed —the GPU may still run what was submitted to the queue: its reference is held.mid_list_write64_wait64_split_avoids_cycle_and_reuses_spares,rotating_queue_self_deadlock_and_non_monotonic_rescue_do_not_hang,timestamps_outside_unified_memory_land_after_the_queue),--test-threads=2, 5 runs: 3 passed, 0 failed each time.cargo test -p xcl --lib hle::d3d12x:: -- --test-threads=2, 2 runs: 180 passed, 0 failed, 2 ignored each time, no device removal.Regression run
main (
426a5a7, clean tree, no local changes):PR (
f71cf21, clean tree, no local changes):Not tested
hle::d3d12x::subset with two threads were clean on this RTX 5080, so the deferral is shown by the new test (the released queue is held while its work is in flight) rather than by a device removal that no longer happens.AI use
present/late_release/q_release, wrote the fix and the tests (and confirmed each fails with the change it covers taken out), applied the reviewers' ownership change and the deferred queue release, rebased onto568e7db, ran the test suite, the named tests and thescripts/smoke.ps1runs, and drafted this PR description.