Skip to content

D3D12.X: the late-release drain gets the sparse queue without the sparse state's lock - #968

Merged
theaustinayers merged 1 commit into
xcl-dev:mainfrom
imnicho:late-release-sparse-queue
Nov 24, 2026
Merged

theaustinayers merged 1 commit into
xcl-dev:mainfrom
imnicho:late-release-sparse-queue

Conversation

@imnicho

@imnicho imnicho commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

With XCL_DRED=1 a retail title stands still a few seconds after it starts – two reports of that in #675 ("stalls the title at ~9 s", "stalls at startup here too (3 of 3)") – so nobody gets the breadcrumbs of the device removal that issue is about. It is two threads waiting for each other, and there are two ways into it. #789 closes one; this closes the other. Part of #675.

From thread dumps here (frames of XCL symbolised from the build's PDB):

  • thread A, a submit of the title's: q_execute_command_lists → title_textures::refresh → sparse::before_execute → State::upload_dirty → State::begin_slot → ID3D12CommandAllocator::Reset, waiting for a lock inside D3D12Core – with the sparse state's mutex held;
  • thread B, the title's Reset of a command list: inside D3D12Core, which makes a resource's last Release there → XCL's release hook, which waits for the sparse state's mutex:
    1. on main, in sparse::forget_buffer – D3D12.X: decommit released sparse blocks outside the driver callback #789's path;
    2. with D3D12.X: decommit released sparse blocks outside the driver callback #789 merged, in late_release::hold → drain_known → sparse::queue(), which took the mutex only to clone the queue – this PR.

What is in it

  • crates/xcl/src/hle/d3d12x/sparse.rs: the state's queue is kept a second time outside STATE (QUEUE), set when the state is made or replaced, and queue() answers from there. Test the_queue_is_answered_while_the_state_is_locked (on main it fails after its 5 s: "queue() waited for the sparse state's lock").
  • 29 lines added, 2 removed, one file.

Tested

  • hardware: Intel Core i7-7700K (4 cores / 8 threads), 16 GB RAM, NVIDIA GeForce RTX 5080 16 GB (driver 610.47), Windows 10 22H2 (19045), Agility SDK 620, DXC 1.9.2602.17, rustc 1.100.0 stable-x86_64-pc-windows-msvc; debug for the tests, release for the title.
  • cargo build --workspace && cargo test --workspace -- --test-threads=4 on 9beaa73: 717 passed, 0 failed, 41 ignored (SKIPPED GPU tests: gpu_wave32_program_in_wave64_hardware, gpu_geometry_wave32_prefix_count_over_a_mask – no wave64).
  • game checked: the newer retail title of the README, XCL_NETWORK=0, XCL_DRED=1, no input (its first screens), 45 s runs, four builds in turn, 3 rounds, release. Frames shown in the run, and the time of the last line of the 2 s activity log (it stands still with the title):
build round 1 round 2 round 3
main (077ce40) 1 frame, still from 10.8 s 1 frame, still from 8.1 s 1 frame, still from 8.3 s
main + #789 (bc82410) 1 frame, still from 10.9 s 1 frame, still from 8.7 s 1 frame, still from 10.5 s
main + this PR 1 frame, still from 10.5 s 1 frame, still from 8.0 s 1 frame, still from 10.5 s
main + #789 + this PR 918 frames 910 frames 920 frames

(The same main without the variable, one run before these that also filled the DXIL cache: 874 frames.)

Regression run (default settings, no XCL_DRED)

main:

xcl-smoke v1
commit: 077ce40c3e371cf3df8c57985b1cc6b1db39e75a
gpu: NVIDIA GeForce RTX 5080
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1363 (PresentX 1363)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14313 MB

PR:

xcl-smoke v1
commit: 9beaa733fbead2d7909d22d36d59f6dc9e16dc64
gpu: NVIDIA GeForce RTX 5080
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1376 (PresentX 1377)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14315 MB

A second round: 1375 frames (main), 1362 (PR). main has moved on to 6bac4b4 since these ran (#923, #849); the branch merges into it without conflicts.

Not tested

  • AMD and Intel GPUs; Windows 11 (the two reports of the stall are from Windows 11 machines; this was checked on Windows 10 only).
  • Whether a third way into the same wait exists on other machines – hold and the drain still call D3D12 (Signal, GetCompletedValue) from inside the release hook; none showed in the runs above.
  • Without XCL_DRED: the same two threads can meet whenever D3D12 makes a resource's last Release inside a call of its own, but I have not seen that stall without the variable.

AI use

  • Claude Code with Claude Fable 5.2: read the thread dumps, wrote the change and its test, ran the suite and the title runs on the machine named, and wrote this description.

Duplicate check (Gate A 09:07 UTC on main 077ce40, Gate B 09:38 UTC on 6bac4b4): no open PR changes how late_release gets the sparse queue; read #789 (the other path, forget_buffer; it does not touch queue() – checked by running it), #461, #433, #236, #496, #532, #923, #930 (other parts of sparse.rs), and issue #344 (closed: the same mutex, at state replacement).

🤖 Generated with Claude Code

…rse state's lock

A resource's last Release goes to late_release::hold, whose drain asks sparse::queue()
for the tile-mapping queue, and queue() took the sparse state's lock to clone it. That
lock is held around D3D12 calls (an upload's allocator Reset in begin_slot), and D3D12
can make a resource's last Release inside a call of its own on another thread: with
XCL_DRED=1 a list's Reset does, every run. The Reset under the lock then waits for
D3D12's lock and the Release inside D3D12 for the sparse state's: the title stands
still a few seconds after it starts.

The queue is kept a second time outside the state (QUEUE), set when the state is made
or replaced, and queue() answers from there.

Test: the_queue_is_answered_while_the_state_is_locked.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@oni-swr

oni-swr commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Test report for #968 at 9beaa73 on AMD (the description has an NVIDIA run only).

Tested

  • AMD Radeon RX 7800 XT (RDNA3), driver 32.0.31035.1003; Ryzen 7 5700X3D, 64 GB; Windows 11 Pro 26200; Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug.
  • cargo build --workspace && cargo test --workspace -- --test-threads=4, each tree in its own target directory:
    • main 02bfd1d: 727 passed, 0 failed, 41 ignored, 0 SKIPPED.
    • main 02bfd1d + 9beaa73 (merges cleanly): 728 passed, 0 failed, 41 ignored, 0 SKIPPED. The one extra is the_queue_is_answered_while_the_state_is_locked.
  • Read the diff: STATE is only ever set in init, which sets QUEUE just before it, so queue() cannot outlive or lag the state it mirrors.

Not tested

  • The retail title, XCL_DRED=1 runs, a smoke pair.

AI use: Claude Code (Claude Opus 5.5) ran the suites and read the diff; I checked the report.

@SlopTart

Copy link
Copy Markdown

Linux / AMD RDNA3 datapoint.

Merged state: head 9beaa73 onto main 9aec53d, clean merge.

Full suite, cargo test --workspace --release --no-fail-fast --target x86_64-pc-windows-gnu -- --test-threads=4: 718 passed, 7 failed, 41 ignored; failures are the known Wine-lane set from my #42 rows. late-release drain + sparse queue tests green; this rig is exactly the "can only see it at Wine scale" case and the leak did not bite in-lane.

Not tested: retail titles (none here), Windows, RDNA4.
Counts only, no game data.

Machine: RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, Rust cross x86_64-pc-windows-gnu, XCL_NETWORK=0, release profile, --test-threads=4. My Linux rows: #42 / #718.

AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.

@raylitebull

Copy link
Copy Markdown
Member

Code/CI review only (not independently runtime-tested by me): clean merge with both checks green (Build and test + PR description). Moving the sparse queue acquisition outside sparse::STATE in late_release drain cleanly fixes that part of the #675 deadlock. Recommend merging, @ivall.

@DavidM1911

Copy link
Copy Markdown
Contributor

Independent verification, merged onto current main 384f7f7 locally (clean merge).

Machine: Windows 11, Ryzen 9 7900X + RTX 3060 Ti; Rust stable MSVC, debug.

  • cargo test -p xcl --lib sparse: 17 passed, 0 failed, 1 ignored — includes the new the_queue_is_answered_while_the_state_is_locked, and the GPU test gpu_sparse_vram_descriptors_buffers_and_xmem passed on this run.

AI use: test runs by Devin (Cognition, SWE-2); no code changes.

@thehollowedone

Copy link
Copy Markdown

Independent native GPU queue check on 9beaa73 applied cleanly to 930e8b4 in a scratch checkout. Windows 11 build 26300, RTX 3080 Ti / 621.35, Rust 1.99.1 MSVC, debug.

I initialized the real sparse state, held its mutex, and asked a second thread to look up the queue and signal a native fence. It returned the correct queue and the fence completed while the mutex was still held. I repeated the check after replacing the sparse state and got the new queue, with its fence also completing. On unmodified 930e8b4, the same fixture timed out on its first lookup while the mutex remained held.

This checks the queue lookup implicated in the DRED hang. No retail or DRED-enabled run. AI-assisted. Codex (GPT-6, exact variant unavailable) wrote and ran the scratch fixture and drafted this report.

@deepdev237

Copy link
Copy Markdown

Retail DRED run with #968 and #789 on AMD RDNA4

Tested

  • AMD Radeon RX 9060 XT (RDNA4, driver 32.0.32015.7029), Ryzen 9 5950X, Windows 11 build 26300, Rust 1.100.0 MSVC, release.
  • Applied D3D12.X: the late-release drain gets the sparse queue without the sparse state's lock #968 9beaa733fbead2d7909d22d36d59f6dc9e16dc64 and D3D12.X: decommit released sparse blocks outside the driver callback #789 bc82410abd9ccad26987ed86ec82f4194e06a888 together to a local diagnostic stack based on 47efa2ecea0a12934719ae69b81930cf02a4b1c3 (resulting Git tree f4890332e2b99b49ef23de068079e86e2b4cfbef).
  • cargo test --offline --locked --release -p xcl --lib hle::d3d12x::sparse::tests -- --nocapture --test-threads=1: 14 passed, 0 failed, 1 ignored, zero GPU skips. This included the_queue_is_answered_while_the_state_is_locked.
  • xcl.exe run "<retail-title>" with XCL_DRED=1, XCL_NETWORK=0, a matched DXIL cache seed and scripted A starting at 44 s. The local control without either patch stalled around 7.4 s. With both patches the run reached story loading and presented through 202.354 s. At 204.029 s, DXGI_ERROR_DEVICE_HUNG produced seven DRED breadcrumbs. The started, unfinished list had 11 of 17 operations complete, with EXECUTEINDIRECT next and page-fault VA 0x0.

Not tested — The retail effect of #968 in isolation, a clean upstream-main comparison, or rendered gameplay.

AI use — OpenAI Codex (gpt-6.2-sol) ran the tests, checked the local receipts and wrote this report.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
…cl-dev#1286-xcl-dev#1291, xcl-dev#1294, xcl-dev#1296-xcl-dev#1297, xcl-dev#1300

Prevent background shader preloading and concurrent DXC/RADV compiles from exhausting host RAM under Wine, and integrate 11 open upstream PRs:
- dxc.rs & real.rs: check free physical RAM (ullAvailPhys.min(ullAvailPageFile)) under Wine instead of swap-inclusive ullAvailPageFile, avoid bypassing the guard after 60 s under Wine, and serialize giant (>= 4 MiB DXIL) driver compiles with BIG_COMPILES under Wine.
- pso_async.rs: cap background preload workers to 1 under Wine.
- title_textures.rs: use real::create_raw_fence in submit_on_title_queue and read coherent-window hash bytes safely via with_title_bytes.
- Integrate upstream PRs xcl-dev#968 (sparse::queue lock-free for late_release), xcl-dev#1286 (v_dot2_f32_f16 NEG_HI abs), xcl-dev#1287 (XMA >8 channels), xcl-dev#1288 (Sleep pauses during PSO bind waits), xcl-dev#1289 (pipeline stream bounds check), xcl-dev#1290 (root signature MAX_ARGS cap), xcl-dev#1291 (console UAV clears xcl-dev#53/xcl-dev#54), xcl-dev#1294 (shadowed PENDING accuracy), xcl-dev#1296 (16-bit compare low halves), xcl-dev#1297 (fence_x pre-cell signal arming), xcl-dev#1300 (log driver compute PSO refusal).

Verified on RX 9060 XT under GE-Proton11-14 (MemoryMax=12G, 80 s): committed RAM stays flat at 4830 MB (down from 27.6 GB OOM), 1493 frames shown, exit 0x0.

Assisted-by: Antigravity (Google DeepMind)
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
@crosettiremi

Copy link
Copy Markdown

Windows 11, RX 7900 XT (RDNA3), driver 32.0.32029.2010. I tested main 930e8b4 and the pair #789 bc82410 + #968 9beaa73. Both builds had the same local file-based controller script, Series X profile, starting application caches, offline mode, DRED enabled and a 28 GiB whole-job limit.

On main the activity log stopped at 13.027 s after two presents in total. No frame dump reached the account prompt. Two local process snapshots taken over a minute apart gave identical stack-scan results for the activity thread waiting on sparse::STATE, a resource release in sparse::forget_buffer, and an upload in State::begin_slot / ID3D12CommandAllocator::Reset. Background pipeline workers continued running. I ended this diagnostic run manually.

With the pair applied, the Player1 prompt rendered. The scripted A press was observed at 33.034 s. The title passed the splash, showed loading artwork, and streamed world assets. At 96.5 s the process had 28,129 MB committed and 8,351 MB in target pages. It subsequently exited 0xc0000409 with zero device removals. The sparse suite passed 16 tests with one ignored, including the lock-held queue lookup and resource-release tests.

This corroborates the startup improvement on another AMD generation. The later world-loading exit is separate. I did not run the two patches individually in this title comparison.

@theaustinayers
theaustinayers merged commit cbea872 into xcl-dev:main Nov 24, 2026
2 checks passed
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
Brings in 20 newly merged upstream PRs (xcl-dev#959, xcl-dev#968, xcl-dev#1079, xcl-dev#1084, xcl-dev#1091,
xcl-dev#1099, xcl-dev#1127, xcl-dev#1133, xcl-dev#1137, xcl-dev#1150, xcl-dev#1211, xcl-dev#1223, xcl-dev#1224, xcl-dev#1265, xcl-dev#1289,
xcl-dev#1290, xcl-dev#1330, xcl-dev#1353, xcl-dev#1354), including in-memory shader cache session
fallback (xcl-dev#1211), CPU-invisible resource Map filtering (xcl-dev#1099), DRED
partially executed list priority (xcl-dev#1330), allocation info alignment
padding (xcl-dev#1354), and DirectStorage status/error/cancel fixes (xcl-dev#1127,
xcl-dev#1223, xcl-dev#1224).
wondercrash added a commit to wondercrash/xcl that referenced this pull request Nov 24, 2026
Conflicts:
- sparse.rs (init): our WORK/STATE split already keeps the sparse queue in
  QUEUE outside both locks, which is what xcl-dev#968 adds. Upstream's second QUEUE
  static and its init lines are dropped; its ordering is kept: QUEUE is
  replaced before the GPU side and the state, so queue() never answers with
  a queue older than the state's.
- sparse.rs (tests): both kept; xcl-dev#968's test asserts queue() answers while
  STATE is held, ours while WORK is held. queue()'s doc names WORK.
- real.rs (DRED): our dred_lines (lines returned for the log, DRED 1.1
  names, no-fault and no-list lines) is kept. xcl-dev#1330's order is taken over:
  unfinished lists the GPU had started are named before unstarted ones
  (unfinished_to_name), at most 64, and the chain is read to at most 4096
  nodes. Its report_dred_lists and its xlog lines are dropped (they would
  log the lists a second time); its test is ported to BreadcrumbNode in our
  dred_tests.

Assisted-by: omp (Claude Opus 5.5)
wondercrash added a commit to wondercrash/xcl that referenced this pull request Nov 24, 2026
…aced

The merge of xcl-dev#968 kept its comment "the queue first: queue() never
answers with one older than the state's", which is true upstream, where
QUEUE is replaced before STATE is taken. Here QUEUE, WORK and STATE are
all replaced in one section under WORK and STATE, so the order inside it
cannot be seen; the comment now says that.

Assisted-by: omp (Claude Opus 5.5)
wondercrash added a commit to wondercrash/xcl that referenced this pull request Nov 24, 2026
…sign

It said that nothing may wait on the state from a release inside a D3D12
call. Here a release does take STATE (forget_buffer, forget_queue), which
is safe because STATE is never held across a D3D12 call; the lock a
release must not wait for is WORK. The doc now says that queue() needs
neither WORK nor STATE.

Assisted-by: omp (Claude Opus 5.5)
raylitebull pushed a commit that referenced this pull request Nov 25, 2026
… lock

`before_execute` holds the sparse state's lock (`STATE`) around D3D12 calls. D3D12 can make
a placed buffer's last Release inside one of its own calls on another thread; that Release
reaches `forget_buffer`, which took `STATE` too: the D3D12 call under the lock waited for
D3D12's lock, the Release inside D3D12 for `STATE`. A retail title's presents stopped after
its third frame on every start (black screen) with both threads in those waits.

`forget_buffer` now queues the resource in `FORGOTTEN` and only takes `STATE` if it is free
(`try_lock`); every other user of the state takes it through `lock_state`, which first lets
the queued buffers go. #968 fixed the other half of the same cycle (`queue()`).

Test: a_buffer_released_while_the_state_is_held_does_not_wait_for_it (fails on main after
its 5 s timeout: "forget_buffer waited for the sparse state's lock").

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

9 participants