D3D12.X: a placed buffer's last Release does not wait for the sparse lock #1478
No reviewers
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!1478
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1478/head"
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?
@jessenic on GitHub · 2026-11-24 16:41 UTC · original
jessenic:fix/sparse-forget-off-lock→main· +148 −13 · 1 files · 1 commits · closed without mergingA placed buffer's last
Releaseno longer waits for the sparse state's lock. In a retail title's story load, the frame-loop thread blocked there behind threads that held the lock across GPU waits and a tile mapping on a stalled sparse queue. Its heartbeat stopped and the title's own stall check ended the run (+0x23cf683). Measured and symbolised in #505 (comment). Part of #505.What is in it
crates/xcl/src/hle/d3d12x/sparse.rs, one commit:forget_buffer(called byreal::res_releasefor every resource) queues the pointer on a newFORGETlist and only triesSTATE. If it gets the lock, it applies the queue, or clears it when there is no sparse state.State::forget_pending→forget_all, the old body unchanged):before_execute(every title submit);take_tile, before a new pool is made;place_buffer, at the start and again right before the new buffer is recorded, becausebuffersis keyed by the resource's address.STATE→FORGET;forget_bufferholds neither while it takes the other.Releasemade while the same thread already holdsSTATE(from inside a D3D12 call under the lock) now queues instead of deadlocking.a_released_buffer_is_forgotten_while_the_state_is_lockedholdsSTATEand callsforget_bufferon another thread. Onmainit fails after its 5 s.a_forgotten_buffer_gives_back_only_its_unused_tilescovers which tiles a forgotten buffer gives back, and a release queued while the lock is held being applied by the next holder. It uses the real GPU, or WARP if there is none.Related open PRs
forget_buffer, to release pins outside the driver callback. It conflicts withmainand keeps the blocking lock.STATE. It complements this one: that PR frees the holder of the lock, and this one frees the waiter.Tested
cargo test --workspace -- --test-threads=4onb3fb51c(the same tree as the head792c69a, which only rewords the commit message): 772 passed, 0 failed, 41 ignored.gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask: no wave64,gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware: no wave64.scripts/smoke.ps1, 60 s, no input (the start screen; every resourceReleasegoes throughforget_bufferthere too), againstmainc160d86. Blocks below.Regression run
Not tested
XCL_PSO_WAIT_MS=50and thread dumps through the story load) has not been rerun with this change, so whether the frame loop now gets further there is not measured. WithoutXCL_PSO_WAIT_MSthe title stops earlier for another reason (pipeline builds; #1288), and the smoke runs stay on the start screen, short of the story load.STATE, so still able to block (separate changes):sparse::freefromres_releasefor a resource that owns its sparse unified-memory block (decommittedtakesSTATE; found in review by @GonZiin, who measured it waiting with a probe). Deferring it needs the reservation kept out of reuse until the decommit is done, so it is left for its own PR;before_execute/mapped_rangeson every submit;UpdateTileMappingsinmap_tiles.res_release, the object is released beforeforget_bufferruns. So a buffer placed at the same address in between can still be unpinned by the late forget, as onmain.AI use
🤖 Generated with Claude Code
github-bot referenced this pull request2026-11-26 04:59:09 +00:00
@futurepro62 on GitHub · 2026-11-24 16:59 UTC · original · edited 2026-11-24 17:15 UTC
Full-suite run, since this PR has no test report yet. Tested exact head
b3fb51c(on its baseb7aa9f3).Tested
cargo build --workspace, thenXCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 772 passed, 0 failed, 41 ignored. SKIPPED (no wave64):gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware.a_released_buffer_is_forgotten_while_the_state_is_locked,a_forgotten_buffer_gives_back_only_its_unused_tiles.XCL_ADAPTER=radeon),cargo test --workspace -- --test-threads=4: 772 passed, 0 failed, 41 ignored, no skips.Not tested
AI use
@eizispark on GitHub · 2026-11-24 17:18 UTC · original
Hardware test report — commit
b3fb51cChecked
b3fb51cfbde3f95947c4d7c59cf6fe278d2ba11f(baseb7aa9f3bd212088e0d927439284dc5ed325ce3c7; verified clean merge with currentmain9e3831e1f570d3646e53ab753b19ec07eb8f1485): pass.Tested
rustc 1.100.0 (0ef1bc386 2026-11-09), release + test profilecargo test --workspace --no-fail-fast -- --test-threads=4:772 passed, 0 failed, 41 ignored(GPU tests skipped on this adapter:none), includinghle::d3d12x::sparse::tests::a_released_buffer_is_forgotten_while_the_state_is_locked,hle::d3d12x::sparse::tests::a_forgotten_buffer_gives_back_only_its_unused_tiles, and both wave64 hardware tests (gpu_wave32_program_in_wave64_hardwareandgpu_geometry_wave32_prefix_count_over_a_mask)Regression run
main(b7aa9f3):PR (
b3fb51c):Not tested
STATEis held across a stalled GPU wait,XCL_SAMPLE_*AI use
@KaliemSB on GitHub · 2026-11-24 18:01 UTC · original
Test report: RTX 4060 (NVIDIA, 32-lane),
XCL_DRED=1:mainstops presenting at ~6 s in both rounds (4 and 3 frames in 60 s); this PR runs normally (296 and 277)Tested
XCL_DXC_DIR).b3fb51candmain9e3831e, release builds of each. The newer commits onmainsince this PR's base don't touchsparse.rs,real.rsoralloc_pool.rs.scripts/smoke.ps1 -Game <retail title> -Seconds 60withXCL_DRED=1, alternatingmain/ PR, two rounds. About 14.7 GB of commit free at start in every run (under the 17 GB check, so the 512 MB coherent window), the same on both sides.main, round 1main, round 2main(b7aa9f3) on this machine, withXCL_DRED=1and the older driver 596.49, had a thread dump symbolised with the build's PDB. It showed the cycle this PR describes:q_execute_command_lists→title_textures::refresh→sparse::before_execute→State::upload_dirty→State::begin_slot→ID3D12CommandAllocator::Reset, waiting in D3D12Core with the sparse-state lock held;list_x::reset_x→alloc_pool::reset_list→ D3D12Core →real::res_release→sparse::forget_buffer, waiting for that lock;XMemMapPhysicalPagesScatter→sparse::committed, also waiting for it.XCL_DRED, earlier the same day (mainb7aa9f3268 frames, this PR 311), no device removal and no crash on either.cargo test --workspace -- --test-threads=4onb3fb51c(debug): 772 passed, 0 failed, 41 ignored. SKIPPED:gpu_geometry_wave32_prefix_count_over_a_maskandgpu_wave32_program_in_wave64_hardware(no wave64). Both of this PR's tests (a_released_buffer_is_forgotten_while_the_state_is_locked,a_forgotten_buffer_gives_back_only_its_unused_tiles) ran on the RTX 4060 and passed.Not tested: no thread dump of the frozen
mainruns on this commit, and nothing past 60 s with DRED.AI use: Claude Code (Claude Opus 5.5) ran the builds, tests and runs, symbolised the thread dump and wrote this report. The runs are from the machine named.
xcl-smoke blocks (main, then this PR; round 1)
xcl-smoke blocks (round 2)
@DavidM1911 on GitHub · 2026-11-24 18:53 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodifiedmain.)Thanks!
@jessenic on GitHub · 2026-11-24 19:11 UTC · original
@GonZiin thanks, you're right, and thanks for the probe. The title claimed more than the change does:
sparse::free→decommittedfromres_release, for a resource that owns its sparse unified-memory block, still takesSTATE. I narrowed the claim rather than widening the change:792c69a; same tree asb3fb51c, only the message changed). The commit message and Not tested name the owned-block path and credit your finding.mainc160d86(60 s, both clean, 1646 / 1643 frames), in the description.AI use: Claude Code (Claude Opus 5.5) made the change and wrote this reply.
@alexodee on GitHub · 2026-11-24 19:41 UTC · original · edited 2026-11-24 19:47 UTC
This also fixes a second path into the same deadlock: with
XCL_DRED=1, the retail title (1.0.2.1) hung at 0 FPS on both starts I tried onc160d86(RTX 3070 Ti Laptop, driver 596.36, Windows 11 26200). WithoutXCL_DREDit ran at 30 FPS.Thread dump (
XCL_THREAD_DUMP_AT=60,120, symbolised with the release PDB):I wrote the same change locally before finding this PR (
forget_bufferonly triesSTATEand queues the pointer otherwise; the queue is applied inbefore_executeand inplace_bufferbefore the new buffer is recorded). With it, the sameXCL_DRED=1run no longer hangs: it presented at least 2,400 frames (about 30 fps), then ended with a device removal at 112 s, reported in #675. I did not check which screen it had reached, and this is one run.So, as a data point: the same approach removed the
XCL_DRED=1hang here. I tested my own version of the change, not this PR's commit.Edited: corrected claims I had not verified (every start, story load, GPU page fault). Analysis and text written with AI assistance.
@throny on GitHub · 2026-11-24 20:24 UTC · original
Two contributors checked independently and found that #1697 solves the same problem (for #505) in a different way: #1607, group D42. You may want to compare them with the other author and agree on one, or say in the PR why both are needed.
This is a hint, not a request from the maintainers; nobody from the project has adopted #1607 so far.
AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.
@jessenic on GitHub · 2026-11-24 20:34 UTC · original
Closing in favour of #1697 (@shzyjbr06-dev), which covers everything this PR does and more: the same non-blocking
forget_bufferwith the queue drained inbefore_executeandplace_buffer, plus per-buffer generation IDs (which also close the address-reuse race noted in @GonZiin's review), a lock-freepool_bytes, andCreateReservedResource/CreateHeapoutsideSTATE. Thanks for the hint (#1607, D42).What was measured on this PR, in case it helps #1697's review, since the mechanism is the same:
XCL_DRED=1startup deadlock fixed: @KaliemSB (RTX 4060:main4 and 3 frames in 60 s, this PR 296 and 277) and @alexodee (RTX 3070 Ti Laptop,c160d86: 0 FPS on every start without it).XCL_PSO_WAIT_MS=50, the frame-loop thread blocked inforget_bufferbehindreadback_now/map_tilesholdingSTATE.Thanks everyone who tested and reviewed.
AI use: Claude Code (Claude Opus 5.5) compared the two PRs and wrote this comment.
@DavidM1911 on GitHub · 2026-11-26 05:27 UTC · original
Re-verification on RTX 3060 Ti (Windows 11): still a merge conflict with current
mainon the new head — needs another rebase before it can be tested.@GonZiin on GitHub · 2026-11-24 17:48 UTC · original · reviewed
The final Release can still wait for
STATEwhen the resource owns its sparse UMA allocation.place_console_buffer_sparserecords that resource withowned = true. After the new non-blockingforget_buffer,res_releaseremoves the entry fromUMA_BUFFERSand callssparse::free→decommitted→STATE.lock(). This is a separate lock acquisition from the one this PR removes.Tested
b3fb51cfbde3f95947c4d7c59cf6fe278d2ba11f, Windows 11 Pro build 26300, Ryzen 7 7800X3D, Rust 1.100.0 MSVC, debug. UsedXCL_LATE_RELEASE=0andXCL_COHERENT_MB=16in an isolated checkout.cargo test -p xcl --lib a_released_buffer_is_forgotten_while_the_state_is_locked -- --nocapture --test-threads=1passed (1 passed, 0 failed, 0 ignored).cargo test -p xcl --lib review_last_release_of_owned_sparse_buffer_does_not_wait_for_state -- --nocapture --test-threads=1ran a temporary probe using the actualres_releasewrapper, a mock COM last-release callback, and a real sparse UMA allocation. WithSTATEheld, the untracked control returned. The owned sparse release timed out after 400 ms and finished once the lock was released (0 passed, 1 failed, 0 ignored).Please narrow the claim to the placed-buffer bookkeeping, or cover the owned sparse path too. If decommit is deferred, the reservation must stay unavailable for reuse until decommit finishes.
Not tested
Retail title behavior and the default late-release setting.
AI use
Codex (
gpt-6.2-sol) traced the call path, wrote and ran the probe, and drafted this review.Pull request closed