Skip to content

D3D12.X: release sparse buffer pins outside the driver callback - #789

Open
badoomtch wants to merge 1 commit into
xcl-dev:mainfrom
badoomtch:fix/sparse-release-lock
Open

badoomtch wants to merge 1 commit into
xcl-dev:mainfrom
badoomtch:fix/sparse-release-lock

Conversation

@badoomtch

@badoomtch badoomtch commented Nov 24, 2026 •

Copy link
Copy Markdown

A final D3D12 resource release can run while a command allocator resets with XCL's sparse-state mutex held. If the release callback takes that mutex to unpin the buffer, the reset and the callback can wait for each other. I saw this stack in a local instrumented build. On clean main, a native GPU regression test also blocks when releasing a buffer under that lock. This is a second path into the same mutex after the device-replacement fix in #443.

What is in it

  • real.rs captures the buffer's pin registration before the original COM release. On the final release it detaches those pins and queues any emulator-owned sparse allocation for reclamation.
  • sparse.rs drains released pins on the owning state and reclaims released blocks on a later submission or allocation. The tests cover final release under the sparse lock and reuse of a resource address before the old callback finishes.

Tested

  • Windows 11 build 26300.9974, Intel Core Ultra 7 265, NVIDIA GeForce RTX 5080 with driver 32.0.16.1088. Rust 1.96.0, MSVC.
  • cargo build --workspace --frozen succeeded. cargo test --frozen --workspace --no-fail-fast -- --test-threads=4 --show-output reported 706 passed, 0 failed and 41 ignored in the debug profile. Four tests reported internal skips. Two require native wave64 (gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware), and two require the optional D3D12 debug layer (test_title_draws_with_a_root_signature_under_the_debug_layer, uploads_start_from_each_subresources_state).
  • Release sparse tests ran serially on the same GPU. Thirteen passed and one benchmark was ignored. final_buffer_release_completes_with_sparse_state_locked timed out on unmodified main with only the regression test added and passed with the patch.

Regression run

Both release builds ran the same title for 60 seconds with upstream scripts/smoke.ps1. A local launcher started the measured binary inside a zero-network-capability Windows AppContainer and forwarded its native log path and process exit code. The following blocks are the script's output.

Main

xcl-smoke v1
commit: 6025201c5adad473483b2dc4f085e923ded49f1f
gpu: NVIDIA GeForce RTX 5080
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 197 (PresentX 198)
presents per 2 s (last 3): 9 9 10
device removals: 0
crashes: 0
peak commit: 15081 MB

PR

xcl-smoke v1
commit: bc82410abd9ccad26987ed86ec82f4194e06a888
gpu: NVIDIA GeForce RTX 5080
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 228 (PresentX 228)
presents per 2 s (last 3): 11 9 10
device removals: 0
crashes: 0
peak commit: 15111 MB

Not tested

The short runs recorded continued presents through the final sampling intervals. They did not measure time to menus or reproduce the intermittent pre-menu hang. The deterministic release test covers the lock inversion. World loading, long sessions, AMD and Intel GPUs remain unverified for this patch.

AI use

OpenAI Codex (GPT-6) investigated the thread sample, wrote the patch and regression tests, ran the hardware checks and drafted this description at the contributor's direction.

An allocator reset can hold sparse state while D3D12 finalises a resource. Queue the retired pins for their owning state and keep a reused interface address separate. Defer emulator-owned sparse block reclamation to a submission or allocation.

Assisted-by: OpenAI Codex (GPT-6)
@MesshM

MesshM commented Nov 24, 2026

Copy link
Copy Markdown

Test run of bc82410abd9ccad26987ed86ec82f4194e06a888 on AMD RDNA4. I merged it onto current main e50836b locally (clean merge) and tested that tree.

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug
  • cargo build --workspace + cargo test --workspace -- --test-threads=4 on the merge: 706 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 665 passed, 0 failed, 21 ignored
  • 0 SKIPPED; the sparse tests 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 onto main.

Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.

@imnicho

imnicho commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Test report: with XCL_DRED=1 this PR's path is the first of two (RTX 5080, a retail title)

bc82410 merged onto main 077ce40 (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):

build round 1 round 2 round 3
main (077ce40) 1 frame, still from 10.8 s 1 frame, still from 8.1 s 1 frame, still from 8.3 s
main + this PR 1 frame, still from 10.9 s 1 frame, still from 8.7 s 1 frame, still from 10.5 s
main + #968 1 frame, still from 10.5 s 1 frame, still from 8.0 s 1 frame, still from 10.5 s
main + this PR + #968 918 frames 910 frames 920 frames

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

Arvi23 commented Nov 24, 2026

Copy link
Copy Markdown

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 touches sparse.rs or res_release):

  • q_execute_command_lists → title_textures::refresh → sparse::before_execute → State::upload_dirty → State::begin_slot (holding STATE) → ID3D12CommandAllocator::Reset → D3D12Core, waiting on a critical section;
  • list_x::reset_x → the native list Reset in D3D12Core → real::res_release → sparse::forget_buffer, waiting for STATE.

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

Copy link
Copy Markdown

Retail DRED startup lock on AMD RDNA4

Tested

  • AMD Radeon RX 9060 XT (RDNA4, driver 32.0.32015.7029), Ryzen 9 5950X, Windows 11 build 26300, Rust 1.100.0 MSVC, release.
  • xcl.exe run "<retail-title>" with XCL_DRED=1, XCL_NETWORK=0 and matching seeded DXIL caches. The control was a local diagnostic stack based on 47efa2ecea0a12934719ae69b81930cf02a4b1c3 (Git tree 33f77129622ede6608187d6a1d68e48bcd8c84f1). 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.
  • Applying D3D12.X: release sparse buffer pins outside the driver callback #789 bc82410abd9ccad26987ed86ec82f4194e06a888 together with D3D12.X: the late-release drain gets the sparse queue without the sparse state's lock #968 9beaa733fbead2d7909d22d36d59f6dc9e16dc64 (tree f4890332e2b99b49ef23de068079e86e2b4cfbef) cleared the startup stall in the paired run. DRED then produced breadcrumbs on DXGI_ERROR_DEVICE_HUNG at 204.029 s.
  • Combined tree, 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

Arvi23 commented Nov 24, 2026

Copy link
Copy Markdown

Test report: the same result on AMD RDNA4 (RX 9070 XT), with XCL_DRED=1, on current main

bc82410 merged onto main 930e8b4, and #968 (pr-968 head) merged on top of that. Both merges have conflicts only in sparse.rs. I kept both sides:

The merged trees differ from main only in real.rs and sparse.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:

build round 1 round 2
main (930e8b4) 1 frame, still from 6.0 s 1 frame, still from 6.0 s
main + this PR 1 frame, still from 6.0 s 1 frame, still from 6.0 s
main + this PR + #968 1104 frames 1179 frames

This 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's queue()). Separately, an earlier run here (RX 9070 XT, e50836b + local changes, XCL_DRED=1) froze in this PR's path: begin_slot → ID3D12CommandAllocator::Reset against reset_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_locked ran 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 without XCL_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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants