D3D12.X: replacing the sparse state deadlocks when the old state still holds placed buffers #344
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl#344
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Kalmarv on GitHub · 2026-11-24 00:03 UTC · original
d3d12x::sparse::initinstalls its new state with*STATE.lock().unwrap() = Some(s);(main3516080,crates/xcl/src/hle/d3d12x/sparse.rs:549). The assignment drops the oldStatewhile the guard is still held. Dropping it releases its D3D12 resources. A placed buffer's release goes through XCL's hookreal::res_release(real.rs:1547), which callssparse::forget_buffer(real.rs:1563), andforget_bufferlocksSTATEagain (sparse.rs:1472–1473).std::sync::Mutexisn't reentrant, so the thread waits for itself forever, and every later user ofSTATEwaits behind it.When it happens
sparse::initruns a second time in one process: everyreal::init()reaches it (real.rs:348), and several GPU tests callreal::init();forget_buffer.So it depends on the order of the tests and on timing.
Seen
A
cargo test --workspace -- --test-threads=4run of #253 at12328ac(on main9ab7d76) hung until the GPU queue killed it at 3600 s. That PR's own test (eh::tests::thread_dumps_while_threads_run_and_exit) prints in-process thread dumps, and its last dump shows the state:gpu::recomp::tests::gpu_uma_import_check_at_init(it callsreal::init()) is in the middle ofdrop_glue<Option<sparse::State>>→drop_glue<sparse::State>→ … →windows_core::IUnknown::drop→real::res_release→sparse::forget_buffer→Mutex::lock_contended.gpu_sparse_vram_descriptors_buffers_and_xmemwaits insparse::before_execute→Mutex::lock_contended.gpu_typed_buffer_loads_and_storeswaits inres_release→forget_buffer→Mutex::lock_contended.Those three, and
gpu_unified_memory_arena(which started after the last dump, so its stack isn't known), were still listed as "running for over 60 seconds" when the run was killed. Symbols come from the PDB of that exact build. The other suite runs on this machine today did not hang, so it is rare.Plan
sparse::init, take the old state out and drop it after the guard:let old = std::mem::replace(&mut *STATE.lock().unwrap(), Some(s)); drop(old);. Its resources' releases then find the new state, where they aren't recorded, and return.real::init()twice, it should hang on main (a watchdog or a thread with a timeout turns that into a failure) and pass with the change.Tested
12328ac. The stack is from that run's own in-process dump, symbolised with the build's PDB.3516080,sparse.rs:549still assigns under the guard, andforget_bufferstill locksSTATE.Not tested
sparse::inittwice, for example by creating a second device.Searched before writing: no open issue or PR mentions
forget_buffer, and no open PR head changesforget_bufferor theSTATEassignment. #262 is a different deadlock (a cross-queue wait for CPU-write uploads).AI use
🤖 Claude Opus 5.5