Skip to content

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

Merged
ufoptg merged 1 commit into
mainfrom
upstream-pr/968
Nov 24, 2026
Merged

ufoptg merged 1 commit into
mainfrom
upstream-pr/968

Conversation

@ufoptg

@ufoptg ufoptg commented Nov 24, 2026

Copy link
Copy Markdown
Owner

With XCL_DRED=1 a retail title stands still a few seconds after it starts – two reports of that in xcl-dev#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. xcl-dev#789 closes one; this closes the other. Part of xcl-dev#675.

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

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 + xcl-dev#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 + xcl-dev#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 (xcl-dev#923, xcl-dev#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 xcl-dev#789 (the other path, forget_buffer; it does not touch queue() – checked by running it), xcl-dev#461, xcl-dev#433, #236, xcl-dev#496, xcl-dev#532, xcl-dev#923, xcl-dev#930 (other parts of sparse.rs), and issue #344 (closed: the same mutex, at state replacement).

🤖 Generated with Claude Code


Mirror of xcl-dev#968 (auto-synced, do not edit).

…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>
@ufoptg
ufoptg merged commit cbea872 into main Nov 24, 2026
2 checks passed
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.

2 participants