D3D12.X: decommit released sparse blocks outside the driver callback #789
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!789
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-789"
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?
@badoomtch on GitHub · 2026-11-24 05:26 UTC · original
badoomtch:fix/sparse-release-lock→main· +127 −22 · 2 files · 1 commits · openThis is what is left of #789 after #1981.
#789 had two halves. #1981 fixed the first one: a placed buffer's last Release (
forget_buffer)no longer waits for the sparse state's lock (
STATE). This PR is the second half.res_releaseandmem_heap_releasegive back a block that XCL took withsparse::alloc. Theycalled
sparse::free, which takesSTATEthroughdecommitted. D3D12 can make a resource's or aheap's last Release inside one of its own calls on another thread.
before_executecalls D3D12with
STATEheld. So the two threads can wait for each other, the same deadlock as in #789.Now the release only queues the block (
release_owned_block). The block stays reserved andcommitted, so its address cannot be handed out again yet. The next
alloc,alloc_inorbefore_executedecommits it and gives it back (reclaim_released_blocks, throughfree). Thatruns without
STATEheld and outside any D3D12 callback. One thread reclaims at a time(
RECLAIMING): a caller that finds the queue empty while another thread is giving blocks backwaits until they are back. #1981's
FORGOTTENpath is unchanged.What is in it
crates/xcl/src/hle/d3d12x/sparse.rs:release_owned_block,reclaim_released_blocks,RELEASED_BLOCKS,RECLAIMING.alloc,alloc_inandbefore_executereclaim first. Two tests.crates/xcl/src/hle/d3d12x/real.rs:res_releaseandmem_heap_releasecallrelease_owned_blockin place offree. Two#[cfg(test)]helpers that give a test buffer orheap a block.
Tested
Rust 1.96.0 MSVC, debug build.
d5723ae, rebased onmain9633138):cargo check --release --testsclean, andcargo test -p xcl --lib -- sparse --test-threads=4: 26 passed, 0 failed, 1 ignored(
early_commit_timing, ignored onmaintoo), including both new tests below.main7b9eabb):cargo build --workspace --frozenwithout warnings; the sparse tests 22 passed / 1 ignored in 8 runs;
cargo test --workspace -- --test-threads=4: 1093 passed, 0 failed, 46 ignored (SKIPPED: 13 tests, all "no wave64","no heap windows" or refused f16 forms; none of them a sparse test). Not repeated on this base.
a_buffer_or_heap_released_while_the_state_is_held_does_not_wait_to_free_its_block(GPU,ran on the RTX 5080): a real buffer and a real heap get their last Release while another
thread holds
STATE. With the two hooks callingfreeagain, it fails after its 5 s timeout:"a last Release waited for the sparse state's lock to free its block".
an_owned_block_released_while_the_state_is_held_does_not_wait_for_it: the release does notwait for
STATE, and the queued block keeps its reservation, its pages and its contents untilit is reclaimed. After the reclaim it is given back.
Regression run
scripts/smoke.ps1onmainand on this head).Not tested
heap_release→console_heap::unregisterstill callssparse::freefrom afinal Release. #789 did not change it, and neither does this PR.
AI use: Claude Code (Claude Opus 5.5) prepared the rebase and the tests.
Rebased on current
mainafter @DavidM1911 reported a conflict.🤖 Generated with Claude Code
@MesshM on GitHub · 2026-11-24 05:46 UTC · original
Test run of
bc82410abd9ccad26987ed86ec82f4194e06a888on AMD RDNA4. I merged it onto currentmaine50836blocally (clean merge) and tested that tree.Tested
stable-x86_64-pc-windows-msvc, debugcargo build --workspace+cargo test --workspace -- --test-threads=4on the merge: 706 passed, 0 failed, 41 ignored, exit code 0;xcllib tests 665 passed, 0 failed, 21 ignoredSKIPPED; thesparsetests pass.Review: Taking the buffer's pins out before the release and dropping them outside the sparse-state lock removes the second wait-for-each-other path (allocator reset holding the lock vs. the release callback taking it), the same pattern #443 used for the device replacement. I found nothing to change.
Not tested: no retail title or regression run (I have no unpacked game), no
XCL_SAMPLE_*tests, release build; the PR's head on its old base was not run, only its merge ontomain.Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.
@imnicho on GitHub · 2026-11-24 09:41 UTC · original
Test report: with
XCL_DRED=1this PR's path is the first of two (RTX 5080, a retail title)bc82410merged ontomain077ce40(clean), release. The newer retail title of the README,XCL_NETWORK=0,XCL_DRED=1, no input (its first screens), 45 s runs, four builds in turn, 3 rounds. Frames shown, and when the 2 s activity log stops (it stands still with the title):main(077ce40)main+ this PRmain+ #968main+ this PR + #968main09940bb) the two threads are the ones this PR describes: one inState::begin_slot→ID3D12CommandAllocator::Resetwith the sparse-state mutex held, the other in a list'sReset→ D3D12Core → the release hook →sparse::forget_buffer.forget_buffer. The same two threads then meet one step later, inlate_release::hold→drain_known→sparse::queue(), which takes the same mutex to clone the queue. That is #968 (queue()only; merging the two gives textual conflicts insparse.rswhere both add lines at the same three places – both sides are kept).XCL_DRED=1; a longer run reached the device removal of #675 and logged its breadcrumbs (on #675).Hardware: Intel Core i7-7700K, 16 GB RAM, NVIDIA GeForce RTX 5080 16 GB (driver 610.47), Windows 10 22H2 (19045), Agility SDK 620, rustc 1.100.0.
AI use: Claude Code with Claude Fable 5.2 read the thread dumps (XCL frames symbolised from the build's PDB) and wrote this; the runs are from the machine named.
@Arvi23 on GitHub · 2026-11-24 13:48 UTC · original
The same cycle on AMD (RDNA4), from a retail run that froze at 5 s and stayed frozen for 20 minutes until it was stopped. Two title threads in the thread dump, symbolised with the PDB of a rebuild of the run's tree (
e50836b+ #708 + #684's CopyFromSubresource fix, none of which touchessparse.rsorres_release):q_execute_command_lists→title_textures::refresh→sparse::before_execute→State::upload_dirty→State::begin_slot(holdingSTATE) →ID3D12CommandAllocator::Reset→ D3D12Core, waiting on a critical section;list_x::reset_x→ the native listResetin D3D12Core →real::res_release→sparse::forget_buffer, waiting forSTATE.The run had
XCL_DRED=1, as in the #675 / #968 reports. The pipeline preload was compiling a big compute program in amdxc64 at the same time, which made it look like #1035, but no preload thread is in the cycle.Setup: AMD Radeon RX 9070 XT 16 GB (driver 26.11.2), Ryzen 7 5800X3D, 32 GB, Windows 10 IoT Enterprise LTSC 21H2 (19044), release build.
I haven't run #789 itself here.
Written with Claude Code (Claude Opus 5.5) from the run's log and thread dump.
@deepdev237 on GitHub · 2026-11-24 14:45 UTC · original
Retail DRED startup lock on AMD RDNA4
Tested
32.0.32015.7029), Ryzen 9 5950X, Windows 11 build 26300, Rust 1.100.0 MSVC, release.xcl.exe run "<retail-title>"withXCL_DRED=1,XCL_NETWORK=0and matching seeded DXIL caches. The control was a local diagnostic stack based on47efa2ecea0a12934719ae69b81930cf02a4b1c3(Git tree33f77129622ede6608187d6a1d68e48bcd8c84f1). Its last output was at 7.436 s. Two thread samples symbolized with the release PDB showed:q_execute_command_lists → sparse::before_execute → State::upload_dirty → State::begin_slot → ID3D12CommandAllocator::Reset, holding the sparse-state mutex inside D3D12Core.list_x::reset_x → D3D12Core → res_release → sparse::forget_buffer, waiting for that mutex.bc82410abd9ccad26987ed86ec82f4194e06a888together with #9689beaa733fbead2d7909d22d36d59f6dc9e16dc64(treef4890332e2b99b49ef23de068079e86e2b4cfbef) cleared the startup stall in the paired run. DRED then produced breadcrumbs onDXGI_ERROR_DEVICE_HUNGat 204.029 s.cargo test --offline --locked --release -p xcl --lib hle::d3d12x::sparse::tests -- --nocapture --test-threads=1: 14 passed, 0 failed, 1 ignored, zero GPU skips.Not tested — #789 alone, clean upstream main, or rendered gameplay.
AI use — OpenAI Codex (
gpt-6.2-sol) ran the tests, checked the local receipts and wrote this report.@Arvi23 on GitHub · 2026-11-24 14:54 UTC · original
Test report: the same result on AMD RDNA4 (RX 9070 XT), with
XCL_DRED=1, on currentmainbc82410merged ontomain930e8b4, and #968 (pr-968head) merged on top of that. Both merges have conflicts only insparse.rs. I kept both sides:main's newparkedfield andflush_parkedstep next to this PR'sreleased_pins.before_executerunsreclaim_released_pinsfirst, thenflush_parked.main's two newer test constructors takereleased_pinsin place ofbuffers.QUEUEnext to this PR's statics, and both PRs' tests.The merged trees differ from
mainonly inreal.rsandsparse.rs.The retail title of #505, release builds,
XCL_NETWORK=0,XCL_DRED=1,XCL_ACTIVITY=1, no input, 45 s runs (XCL_RUN_SECONDS), the three builds in turn, 2 rounds:main(930e8b4)main+ this PRmain+ this PR + #968This covers the two cases @deepdev237's RDNA4 report leaves out: this PR on its own, and clean
main. On its own it does not get past the start-up here either."Still from" is the last 2 s activity line. No crash or device removal in any run. #789's "could not retire owned block" warning appears in none of the six logs. These runs have no thread dumps, so I can't say where
main+ this PR stops. The pattern is the one @imnicho reported on the RTX 5080 (#968'squeue()). Separately, an earlier run here (RX 9070 XT,e50836b+ local changes,XCL_DRED=1) froze in this PR's path:begin_slot→ID3D12CommandAllocator::Resetagainstreset_x→ D3D12Core →res_release→forget_buffer, symbolised from the build's PDB.cargo test --workspace -- --test-threads=4(debug) on the merged tree (main+ this PR + #968): 754 passed, 0 failed, 41 ignored, no SKIPPED tests. Both of this PR's tests and #968's pass.final_buffer_release_completes_with_sparse_state_lockedran on the GPU and was not skipped.Hardware: AMD Radeon RX 9070 XT 16 GB (RDNA4, driver 26.11.2), Ryzen 7 5800X3D, 32 GB RAM, Windows 10 IoT Enterprise LTSC 21H2 (19044), rustc 1.100.0 MSVC, DXC 1.9.2609.5.
Not tested: this PR's head on its own base (
6025201), runs withoutXCL_DRED=1, runs longer than 45 s.Written with Claude Code (Claude Opus 5.5): it made the merges and the run script, ran the test suite and wrote this report. The title runs are mine, on the machine named.
@DavidM1911 on GitHub · 2026-11-25 11:08 UTC · original
Verification on RTX 3060 Ti (Windows 11): merge conflict with current
main— needs a rebase before it can be tested.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.