D3D12.X: bail out of sparse::upload_dirty ring wait when fence wait times out #1495
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!1495
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1495/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?
@b3IKK on GitHub · 2026-11-24 16:55 UTC · original
b3IKK:d3d12x/sparse-wait-timeout-loop→main· +84 −13 · 1 files · 1 commits · closed without mergingIn
sparse::State::upload_dirty, the ring-space loop calledself.wait_for(fv); self.reclaim_ring();unconditionally. Becausewait_for()logged a warning after 5 s and returned(), a stalled or hung queue causedreclaim_ring()to make no progress and turned the loop into an infinite 5-second-stall loop while holding the globalsparse::STATEmutex, deadlocking every thread callingVirtualAlloc/VirtualFree,before_execute, orreadback_*.This has
wait_for/wait_for_fencereturnboolindicating whether the fence reachedtarget, extractswait_for_ring_space(), and bails out ofupload_dirtycleanly if waiting times out without reclaiming space.What is in it
crates/xcl/src/hle/d3d12x/sparse.rs: returnboolfromwait_for_fence/wait_for, extractwait_for_ring_space()and bail out ofupload_dirtyon timeout/no-progress, and add unit testwait_for_ring_space_bails_on_timeout_and_reclaims_on_progress.Tested
stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1).\scripts\test.ps1(cargo build --workspace+cargo test --workspace -- --test-threads=4): 771 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2no wave64—gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask,gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware)cargo test -p xcl --lib wait_for_ring_space_bails_on_timeout_and_reclaims_on_progress: 1 passed, 0 failedRegression run
main:
PR:
Not tested
AI use
sparse.rs, wrote the fix and unit test, ran the test suite andscripts/smoke.ps1regression runs, and drafted this PR description.github-bot referenced this pull request2026-11-26 04:59:09 +00:00
@WebIdentity1 on GitHub · 2026-11-24 17:03 UTC · original · edited 2026-11-24 17:36 UTC
Additional readback result: the timeout can also overwrite newer CPU bytes with old GPU data. This is now reproduced through production
readback_now, beyond the upload-retry finding below.Same hardware/toolchain as below; each entry is a separate native Windows Session0 process with the identical new synthetic fixture. Counts are passed / failed / ignored.
b7aa9f3bd212088e0d927439284dc5ed325ce3c749bdea91ff6530c710c1fdac13c0f4b8edab4f50b7aa9f349bdea90012965eda27e2a528b02c8722a415bde3c027880012965No skips, harness timeouts or device-removal errors. Each oracle checks all1,024words of one4KiB page. Head failures exit101 after drain/free cleanup; all wrong words are the old
0x11111111, replacing expected0x22222222. The other four runs exit0.The fixture drains initial tile clears, fills the real64MiB ring with0x11 behind a controlled native queue fence, then changes one CPU page to0x22 and calls
readback_now. It primes the ring through productionState::upload_dirtyand seeds that page's hashes throughscan_page, allowing the identical setup on #1385 with its reserved admission space. No fake ring counters or wait results. A guard releases the queue at six seconds, or earlier when readback returns.On this head, upload times out without staging0x22; readback still submits, completes after recovery and copies GPU0x11 over the CPU page. A later explicit same-page retry cannot reconstruct the overwritten bytes. Ring write stays67108864. The parent stages the changed page after recovery (ring67112960). #1385 returns from readback at its five-second admission timeout with CPU0x22 intact; after releasing the queue, retry uploads it correctly. This tests its existing preservation behavior, not a new proposed implementation.
Command,
XCL_ADAPTER=3090orAMD:All227source hashes per tree matched before/after. Fixture SHA256:
f072877a38b6bf69a18167049ab997a12db05127cd6c7c583b76829f183183c4. Patch reverse-apply/diff checks pass. No source push or competing PR.Scope: this calls
readback_nowdirectly, not the public Map ABI. No concurrent CPU write during readback, permanent stall, device-removal recovery, partial multi-run suffix, release/full-suite or retail claim. #1385's separate integration caveat remains in its existing report. AI use: Codex (GPT-6) wrote the fixture, ran/checked these tests and prepared this report.Complete additional readback fixture patch
Native Windows timeout-recovery finding on exact head
49bdea91ff6530c710c1fdac13c0f4b8edab4f50: after the new early return, an unsubmitted dirty page remains marked sent and is skipped on retry. Reproduced on RTX3090 and AMD integrated Graphics. The bounded wait is useful; preserving the pending bytes is also necessary.Overlap follow-up: the earlier #1277 has the same recovery failure (matched native controls). #1385 already identified the hash-loss risk and keeps uploads pending while releasing STATE during waits; its exact-head tests on both GPUs now preserve bytes and pass the existing lock-progress test. Please coordinate these existing alternatives rather than duplicate them. This does not establish full merge readiness.
Tested
Local synthetic fixture (complete patch below), calling production
before_execute/upload_dirty:0x11, and fill the real staging ring behind an explicitly blocked queue fence.0x22, then callbefore_executeagain. The real five-second fence wait expires.senthashes and retry the unchanged CPU bytes. All 1,024 words then match.The same fixture has a six-second recovery guard so the parent implementation can finish its repeated wait. It does not alter ring positions, stage fake data, inject wait results, or hang the GPU. Queue fences drain and
GetDeviceRemovedReasonsucceeds before cleanup/assertions.b7aa9f3bd212088e0d927439284dc5ed325ce3c749bdea9b7aa9f349bdea9No skips or harness timeouts. Head failures exit101 on
retry must upload bytes that timed out before staging; parent runs exit0. All mismatches on head are the old0x11111111words. Ring write position remains67108864 after timeout and retry on head; parent advances to67112960 when recovery permits the page upload.Mechanism / suggested follow-up
scan_pageupdatesentry.sentbeforeupload_dirtyruns. The newreturnonwait_for_ring_space == falsedrops the unsubmitted suffix;before_executethen clearsdirty_runs. On the explicit retry, the CPU hashes already matchsent, so no upload occurs.readback_nowhas the same scan-before-upload ordering.Please retain/retry the unsubmitted ranges or propagate the failure so a submit cannot silently consume stale bytes. Hash invalidation plus the explicit dirty-page retry above is a diagnostic control, not a complete proposed fix: the normal write-watch path uses reset, so the next scan need not rediscover that page. The parent control only proves byte recovery after a transient stall; its indefinitely repeated waits still need fixing.
Command for each fresh process,
XCL_ADAPTER=3090orAMD:cargo test --locked -p xcl --lib timed_out_sparse_upload_retries_unsent_bytes -- --test-threads=1 --show-output --nocaptureWindows10 Home19045; Ryzen7 7800X3D; RTX3090 driver591.74 / AMD Radeon integrated32.0.21030.2001; Rust1.98.1 MSVC, Agility1.620.2, debug, SSH Session0. Full227-file source manifests matched each native test tree. Only runtime file differing between parent/head is
sparse.rs; the same diagnostic is wired into both. Head + fixture restored afterward, all hashes verified. Fixture patch reverse-apply and diff checks pass.Not tested
Full workspace with this fixture, retail /
xcl-smoke, device-removal recovery, partial multi-run suffixes, Linux/Wine, or a release build. This is a transient queue-delay reproducer, not evidence that it caused a particular game's missing assets. Run alone in a fresh process because it initializes sparse globals. No runtime fix or competing PR is included.AI use
Codex (GPT-6) inspected the code, wrote the fixture, ran native validation and prepared this report. Public source and synthetic bytes only.
Complete local diagnostic patch against49bdea9
@b3IKK on GitHub · 2026-11-24 18:28 UTC · original
Thank you @WebIdentity1 for the detailed RTX 3090 and AMD iGPU timeout-recovery reproducers — that is a real bug in this PR's early-return path (leaving \entry.sent\ hashes updated for unsent pages and allowing
eadback_now\ to overwrite newer CPU bytes). Since #1385 already addresses this cleanly by releasing \STATE\ during waits and preserving pending uploads, I am closing #1495 in favor of #1385.
@DavidM1911 on GitHub · 2026-11-24 18:53 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodifiedmain.)Thanks!
Pull request closed