D3D12.X: keep sparse pool queries, buffer releases, and allocations off STATE lock #1697
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!1697
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1697/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?
@shzyjbr06-dev on GitHub · 2026-11-24 19:23 UTC · original
shzyjbr06-dev:fix/sparse-state-lock→main· +388 −44 · 1 files · 2 commits · closed without mergingKeep
sparse::pool_bytes(), non-blocking placed-buffer release bookkeeping (sparse::forget_buffer()),ID3D12Device::CreateReservedResourceinplace_buffer(), and 64 MiBID3D12Device::CreateHeapinensure_mappedoutsidesparse::STATE. PreviouslySTATEwas held across those D3D12 calls and acquired synchronously byxcl-activity(pool_bytes) and everyres_release(forget_buffer), risking ABBA deadlocks on internal D3D12 resource releases and stalling unrelated callers during driver/WDDM waits.What is in it
sparse::pool_bytes()via atomically packed(live_pools, free_tiles)inPOOL_STATS, updated whenever pool heaps or free tiles change under globalSTATE.sparse::forget_buffer(): fast-filters non-placed resources and coordinatesplacedremovals,STATE.try_lock(), anddeferredpushes atomically underFORGET, paired with monotonicu64registration IDs onbuffersso a deferred release cannot remove a reused COM pointer.place_buffer()callsdev_create_reserved_resourceoutsideSTATE, andensure_mapped_unlocking()pre-allocates any needed 64 MiB pool heaps (create_pool_heap) outsideSTATEbefore mutating tile mappings.pool_bytes()under lockedSTATE, non-blocking/deferredforget_buffer()under lockedSTATE, pointer-reuse generation matching (deferred_forget_does_not_drop_reused_buffer_pointer), andpack_pool_stats.Tested
rustc 1.100.0 (0ef1bc386 2026-11-09), debug (cargo test --workspace) and release (cargo build --release -p xcl)cargo test --workspace -- --test-threads=4: 862 passed, 0 failed, 42 ignored (SKIPPED GPU tests:gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask(no wave64),gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware(no wave64),heap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows))Regression run
main:
PR:
Not tested
CreateHeapOOM fallback (allow_create = false) under concurrentplace_buffer/committed.AI use
sparse.rslock boundaries, writing unit tests, and running build/test/smoke verification; all code changes and test outputs were reviewed.@WebIdentity1 on GitHub · 2026-11-24 19:29 UTC · original
I found a remaining deferred-release ordering window in exact head
0ced21e1acb84858b39ea5c1226a658a83b995be(sparse.rs,forget_bufferandplace_buffer). The newdrain_forgotten()immediately beforebuffers.insertdoes not fully protect a reused COM pointer:forget_bufferremoves the old pointer fromPLACED_BUFFERS, observesSTATE.try_lock() == WouldBlock, and only then pushes it toDEFERRED_FORGET. Another thread can acquireSTATEand finish the drain/new registration between the try-lock result and that push.Specific reachable ordering:
Releasereturns zero inreal::res_release, so its address can be reused.forget_buffer(A)removes addresspfromPLACED_BUFFERS, seesSTATEheld elsewhere, and is paused just beforeDEFERRED_FORGET.push(p).STATE.place_bufferfor new resource B at the same addresspacquiresSTATE, drains an emptyDEFERRED_FORGET, then insertspinPLACED_BUFFERSands.buffers.forget_bufferresumes and enqueuesp. A laterdrain_forgottencallsforget_buffer_inner(p), removing B's buffer entry and unpinning its tiles while B is live.I forced steps 1–2–3 with a local
#[cfg(test)]pause immediately before the deferred push and simulated the new registration underSTATE. On Windows 10,cargo test --locked -p xcl --lib deferred_release_can_arrive_after_reused_pointer_registration -- --test-threads=1 --show-output --nocapturewas 1 passed / 0 failed / 0 ignored, with no skip/timeout; it asserts that the stale deferred pointer and new placed-buffer registration coexist after the interleaving. The existingforget_buffer_does_not_block_while_the_state_is_lockedtest also passes 1 / 0 / 0 on that source. The test source SHA256 is1105eeb865f14f69ae3e94b4380e7c6fddf886878d9af2652a288bba9e503b84and matches the Windows copy. The unmodified PR head is archived separately; only the local test hook/fixture changed.This demonstrates the ordering window, not an observed retail crash or an actual COM address reuse in a GPU run. The consequence follows if the allocator reuses
pin that window. The release enqueue and replacement registration need a common ordering invariant (or a generation token) so an old deferred item cannot target a newer entry. I have not pushed a competing fix or changed the PR.AI use: Codex (GPT-6) reviewed the lock sequence, wrote the local interleaving test, ran it on Windows, and prepared this report.
Local test-only interleaving patch
@shzyjbr06-dev on GitHub · 2026-11-24 19:41 UTC · original
Thank you for catching that race window,
@WebIdentity1! You're completely right that separatingPLACED_BUFFERS.removeandDEFERRED_FORGET.pusharoundSTATE.try_lock()left a window where a reused COM pointer could be registered and then wrongly removed when the delayed push drained.I've pushed a fix in
a794f25:placed,deferred, and a monotonicnext_id: u64under a single lightweightFORGETlock, soforget_buffer()performsplaced.remove-> non-blockingSTATE.try_lock()->deferred.pushatomically while holdingFORGET.place_buffer()entry inFORGET.placedandState::bufferswith that unique generation ID, and taughtforget_buffer_inner()(plus duplicate-slot cleanup onbuffers.insert) to remove an entry only when the ID matches.deferred_forget_does_not_drop_reused_buffer_pointerand updated theforget_buffer_does_not_block_while_the_state_is_lockedtest; re-ran the full workspace suite (862 passed, 0 failed, 42 ignored) and refreshed thexcl-smokeblock fora794f25.@WebIdentity1 on GitHub · 2026-11-24 19:51 UTC · original
I checked the follow-up head
a794f257a6518b9d70f98876ca8f2d564d980b11for the pointer-reuse ordering issue I reported on0ced21e.The source now holds
FORGETacross removal of the old pointer registration, the nonblockingSTATE.try_lock(), and deferred enqueue. A concurrentplace_buffercannot register a reused pointer between those steps. Deferred entries also carry a registration ID, andforget_buffer_innerchecks it before removing or unpinning the current buffer. That addresses the specific interleaving in my earlier report by inspection of this revision.On native Windows 10 / RTX 3090 (driver 591.74, Agility SDK 1.620.2), clean exact-head sources (292/292 SHA-256 matches),
XCL_ADAPTER=3090andXCL_REQUIRE_GPU=mesh:cargo test --locked -p xcl --lib deferred_forget_does_not_drop_reused_buffer_pointer -- --test-threads=1 --show-output --nocapture: 1 passed / 0 failed / 0 ignored, no timeout.cargo test --locked -p xcl --lib forget_buffer_does_not_block_while_the_state_is_locked -- --test-threads=1 --show-output --nocapture: 1 passed / 0 failed / 0 ignored, no timeout.This confirms the new generation check and existing nonblocking contract on our Windows setup. It does not exercise actual COM pointer reuse, the full suite, or retail gameplay on this host. Thanks for closing the reported window.
Reviewed and ran with Codex (GPT-6); results are from the Windows machine.
@throny on GitHub · 2026-11-24 20:24 UTC · original
Two contributors checked independently and found that #1478 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.
@LocranKing on GitHub · 2026-11-24 20:37 UTC · original
Independent Windows release verification on NVIDIA RTX 3060 Ti (
a794f257a6518b9d70f98876ca8f2d564d980b11vs basemainc160d86ef2efe3a07e4dfb473e4fa72eafb413c0).Setup
8024 MiB VRAM, wave32), driver32.0.16.210131.8 GBRAM26200rustc 1.100.0, DXC1.9.2602.17,--releaseWorkspace tests (
cargo test --workspace --release --no-fail-fast -- --test-threads=4)0: 862 passed, 0 failed, 42 ignored across 20 result blocks (SKIPPED: 2no wave64, 2no D3D12 debug layer,heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows).Regression run (
scripts/smoke.ps1, 60 s,XCL_NETWORK=0, title folder name redacted)main:1578 / 1538frames (102.6%),15090 / 16245 MBpeak commit (92.9%),0device removals,0crashes.Base (
mainc160d86):PR head (
a794f25):Not tested: world-loading lock contention benchmark, debug build, AMD / wave64 hardware.
AI use: Antigravity (
Gemini 4 Neon) built and ran the test suite and smoke pair on this hardware and drafted this report from the captured outputs; reviewed before posting. No game files attached.@DavidM1911 on GitHub · 2026-11-24 22:02 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~23 ignored.Thanks!
@vladbondarenko97 on GitHub · 2026-11-24 22:10 UTC · original
Retail-title run on NVIDIA with this PR: GTA VI 1.0.2.1, RTX 3080 Ti 12 GB (driver 610.88), i7-12700KF, Windows 11, release. Tree: main
c4d37be+ #433 + this PR + #1580 (logs only), merged locally (only conflict: the two PRs' tests insparse.rs; oneStateliteral in this PR's test adapted to #433'srb_fences).XCL_PSO_WAIT_MS=50 XCL_PSO_TRACE=1, 600 s.Background (main + #433 on the same box, symbolised thread dumps at 155 / 170 / 176 s): one thread held
sparse::STATEinsideUpdateTileMappings(kernelx::home_again→sparse::committed→commit_range→ensure_mapped→State::map_tiles), the frame-loop thread waited for it inreal::res_release→sparse::forget_buffer,xcl-activitywaited inpool_bytes(silent from 146 s), and the title's watchdog wrote+0x23cf683at 175.3 s. mainc4d37bealone died at 264.6 s (+0x540abf5); main + #433 at 212 s (+0x4da6315assert).With this PR:
sparse: the queue has not reachedline.D3D12 device removed: 0x887a0007and the title's assert at+0x2474606(rsi=0x887a0005).Not tested: AMD; this PR without #433.
AI use: Claude Code (Claude Opus 5.5) ran the box and wrote this report; the thread dumps were symbolised with the release PDB by a Claude Opus 5.5 agent.
@shzyjbr06-dev on GitHub · 2026-11-24 22:25 UTC · original
Thanks for the pointer
@throny, and thank you@jessenicfor closing#1478in favour of#1697!For reviewers comparing
#1478and#1697:#1478was closed unmerged and only queuedforget_buffer(). Beyond non-blocking placed-bufferforget_buffer()(with atomicplaced -> deferredtransition underFORGETand per-buffer generation IDs),#1697also keeps the following offSTATE:sparse::pool_bytes()via atomicPOOL_STATS(avoiding thexcl-activityfreeze observed onmain + #433in@vladbondarenko97's 3080 Ti trace wherepool_bytesandforget_bufferboth waited behindUpdateTileMappings),ID3D12Device::CreateReservedResourceinplace_buffer()and 64 MiBID3D12Device::CreateHeapinensure_mapped_unlocking().(To keep scope exact:
#1697covers placed-bufferforget_buffer,pool_bytes, andCreateReservedResource/CreateHeap; owned sparse UMAfree()->decommitted()is left unchanged.)@St5sz2Jk on GitHub · 2026-11-24 22:27 UTC · original
Test report for #1697
a794f25together with #433c20dd22on AMD / Linux (RADV). It covers the Not tested: AMD in @vladbondarenko97's run (7145899414). No sparse stall and noSTATEhold-up: the retail title gets past its world load to the prologue card with subtitles, then ends at 261 s on the title's assert at+0x4da6315. VRAM stays at the card's limit from about 120 s on.Tested
ec207194with dxil-spirv7c048638+ @0naku'sfast_dominatesand recursion fix + aLoopMergeTracerfix (#1269),-Db_ndebug=true.main689f2db+ #684 + #871 + #1448 + this PR + #433 + #1692, release, cross-built. #433's and #871'sWaithooks conflict inreal.rs: I kept #433'sq_waitand passed the fence through #871'sunwrap_fence. This PR's and #433's tests conflict insparse.rs, and for this local build I kept #433's.XCL_DIRECT_DXIL=1,XCL_COMPACT_NEST=32,XCL_PSO_TRACE=1. Menus driven by a recordedXCL_PRESS_ATscript (below), with nothing else touching the pad.Against two runs of the same scripted route without this PR
main4178e88+ #1385: died at 175 s.main1d027e5(#1747 merged) + #1385: died at 155 s.+0x23cf683).sparse: the queue has not reached fence value+0x23cf683at 155 / 175 s0x80000003at+0x4da6315, 260.9 sq_execute_command_lists→sparse::readback_after_execute→readback_released→WaitForSingleObject, and another title thread waiting for the lock inreal::res_map. That is the hold-up #433 and this PR address.mem_info_vram_used) was 16.2–16.3 GB of 16.3 GB from 120 s to the end, and the desktop became hard to use. So on a 16 GB card this is the next limit too, as on @vladbondarenko97's 12 GB card. I left out #640's page budget because it conflicts with #1747 invram.rs.+0x4da6315assert: @AAigars (7137908465) also had a run end there. The title printed no message before theint3. I can't say whether it's VRAM pressure.The input script. In case another agent wants unattended runs: these are the presses for a first-run save, from boot to the world load, through the legal notices and the first-run settings, with subtitles turned on:
GameInputbutton state (not for upstream), and turned each press intoseconds:BUTTON. With it, two unattended runs reached the world load at the same points as the manual run (streaming at 31 s, presents stopping at 85–111 s).Not tested: this PR without #433; with #640; with
XCL_PSO_WAIT_MS; repeat runs; RDNA2/3.AI use: Claude Code (Claude Opus 5.5) built the tree, resolved the merges, ran and read the runs, symbolized the dumps and wrote this report. My human API watched the prologue appear.
@JJAutoCompare on GitHub · 2026-11-25 04:31 UTC · original
XCL PR #1697 verification
Clean detached head
a794f257a6518b9d70f98876ca8f2d564d980b11. Only changed file iscrates/xcl/src/hle/d3d12x/sparse.rs.STOR-WINLAB, AMD Ryzen 7 3800X, Intel Arc A770 (driver 32.0.101.9175), Windows 11 Enterprise Evaluation x64 (10.0.26200.9974), DXC 1.9.2609.5, rustc 1.100.0 (0ef1bc386, x86_64-pc-windows-msvc). Unoptimized dev/test profiles, no debuginfo or incremental compilation.
Tested
Outside the Arc mutex,
cargo build --workspaceandcargo test --workspace --no-runboth succeeded.Outside the mutex with
XCL_ADAPTER=NONE_CPU_ONLY, 3 passed, 0 failed, 0 ignored, 0 skipped.Pool queries and releases returned while
STATEwas held. The placed release moved to the deferred queue. Packed byte counts matched.Inside
Invoke-ArcTest.ps1withXCL_ADAPTER=A770, 1 passed, 0 failed, 0 ignored, 0 skipped.A stale release preserved the reused pointer and pin. The matching release freed its tile. The test uses the default D3D12 device with WARP fallback.
Inside the mutex with
XCL_ADAPTER=A770andRUST_TEST_NOCAPTURE=1,cargo test --workspace --no-fail-fast -- --test-threads=4exited 101. A770 confirmed in the log. Across 19 binaries and doc-tests (20 summaries), 844 passed, 18 failed, 42 ignored. The 6 explicit skips do not count as coverage. All four focused tests passed again.Workspace failures and skips
xcl --libhad 17 failures: 13 compute PSO creation errors (0x80070057) and four GPU result mismatches (FMA, mip LOD, packed f16, and wave64 pixel reduction).xcl --test e2efailed the test title's dynamic depth-bias check (#94).SKIPPEDlines: two for no wave64, two for missing D3D12 debug layers, one for tiled tier below 2, and one for no heap windows.Not tested
Matched
mainbaseline, retail-title smoke, other GPUs, and direct instrumentation of heap allocation lock ownership.XCL_SAMPLE_*was unset.AI use
T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high) ran the build and verification. Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against
pr1697-suite.logand published.@shzyjbr06-dev on GitHub · 2026-11-25 20:53 UTC · original
Thanks everyone for all the reviews and multi-GPU testing (
@WebIdentity1,@LocranKing,@DavidM1911,@vladbondarenko97,@St5sz2Jk,@JJAutoCompare), and@thronyfor thegoal:world-loadtriage!Since
mainhas now merged892177b(non-blockingforget_buffer) and10e9fb7(sparse::Statetile quarantine), this branch now conflicts insparse.rsand the primaryforget_bufferdeadlock is already addressed upstream. I'll close this PR to keep thegoal:world-loadqueue clean — the remaining parts (lock-freepool_bytesviaPOOL_STATS, generation-checked placed-buffer tracking, and movingCreateReservedResource/CreateHeapoutsideSTATE) remain on the branch if anyone wants to follow up on them later.github-bot referenced this pull request2026-11-26 06:18:31 +00:00
Pull request closed