D3D12.X: run sparse::readback_after_execute asynchronously per queue #1732
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!1732
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1732"
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?
@gustavsi on GitHub · 2026-11-24 20:01 UTC · original
gustavsi:wine/async-sparse-readback→main· +1344 −87 · 13 files · 4 commits · openMove
sparse::readback_after_executeoffsparse::State::queueand out from underSTATE.lock()into per-queue FIFO background workers, completing asynchronously when the queue has an unsatisfied title/wait-before-signal GPUqueue.Wait(avoiding CPU/GPU deadlocks on wait-before-signalWait64BitValueX) and synchronously otherwise (preserving immediate CPU visibility after a GPU fence wait). Part of #1452.Stacked on #877; only the top commit (
87287c44) belongs here.Previously,
sparse::readback_after_executelockedSTATE, calleds.queue.Wait(&s.rb_fence, v), and synchronously executeds.readback_ranges(&merged)(s.wait_for(s.value)with a 5,000 ms timeout) insideExecuteCommandLists. When an async compute queue carried both a sparse memory write and a wait-before-signalWait64BitValueXwhose producer direct queue had not yet been submitted on the same thread, this deadlocked both the submitter thread (preventing submission of the producer queue) andsparse::State::queuefor 5,000 ms per submit, triggering repeatedxcl-sync-watchdogtimeouts and causing a retail title's stall watchdog to abort after 5–6 consecutive submits.With per-queue FIFO workers waiting on a raw per-queue fence outside
STATE.lock()before invokingreadback_ranges,sparse::State::queueis never stalled behind a blocked title queue. Active unsatisfied titlequeue.Waitcalls and unsubmitted wait-before-signalWait64BitValueXbridges are tracked viasparse::note_queue_wait(ignoring XCL's own internal fences such assparse::before_execute'ss.fenceso an in-flight internal upload underXCL_D3D12_DEBUG=1never causesreadback_after_executeto return beforeCopyBufferRegioncompletes, fixing theWrite32BitValueBottomOfPipeXzero-read reported by @razormontana).If a fence wait times out after 5,000 ms (while the device is still alive), the worker wakes any synchronous caller with
RbStatus::Deferred(never falsely claimingRbStatus::Completed) and retains the job in a per-worker FIFOdeferred: VecDeque<RbJob>queue, polling and draining it in order once the fence completes so CPU coherence is never silently lost (fixing @bmjask's P1).What is in it
crates/xcl/src/hle/d3d12x/sparse.rs:RB_QUEUESmap (RbQueueStateholding a rawID3D12Fenceviasuper::real::create_raw_fence, monotonic fence value, and channel sender to a dedicatedxcl-sparse-rb-<queue>FIFO worker thread) andQUEUE_WAITStracking (note_queue_wait,queue_has_unsatisfied_wait,forget_queue).readback_after_executefilter/merge sparse ranges usinguma::get(), signal the queue's fence, register new queues withs.note_queue(queue)(preserving #2345's parked-tile quarantine tracking outside the hot path), and enqueue anRbJobwithout holdingSTATEacross GPU waits — returning immediately ifqueue_has_unsatisfied_waitis true, or waiting on the job'sRbStatuscondvar outsideSTATE.lock()otherwise (logging when a synchronous wait is deferred instead of completed).spawn_rb_worker_with) wait on its fence outsideSTATE.lock()(5,000 ms timeout). On completion, drain any earlier deferred jobs first in FIFO order, runreadback_ranges, and reportRbStatus::Completed; on timeout (whileGetCompletedValue() != u64::MAX), reportRbStatus::Deferredand retain the job indeferred: VecDeque<RbJob>so it retries every 20 ms (and on subsequent jobs / bounded teardown drain) until the fence completes.readback_after_execute_does_not_block_on_stalled_queueinternal_fence_wait_keeps_readback_synchronoustimeout_then_completes_still_reads_back_cpu_memory(verifies a timed-out job reportsRbStatus::Deferredinstead ofCompleted, does not run readback early, and automatically runs once the fence later signals, followed by a subsequent job completing withRbStatus::Completedin FIFO order).crates/xcl/src/hle/d3d12x/real.rs&crates/xcl/src/hle/d3d12x/list_x.rs:queue.Waitcalls (is_fenceinq_wait_pcandqueue_dispatch) and unsubmittedWait64BitValueXGPU bridges (unsubmittedintry_gpu_wait) viasparse::note_queue_wait, and clean up per-queue state inq_releaseviasparse::forget_queue.Tested
GE-Proton11-14-x86_64,vkd3d-proton(-Db_ndebug=true), DXC 1.9.2609.5, cross-compiledx86_64-pc-windows-msvc(clang-cl+lld-link).main08db8020+ updated #867 (e57cb659) + #871 (8f08d7cd) + #877 (a553a224) at87287c44and verified under Proton (XCL_DXC_DIRset):hle::d3d12x::sparse:: --test-threads=1: 21 passed, 0 failed, 1 ignored (includingtimeout_then_completes_still_reads_back_cpu_memory,readback_after_execute_does_not_block_on_stalled_queue, andinternal_fence_wait_keeps_readback_synchronous)hle::d3d12x::list_x:: --test-threads=1: 40 passed, 0 failed, 0 ignoredhle::d3d12x::real:: --test-threads=1: 62 passed, 0 failed, 0 ignoredhle::d3d12x::alloc_pool:: --test-threads=4(× 3): 4 passed, 0 failed, 0 ignored eachpwsh ./scripts/smoke.ps1(withGE-Proton11-14wrapper):646frames shown (PresentX 646,0 0 29/2 s),exit: 0x0,0crashes,0device removals.Regression run
Produced under Wine (
GE-Proton11-14, AMD Radeon RX 9060 XT,XCL_NETWORK=0 XCL_PSO_PRELOAD=0 XCL_RUN_SECONDS=60 XCL_ACTIVITY=1,VKD3D_CONFIG=""). The PR run used unmodifiedpwsh ./scripts/smoke.ps1via a thin Wine wrapper;main(e0d93c84) crashed before writingreport.json, so its block was extracted from the samexcl.log(peak commit: 0 MBis what Wine reports inxcl.log).main(e0d93c84):This PR (
87287c44, stacked on #877):Not tested
XCL_D3D12_DEBUG=1).AI use
RbStatus+ retained FIFOdeferredretry fix andtimeout_then_completes_still_reads_back_cpu_memoryregression test for @bmjask's P1 review, rebasing ontomain(08db8020) + updated #877 (a553a224), running the Proton test/smoke verification, and drafting this update.@LocranKing on GitHub · 2026-11-24 20:37 UTC · original
Independent Windows release GPU check on NVIDIA RTX 3060 Ti (
00eec16bbc2b41bc4f56d0f8486dfbcbe8073169, merge-baseb7aa9f3bd212088e0d927439284dc5ed325ce3c7):test_title_runs_and_game_folder_is_untouchedfails onWrite32BitValueBottomOfPipeX: 0x0(the 60 s retail smoke passes).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)101: 773 passed, 1 failed, 41 ignored across 20 result blocks (SKIPPED: 2no wave64, 2no D3D12 debug layer).crates\xcl\tests\e2e.rs:132:5(test_title_runs_and_game_folder_is_untouched): This looks directly related to movingsparse::readback_after_executeonto an asynchronous per-queue worker: after the title's GPU fence wait completes, the CPU reads0x0before the async readback copies the GPU write back to CPU memory.b66a150,fbf1440) on top ofb7aa9f3.Regression run (
scripts/smoke.ps1, 60 s,XCL_NETWORK=0, title folder name redacted)b7aa9f3:1585 / 1508frames (105.1%),15209 / 14730 MBpeak commit (103.3%),0device removals,0crashes.Base (
mainb7aa9f3):PR head (
00eec16):Not tested: Linux / Wine, repeating
e2eto measure flake rate vs deterministic failure, AMD / wave64 hardware.AI use: Antigravity (
Gemini 4 Neon) built and ran the workspace test suite and smoke pair on this hardware and drafted this report from the captured outputs; reviewed before posting. No game files attached.@gustavsi on GitHub · 2026-11-24 21:13 UTC · original
Thanks @LocranKing for catching that on Windows!
Your diagnosis was spot on: when an unstalled queue (like
testtitle'sWrite32BitValueBottomOfPipeX+wait(&queue, &fence, 1)) completes, the title's own GPU fence completed before the background worker finishedreadback_ranges.Updated
64cb447to track active unsatisfiedqueue.Waitcalls (sparse::note_queue_waitinq_wait_pcandlist_x::try_gpu_wait, cleaned up inq_releaseviasparse::forget_queue):queuehas an unsatisfiedqueue.Wait(wait-before-signalWait64BitValueXwhose producer is not yet submitted),readback_after_executereturns immediately while the per-queue FIFO worker finishes asynchronously (never deadlocking the submitter thread or stallingsparse::State::queue).queuehas no unsatisfiedqueue.Wait,readback_after_executestill waits on the queue's fence outsideSTATE.lock()and offsparse::State::queue, but waits for the FIFO worker's completion condvar before returning so CPU reads right after a GPU fence wait always observe the updated bytes.(The two earlier commits
b66a150/fbf1440are there because this PR is stacked on #877 for Wine smoke testing; only the top commit64cb447belongs to this PR.)@DavidM1911 on GitHub · 2026-11-24 22:37 UTC · original
Verification on RTX 3060 Ti (Windows 11): merge conflict with current
mainincrates/xcl/src/hle/d3d12x/vram.rs— needs a rebase before it can be tested.@gustavsi on GitHub · 2026-11-24 22:44 UTC · original
Thanks @DavidM1911! Rebased the stack (#867 -> #871 -> #877 -> #1732) onto
main689f2db(HEADe4d8229, resolving thevram.rsconflict) and re-verified unit/GPU tests and the 60 s smoke run under Wine — ready for Windows testing.@JJAutoCompare on GitHub · 2026-11-25 04:09 UTC · original
XCL PR #1732 verification on Intel Arc A770
Head
e4d8229650344e003513bd3775eb90502854c96b, detached and clean. STOR-WINLAB ran Windows x64 build 26200.9974 on an AMD x64 CPU and Intel Arc A770 (driver 32.0.101.9175). DXC 1.9.2609.5 and rustc 1.100.0 (0ef1bc386, x86_64-pc-windows-msvc). Debug profiles, with debug info and incremental compilation disabled.Tested
cargo build --workspaceandcargo test --workspace --no-runsucceeded outside the Arc mutex. Cargo listed 19 test binaries.cargo test -p xcl --lib hle::d3d12x::sparse::tests::<name> -- --exact. Each reported 1 passed, 0 failed, 0 ignored and 0 skip markers.readback_after_execute_does_not_block_on_stalled_queueexercised sparse UMA on the A770. It asserted return in under one second with an unsignaled compute-queue fence, availability ofSTATE, and queue drain after the fence was signaled. It then exercised the unstalled call.ensure_mapped_with_query_holes_skips_uncommitted_pages_on_readbackchecked that readback across sparse holes did not fault and that a write to a newly committed page was detected. Both D3D12 filters ran under the Arc mutex withXCL_ADAPTER=A770. The holes test selects the default D3D12 device with a WARP fallback internally.lazy_range_helpers_track_tile_overlap_holes_and_nonzero_pageschecked overlap, hole masks and nonzero-page detection withXCL_ADAPTER=NONE_CPU_ONLYoutside the mutex.cargo test --workspace --no-fail-fast -- --test-threads=4ran once underInvoke-ArcTest.ps1withXCL_ADAPTER=A770andRUST_TEST_NOCAPTURE=1. Exit 101. All 20 result lines (19 binaries and one doctest suite) sum to 954 passed, 25 failed and 45 ignored. All three focused tests also passed in this run.Workspace failures and skips
24 DXIL/recompiler tests failed (20 compute PSO rejections with 0x80070057 and four output mismatches). The title e2e failed its dynamic depth-bias check (blue pixel, expected green). The log contains 25 exact
SKIPPEDlines, excluded from coverage.Not tested
Matched main run, retail-title smoke, sample-data coverage, Wine or other GPUs.
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
pr1732-suite.logand published.@gustavsi on GitHub · 2026-11-25 15:20 UTC · original
Thanks @JJAutoCompare for verifying all three focused
sparse::testson Intel Arc A770!Rebased onto
main(06c9f55) + updated #877 (aec41e2) at2fb4601, verifiedsparse::17/0/1,list_x::34/0,alloc_pool:: --test-threads=44/0 × 3, and a fresh 60 s smoke run (exit: 0x0,1066frames,0crashes,0removals).@razormontana on GitHub · 2026-11-25 16:00 UTC · original
Independent native Windows release test for #1732 on NVIDIA RTX 3070.
The synthetic title's D3D12 debug-layer run read
0x0afterWrite32BitValueBottomOfPipeX, which expects0x12345678intests/testtitle/src/gpu.rs. The assertion surfaced atcrates/xcl/tests/e2e.rs:293. The parent stack passed all five isolated debug-layer trials. The PR head and its local merge each reproduced the zero read in all five trials.Tested
x86_64-pc-windows-msvc, DXC 1.9.2602.17. Release builds ran in a standard user session withXCL_ADAPTER=3070andXCL_NETWORK=0.aec41e2cd15e0dd81ec4c28d82ff4a26929e892a, PR head2fb46019a11a3641453d7c2eef97e72fe894be20, and a cleanly applied local merge of that PR head intomainsnapshot082944135cd2b96288470a595861fa608eee08dc(tree52387c8562305f6f1dd1f58689f337e0a536109f). Each revision had its own Cargo target directory.test_title_runs_and_game_folder_is_untouchedreadback_after_execute_does_not_block_on_stalled_queuetest_title_draws_with_a_root_signature_under_the_debug_layer, isolatede2etest binary, four test threadsCommands used for the build, isolated tests, grouped E2E, and full suite:
Not tested
AI use
@gustavsi on GitHub · 2026-11-25 19:43 UTC · original
Thanks @razormontana for catching and isolating the 5/5
XCL_D3D12_DEBUG=1zero-read on Windows!Root cause:
sparse::before_executecallsqueue.Wait(&s.fence, s.value)on the adopted title queue, which goes throughreal::q_wait_pc. UnderXCL_D3D12_DEBUG=1,s.queue's upload was still in flight whenreadback_after_executeran, soq_wait_pchad recorded XCL's own internals.fenceinQUEUE_WAITS, causingreadback_after_executeto treat the queue as stalled and return before the readback worker finishedCopyBufferRegion.Rebased onto
main(2898511, preserving #2345'ss.note_queue(queue)) + updated #877 (2da0233) at6fa3a01:q_wait_pcnow only records title fences (is_fence(fence)), never XCL's internalcreate_raw_fencewaits;queue_dispatchtracks console title waits;try_gpu_waitonly recordsunsubmittedwait-before-signal bridges.sparse::tests::internal_fence_wait_keeps_readback_synchronousverifying that an in-flight internal raw-fencequeue.Waitdoes not mark the queue stalled and keepsreadback_after_executesynchronous.sparse::20/0/1,list_x::36/0,alloc_pool:: --test-threads=44/0 × 3) and a fresh 60 spwsh ./scripts/smoke.ps1run (exit: 0x0,983frames,57 57 56/2 s,0crashes,0removals). Ready for a Windows debug-layer re-check!@gustavsi on GitHub · 2026-11-25 20:32 UTC · original
Rebased onto
main(e0d93c84) + updated #867–#877 (08abaa07, picking up theUnadoptGuard/orig_fnrace fix and #2118 guards) at1be3831a, verified Proton tests (sparse::20/0/1,list_x::40/0,alloc_pool:: --test-threads=44/0 × 3) and a fresh 60 spwsh ./scripts/smoke.ps1run (exit: 0x0,985frames,54 56 55/2 s,0crashes,0removals).@DavidM1911 on GitHub · 2026-11-26 00:29 UTC · original
Re-verification on RTX 3060 Ti (Windows 11), new head merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.Thanks!
— Devin
@gustavsi on GitHub · 2026-11-26 02:22 UTC · original
Thanks @bmjask for catching the timeout coherence bug and @DavidM1911 for the Windows 11 re-verification!
Addressed the P1 timeout coherence issue and rebased onto
main(08db8020) + updated #867–#877 (a553a224) at87287c44:RbStatus::{Pending, Completed, Deferred}:RbJob::donenow carriesRbStatusinstead ofbool. Whenwait_fence_mstimes out (or sees device removalu64::MAX), the worker notifiesRbStatus::Deferredrather than claiming synchronous completion, andreadback_after_executelogs that synchronous visibility was deferred instead of silently returning as completed.deferred: VecDeque<RbJob>queue. The worker pollsrx.recv_timeout(20 ms)whiledeferredis non-empty, drains ready jobs in FIFO order oncefence.GetCompletedValue() >= value(and before any later job on the same monotonic fence, plus a bounded drain on queue teardown), so CPU coherence catches up once the fence completes.sparse::tests::timeout_then_completes_still_reads_back_cpu_memory(factorsspawn_rb_worker_withwith a 50 ms timeout on a real raw D3D12 fence): verifies the timed-out job reportsRbStatus::Deferred, does not run readback early, automatically runs oncefence.Signal(1)fires after timeout, and preserves FIFO ordering for subsequentRbStatus::Completedjobs.GE-Proton11-14(RX 9060 XT):sparse::21/0/1,list_x::40/0,real::62/0,alloc_pool:: --test-threads=44/0 (× 3), plus a fresh 60 spwsh ./scripts/smoke.ps1run (exit: 0x0,646frames shown,0crashes,0device removals; block updated in PR description).AI use: Antigravity (Gemini 4 Neon) implemented the
RbStatus+deferredretry fix and regression test, rebased ontomain+ updated #877, ran the Proton tests and smoke run, and drafted this comment.mainreaches on Windows; the obstacle is replaced vtables — proposal: proxies #175View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.