Skip to content

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

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

real-alponzo wants to merge 269 commits 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.

ivall and others added 30 commits November 25, 2026 14:02
Each chained dispatch made a scratch buffer for all its groups and kept it until the allocator's reset. A retail title's 176 split programs need 187 KB a group (median), 3 GB for 960x540 pixels in groups of 8x4. At most XCL_SPLIT_SCRATCH_MB (256) of groups now run at once, each piece adding the slab's origin to the group ids, and the chains recorded on one list share the buffer.
In a pixel shader EXEC holds helper lanes (s_wqm), and on a primitive's
edge the first lane of EXEC is often one. v_readfirstlane read that lane.
An RDNA2 driver (RX 6700 XT, 32.0.21045) gives 0 for everything a helper
lane holds once a WaveReadLaneAt ran inside a loop, quad reads included.
A loop whose state the console's compiler carries in a vector register
(v_mov v, s ... v_readfirstlane s, v) then read 0 back on each pass and
ran to the loop budget: a retail title's volumetric light pass took
seconds per draw at its world start and Windows reset the GPU (#675).

v_readfirstlane now reads the first lane of EXEC that is live
(ballot(true), per half in the wave32-in-64 form) when EXEC has one, and
the first lane of EXEC as before when it has none. The value is the same:
the console's compiler reads the first lane of a value equal in every
lane, or of a lane it then removes from EXEC (a waterfall loop).

The new GPU test draws that title's list-loop shape on two triangles
sharing a diagonal. Without the change, on the RX 6700 XT, 69 of 1024
pixels run the loop 65 536 times (the budget) with wrong results; with
it, none, and at most 16 passes.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A retail game unmaps addresses while it streams its world with
XMemMapPhysicalPagesScatter(addresses, n, NULL); it checks the result
and runs into its own int3 when the call fails (+0xb18de7, then its
crash reporter). XCL refused a NULL page array with
ERROR_INVALID_PARAMETER. Page 0 already means "unmap this address" in a
scatter, so no array is taken as page 0 for every address.

Test scatter_without_pages_unmaps: two pages mapped and written, unmapped
with no array (the call succeeds, the addresses are no longer committed),
mapped again they read what was written. It fails without the change
("refused").

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A retail title keeps its destination page lists in slots of its own
table and writes a slot's pages after EnqueueRequest. At enqueue such a
slot can still name the pages of the slot's previous request, and the
snapshot taken then is what execute() wrote to (#289 rereads only the
entries that are 0). Over 16 000 requests a run were written into pages
the title had since reused: its objects got garbage pointers and it
crashed about 20 s into world loading; when the old pages were freed,
the request failed with E_ACCESS_VIOLATION.

The console reads the list when it runs the request. execute() now
reads it again (through read_own, as the snapshot) and takes it when it
differs and every page in it is allocated (kernelx::physical_pages_live).
A list that was on the enqueuing thread's stack keeps the snapshot: that
memory is reused once the call returns, and a page ID written there
since can belong to another live allocation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…heir pages with their texels

A retail title places its streamed textures at full size and has memory behind
their levels only as it loads them, the small ones first. vram::place_pages
gives a sampled texture a 64 KiB page of video memory for every tile at once:
when that title's world is set up about 92 % of those pages have nothing behind
them (80 690 pages, 6 809 committed, on one card).

With the switch (off by default) a sampled 2D texture of one slice is placed
with no tile mapped. Its tiling is kept as groups of tiles, one for each level
with tiles of its own and one for the packed levels, and a group gets its pages
before the first upload that has texels for it - the same pages by address as
before, so textures placed at one address still share them. A texture the GPU
writes gets all its pages.

Part of #1773.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
ivall and others added 12 commits November 26, 2026 19:19
…load

Fixes, each run in a retail title's world on an AMD RX 9070 (16 GB):
- list_x: a wait an earlier signal of the same cell or fence already
  satisfies is not part of a cycle (nvidia-dev 4cdb71f, f98a1d6).
  Every pipelined frame (wait N armed, signal N+1 next) counted as one:
  16 false cycle breaks a run before, none after.
- dispatch_chain: whole_in_cooldown takes CHAINS with try_lock, and a
  replaced chain is dropped after the lock: title threads blocked there.
- bind: prelude job tables live in pooled 1 MiB persistently mapped
  blocks (64 kept) instead of a committed buffer per use: ~1 250
  CreateCommittedResource a second during the world load before.
  XCL_TWO_PASS_LIST_MB sizes a list's two-pass record buffer (32 MiB,
  as before).
- title_textures: a submit whose lists were all closed before the last
  write-watch look began, in the same frame, takes no look of its own
  (XCL_LOOK_SKIP=0: off). A quarter of the world's submits skip it.
- sparse, vram: a submit waits on the CPU (XCL_SPARSE_CPU_WAIT_MS, 1 s)
  for the tile mappings its queue needs, then on the GPU only if they
  are late; placements no longer signal the sparse queue one by one.
- pso_async: workers are throttled by the system's free commit, not
  its free RAM: the world load dropped free RAM to 1.3 GB with 12 GB of
  commit free, every worker idled and a bind waited 14 s for a compute
  pipeline.
- real: pipelines waiting to be built (pso_async::lazy) share their
  copies of console shaders (same address, same bytes): ~80 000 of them
  in the first minute held 318 MB of copies after this.

Diagnostics (XCL_ACTIVITY):
- prof: a "profile (2 s)" line, where the title's threads waited in
  XCL: pipeline waits, submits (write-watch, sparse copies, texture
  uploads, list segments, driver), placements, frame events, presents.
- flight: every queue XCL signals, with a stall warning after 1 s and,
  at a device removal or crash, the queues (the first stopped first)
  and the last 400 events; tile mappings and creations a line. After
  3 s without GPU progress its thread reports the GPU culprit
  (XCL_GPU_CULPRIT=1) and after 8 s dumps the threads
  (XCL_STALL_DUMP=1): in the activity thread they never came, its DXGI
  query blocked in the hung driver.
- memory_report (xcl-dev/xcl#2697): "memory by owner" against DXGI's
  budget, the title's committed resources alive by kind, and every
  10 s the address space walked.
- eh: thread dumps go 40 frames deep.

Not fixed: the device is still removed 60-110 s into the world. The
culprit report named an indirect compute dispatch in one run; in the
others no dispatch was in flight and every queue waited.
A driver device limit can end workers during startup. Retry their batches once after the other workers finish, and count only batches that still fail.

Assisted-by: Claude (exact model unknown), Codex (GPT-6 family, exact model unknown)
Port #2865 to keep per-region budgets in compute and kernel shaders. Charge more budget for longer loops so a compute dispatch cannot spend its full iteration budget in a large loop.

Assisted-by: Claude (exact model unknown), Codex (GPT-6 family, exact model unknown)
Port #2868. Use the pipeline workers' free-commit measure so low free RAM alone does not stall big compiles.

Assisted-by: Claude (exact model unknown), Codex (GPT-6 family, exact model unknown)
Port #2859. Keep a readable dword beyond the logical blob length for the driver.

Assisted-by: Claude (exact model unknown), Codex (GPT-6 family, exact model unknown)
Port #2842. Check the fence after each event wake-up and keep a timed-out staging job alive while the GPU can still write to it.

Assisted-by: Claude (exact model unknown), Codex (GPT-6 family, exact model unknown)
A shared fence could move backward as separate title queues completed out of order. Signal a separate fence on each source queue.

Assisted-by: Claude (exact model unknown), Codex (GPT-6 family, exact model unknown)
Port #2630. Smaller pools let more video memory return when a title frees runs of tiles and keeps the tiles between them.

Assisted-by: Claude (exact model unknown), Codex (GPT-6 family, exact model unknown)
Keep full read-write sparse pages GPU-only until the title touches them on the CPU. Preserve title-facing query and protection behavior for lazy pages.

Assisted-by: Claude (exact model unknown), Codex (GPT-6 family, exact model unknown)
Record the compute, graphics or mesh pipeline in the driver when compilation stops the process. Skip the recorded pipeline on later launches and retain the available shader diagnostics.

Assisted-by: Claude (exact model unknown), Codex (GPT-6 family, exact model unknown)
Track active profiling spans, queue waits and submissions, and report the dispatch associated with a device removal.

Assisted-by: Claude (exact model unknown), Codex (GPT-6 family, exact model unknown)
…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.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head baaf024

This branch carries about 220 commits from an older amd-dev history that origin/amd-dev no longer contains. Only the top commit (baaf024) is this PR's change.
The same change already went into amd-dev as 706d0ce ("reclaim completed texture uploads across queues"). Current origin/amd-dev has title_textures::on_queue_release with the same body and doc comment, and q_release calls it.
amd-dev has since rewritten the per-queue upload state (QueueUploadState, reclaim(q, cap, wait_ms)) and removed reclaim_completed_on_queue. The all-queues drain in this diff has nothing left to apply to.
Recommendation: close (superseded by amd-dev commits 706d0ce / 6fa964d).

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

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.