Skip to content

D3D12.X: reclaim ON_QUEUE uploads across all queues and clean up on release - #2912

Open
real-alponzo wants to merge 1 commit into
xcl-dev:amd-devfrom
real-alponzo:fix/amd-on-queue-reclaim
Open

real-alponzo wants to merge 1 commit into
xcl-dev:amd-devfrom
real-alponzo:fix/amd-on-queue-reclaim

Conversation

@real-alponzo

@real-alponzo real-alponzo commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Reclaim completed ON_QUEUE texture upload batches across all tracked title queues and remove released queues from ON_QUEUE in q_release.

Why

  • reclaim_completed_on_queue previously only polled the submitting queue_key, allowing completed upload batches on idle or secondary command queues to keep staging buffers pinned until those queues uploaded again.
  • q_release cleaned up list_x state for the released queue but left its entry in title_textures::ON_QUEUE, leaking its ID3D12Fence and any InFlight staging buffers (up to 512 MiB) and risking pointer-reuse ABA if a later queue is allocated at the same address.

What is in it

  • Updated reclaim_completed_on_queue in crates/xcl/src/hle/d3d12x/title_textures.rs to drain completed batches across all tracked queues via drain_completed.
  • Added title_textures::on_queue_release(queue_key) and wired it into q_release in crates/xcl/src/hle/d3d12x/real.rs.
  • Added unit tests drain_completed_reclaims_only_finished_batches and on_queue_release_removes_tracked_queue_entry.

Regression run

Base (main):

xcl-smoke v1
commit: 8b957bec6f82495aec940944c6bf47faa02db590
gpu: AMD Radeon RX 6800
title: 6ca5cab7
seconds: 60
exit: 0x0
frames shown: 1525 (PresentX 1525)
presents per 2 s (last 3): 60 61 59
device removals: 0
crashes: 0
peak commit: 14867 MB

PR head (baaf024d):

xcl-smoke v1
commit: baaf024d2c0b3c19c2944ce45c501ab768896e4c
gpu: AMD Radeon RX 6800
title: 6ca5cab7
seconds: 60
exit: 0x0
frames shown: 1540 (PresentX 1540)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14871 MB

Tested

  • Hardware: Windows 11 Pro for Workstations x64 (Build 26300), Intel Core i9-9900K, 32 GB RAM, AMD Radeon RX 6800 (Driver 32.0.21045.29003), rustc 1.100.0, DXC 1.9.2602.17.
  • cargo test -p xcl --lib drain_completed_reclaims -- --nocapture: 1 passed; 0 failed; 0 ignored; 1695 filtered out.
  • cargo test -p xcl --lib on_queue_release_removes -- --nocapture: 1 passed; 0 failed; 0 ignored; 1695 filtered out.
  • .\scripts\smoke.ps1 -Game "C:\VIctory-SSD-test\game" -Seconds 60 on 8b957bec and baaf024d (blocks above).

Not tested

  • Full cargo test --workspace on amd-dev (note amd-dev has pre-existing no-GPU CI test failures unrelated to this change).
  • Multi-hour soak verifying peak staging memory reduction across secondary queues.

AI use

  • Antigravity (Gemini 4 Neon) identified the missing cross-queue reclaim and q_release cleanup, implemented the fix and unit tests, ran the tests and paired smoke runs, and drafted this PR description.

…elease

reclaim_completed_on_queue now drains completed InFlight batches across
all tracked title queues so idle/secondary queues do not pin staging
buffers. Also remove released queues from ON_QUEUE in q_release to avoid
leaking fences/staging buffers and pointer-reuse ABA.

Assisted-by: Antigravity (Gemini 4 Neon)
@DarkPanda69

Copy link
Copy Markdown

RDNA4 run next to your RX 6800 one: the two new tests pass, and the PR adds no failure. One title_textures test already fails on amd-dev without the PR.

Tested: head baaf024 applied on its base amd-dev bf7c82e, debug, Rust 1.100.0, Windows 11 Pro 26200, Ryzen 7 5800X, AMD RX 9070 XT (RDNA4), driver 32.0.32029.2010.

  • cargo test -p xcl --lib -- drain_completed_reclaims_only_finished_batches on_queue_release_removes_tracked_queue_entry --nocapture: 2 passed, 0 failed, 0 SKIPPED.
  • cargo test -p xcl --lib -- title_textures, 3 runs at --test-threads=4 and 1 at --test-threads=1:
    • this PR: 35 passed, 1 failed every time;
    • amd-dev alone: 33 passed, 1 failed every time (and one of the 4-thread runs also had gpu_uploads_on_the_title_queue_run_before_its_later_work_and_are_released and placed_title_textures_share_vram_and_preserve_pixels fail).

The one that fails with and without the PR, also single-threaded (panic text from the amd-dev-alone run):

title_bytes_are_used_in_place_when_all_are_readable
panicked at crates\xcl\src\hle\d3d12x\title_textures.rs:2905:13:
a committed page is not copied

The new tests make their device with D3D12CreateDevice(None, ..), so they ran on the first adapter, the RX 9070 XT here.

Not tested: the full workspace suite, a soak or title run, NVIDIA (these tests don't follow XCL_ADAPTER), Intel.

AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

@vibryxcx

vibryxcx commented Nov 27, 2026 •

Copy link
Copy Markdown

Title run on RDNA2 (the report above ran unit tests only): the 60 s pair is fine, but in 300 s runs this head lost the device in 2 of 2 runs, and its base in 0 of 2. There is also one review point in on_queue_release that could explain a GPU-side problem. I have not shown that it does.

Setup: AMD Radeon RX 6800 (driver 32.0.21045.5002), i5-10600KF, 32 GB, Windows 11 Pro 26200, release. Head baaf024d vs its base amd-dev bf7c82ee, each in its own worktree with no uncommitted changes. Same retail title, warm caches.

Regression run (60 s, after one warm-up run of base)

xcl-smoke v1
commit: bf7c82ee1b2685bb40417e09c4128177aa68d719
gpu: AMD Radeon RX 6800
title: 2c508222
seconds: 60
exit: 0x0
frames shown: 1288 (PresentX 1288)
presents per 2 s (last 3): 64 61 60
device removals: 0
crashes: 0
peak commit: 13650 MB
xcl-smoke v1
commit: baaf024d2c0b3c19c2944ce45c501ab768896e4c
gpu: AMD Radeon RX 6800
title: 2c508222
seconds: 60
exit: 0x0
frames shown: 1321 (PresentX 1321)
presents per 2 s (last 3): 60 60 64
device removals: 0
crashes: 0
peak commit: 13282 MB

300 s, XCL_PRESS_A_AT every 10 s, alternating base / head

run tree result peak commit
1 bf7c82ee ran to 300 s, 2410 frames 30652 MB
1 baaf024d 0x887a0006 at 239 s 28837 MB
2 (XCL_DRED=1) bf7c82ee ran to 300 s, 2246 frames 32156 MB
2 (XCL_DRED=1) baaf024d 0x887a0006 at 273 s 27330 MB

Review point: on_queue_release drops buffers the GPU may still be copying from.

  • release_taking_first runs its take closure before the original Release when the count was 1. So title_textures::on_queue_release removes the queue's QueueUploads (its in_flight texture::InFlight staging buffers) before the queue goes away, with no check of q.fence against q.value.
  • If an upload batch is still queued, its staging buffer is freed while the copy is pending. This is the same class of bug as the one D3D12.X: amd-dev readback waits: no stale wake-up, no buffer freed under a queued copy #2842 fixes for readback jobs.
  • Keeping only the entries whose fence has completed, or waiting on q.fence for q.value (bounded) before removing the entry, would close it.
  • I did not prove that this is what hangs the runs above: the log does not say when a title queue is released.

Reclaim across all queues. reclaim_completed_on_queue now locks ON_QUEUE and calls GetCompletedValue on every tracked queue on each call. That seems fine for a handful of queues. I note it only because the function keeps its _queue_key parameter and its old name.

Not tested: the full suite on this head; whether the hang is in the release path or the cross-queue reclaim (no per-queue logging); NVIDIA.

AI use: Claude Code (Claude Opus 5.5) read the diff, ran the builds and title runs, read the logs and wrote this comment. The numbers come from those runs on the hardware above.


Correction, after a soak of the base: bf7c82ee alone (same title, same settings, A every 10 s) lost the device in 3 of 3 600 s runs: 0x887a0006 at 226 s, then 0x887a0007 at 407 s and at 380 s. The last two were followed by the title's own int3 at game_scarlett_master.exe+0x2474606. With the two 300 s base runs above that survived, the base lost the device in 3 of 5 runs. So the 2 of 2 on this head does not show that this PR causes the hangs: on this card the base hangs about as often. The review point about on_queue_release stands on its own; it does not depend on these runs.


Update: full lib suite on this head (baaf024d, RX 6800, debug, cargo test -p xcl --lib -- --test-threads=1, with the tests skipped that hang or abort only inside the full amd-dev run, see #42): 1654 passed, 11 failed, 27 ignored. Against base bf7c82ee run the same way (1651 / 12 / 27), the two new tests (drain_completed_reclaims_only_finished_batches, on_queue_release_removes_tracked_queue_entry) pass. The only failure that changed is gpu_uploads_on_the_title_queue_run_before_its_later_work_and_are_released, which passed here, and it is the known flaky one on this card (#2842). No failure is new on this head. The review point about on_queue_release is unchanged: as @pickles976 noted, the new test uses an empty in_flight, so it cannot catch it.

@JJAutoCompare

Copy link
Copy Markdown

Tested

Clean baaf024d2c0b3c19c2944ce45c501ab768896e4c, Windows 11 build 26200.9974, Ryzen 7 3800X, Intel Arc A770 driver 32.0.101.9175, Rust 1.100.0 MSVC debug. Used synthetic inputs. Built the libtest artifact with Cargo restricted to two jobs outside the shared GPU lock. With XCL_ADAPTER=A770 XCL_NETWORK=0, ran these libtest filters separately under the lock with --exact --test-threads=1 --nocapture.

  • hle::d3d12x::title_textures::tests::gpu_uploads_on_the_title_queue_run_before_its_later_work_and_are_released: later queue work read back the uploaded pixels and tracked upload bytes cleared after completion.
  • gpu::texture::tests::gpu_large_mixed_upload_keeps_tight_staging_and_exact_pixels: the 138,412,032-byte RGBA8/BC7 request grew staging capacity from 134,217,728 to 150,994,944 bytes, reused it on repeat and read back exact bytes.

Both passed with zero failures, ignores or skips. Both logged the Arc A770 backend. The executable SHA-256 matched before, under and after the lock.

Not tested

A submit on one queue reclaiming completed uploads from a second tracked queue, final release with an upload pending, aggregate staging-pool totals during rendering, full workspace suite and retail smoke. These Arc results do not exercise the reported RX 6800 device hangs.

AI use

T3 Code / Codex (gpt-6.2-sol for the worker run) built and ran the existing tests. Codex in the coordinator session independently reran these two and drafted this report.

@pickles976

Copy link
Copy Markdown

Pending upload lifetime concern at baaf024d2c0b3c19c2944ce45c501ab768896e4c (source review, no title/test run).

The new cross-queue completed-batch drain checks each fence and looks appropriate for reclaiming idle-queue staging. The final-release hook needs the same ownership protection:

  1. q_release / release_taking_first ordinarily runs its cleanup closure before the native final Release.
  2. title_textures::on_queue_release unconditionally removes QueueUploads, including all unfinished in_flight batches, without checking their fence values or transferring ownership.
  3. texture::InFlight explicitly requires retention until submission completion. Dropping it returns small staging buffers to the reusable pool and frees oversized ones, as well as releasing its allocator/list.

[INFERENCE] If final queue release occurs while an upload is pending, staging can therefore become reusable/freed before its consumer completes. This is independent of whether native queue destruction might subsequently wait. I have not reproduced GPU corruption/device removal, and am not attributing other reporters' device removals to this path.

The new on_queue_release_removes_tracked_queue_entry uses an empty in_flight deque, so it cannot detect the lifetime problem.

Suggested correction: remove the queue-address entry immediately to avoid stale-address reuse, but transfer unfinished batches and their fence/value into fence-owned retirement; reclaim only after completion or an explicitly handled device-teardown path. Do not block waiting while holding ON_QUEUE's mutex. Add a deterministic pending-fence/drop-or-reuse regression proving staging stays retained after queue cleanup and becomes reclaimable only after completion. That is the useful next memory gate here, rather than another long title run.

Actual PR base is amd-dev bf7c82ee1b2685bb40417e09c4128177aa68d719; this review does not establish compatibility with our separate stock-vkd3d integration. AI-assisted review: omp (openai-codex/gpt-6-astra); the cited ownership/release code was inspected directly.

ivall added a commit that referenced this pull request Nov 27, 2026
Port #2912 so finished staging allocations are reaped even when the originating queue goes quiet.

Assisted-by: Codex (exact model identifier unavailable)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants