Repository navigation
D3D12.X: leave releases made inside a list Reset to the late-release thread - #3356
Conversation
…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>
|
GTA 6 test report (part of #505): the same lock cycle in a second place, and this PR clears it In GTA 6 (with
This PR's
(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: 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. |
|
Thanks for the run and the stacks. On the three
I'll open a separate test-only PR against main for the test lock. Until then, On the second path (texture downloads → (Checked and written with Claude Code, Claude Opus 5.5.) |
CharlyRien
left a comment
There was a problem hiding this comment.
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
HELDinlate_release::hold(reached fromres_release); - the thread in
drain_knownholdingHELDand 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.
|
Ran the late-release and list-Reset tests at System
Results
What this adds Not tested 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. |
|
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
OpenAI Codex with GPT-6.2 Sol wrote and ran the fixture. |
|
merge-check
|
|
merge-check |
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.
With
XCL_DRED=1a retail title deadlocks during start-up onmain(0 presents and 0 submits from then on). Two threads wait on each other:queue_submit.rs, readback after execute) and waits in D3D12Core'sCCommandAllocator::Resetfor the allocator lock;Reset, which holds that lock. There D3D12Core releases DRED's breadcrumb buffer; the release goes throughlate_release::hold, whosedrain_knownsignals 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_DREDthe title does not stall. The cycle exists since the per-queue submit lease (7a37be8).The same
drain_knownsplit also removes a second cycle, reported in testing on this PR (comment of 2026-11-29: a freeze at ~556 s onmain, 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 forHELD, whilexcl-fences, releasing a finished download's readback buffer, holdsHELDindrain_knownand waits for that queue's submit lease. With the signals made outsideHELD(begin_seal/end_seal), no caller ofdrain_knownwaits 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 listResetinalloc_pool::reset_listand thecl_resethook.late_release.rs: while the guard is set,holdleaves the release to the late-release thread.Held::drainis split so no lease is taken withHELDlocked (begin_sealunderHELD, the signals outside it,end_sealrelocks 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 pinnedholdwaits for its release.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 inalloc_pool'ssubmit_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
cargo test --workspace -- --test-threads=4: 2622 passed, 0 failed, 49 ignored; 27SKIPPEDlines (wave64, f16 refusals, heap windows). One earlier run of the same command stopped at 2479 passed, 4 failed, 29 ignored in thexcllib: the knownshaders::pipeline_library/warm_libraryrace, which also fails onmaind8bd9a3 (4 of 12cargo test -p xcl --libruns there; 0 of 12 on this commit).XCL_DRED=1(150 s, no presses):maind8bd9a3 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
Both with
XCL_PREPARE=0and a scripted A press at 16 s, 60 s, after an untimed warm-up run of each binary.Not tested
Resethook (reset_pc_allocator) and a list's finalRelease. I did not see them deadlock; they would get the same guard in a follow-up if they do.late_release.rs) and D3D12.X: a native host's last Release only queues the resource #2445 / D3D12.X: serialize allocator and list resets #1721 will need textual rebases on top of this; I checked no semantic conflict with D3D12.X: a native host's last Release only queues the resource #2445.AI use
🤖 Generated with Claude Code