D3D12.X: read back sparse-window Wait64BitValueX counters during CPU waits #1037
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1044"
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?
Imported from ivall/xcl. Originally posted by xroneyaa on 2026-11-24T10:48:40Z.
When a
Wait32/64BitValueXfalls back to CPU polling (PendingWait::wait_until_satisfied) for a counter inside a sparse VRAM window, CPU memory only holds the last uploaded/copied-back value while GPU writes live in sparse VRAM. This reads back[va, va + width)from sparse VRAM (sparse::readback_now) before spinning and at 10 ms intervals during the sleep loop (plus a final readback on timeout). Addresses item #2 measured in#505(and keeps coherent-window / heap addresses lock-free on the fast path viauma::is_sparse). Part of #505.What is in it
crates/xcl/src/hle/d3d12x/sparse.rs:sparse::contains(va): checksgpu::uma::get().is_some_and(|u| u.is_sparse(va))before takingSTATEto verify an active sparse window coversva.crates/xcl/src/hle/d3d12x/list_x.rs:PendingWait::wait_until_satisfied/wait_until_satisfied_with: preserves the zero-overhead fast path when CPU memory already satisfies the wait; for unsatisfied sparse-window addresses, runssparse::readback_now(va, width)before spinning, throttled at 10 ms intervals while polling, and once on timeout expiry.pending_wait_sparse_readback_pulls_gpu_writes_and_skips_coherentverifying coherent waits never call readback and sparse waits pull delayed writes cleanly.pending_wait_reads_back_gpu_write_in_sparse_windowverifying a realCopyBufferRegioninto a sparse window buffer (invisible to CPU-only polling) is read back and satisfiesPendingWait::wait_until_satisfied.Tested
stable-x86_64-pc-windows-msvc), debug (scripts/test.ps1) and release (cargo build --release -p xcl).cargo test --workspace -- --test-threads=4(scripts/test.ps1): 729 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2 (no wave64:gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware)).cargo test -p xcl --lib pending_wait_ -- --test-threads=4: 3 passed, 0 failed (run 3 consecutive times with 0 flakes). Inpending_wait_reads_back_gpu_write_in_sparse_window, CPU-only polling (wait_until_satisfied_with(..., false, ...)) fails on the real GPU sparse-VRAM write beforewait_until_satisfiedpasses with sparse readback enabled.Regression run
main:
PR:
Not tested
Wait64BitValueXcounter explicitly lands in a sparse window on main (not yet triggered during our 60 s retail smoke run).AI use
#505and the D3D12.X sync/sparse implementation, wrote the fix and tests, and ran the test suite and retail smoke runs.Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T11:25:32Z.
Independent verification, merged onto current
main384f7f7locally (clean merge).Machine: Windows 11, Ryzen 9 7900X + RTX 3060 Ti + Radeon iGPU; Rust stable MSVC, debug.
cargo test -p xcl --lib wait: 15 passed, 0 failed — includes the two new testspending_wait_sparse_readback_pulls_gpu_writes_and_skips_coherentandpending_wait_reads_back_gpu_write_in_sparse_window(the latter exercises the real UMA/sparse path).AI use: test runs by Devin (Cognition, SWE-2); no code changes.
Imported from ivall/xcl. Originally posted by AlexandreSchuelter on 2026-11-24T11:26:55Z.
Test report on AMD (RX 6900 XT, RDNA2): no new failures, and the sparse-window GPU test runs (not skipped) and passes here.
Tested
stable-x86_64-pc-windows-msvc, debug; DXC 1.9.2602.17;XCL_NETWORK=0,XCL_REQUIRE_GPU=wave64; no SKIPPED testscargo build --workspace+cargo test --workspace --no-fail-fast -- --test-threads=4:main47efa2e8fd5921) merged onto47efa2emain: the RDNA2 packed-mip failure inplaced_title_textures_share_vram_and_preserve_pixels(fixed by #470 / #1028) and its twoPoisonErrorcascades.pending_wait_reads_back_gpu_write_in_sparse_windowandpending_wait_sparse_readback_pulls_gpu_writes_and_skips_coherentpass; neither printed aSKIPPEDline (no "no GPU" / "no sparse UMA" skip).Not tested
scripts/smoke.ps1(no game here), release build, repeated runs of the new tests, Linux / vkd3d-protonmain)AI use: Claude Code (Claude Opus 5.5) fetched the branch, ran the suites and wrote this report; the runs are real, on the hardware above.
Imported from ivall/xcl. Originally posted by pvfreis on 2026-11-24T12:35:56Z.
Review: COMMENTED
Review of
8fd5921against its merge base6efdabc, by reading the code; nothing was built or run here. The change is small and the lock side is clean:wait_all_onis reached with no XCL lock held (real.rs:5101,list_x.rs:2805after theLISTSguard is dropped),sparse::containsandreadback_nowtake onlySTATE, and nothing underSTATEtakesLISTSorSYNC_GRAPH, so I found no lock-order deadlock. The problem is in whatreadback_nowdoes while it holdsSTATE, which this PR now runs every 10 ms on the waited cell.CONFIRMED: a poll can overwrite a CPU write to the waited cell with the old VRAM value (
crates/xcl/src/hle/d3d12x/sparse.rs:1293-1303, copy at:1032, hash at:1037).readback_nowfirst scans the page and uploads what the CPU changed (:1293,:1301), then submits the copy back, waits for the sparse queue (:1018) and writes the 8 bytes from the staging buffer into the cell (:1032). Nothing stops a title thread from storing to the cell between the scan and the copy; that takes a GPU round trip. Scenario: aWait64BitValueXfalls back to the CPU because noWrite64was recorded for the address (list_x.rs:1803,None => FallbackCpu), and the producer is a title thread that stores the counter on the CPU. If its store lands inside the window, the copy puts the old value back andsync_sent_rangerecords that as sent, so the write is gone for the CPU and never reaches VRAM. Onmainthe same window exists inres_mapandreadback_after_execute, but only for ranges the title asked to read or the GPU just wrote, once; here it is every 10 ms on the cell a writer is expected to hit. Fix: after the copy back, do not store over a cell whose CPU bytes changed since the scan (compare with the value read before the round trip, or compare-exchange for a 4/8-byte range), or copy into a local and only use it for the comparison.CONFIRMED (minor): the cost is not measured, and the regression run does not reach the code. Every readback is a synchronous submit + fence wait on the sparse queue under the global
STATElock, plus allocator and list resets; the first one runs before the 512 spins (list_x.rs:239-244), so a sparse-window wait that another thread would have satisfied within microseconds now pays a GPU round trip. The description says under Not tested that no CPU-fallback wait landed in a sparse window in the 60 s smoke run, so the twoxcl-smokeblocks show only that the fast path is unchanged. Lists that recordWrite32/64into a sparse window are already copied back after execution onmain(list_x.rs:2794,:2817,real.rs:5105), so this PR only adds writes XCL does not record (a shader, a copy).CONFIRMED: the tests cover the first readback on a real sparse window, not the polling.
pending_wait_reads_back_gpu_write_in_sparse_window(list_x.rs:4084-4170) does go throughsparse::alloc,contains, a realCopyBufferRegioninto the window buffer and the realreadback_now, and checks that the CPU view is still zero before; that part does what the description says, and two reports on the PR say it ran unskipped (NVIDIA, AMD RDNA2). But the copy has completed before the wait starts (:4150), so only the readback before the spin runs on a GPU. The 10 ms loop and the readback on expiry are covered with a closure only (:4041-4081), and nothing runs a wait while another thread writes the cell (finding 1). The skip reason"no sparse UMA"(:4093) is new; CONTRIBUTING lists the reasons used so far.Question:
wait_forgives up after 5 s andreadback_rangesthen copies the staging buffer whether or not the copy ran (sparse.rs:811-820,:1018,:1032; that part ismain's). With the sparse queue held behind a title queue (the case #433 is about), is it intended that this wait's readbacks block on it underSTATEand then use those bytes?Against CONTRIBUTING: Regression run, Not tested and AI use are there and the description check is green. AI use names the tool but says the exact model is not known; CONTRIBUTING asks for the exact model, so that is the maintainer's call. Related: #433 (open) changes
readback_after_executeand removesrb_fence; #795 / #797 (merged) and #1045 (open, diagnostics) touch the same wait path inlist_x.rsbut not these lines.Verdict: not ready to merge as it is; the idea is right and the locking is sound, but the poll should not store over a concurrent CPU write (1), and that is not tested.
Review by Claude Code (written by Claude Fable 5.2, checked and edited with Claude Opus 5.5); each point checked by a person before posting.
Imported from ivall/xcl. Originally posted by JJAutoCompare on 2026-11-25T05:31:31Z.
Empirical test report (
8fd59213)Commit
8fd59213003554c868d6b8729ecdb1fb7d09a77c(PR #1044).Hardware / environment
XCL_ADAPTER=A770, Windows x64 build 26200, and an AMD Family 23 Model 113 CPU. The fixture initialized three sparse VRAM windows and a 512 MB coherent window. The GPU driver version was not recorded.rustc 1.100.0 (0ef1bc386 2026-11-09), DXC 1.9.2609.5, and Cargo's unoptimized test profile with debug info and incremental compilation disabled. The focused run usedRUST_TEST_NOCAPTURE=1.Commands and results
cargo test --workspace --no-runcompiled the workspace test binaries outside the Arc lock (exit 0).Invoke-ArcTest.ps1, ran only the two new fixtures using the prebuiltxcllibrary test executable (exit 0):Observed behavior
Not tested
The full GPU workspace suite and game smoke runs were omitted.
AI use
Verified with T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high). Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against
pr1044-focused.logand published.Imported from ivall/xcl. Originally posted by luckyteagirl on 2026-11-25T06:17:57Z.
Independent native Windows AMD GPU check of exact PR head
8fd59213003554c868d6b8729ecdb1fb7d09a77c.Tested
30.0.13002.13003, Rust 1.99.0 MSVC, DXC/DXIL 1.9.2609.5.XCL_ADAPTER=6800M XCL_REQUIRE_GPU=wave64 cargo test --locked -p xcl --lib -j 2 pending_wait_ -- --test-threads=1 --show-output: 3 passed, 0 failed, 0 ignored in 1.26 s, with noSKIPPEDline.pending_wait_reads_back_gpu_write_in_sparse_window. Its log shows three sparse VRAM windows and D3D12.X UMA initialization on the RX 6800M; the GPU fixture completed. The other two wait tests passed as well.This checks the focused sparse readback regression on the PR head. I did not run a full workspace suite, a current-main merge, or a retail title phase with a sparse counter wait. No game data was used or uploaded.
AI-assisted testing and report drafting with OpenAI Codex (GPT-6); I checked the exact revision and test log before posting.
Imported from ivall/xcl. Originally posted by upipibi on 2026-11-25T18:19:21Z.
NVIDIA test report for
8fd5921(head as is, base6efdabc), for #1607's NVIDIA list. RTX 3070 8 GB (Ampere, 32-lane waves), driver 616.56, Windows 11, debug, aftercargo build --workspace:cargo test --workspace --no-fail-fast -- --test-threads=4 --skip hle::xaudio2: 720 passed, 0 failed, 41 ignored. The end-to-end title tests pass.mainat0829441(not currentmain) on the same machine, same command: 1263 passed, 0 failed, 46 ignored (the PR's base is older, so it has fewer tests).hle::xaudio2, because its tests fail or hang on this machine onmaintoo. The PR doesn't touch it.no wave64on this card.AI-assisted (Claude Code, Claude Opus 5.5). Synthetic tests only; no title run.
Pull request closed