D3D12.X: sparse readbacks don't wait for a queue held by a later signal #433
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!433
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/433/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?
@Kalmarv on GitHub · 2026-11-24 00:13 UTC · original
Kalmarv:fix/sparse-readback-without-cpu-wait→main· +457 −42 · 4 files · 1 commits · closed without mergingAfter a title's
ExecuteCommandListswhose lists write sparse windows on the GPU (Write32/64BitValue…X,FillMemoryWith32BitValueX,CopyMemoryToMemoryX),sparse::readback_after_executecopies those bytes back to the CPU's view. It waited on the CPU for the title's queue to get there, inside the title's call and while holding the sparse lock. A queue may GPU-wait for a fence that a later submit signals; async compute does this. The wait then never ends, the later submit never comes, and every other submit stops at the sparse lock. Part of #262, which covers the other half of the sparse windows' cross-queue problem: the CPU-write uploads.What is in it
crates/xcl/src/hle/d3d12x/sparse.rs:rb_fencethat all title queues signalled is gone. Its values could complete out of order across queues.Signalfails they are never released (from review).crates/xcl/src/hle/d3d12x/real.rs: the queue'sWaitis noted, both from the PC method (a new override) and from the console's queue slots. XCL's own waits, made inside its own uploads, are not noted. A queue the title releases has its noted waits forgotten (sparse::forget_queuefromq_release).cpu_writes.rs: it does bottom-of-pipe writes outside unified memory always on a worker, after the GPU. So there a CPU read right after the title's fence wait can always see the old value, and the worker writes anyway after 10 s. This PR keeps that window to the case where main hangs.crates/xcl/tests/, each in its own process, with the device adopted as the title's:sparse_readback_waits.rs: queue A waits for F, runs a list writing 8 bytes of a sparse window, and is read back; queue B then submits and signals F. A must finish within 5 s, and the bytes must land.sparse_readback_lands.rs: 20 times, a list writes 8 bytes, the title waits for its own fence and reads them at once.noted_queue_waits_stay_one_per_fenceinsparse.rs: 1,000 waits on one fence keep one entry, a second fence makes two, completed waits go, a released queue has none. It fails without the bound (1,000 entries).Tested
c20dd22on mainb7aa9f3: rebased over #968, with two conflicts insparse.rs(#968'squeue()doc and body kept, this PR's doc stays onreadback_after_execute; #968's testthe_queue_is_answered_while_the_state_is_lockedkept beside ours). #968 only changes how the late-release drain gets XCL's sparse queue; this PR doesn't callqueue(), drops its readback jobs outside the sparse lock, and puts its copy lists on title queues the drain already waits on, so the merge adds no lock order. Before that,83bb744on930e8b4was19004e1rebased (one conflict, in the doc comment abovereadback_after_execute; two test constructors main added moved torb_fences), plus the bound on noted waits.19004e1was7184866(the review fix to7709697, on9ab7d76) rebased onto9ce2070. The runs by @nullmarsh and @TheHoracio below were on7709697, and @srcamarda's on7184866.9ab7d7619004e1)cargo test -p xcl --test sparse_readback_waitscargo test -p xcl --test sparse_readback_landshle::d3d12x::sparse::tests, inside the whole suite onc20dd22: 15 passed, 1 ignored.cargo test --workspace -- --test-threads=4:c20dd22: 773 passed, 0 failed, 41 ignored.83bb744: 754 passed, 0 failed, 41 ignored.19004e1: 686 passed, 0 failed, 41 ignored.7709697: 653 passed, 0 failed, 40 ignored. A first run of it hung in the deadlock of #344.gpu_geometry_wave32_prefix_count_over_a_maskandgpu_wave32_program_in_wave64_hardware(no wave64).7709697merged ontomaina6f5f7a.scripts/test.ps1: 0 failed, no SKIPPED GPU tests; both new tests pass. Withreal.rsandsparse.rsback onmain,a_readback_behind_a_wait_for_a_later_signal_does_not_hangfails after 5.4 s.scripts/smoke.ps1 -Seconds 90, each binary run twice.main508a0c7: 2343 / 2361 frames, peak commit 15764 / 15674 MB. This PR at7184866: 2356 / 2383 frames, peak commit 16491 / 16373 MB. No crash or device removal in any run. He puts the higher peak commit down to that head's base,9ab7d76, 55 commits behindmain;c20dd22is onb7aa9f3.7709697on9ab7d76.cargo test --workspace --no-fail-fast -- --test-threads=4: 653 passed, 0 failed, 40 ignored, no SKIPPED GPU tests; both new tests pass.Regression run
Our own runs, one after the other on the machine under Tested (RTX 5070 Ti, AMD Ryzen 9 9950X), release builds, no uncommitted changes:
mainatb7aa9f3(this PR's base), then this PR's head. 98 % ofmain's frames, 101 % of its peak commit.main:
PR:
Not tested
cpu_writeshas the same property.Size: 499 changed lines (+457 / -42), 245 of them tests. Over the ~400 target because of the tests: the fix and its review changes are about 250 lines in two files, and splitting the tests from the fix would leave the fix without the test that shows the hang.
AI use
🤖 Generated with Claude Code
@ghost on GitHub · 2026-11-24 00:28 UTC · original
AMD run, since Not tested lists AMD:
7709697merged ontomaina6f5f7a(clean merge): pass on RDNA4, and the hang test fails without thereal.rs/sparse.rschanges.Tested
.\scripts\test.ps1: passes, 0 failed; noSKIPPEDGPU tests.cargo test -p xcl --test sparse_readback_lands --test sparse_readback_waits: both pass.XCL_REQUIRE_GPU=wave64,mesh cargo test -p xcl --lib sparse: 13 passed, 1 ignored (early_commit_timing).real.rsandsparse.rsback onmain, new test files kept.a_readback_behind_a_wait_for_a_later_signal_does_not_hangfails after 5.4 s withqueue A did not finish in 5 s: the readback waits on the CPU for A, which waits for B's later submit.gpu_writes_are_there_when_the_titles_fence_completespasses either way.Not tested
smoke.ps1); NVIDIA.AI use
@TheHoracio on GitHub · 2026-11-24 00:36 UTC · original
Test report on AMD RDNA3: RX 7800 XT (16 GB), driver 32.0.32015.7029, Ryzen 7 9800X3D, Windows 11 Pro 10.0.26300, Rust 1.100.0 MSVC, DXC 1.9.2602.17, debug build. No retail data was used.
Tested: the PR head
7709697as it is (on its base9ab7d76, not merged onto current main).cargo build --workspace, thencargo test --workspace --no-fail-fast -- --test-threads=4: 653 passed, 0 failed, 40 ignored, no SKIPPED tests.a_readback_behind_a_wait_for_a_later_signal_does_not_hang(sparse_readback_waits) andgpu_writes_are_there_when_the_titles_fence_completes(sparse_readback_lands). The suite did not hang.Not tested: a regression run on a title, a release build, and the head merged onto current
main.AI use: Claude Code ran the commands and drafted this comment; the runs are real runs on the hardware above.
@Cattn on GitHub · 2026-11-24 00:48 UTC · original
From a static review (no builds or runs) of
7709697:readback_onsubmits the copy before creating or signaling its fence. If either operation fails, the early return drops the readback buffer and command allocator while the GPU may still be using them. Inland,SetEventOnCompletioncan fail and let execution reachMapand copy back while the fence is still pending. These are GPU-ordering and resource-lifetime bugs, and I found no indication of malicious code.Keep the submitted resources alive until GPU completion is confirmed, and require that confirmation before copying back.
github.com/ivall/xcl@770969778a/crates/xcl/src/hle/d3d12x/sparse.rs (L1001-L1010)github.com/ivall/xcl@770969778a/crates/xcl/src/hle/d3d12x/sparse.rs (L1297-L1313)Review by Claude Code (Claude Opus 5.5) with a gpt-6.2-sol audit subagent; I checked each point against the code.
@Kalmarv on GitHub · 2026-11-24 01:06 UTC · original
Thanks, both points were right. They're fixed in
7184866, squashed into the PR's commit:readback_on: the fence is now created before anything is submitted. If theSignalafter the copy fails, nothing can tell when the copy is done, so the readback buffer and command list are deliberately leaked instead of released.land: it returns only once the fence has reached the value, so the buffer is mapped and copied back only after the GPU is done with it. WhenSetEventOnCompletionfails, it now polls every millisecond instead of going ahead.CreateEventWfailing had the same problem (it returned and dropped the buffer while the copy could still be pending), and it now polls the same way.No test covers these paths: the failures of
CreateFence,Signal,CreateEventWandSetEventOnCompletioncan't be forced in a synthetic test. The existing tests and the whole suite were run again on the new head (see the description).🤖 Claude Opus 5.5
@srcamarda on GitHub · 2026-11-24 02:09 UTC · original
Regression run on a retail title, as asked under Regression run.
Tested
scripts/smoke.ps1 -Seconds 90, no input (the title stays on its account screen at 30 fps). Each binary was built from a clean checkout of its commit and run twice; the first run of each has a cold translation cache. Blocks below are from the second run.main508a0c7: 2343 / 2361 frames, peak 15764 / 15674 MB. This PR (7184866): 2356 / 2383 frames, peak 16491 / 16373 MB. No crash or device removal in any run.9ab7d76, 55 commits behindmain. Its peak commit is ~0.7 GB abovemain's here, most likely from the base:main's memory changes since then aren't in it. #443 and #470, both close tomain, matchmain. A rebase would settle it.Regression run
main:this PR's head:
gpu:in this PR's block names a virtual display adapter: the head predates97dc49c, which reads the adapter fromreport.json. XCL ran on the RX 7800 XT in every run.Not tested
AI use
@upipibi on GitHub · 2026-11-24 04:32 UTC · original
A small leak in
19004e1, found by reading the code (not run):note_queue_wait(sparse.rs:1271-1276) pushes aHeld(fence.clone(), value)for every titleWaitthat hasn't completed when it is called. It's called fromq_wait(real.rs:4562) and from the console queue slot (real.rs:4669). Entries are only removed inmay_be_held(:1279-1284), and that only runs fromreadback_after_executewhen the same queue submits a sparse write.q_releasedoesn't clear the queue's entry either.The usual cross-queue sync,
computeQueue->Wait(graphicsFence, n)once per frame on a queue that never writes into a sparse window, or any title with no sparse windows at all (the note is taken beforeSTATEis checked), adds one entry per frame for the whole run. Each entry keeps a COM reference on the title's fence, so the fence outlives the title's lastRelease. If that queue later does one sparse readback,retainwalks the whole backlog under theWAITSlock.Nothing crashes, but there's no upper bound. Possible fix: run the same
retaininnote_queue_waitbefore the push, drop the queue's entry inq_release, and skip the note while no sparse state exists.AI-assisted (Claude Code), read-only review.
@juliptree on GitHub · 2026-11-24 04:34 UTC · original
Independent Windows validation on an RTX 5060 Ti (driver 616.92), Windows 11 build 26200, and Rust 1.100.0 MSVC. I ran both synthetic fixtures three times per revision, comparing PR head 19004e125 with base
cb868b20. A separate probe verified the adapter selected by XCL’s device-creation path.No skips or process timeouts. I copied the two unchanged fixtures into the base worktree. When Cargo stalled linking the base lands fixture, I built it with rustc --test against the base’s Cargo-built libraries. Synthetic coverage only. AI-assisted by Codex (GPT-6).
@bstillbstill on GitHub · 2026-11-24 09:06 UTC · original
Test report:
19004e1with #533 on NVIDIA RTX 3090 Ti (Windows), retail title of #505. It builds and passes on currentmain; the readback stall the title hits on this machine is in theMappath, which this PR does not change.Build:
main09940bb+ #533001e37d+ this PR, merged locally (4dc8428). This PR conflicts withmainin one place insparse.rs:mainaddedpub fn queue()betweenreadback_after_execute's doc comment and the function, where this PR rewrote that comment. I keptmain'squeue()as it is and put this PR's comment back onreadback_after_execute; no code lines were touched.Result: compared with #533 alone (details and table in my comment on #533), the title went from an abort at 107.8 s to 118.8 s. The stall before the abort is the same kind, though: 5 ×
sparse: the queue has not reached fence value 39956 after 5 s (at 39951)from 93 s to 113 s. Thread dumps at 90 s and 105 s show:real::res_map→sparse::readback_now→State::readback_ranges→State::wait_for, holdingSTATE;q_execute_command_lists→sparse::before_execute/sparse::queue()→Mutex::lock_contended.So the Map readback (
readback_now) has the same problem this PR solves forreadback_after_execute: it waits on the CPU, under the sparse lock, for a queue that may need a later submit.I tried that locally: a change that lets
readback_nowwait for the GPU withoutSTATE(own readback buffer and list; its unit test fails without it). On top of #533 + this PR, the title aborted at 109.7 s instead, and the stall moved, not away. Now the submitting thread itself waits inbefore_execute→State::upload_dirty(sparse.rs:1189, the ring wait) for the sparse queue, 6 ×has not reached fence value 36294 after 5 s (at 36293)from 84 s. Ares_release→forget_bufferthread waits on the lock behind it. With this PR, nothing makes the sparse queueWaitany more, yet it stops one value short for 25+ s. Just before, at 70 s, #795's cycle breaker logged sixWrite64 Signal … would close a GPU cycle (waiters=[q3]) – signalled on CPU, and presents went to 0 at 72 s. Local video memory was 14.9 of 24 GB and commit 31.8 GB, so the memory budget is not the reason. I don't know yet what holds the sparse queue's own work.Tested
cargo build --workspace && cargo test --workspace -- --test-threads=4on4dc8428(debug): 723 passed, 0 failed, 41 ignored, includingsparse_readback_landsandsparse_readback_waits; SKIPPED:gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware(no wave64).ntdll.dll, 57 ms after a scheduled thread dump, and is left out (see the #533 comment).Not tested: this PR without #533; AMD / Intel; Linux.
Test runs, analysis and this comment by Claude Code (Claude Opus 5.5); I checked the logs it is based on.
@freemanovec on GitHub · 2026-11-24 09:15 UTC · original
Written by an AI agent (Claude Code, Claude Opus 5.5) on this account, from runs on this machine.
A Linux / RDNA3 data point where this PR removes a stall the title hits there. One run per configuration, so treat the times as indicative.
Setup: RX 7900 XTX, Mesa 26.3.1 RADV, CachyOS (kernel 7.3.5), Wine 11.22 (kernel write watches), vkd3d-proton v3.1 with #257's patch and dxil-spirv
53aac41(#611), DXVK from Proton Experimental. XCL release,x86_64-pc-windows-gnu(llvm-mingw),XCL_NETWORK=0,XCL_LATE_RELEASE=0. Tree:maina1672ef+ #867 + #871 + #684. The newer retail game (#505), A pressed until it loads the world.What stalls without this PR (measured with local timing logs, not in any PR): under Wine #871 places the title's overflow graphics heaps in the sparse windows, so the small GPU-written counters there go through
sparse::readback_after_execute. Each such readback of 8–16 bytes took 2.0–5.0 s (13 times ≥ 100 ms in one run, several ending at the 5,000 mswait_fortimeout) while holding the sparse lock, and title threads inreal::res_map→sparse::readback_nowwaited up to 4.9 s for that lock (7 times). A thread dump at the abort showed the title's queue thread inreadback_rangesand two title threads blocked on the lock.With this PR (cherry-picked; the conflict with #867's fence wrapping resolved by hand:
q_wait_pcunwraps the fence and notes the wait with the raw fence, queue slot 15 notes the raw fence too):The abort still comes ~40 s after the first ListX #101 call, as described in #505, and no title thread was inside XCL at that point.
With #891 and
XCL_PSO_WAIT_MS=50added on top of this PR, two runs ended with amdgpu GPU page faults from vkd3d-proton's queue thread and compute ring resets (one then the device removed, 0x887A0005). Without #433 (two runs with #891) and without #891 (the 539 s run) there were no faults; I have not found which change the faulting work comes from.Tests (release, Wine, headless gamescope):
--test sparse_readback_waits1/0/0,--test sparse_readback_lands1/0/0; lib filtershle::d3d12x::sparse::,hle::xg::,hle::d3d12x::pso_async::20 passed, 0 failed, 1 ignored. No SKIPPED.Not run: Windows, NVIDIA, the full suite on this tree, more than one run per configuration.
@requiemsnkrp on GitHub · 2026-11-24 11:57 UTC · original
Test report: this PR on an NVIDIA RTX 3060 (Windows), retail title of #505. The sparse-queue stall is gone in this run; the run then ends in a device removal instead.
Build:
main384f7f7+ #605 (c3d350a) + #495 (3ae0841) + this PR (19004e1), merged locally. The one conflict insparse.rsis the same as @bstillbstill's: I keptmain'squeue()and put this PR's comment back onreadback_after_execute. Two test constructors thatmainadded since (insparse.rs's tests) still built aStatewithrb_fence/rb_value; I changed them torb_fences: FxHashMap::default().Tested
cargo test --release -p xcl --test sparse_readback_waits --test sparse_readback_lands: both pass.cargo test --release -p xcl --lib d3d12x::sparse: 13 passed, 0 failed, 1 ignored. The full suite was not run on this tree.XCL_NETWORK=0 XCL_ACTIVITY=1 XCL_PSO_WAIT_MS=50, input by hand, one run each:device_type = "lockhart")sparse: the queue has not reached fence value … after 5 sGPU queue.Wait … did not complete within 5000 mswould close a GPU cycleactivity (2 s)windows+0x23cf683at 220.0 s0x887a0005at 98.5 sThe two runs differ in the console profile as well (I had switched to Series S for the run without this PR and back to Series X for this one), so the table is not a clean A/B. On
main384f7f7alone, Series X, the run before both ended with0x887a0007at 110.1 s; I no longer have its log to count these lines.activity (2 s)window before the removal has 7,028 dispatches (0 presents, 23 submits); the windows before it have 13–154. The same burst shape @am-cob counted before the faults in #675. Local video memory was 14.1 GB on this 12 GB card.ListX #101, with threeWait64BitValueX … bridged to GPU queue.Wait (… prod=qNone …; wait-before-signal)lines 0.1 s before it.Not tested: more than one run of this tree; the same profile with and without this PR; whether this PR plays any part in the device removal (the Series X run on
mainalone also ended in a removal).AI use: Claude Code (Claude Opus 5.5) merged and built the tree, ran the tests, read the logs and wrote this report; the title runs were made by hand on my PC.
@thehollowedone on GitHub · 2026-11-24 12:01 UTC · original
I checked deferred readback order at 19004e1 on Windows 11, RTX 3080 Ti (621.35), Rust 1.99.1 MSVC. The offline workspace build and both stock sparse readback tests passed.
The scratch fixture queued two different writes to the same sparse address on one direct queue, each behind a separate fence value. Both readback submissions returned before either value was signaled. After the compute queue signaled the first value, the CPU view showed the first write while the second was still held. After the second signal it showed the second write. The fixture sampled under the sparse-state lock and passed in all three processes, with no device removal.
Synthetic coverage only. AI-assisted. Codex (GPT-6) extended the fixture and ran the tests.
@Ali-AbdulHadii on GitHub · 2026-11-24 12:29 UTC · original
An independent repro of this on Linux, and an alternative fix.
Setup: RTX 5080 (NVIDIA 620.73.04), proton-cachyos-slr Wine, vkd3d-proton master
30b0eb9+ the repo patch. XCL: a local branch ofmain47efa2e(+ #640, #765, #172 and others, without this PR), retail title 1.0.2.1 in its world.What happened: at ~150 s the whole process froze for ~28 s, until the title's watchdog (
+0x23cf683). XCL's own activity log stopped too. In the crash dump,xcl-activitywaits for the sparse lock insparse::pool_bytes, and the title's submitting thread is insparse::before_executewaiting for an upload slot (sparse: the queue has not reached fence value 54578 after 5 s, logged at 154, 159 and 164 s). It ran right after the fence bridge had released cross-queueWait64waits that the title's graphics and compute queues held on each other. That is the "queue held by a later signal" case this PR describes.Alternative fix tried locally:
readback_after_executesignalsrb_fenceon the title's queue and returns. A worker thread waits for that fence, without the lock, then makes the copy back under the lock, one readback after another, in order. XCL's sparse queue then never waits for a title queue. The cost is that the CPU copy lands just after the GPU work instead of before the title'sExecuteCommandListsreturns.XCL_SPARSE_SYNC_READBACK=1keeps the old way.After: much rarer, not gone. In 12 runs since, 10 logged no
sparse: the queue has not reached …, and 2 logged it 3–4 times (no whole-process freeze seen). So something else still fills the upload slots. I have no unit test for the worker yet.Not tested: Windows, AMD, this PR's own approach.
AI use: Claude Code (Claude Opus 5.5) diagnosed this, wrote the local change and this text; the user approved posting it.
@maephisto666 on GitHub · 2026-11-24 14:40 UTC · original
A retail data point for this PR and #262: retail title 1.0.2.1 on NVIDIA, with thread dumps of the stall. The PR's tests do what they say on today's
main. On the title, the sparse lock-up still happens, throughreadback_now, which this PR doesn't change.Setup
XCL_NETWORK=0.19004e1rebased ontomain47efa2e. One conflict, in the doc comment abovereadback_after_execute, wheremainaddedpub fn queue(); both are kept. TwoStatetest fixtures added onmainsince then needed the samerb_fence/rb_value→rb_fenceschange the PR makes to the existing one.wait_fortimeout naming the queue's last operations). None of them change the sparse code's behaviour.Tests (
47efa2e+ this PR)cargo test -p xcl --test sparse_readback_waits: fails onmainafter 5.3 s, passes with the PR 3/3.cargo test --workspace -- --test-threads=4: 743 passed, 0 failed, 41 ignored; SKIPPEDgpu_geometry_wave32_prefix_count_over_a_maskandgpu_wave32_program_in_wave64_hardware(no wave64).On the title (4 runs with this PR, 2 without, same inputs)
+0x23cf683)mainmain+ this PRmain+ this PRmain+ this PRWhen it happens, the sequence matches the issue:
Mapgoes tores_map → sparse::readback_now → readback_ranges → State::wait_for, which waits on the sparse queue while holdingSTATE.wait_fortimes out 3× at 5 s, and the activity log is silent for those 15 s.STATEstays held for good. Without the PR it is held byXMemMapPhysicalPagesScatter → kernelx::home_again → sparse::committed → map_tiles → UpdateTileMappings, in a kernel wait inside the D3D12 runtime/driver. With the PR, by the title's submit thread inq_execute_command_lists → title_textures::refresh → sparse::before_execute → upload_dirty, which loops onwait_foruntil the 64 MB ring has room.STATE: the title's submit thread (nestedq_execute_command_listsfromtexture::upload_batch → late_release::drain_known → sparse::queue),res_release → forget_buffer,xcl-late-release, and a DirectStorage worker (write_physical_pages). Nothing is submitted any more, and the title's watchdog ends it.What the stuck operation was, from the timeout log in the 243 s run:
readback_rangesflush). The 8UpdateTileMappingsand 2 upload lists before it completed.GetDeviceRemovedReasonisOk).late_release): the sparse queue and two title queues are up to date; four title queues are behind, all at the same value.So a plain copy list on XCL's queue, which has no
Waitin it with this PR, does not complete while four title queues are held. I don't know yet why: the driver ordering the copy behind the held queues' use of the same reserved buffer, or those queues waiting on the sparse fence. A run that logs every queue's pending waits at the timeout got no data: the stall did not happen in that run (the 288 s one).In the 288 s run the title slows to 8 → 1 presents per 20 s instead. In every run about 180 compute pipelines are built after world entry, single builds 43–148 s in the driver, and ~30
xcl-pso-*threads mostly wait their turn. That may be what shifts the timing.Not tested: AMD; more runs to say how often the lock-up happens; the synthetic case of a copy on one queue reading a reserved buffer while another queue using it is held.
AI use: Claude Code, Claude Opus 5.5. It rebased the PR, ran the tests and the title runs, read the thread dumps and wrote this report. The runs were on the hardware above.
@Kalmarv on GitHub · 2026-11-24 15:20 UTC · original
Rebased onto
main930e8b4as83bb744(one commit; whole suite on an RTX 5070 Ti: 754 passed, 0 failed, 41 ignored, 2 SKIPPED for no wave64). The smoke pair for this head follows in the description. Replies to the open points:@upipibi (WAITS leak): fixed as you read it.
note_queue_waitdrops the queue's completed waits before adding one and keeps one entry per fence (the highest value);q_releaseforgets a released queue's waits. New testnoted_queue_waits_stay_one_per_fence(1,000 frame-style waits on one fence leave one entry); it fails without the fix.@requiemsnkrp, @bstillbstill: the merge conflicts you described (the doc comment above
readback_after_execute, and the test constructors still usingrb_fence/rb_value) are resolved in this head.@bstillbstill, @maephisto666: the lock-up that remains goes through
readback_now(res_map) andupload_dirty, which this PR doesn't change; it needs its own PR. maephisto666's note that the stuck operation is a read-back list on XCL's queue while four title queues are held is a good lead for that one.@Ali-AbdulHadii (alternative fix): we keep this approach for two reasons. Titles read GPU-written sparse memory on the CPU as soon as their own fence after the work completes; with every copy back on a worker the bytes land later, and
sparse_readback_lands(write, wait for the title's fence, read at once) fails in round 0 that way. And onerb_fencesignalled from several title queues can complete out of order, so each title queue gets its own fence.@freemanovec, @requiemsnkrp (faults / removal on Linux and with #891): what we checked: the readback buffer, allocator and list live until their fence completes, and we found no path that frees them earlier. One ordering change: the copy now runs on the title's queue, so a later tile unmap on XCL's queue is not ordered after it. On a held queue the copy can read a tile already unmapped, which D3D12 defines as zero (tiled resources tier 2); the title's own lists on that queue read the windows with the same ordering. What we can't tell: we have no RADV machine and didn't check what RADV does on such a read, and the reports have no faulting address. The amdgpu fault lines (VA, client) next to the XCL log, or a run of this head and of
mainwith the same profile andXCL_DRED=1, would show whether a copy list from this PR was running.AI use: Claude Code (Claude Opus 5.5)
@upipibi on GitHub · 2026-11-24 15:49 UTC · original
Checked
83bb744'snote_queue_waitandforget_queue: this closes the WAITS point. Completed waits are dropped before each new one, there is one entry per fence (at the highest value), and a released queue forgets its waits. Keeping only the highest value can makemay_be_heldsay "held" a little longer, while a lower wait on the same fence is already done but the higher one is not. That is the conservative side, so readbacks are never let through early. Read, not run.AI-assisted (Claude Code).
@vladbondarenko97 on GitHub · 2026-11-24 21:19 UTC · original · edited 2026-11-24 21:38 UTC
Retail-title A/B on NVIDIA for this PR. GTA VI 1.0.2.1, RTX 3080 Ti 12 GB (driver 610.88), i7-12700KF, Windows 11, release build,
XCL_PSO_WAIT_MS=50 XCL_PSO_TRACE=1, first-run input scripted, 900 s requested.main
b9b6ea6: frames stop at ~150 s. From 154 ssparse: the queue has not reached fence value … (at 40159)every 5 s with the sparse queue stuck at 40159; the labelqueue.Waits are released on CPU but the producers stay atcompleted=0x9da. The title's watchdog ends the run at 179.99 s (+0x2215c35, write at 0), ~30 s after the last present.main
4178e88+ this PR (c20dd22, clean merge →2c7f851):sparse: the queue has not reachedline in the whole run, so on this card the sparse stall is gone.Write64 Signal … on q2/ty2 would close a GPU cycle (waiters=[q3]) – signalled on CPU(q1 too), then at 141.9 sGPU queue.Wait … >= 0x98d did not complete within 5000 ms (waiter=q1/ty2, prod=qSome(3)/tySome(0))and(waiter=q3/ty0, prod=qSome(0)/tySome(2)).0xc0000005 in game_scarlett_master.exe+0x23cf683 (write at address 0x0)(#675's signature).(
2c7f851is a local merge commit of this PR onto main, so the block is evidence, not this PR's required regression block.)So on this title the PR removes the sparse-queue stall. Correction (edited): I first read what is left as a wait cycle among the title's queues; the thread dumps say otherwise. Symbolised with the release PDB, all three dumps (155.3, 170.1, 176.6 s) show:
sparse::STATEinsideUpdateTileMappings(blocked in the NVIDIA driver):kernelx::home_again→sparse::committed→commit_range→ensure_mapped→State::map_tiles;STATEinreal::res_release→sparse::forget_buffer;xcl-activitywaiting for it inpool_bytes(last activity line 146.354 s), and the title's watchdog firing ~29 s later.The 5 s GPU-wait releases (141.9–150.1 s) had stopped by then. Local VRAM use was 14.1–14.4 GB on this 12 GB card from ~106 s (inferred cause of the slow driver call). That is #505's deadlock, which #1697 addresses; a run of main + this PR + #1697 is queued.
Not tested: AMD; this PR together with #1385 (they conflict in
sparse.rs).AI use: Claude Code (Claude Opus 5.5) ran the box, read the log and wrote this report.
@vakaobr on GitHub · 2026-11-25 10:15 UTC · original
Test report from macOS (CrossOver + D3DMetal): #433 at
c20dd22merged intomain568e7db, on its own and under #1329's copy path. @Kalmarv this is the host where #1329 turns the committed window into a copy in video memory by default, so the readbacks this PR fixes run there on every title.Merge notes (local, not pushed):
568e7db: one conflict insparse.rsreadback_after_execute.mainhas since added alist_x::note_internal_wait(…, "sparse readback behind a title queue", &s.rb_fence, v)after the shared-fence wait; I took this PR's side, since that wait andrb_fenceare gone.9ef4696,88cd3a5,ac4b997): one more insparse.rs, where #1326 moves theStateconstruction intonew_state; thererb_fence/rb_valuebecomerb_fences: FxHashMap::default().On this host the tests need two other changes to run at all: #1789 (D3DMetal releases on a thread of its own, where the first read of
XCL_LATE_RELEASEnever returns) and @Ahmet-Dedeler'sddf3be7(D3DMetal's object tables). Without them both tests hang before they reach the readback, onmainand on this PR alike. Every tree below has both merged in.Tested (MacBook Pro M5 Pro, macOS 27.2.1, CrossOver 26.3 with D3DMetal 3.0, Rosetta 2, Rust 1.100.0
x86_64-pc-windows-gnu, debug; each test in its own process, three times; each tree built in its own target directory, and I checked that only the PR's builds contain its code):sparse_readback_waitssparse_readback_landsmain+ this PR's two tests onlyqueue A did not finish in 5 sq_wait(removed again), the title thread'sWaitreaches the new override on D3DMetal and the readback sees queue A as held, as designed.hle::d3d12x::sparse::testspass (noted_queue_waits_stay_one_per_fenceincluded;the_sparse_state_is_replaced_outside_its_lockskips, no GPU UMA), andsparse_reinitpasses.Not tested: Windows, the whole suite, a title, @CharlyRien's per-queue variant.
AI use: Claude Code, Claude Opus 5.5 merged the trees, ran the tests above on this machine and wrote this report.
@Kalmarv on GitHub · 2026-11-25 14:28 UTC · original
Closing in favour of @Ariorh1337's #1993. It fixes the same stall more fully: copies back run asynchronously on queues of their own, so a submit no longer waits on the CPU while holding the sparse lock. @lucsoft confirmed on #505 that with #1993 the submit thread no longer waits on the sparse
STATElock. Anything still useful from this PR's queue-wait bookkeeping can go into a follow-up on top of #1993 if review asks for it.Thanks to everyone who tested this PR.
AI use: Claude Code (Claude Opus 5.5) wrote this note.
@DavidM1911 on GitHub · 2026-11-25 14:29 UTC · original
Verification on RTX 3060 Ti (Windows 11): merge conflict with current
main(crates/xcl/src/hle/d3d12x/sparse.rs) — needs a rebase before it can be tested.Pull request closed