D3D12.X: PAGES / COPY_SCRATCH lock-order deadlock: flush_zero_tiles runs a command list while holding PAGES #3069

Open
opened 2026-11-27 19:54:19 +00:00 by kleborgn · 1 comment
kleborgn commented 2026-11-27 19:54:19 +00:00 (Migrated from github.com)
Contributor

Imported from ivall/xcl. Originally posted by kleborgn on 2026-11-27T19:54:19Z.


Setup: AMD Radeon RX 7900 XTX 24 GB (driver 32.0.32029.2010), Ryzen 9 7950X3D, 31 GB RAM, Windows 11 Pro 26300, Rust 1.100.0, release, DXC 1.8.2505.32. Tree: amd-dev 7c795f5 + #3024 (b7fc3b4) + #3025 (d818f46) applied as patches. XCL_NETWORK=0 throughout.

What happens: the title stops presenting, the xcl-activity thread stops logging (no activity / profile / memory
lines), nothing is building, audio keeps playing. No device removal, no crash. It is a race: it hit 1 of 7 runs of the same exe.

Evidence: I attached a read-only debugger (cdb -pv) to the stalled game process and printed every thread's stack. Three
threads are on one chain (function names only; the build is amd-dev 7c795f5 + #3024 + #3025):

thread A (title texture refresh):
  title_textures::refresh -> refresh_once -> upload_all -> vram::before_execute        <- holds PAGES
  -> vram::Pages::flush_zero_tiles -> title_textures::own_work
  -> ID3D12GraphicsCommandList::Reset -> real::cl_reset -> list_x::on_pc_reset
  -> list_x::reset_copy_scratch -> Mutex::lock_contended                                <- waits for COPY_SCRATCH

thread B (title copy):
  list_x::copy_texture_region_x -> format_alias::try_copy_texture_region
  -> copy_one_subresource_through_buffer -> list_x::acquire_scratch_for_copy
  -> CopyScratchCache::acquire                                                           <- holds COPY_SCRATCH
  -> real::res_release -> late_release::hold/enqueue -> late_release::drain_known
  -> vram::recycle_ready -> Mutex<BTreeMap<usize, Option<Pages>>>::lock (PAGES)        <- waits for PAGES

thread C (xcl-activity): vram::page_bytes -> PAGES.lock()                               <- also waits for PAGES

In the source: COPY_SCRATCH is one global Mutex<CopyScratchCache> (list_x.rs). acquire_scratch_for_copy locks it and
CopyScratchCache::acquire releases a resource while holding it; reset_copy_scratch locks it again. flush_zero_tiles
(added by d625b20, only on amd-dev, main has none) runs a command list from before_execute, which holds PAGES
(Pages::flush_zero_tiles is called on &mut Pages under PAGES.lock()).

Earlier sighting: on amd-dev b5c0275 a stalled run showed a different stack in the same area (flush_zero_tiles ->
own_work -> q_execute_command_lists -> present::note_execute -> late_release::drain_known -> vram::recycle_ready,
all under PAGES). That is not the cycle above.

What I have: one occurrence, in the run described below, and the stacks above. What I do not have: a way to trigger it on
demand, a second occurrence, or a fix. I am not proposing one in this issue.

Run: the setup line above. XCL_DIRECT_DXIL=1 XCL_PIPELINE_MAX_KB=1500 XCL_SPLIT_WAVE64=1 XCL_RT_GATE=auto XCL_DRED=1 XCL_FRAME_DUMP=45, A pressed every 6 s. The activity lines stopped at 494 s.

AI use: Claude Code, Claude Sonnet 5.5 ran the runs, read the stacks and wrote this.

<!-- greyfinch-sync:ivall/xcl:issue:6653558409 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/3069). Originally posted by [kleborgn](https://github.com/kleborgn) on 2026-11-27T19:54:19Z. --- **Setup:** AMD Radeon RX 7900 XTX 24 GB (driver 32.0.32029.2010), Ryzen 9 7950X3D, 31 GB RAM, Windows 11 Pro 26300, Rust 1.100.0, release, DXC 1.8.2505.32. Tree: `amd-dev` `7c795f5` + #3024 (`b7fc3b4`) + #3025 (`d818f46`) applied as patches. `XCL_NETWORK=0` throughout. **What happens:** the title stops presenting, the `xcl-activity` thread stops logging (no `activity` / `profile` / `memory` lines), nothing is building, audio keeps playing. No device removal, no crash. It is a race: it hit 1 of 7 runs of the same exe. **Evidence:** I attached a read-only debugger (`cdb -pv`) to the stalled game process and printed every thread's stack. Three threads are on one chain (function names only; the build is `amd-dev` `7c795f5` + #3024 + #3025): ``` thread A (title texture refresh): title_textures::refresh -> refresh_once -> upload_all -> vram::before_execute <- holds PAGES -> vram::Pages::flush_zero_tiles -> title_textures::own_work -> ID3D12GraphicsCommandList::Reset -> real::cl_reset -> list_x::on_pc_reset -> list_x::reset_copy_scratch -> Mutex::lock_contended <- waits for COPY_SCRATCH thread B (title copy): list_x::copy_texture_region_x -> format_alias::try_copy_texture_region -> copy_one_subresource_through_buffer -> list_x::acquire_scratch_for_copy -> CopyScratchCache::acquire <- holds COPY_SCRATCH -> real::res_release -> late_release::hold/enqueue -> late_release::drain_known -> vram::recycle_ready -> Mutex<BTreeMap<usize, Option<Pages>>>::lock (PAGES) <- waits for PAGES thread C (xcl-activity): vram::page_bytes -> PAGES.lock() <- also waits for PAGES ``` In the source: `COPY_SCRATCH` is one global `Mutex<CopyScratchCache>` (`list_x.rs`). `acquire_scratch_for_copy` locks it and `CopyScratchCache::acquire` releases a resource while holding it; `reset_copy_scratch` locks it again. `flush_zero_tiles` (added by `d625b20`, only on `amd-dev`, `main` has none) runs a command list from `before_execute`, which holds `PAGES` (`Pages::flush_zero_tiles` is called on `&mut Pages` under `PAGES.lock()`). **Earlier sighting:** on `amd-dev` `b5c0275` a stalled run showed a different stack in the same area (`flush_zero_tiles` -> `own_work` -> `q_execute_command_lists` -> `present::note_execute` -> `late_release::drain_known` -> `vram::recycle_ready`, all under `PAGES`). That is not the cycle above. **What I have:** one occurrence, in the run described below, and the stacks above. **What I do not have:** a way to trigger it on demand, a second occurrence, or a fix. I am not proposing one in this issue. **Run:** the setup line above. `XCL_DIRECT_DXIL=1 XCL_PIPELINE_MAX_KB=1500 XCL_SPLIT_WAVE64=1 XCL_RT_GATE=auto XCL_DRED=1 XCL_FRAME_DUMP=45`, A pressed every 6 s. The activity lines stopped at 494 s. AI use: Claude Code, Claude Sonnet 5.5 ran the runs, read the stacks and wrote this.
thehollowedone commented 2026-11-28 02:53:46 +00:00 (Migrated from github.com)
Author
Contributor

Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-28T02:53:46Z.


The reported two-thread cycle has a narrower entry point than flush_zero_tiles itself. On amd-dev at 7c795f5, the zero-fill list resets inside title_textures::own_work while PAGES is held. A successful PC Reset still calls the title-list reset hook, which enters COPY_SCRATCH through reset_copy_scratch. In the other direction, CopyScratchCache::acquire can drop a replaced resource while holding COPY_SCRATCH; its COM release can drain into vram::recycle_ready, which waits for PAGES. That matches the two stacks in this issue. #2703 bypasses the title hooks for internal ExecuteCommandLists, but does not cover Reset.

For this Reset edge, I suggest skipping the title-list reset hook during XCL's own work. Keep the native Reset, vtable preservation, HRESULT handling and DRED bookkeeping. The ZeroRing list records native buffer copies and barriers; it has no title-list scratch or binding state to clear.

Candidate one-line guard
--- a/crates/xcl/src/hle/d3d12x/real.rs
+++ b/crates/xcl/src/hle/d3d12x/real.rs
@@
     preserve_vtable(this, ext);
     if hr >= 0 {
-        super::list_x::on_pc_reset(this);
+        if !super::title_textures::is_own_work() { super::list_x::on_pc_reset(this); }
         super::dred::reset(this);

A focused regression can use the existing fake adopted-list pattern in real::queue_tests and the test-only dispatch_chain::seed_shared_for_test / has_shared_for_test helpers: seed state for the fake list, call successful native Reset inside own_work, and verify native Reset ran while the title-list reset hook did not clear that state. A normal successful Reset should clear it; a failed Reset should leave it. A repeated run of the reported AMD setup would then check the actual hang.

This guard addresses the observed PAGES -> COPY_SCRATCH Reset edge. COM releases elsewhere under COPY_SCRATCH and other internal calls made while holding PAGES still need a separate lock-order audit. I checked the source path; I have not run this candidate or a title test.

AI use: Codex (GPT-6.2 Sol) traced the path and wrote this note; Codex (GPT-6.2 Astra) independently checked the lock and lifecycle edges.

<!-- greyfinch-sync:ivall/xcl:comment:7232662778 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/3069#issuecomment-7232662778). Originally posted by [thehollowedone](https://github.com/thehollowedone) on 2026-11-28T02:53:46Z. --- The reported two-thread cycle has a narrower entry point than `flush_zero_tiles` itself. On `amd-dev` at `7c795f5`, [the zero-fill list](https://github.com/xcl-dev/xcl/blob/7c795f5/crates/xcl/src/hle/d3d12x/vram.rs#L1438-L1476) resets inside `title_textures::own_work` while `PAGES` is held. A successful PC Reset still calls [the title-list reset hook](https://github.com/xcl-dev/xcl/blob/7c795f5/crates/xcl/src/hle/d3d12x/real.rs#L3949-L3965), which enters `COPY_SCRATCH` through `reset_copy_scratch`. In the other direction, `CopyScratchCache::acquire` can drop a replaced resource while holding `COPY_SCRATCH`; its COM release can drain into `vram::recycle_ready`, which waits for `PAGES`. That matches the two stacks in this issue. [#2703](https://github.com/xcl-dev/xcl/pull/2703) bypasses the title hooks for internal `ExecuteCommandLists`, but does not cover Reset. For this Reset edge, I suggest skipping the title-list reset hook during XCL's own work. Keep the native Reset, vtable preservation, HRESULT handling and DRED bookkeeping. The ZeroRing list records native buffer copies and barriers; it has no title-list scratch or binding state to clear. <details><summary>Candidate one-line guard</summary> ```diff --- a/crates/xcl/src/hle/d3d12x/real.rs +++ b/crates/xcl/src/hle/d3d12x/real.rs @@ preserve_vtable(this, ext); if hr >= 0 { - super::list_x::on_pc_reset(this); + if !super::title_textures::is_own_work() { super::list_x::on_pc_reset(this); } super::dred::reset(this); ``` </details> A focused regression can use the existing fake adopted-list pattern in `real::queue_tests` and the test-only `dispatch_chain::seed_shared_for_test` / `has_shared_for_test` helpers: seed state for the fake list, call successful native Reset inside `own_work`, and verify native Reset ran while the title-list reset hook did not clear that state. A normal successful Reset should clear it; a failed Reset should leave it. A repeated run of the reported AMD setup would then check the actual hang. This guard addresses the observed `PAGES -> COPY_SCRATCH` Reset edge. COM releases elsewhere under `COPY_SCRATCH` and other internal calls made while holding `PAGES` still need a separate lock-order audit. I checked the source path; I have not run this candidate or a title test. AI use: Codex (GPT-6.2 Sol) traced the path and wrote this note; Codex (GPT-6.2 Astra) independently checked the lock and lifecycle edges.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl#3069
No description provided.