Skip to content

D3D12.X: leave releases made inside a list Reset to the late-release thread - #3356

Merged
Prime1997 merged 1 commit into
xcl-dev:mainfrom
Pipodi:dred-reset-release
Nov 30, 2026
Merged

Prime1997 merged 1 commit into
xcl-dev:mainfrom
Pipodi:dred-reset-release

Conversation

@Pipodi

@Pipodi Pipodi commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

With XCL_DRED=1 a retail title deadlocks during start-up on main (0 presents and 0 submits from then on). Two threads wait on each other:

  • the title thread holds a queue's submit lease (queue_submit.rs, readback after execute) and waits in D3D12Core's CCommandAllocator::Reset for the allocator lock;
  • the recording thread is inside a native list Reset, which holds that lock. There D3D12Core releases DRED's breadcrumb buffer; the release goes through late_release::hold, whose drain_known signals the queues and waits for the lease the title thread holds.

Thread stacks of a stalled run (cdb, non-invasive) show exactly these frames. Without XCL_DRED the title does not stall. The cycle exists since the per-queue submit lease (7a37be8).

The same drain_known split also removes a second cycle, reported in testing on this PR (comment of 2026-11-29: a freeze at ~556 s on main, none to 900 s on this head). A title thread drops a stale texture-download plan inside its queue turn (Signal/SignalX → submit_prepared_downloads) and waits for HELD, while xcl-fences, releasing a finished download's readback buffer, holds HELD in drain_known and waits for that queue's submit lease. With the signals made outside HELD (begin_seal / end_seal), no caller of drain_known waits for a lease under the lock; the list-Reset guard plays no part there. That path was checked by reading the code, not by our own run.

What is in it (one commit)

  • alloc_pool.rs, real.rs: a thread-local guard (InListReset) around the native list Reset in alloc_pool::reset_list and the cl_reset hook.
  • late_release.rs: while the guard is set, hold leaves the release to the late-release thread. Held::drain is split so no lease is taken with HELD locked (begin_seal under HELD, the signals outside it, end_seal relocks to push the batch or put it back in order). Only one seal runs at a time, so the (non-FIFO) leases cannot order two seals' signals wrongly, and a batch in flight still counts as held, so a pinned hold waits for its release.
  • Tests: hold_inside_a_list_reset_leaves_the_release_to_the_thread, a_release_inside_a_list_reset_is_left_to_the_thread, a_seal_in_flight_counts_as_held_and_is_the_only_one, a_batch_whose_signals_failed_goes_back_in_order, and guard assertions in alloc_pool's submit_reservation_keeps_pre_reset_attribution_across_queues. Each fails with its part of the change reverted (the put-back test only covers the new seal code).

Tested

  • NVIDIA GeForce RTX 4090 (driver 621.40), Intel Core i9-13900K, Windows 11 10.0.26300, rustc 1.100.0; tests in debug, title runs in release.
  • On this commit's tree (ab08f4d2, reworded since): cargo test --workspace -- --test-threads=4: 2622 passed, 0 failed, 49 ignored; 27 SKIPPED lines (wave64, f16 refusals, heap windows). One earlier run of the same command stopped at 2479 passed, 4 failed, 29 ignored in the xcl lib: the known shaders::pipeline_library / warm_library race, which also fails on main d8bd9a3 (4 of 12 cargo test -p xcl --lib runs there; 0 of 12 on this commit).
  • The title with XCL_DRED=1 (150 s, no presses): main d8bd9a3 stalled in 2 of 2 runs; this commit's tree stalled in 0 of 3 (4147 / 4237 / 4244 presents, presenting to the end, no device removal).

Regression run

xcl-smoke v1
commit: d8bd9a38204667f3ca7dd9eeffcc2f1c937b07b0
gpu: NVIDIA GeForce RTX 4090
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1695 (PresentX 1695)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17756 MB
xcl-smoke v1
commit: d783592c5c72e22267cd4e607f699fea2d61000e
gpu: NVIDIA GeForce RTX 4090
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1696 (PresentX 1696)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 18634 MB

Both with XCL_PREPARE=0 and a scripted A press at 16 s, 60 s, after an untimed warm-up run of each binary.

Not tested

AI use

  • Claude Code with Claude Opus 5.5: found the cause from the run logs and thread stacks, wrote the code, the tests and this description, and ran the tests and the title runs on the hardware above; two review passes were also done with it.

🤖 Generated with Claude Code

…thread

With XCL_DRED=1 a retail title stalled: main d8bd9a3 stalled 2 of 2
runs (the earlier main fa20459 3 of 4); without DRED 0 of 3 stalled.
Two threads deadlocked. The title thread takes a queue's submit lease
(readback after execute) and waits in CCommandAllocator::Reset on
D3D12Core's allocator lock. The recording thread, inside a native list
Reset that holds that lock, has D3D12Core release DRED's breadcrumb
buffer, which enters late_release::hold; its drain_known signals the
queues and waits for the lease the title thread holds.

A thread-local guard (InListReset) is set around the native Reset in
alloc_pool::reset_list and in the cl_reset hook (XCL's own list Resets
do not go through reset_list). While it is set, hold treats the release
as busy and leaves it to the late-release thread.

That alone is not enough: drain_known held HELD across Held::drain, whose
native_queue_signal takes the lease, so another drain_known caller could
wait for the lease with HELD locked, and the guarded hold would block on
HELD. The drain is now split: begin_seal (under HELD) takes the open
batch out and reserves fence values, the signals are made with HELD
unlocked, end_seal relocks to push the batch (or put it back in order if
a signal failed). Because the signals are no longer under the lock, two
seals could interleave and the (non-FIFO) leases could order their
signals wrongly: only one seal runs at a time, and a batch in flight
counts as held (is_empty), so a pinned hold still waits for its release.
A seal skipped because another is under way leaves the batch open for
the next one.

Measured with XCL_DRED=1 on the same title (150 s, RTX 4090): this
commit 0 of 3 runs stalled, main d8bd9a3 2 of 2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:memory Virtual/physical memory, arenas, VRAM budget, UMA gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Nov 29, 2026
@BBareth

BBareth commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

GTA 6 test report (part of #505): the same lock cycle in a second place, and this PR clears it

In GTA 6 (with XCL_DRED=1 set, as in all my runs) the title froze at about 556 s, once the world had loaded (0 presents and 0 submits from then on, audio still decoding). A thread dump at 600 s, symbolised against the PDB, shows the cycle this PR describes, reached through texture downloads rather than a list Reset:

  • a title submit thread holds the queue's submit lease (queue_submit.rs with), drops a texture download plan in title_textures.rs, and its last Release goes through late_release::hold, which waits for HELD;
  • xcl-fences drops a finished download, its Release goes into hold -> drain_known(true) -> Held::drain with HELD locked -> native_queue_signal, which waits for that same lease.

This PR's begin_seal / end_seal (signals made with HELD unlocked) breaks that one too. The list-Reset guard is not what helps here.

  • Tree: a local branch on main fa20459 (gta-main a056e9fd plus some open PRs and local diagnostics). The only difference between the runs is the late-release change.
  • RTX 5070 Ti, driver 32.0.16.2124; i7-12700K, 32 GB; Windows 11 Pro 26200; rustc 1.95.0; release.
  • Env: XCL_ALIAS_COPY=1 XCL_DRED=1 XCL_PLACE_RETIRE=0 XCL_TEXTURE_LEVEL_PAGES=1 XCL_PRESS_A_AT=450 XCL_ACTIVITY=1 XCL_CS_PSO_WAIT_MS=250 XCL_DEFER_PRIVATE_HOME_TILES=1 XCL_LOOK_SKIP=1, plus XCL_THREAD_DUMP_AT.
run late_release result
up25 as on main froze ~556 s; the dump above
up27 this PR, d783592 presents to the 900 s limit, no freeze

(A local alternative, skipping the signal when another thread has the queue's turn, also ran to the 900 s limit; I am not proposing it, this PR covers it.) Frame rate after the world load is about 1 fps in both kinds of run; that is a separate problem.

Tests on the same tree with this PR: cargo test -p xcl --lib -- late_release alloc_pool queue_submit: the late_release and queue_submit tests pass, and 3 alloc_pool tests fail (completion_queries_run_outside_allocator_state, submit_marking_calls_out_unlocked_and_revalidates_the_queue_marker, transferred_owner_is_released_once_outside_state_after_logical_forget). The same filter fails the same way without this PR, and alloc_pool alone passes (27 of 27), so it looks like shared state between the two modules' tests, not this PR. I did not check it on clean main.

Not tested: the whole suite; AMD; more than one run each; clean main.

Claude Code, Claude Opus 5.5: ran the runs, symbolised the dump and wrote this report from the logs.

@Pipodi

Pipodi commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the run and the stacks.

On the three alloc_pool failures: they are not from this PR. They fail on main too.

  • Command (cargo needs the -- before several filters): cargo test -p xcl --lib -- late_release alloc_pool queue_submit
  • 30 runs of the test binary on each tree, RTX 4090, 32 threads: main fa20459 failed in 22/30 runs, this PR's head d783592 in 22/30. All three named tests fail on main as well. alloc_pool on its own fails too (25/30 on main), so a 27/27 pass is down to timing.
  • With --test-threads=1: 0/30 on both trees.
  • Cause: the module's tests share the process-global STATE (alloc_pool.rs:124) and take no common test lock. completion_queries_run_outside_allocator_state and submit_marking_calls_out_unlocked_and_revalidates_the_queue_marker assert STATE.try_lock().is_ok(), which fails whenever another test thread holds STATE at that moment. transferred_owner_is_released_once_outside_state_after_logical_forget can lose its backing to a sweep (sweep_release_owners_with) run by a concurrent test. It came in with c3da8f3, d59c05d and 0ac14d3 (2026-11-25). The PR's change there is a thread-local guard, which other test threads cannot see.

I'll open a separate test-only PR against main for the test lock. Until then, --test-threads=1 is the workaround.

On the second path (texture downloads → late_release::hold / Held::drain): this PR was written and measured only for the list-Reset path. I'm checking whether that path goes through the same guard before I claim it in the description.

(Checked and written with Claude Code, Claude Opus 5.5.)

@CharlyRien CharlyRien left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. This fixes a freeze I hit on the retail title (RTX 3090, Windows 11) without DRED: the same lock cycle you describe, reached through a queue's submit lease instead of a list Reset.

What I saw: two runs froze in the world, at 389 s and at 274 s, with 0.7 of a core busy. In the second run, the 580 thread samples taken during the freeze all show:

  • one of the title's threads holding a queue's submit lease and waiting for HELD in late_release::hold (reached from res_release);
  • the thread in drain_known holding HELD and waiting for that queue's lease, inside the signal.

Both runs used an env that makes many more queue operations with releases inside them. None of ~15 runs of the same stack without that env froze, but the cycle is in main's code.

Stack (exact): main at 7a649b0 plus 28 local commits (D3D12.X, recompiler and diagnostics), plus your 4d3295fd cherry-picked without conflicts.

Test: I added a test that holds a real queue_submit lease and releases a pinned resource inside it while another thread seals the same queue. On the code before this PR (the signal made with HELD locked) it fails after its 10 s timeout, with the release and the seal waiting for each other; with this PR it passes. I can share it as a patch here or as a follow-up PR on top of yours, whichever you prefer.

A read of the diff found nothing blocking. One small point: if signal() panicked, sealing would stay true and every later held release would leak; a Drop guard on the seal would prevent that.

In game with this PR (same stack and env as the two frozen runs): no lock freeze. It ran 255 s in the world (past both earlier freeze times), and none of the thread samples taken there shows a thread waiting in late_release::hold or on a submit lease. The run then ended on a GPU hang (DEVICE_HUNG, 664 MB over the video memory budget with that env), which has nothing to do with this PR: the CPU threads kept running until the device was removed.

AI use: found and written with Claude Code (Claude Opus 5.5), checked and posted by me.

@Aniseto

Aniseto commented Nov 29, 2026

Copy link
Copy Markdown

Ran the late-release and list-Reset tests at d783592c on an NVIDIA Blackwell desktop part.

System

  • GPU: NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, mesh shaders), driver 32.0.16.2140 (621.40)
  • CPU: Intel Core i5-12400F, 64 GB RAM
  • OS: Windows 11 Pro build 26200 x64
  • Toolchain: rustc 1.100.0 (0ef1bc386 2026-11-09), MSVC 14.44.35207, DXC 1.9.2609.5
  • Build: debug

Results

  • XCL_ADAPTER=NVIDIA cargo test -p xcl --lib hold_inside_a_list_reset_leaves_the_release_to_the_thread -- --test-threads=1: 1 passed, 0 failed, 0 ignored.
  • ... a_release_inside_a_list_reset_is_left_to_the_thread: 1 passed, 0 failed, 0 ignored.
  • ... a_seal_in_flight_counts_as_held_and_is_the_only_one: 1 passed, 0 failed, 0 ignored.
  • ... a_batch_whose_signals_failed_goes_back_in_order: 1 passed, 0 failed, 0 ignored.
  • ... submit_reservation_keeps_pre_reset_attribution_across_queues: 1 passed, 0 failed, 0 ignored.

What this adds
All five focused tests pass on a second NVIDIA adapter and driver. They cover the release left to the late-release thread during a list Reset, the in-flight seal and its put-back path, and the queue attribution assertion. The thread's runs are on RTX 4090 with a retail title; this is a synthetic 5070 Ti datapoint and I did not reproduce the DRED deadlock or the 556 s freeze.

Not tested
A retail title, a paired smoke run, the full workspace suite here, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data.

AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - ran the commands above on this machine and wrote this report; no game data was used.

@andrewDoing

Copy link
Copy Markdown
Contributor

I checked the release-lock boundary from the texture-download report with a native DIRECT queue on RTX 5070. The fixture held the queue's submit lease and waited until the production drain_known(true) was blocked in that lease's waiter count. While the signal waited, the lease owner tried to acquire HELD and append a second deferred heap release. The lock probe was bounded so both sides could clean up.

  • Main 1bd9cee1: HELD was busy in all three processes. The second release could not enqueue while the signal waited. The original batch sealed after the lease was released.
  • d783592c applied to the same main base (0e0f5bdf): the second release enqueued in all three processes while the signal was still waiting. After the signal was submitted, the first heap was in the sealed batch and the second was still in the open batch. Both drained after GPU completion.

XCL_ADAPTER=5070 cargo test --release --offline --locked -p xcl --lib queued_seal_allows_another_release_during_its_signal_wait -- --test-threads=1 --nocapture. One expected assertion failure per main process, one pass per PR process, zero ignored and zero explicit skips. Windows 11 26300.10075, RTX 5070 12 GB (616.92), Ryzen 7 5700X3D, rustc 1.100.0 MSVC. The test uses synthetic heaps and a native fence to check the lock boundary and batch ordering. Retail behavior, stall duration, and the separate list-Reset route remain unmeasured here.

OpenAI Codex with GPT-6.2 Sol wrote and ran the fixture.

@tiagonleal

tiagonleal commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

merge-check
base: 5b0d5fa
head: d783592
merge: clean
build: cargo build --workspace -> ok (also cargo build --release -p xcl)
tests: cargo test --workspace --no-fail-fast -j 8 -- --test-threads=4 -> 2780 passed, 0 failed, 49 ignored; SKIPPED: 27 lines (22 no wave64, 3 f16/f32 cases refused, 2 no heap windows), the same as on the base; failing: none. Base alone on this PC: 2776 passed, 0 failed, 49 ignored. The eight late_release tests pass, the new ones included.
review: whole diff read (+228/-35, three files). The signal is now made with HELD unlocked (begin_seal / end_seal around seal.signal() in drain_known), so no path signals a queue while holding HELD: that removes the HELD side of the cycle everywhere. The D3D12Core side is removed for list Resets only: InListReset::enter() is called in two places, alloc_pool::reset_list and the list Reset in real.rs. A pinned release that the driver makes inside another native call (an allocator Reset, a Close) still goes through hold -> drain_known(true) -> the queue's lease on the calling thread. I have no report or stack of that path hanging, so it is a note for a follow-up. Smaller: sealing is set in begin_seal and cleared only in end_seal; if seal.signal() panics it stays set and nothing seals again in that process (a drop guard would cover it). hold_inside_a_list_reset_leaves_the_release_to_the_thread works on the global HELD with a poll; it passed here in the one suite run. Not tested: I did not reproduce the freeze itself on the base, so this run shows no regression and does not show the fix working.
performance: one thread-local read per hold, one guard per list Reset, one more HELD lock per drain. Measured with scripts/smoke.ps1, 60 s of a retail title, release: 1673 frames and 15341 MB peak commit on the merged tree against 1667 and 1685 frames, 15247 and 15488 MB on the base (run before and after). No device removal, no crash.
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB (617.42), Ryzen 7 9800X3D, 32 GB, Windows 11 26300, rustc 1.100.0 / Claude Code (Claude Fable 5.2 ran the build, suite and smokes and wrote this; Claude Opus 5.5 read the diff first, and I checked its two main points in the merged source)

  • Tiago

@github-actions github-actions Bot added needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU labels Nov 29, 2026
@github-actions github-actions Bot added needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) and removed needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU labels Nov 29, 2026
@Parakeet-Wheat

Parakeet-Wheat commented Nov 30, 2026 •

Copy link
Copy Markdown

merge-check
base: cb80246
head: d783592
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2813 passed, 1 failed, 51 ignored; SKIPPED: 29 (22 no wave64, 3 wave32 per-lane form refused (#1426), 2 no heap windows, 1 driver cache needs Developer Mode, 1 no GPU_UPLOAD heaps); failing: hle::d3d12x::standin::tests::concurrent_shell_miss_reuses_winner_and_releases_loser_pipeline fails on the base alone too (3 of 3 runs on the base, 3 of 3 on the merge)
review: No blocking finding; whole diff read. native_queue_signal takes the queue's submit lease through queue_submit::with (real.rs:1192). On main, drain_known makes these signals with HELD locked; with this PR, it makes them with HELD unlocked. The four new tests and the guard assertions in alloc_pool pass on the merge. We could not mutation-test them: they call functions this PR adds, so the tree with the fix reverted does not compile. One race changes. A pinned hold that arrives during another thread's seal gets no seal of its own: begin_seal returns None while sealing is set. Its drain_known(false) calls in the next 300 µs (IDLE_WAIT) do not seal either. The seal in flight set last_seal when it began, and SEAL_EVERY is 10 ms. So the release goes to the late-release thread. On main, that caller waited for HELD and then sealed its own batch at once. This costs latency in that race, not a deadlock, and no test covers it. We did not run the XCL_DRED=1 start-up case, because it needs the game loaded.
performance: Boot-only smoke pair, 60 s, no input, release, XCL_NETWORK=0: base 1520 frames, peak commit 15031 MB; merge 1638 frames, peak commit 15402 MB. Both runs show 0 device removals and 0 crashes. Default path: each list Reset sets and clears one thread-local, and each drain_known takes HELD once more (twice more when it seals).
verdict: safe to merge (the deadlock fix is sound in the code, the suite and the smoke pair show no regression on our RTX 3070)
hardware / tool and model: RTX 3070 8 GB (610.88), AMD Ryzen 5 5600X, Windows 11 Home 26300, Rust 1.95.0, debug (smoke in release) / Claude Code, Claude Opus 5.5 (merge, build, suite, reruns, smoke and review)

@github-actions github-actions Bot added ready-to-merge Has 2 independent safe merge-checks on current head (#3041) and removed needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU labels Nov 30, 2026
@Prime1997
Prime1997 merged commit 5b025c5 into xcl-dev:main Nov 30, 2026
5 checks passed
dudenudem pushed a commit to dudenudem/xcl that referenced this pull request Nov 30, 2026
Keeps upstream's DXIL IR cuts (xcl-dev#3500-xcl-dev#3503/xcl-dev#3495-xcl-dev#3499: sampler waterfall,
descriptor windows, split-wave64 mask exchange, per-lane exec, direct PS
masks, quad shuffles, packed/normalized buffer decode, commit-aware
compiles), xcl-dev#3269 fixed-point optimizer, xcl-dev#3154 compact compute prologue,
xcl-dev#2123 split atomic add, xcl-dev#2070 offline 64 MB stacks, xcl-dev#3442 split-whole,
xcl-dev#1319 root-constant bounds, xcl-dev#3356 late Reset releases, xcl-dev#1322 empty-BVH/NaN
rays, xcl-dev#2753 3-D texture sizing, XMA/VFS/TLS/loader fixes.

Resolutions:
- real.rs: union of T-156 res_release pinning with upstream's InListReset
  and abi_rs_for_stages; dropped upstream's warm_graphics (T-095 removed
  that path); kept ComputeBuild::IndirectChain for our split-chain variant.
- dispatch_chain.rs: kept our IndirectBuild split-chain architecture (the
  T-095 port removed the preload/whole-worker machinery upstream builds
  on); ported upstream's huge-PSO refusal log.
- pso_async.rs: took upstream's commit-aware build_pieces/build_scoped and
  WORKER_STACK, removed the preload/backlog subsystem our port does not
  have (and its tests), kept our profile_is_series_s.
- late_release.rs: took upstream's Dead enum, Busy/InListReset and
  hold_pipeline/hold_heap/hold_unmap, with our vram release path (no
  recycle pool).
- emit.rs: upstream's additions moved into emit/memory.rs (ADD_TID_ENABLE),
  emit/exp.rs (misc-vector layer/viewport), emit/mimg.rs (SampleCmp with
  bias gradients), emit/valu.rs (abs/neg on shift/align), emit.rs out_struct.
- bind.rs: root-constant bounds clamp + its test; kept our bool
  execute_indirect API.
- bvh.rs: our grow/tri_ret/watertight model plus upstream's empty-root
  bounds and NaN-ray refusal.
- kernel.rs: upstream's mask/waterfall/rodata cuts plus our lanes_upper.
- shaders.rs: upstream's worker stack helpers and mesh/GS precompile paths,
  with our PipelineJob record identity.
- eh.rs: upstream's CLWB TF guard + test, our termination test.
- lower.rs test: 574bda4 makes wave32 SALU words compute S_WQM without
  quad lanes; assert that and keep the wave64 refusal.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:memory Virtual/physical memory, arenas, VRAM budget, UMA gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) ready-to-merge Has 2 independent safe merge-checks on current head (#3041)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants