D3D12.X: a sparse readback its wait gave up on is not copied into title memory #3063
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3063"
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 KOLESNiii on 2026-11-27T18:42:17Z.
Stacked on #3062; only the top commit (
89bcf0d8) belongs here.readback_rangessubmits the copies from the sparse windows into the readback buffer, waits for them (at most 5 s), then copies the buffer into the CPU view and records the sent hashes. When the wait gave up, the GPU copies have not run, and the buffer still holds an earlier readback, of other addresses. Those bytes were written into the title's memory as if they were its own, and hashed as sent. Retail runs log this wait timing out (#675, #505, #846, #646). Part of #3011 (C16).Now that batch's copy and hashes are left out, so the CPU view keeps its own bytes. A rate-limited warning counts these readbacks.
What is in it
crates/xcl/src/hle/d3d12x/sparse.rs:flush_and_copyinreadback_rangesleaves the copy out whenwait_forsays the fence was not reached.a_readback_the_wait_gave_up_on_leaves_the_cpu_view_as_it_was. It fills the readback buffer with an earlier readback's bytes, holds the queue on an unsignalled fence, reads back with a 20 ms bound, and checks that the CPU view is unchanged. Once the queue is released, the same readback must bring the bytes the GPU holds (0x3C, uploaded first) into the CPU view. That retry is the check pickles976 asked for; it failed before the stale-wake fix in #3062.Tested
cargo build --workspacethencargo test --workspace --no-fail-fast -- --test-threads=4at89bcf0d8: 1468 passed, 0 failed, 47 ignored; 25SKIPPED(no wave64 on this adapter, and one "no heap windows").cargo test -p xcl --lib sparse::: 20 passed, 0 failed, 1 ignored (early_commit_timing, ignored onmaintoo). The new test alone: passed 3 of 3.Regression run
Both 60 s,
XCL_PREPARE=0,XCL_PRESS_AT=25:A, a new emptyXCL_DXIL_CACHEfor each run, the same retail game.main:This PR:
Not tested
main.()throughreadback_ranges/readback_now/readback_after_execute, so callers get no failure receipt.AI use
🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by pickles976 on 2026-11-27T19:07:22Z.
Verified stacked production head
1409b38b72(#3062 parent5a9c5ed427) on Wine 11 / Linux 6.17 / real NVIDIA RTX 4060 Laptop, driver 590.48.1. Test-only strengthening selects NVIDIA explicitly and uses panic-safe CPU fence release before State destruction. Diagnostic-relaxed vkd3d-proton 2576c0b4adfae4a+, not stock certification.The allocator-retention test passes, but extending readback to a successful retry exposes the shared-event wait bug.
The original timeout checks pass: real GPU bytes 0x3C are seeded, CPU is changed to 0xAA, stale readback buffer is poisoned 0xBB, and a CPU-held queue gate forces the 20ms timeout. CPU bytes and
senthashes stay unchanged. After releasing the gate and waiting for actual completion, retrying the same 4KiB range fails to publish the GPU bytes. Log says fence4 timed out “after 5 s (at 3)”, yet the complete two-test run took only1.32s. Fence4 had completed by the later assertion, but the CPU copy had already been skipped. This run:1pass/1fail, fresh26.13s compilation.A separate, GPU-work-free fence fixture isolates the event behavior:
fence.SetEventOnCompletion(1, state.event)then CPUfence.Signal(1); leave the old event wake pending.state.wait_for(2)with200ms test budget.Observed:
reached=false, observed=1, final=2, elapsed=33.8us, budget=200ms;0/1fail. The old event wake is consumed by the new wait.WaitForSingleObject's result is ignored, and the helper makes only one completion-value check. Logging the configured budget as elapsed time masks the premature return. This isolates the behavior in this head; not a matched-parent regression claim or a GPU hang.Causal control: a temporary local helper-only probe rechecked the requested fence after every wake and waited against the same absolute deadline (including stale wakes), without resetting the event, forcing completion, raising the production5s budget, or changing the readback algorithm. All3 fixtures then passed, including the actual GPU retry and allocator retirement. Isolated wait:
reached=true, observed=2, final=2, elapsed=20.3044ms. Fresh26.12s build,1.84s tests. The temporary production probe was restored; only test changes remain. This is diagnostic evidence, not an owner-head pass or runtime promotion.Local evidence directories:
verify-xcl3063-timeout-retention-retry-20261127T185842Z/verify-xcl3063-stale-event-wait-20261127T190146Z/verify-xcl3063-deadline-wait-probe-20261127T190403Z/Suggested owner correction: deadline-based fence rechecking, explicit event/failed-wait/device-removal handling, and keep the successful retry assertion alongside the timeout assertion. A simple ResetEvent before waiting does not establish protection against a late old registration. True timeout still returns
()throughreadback_ranges/readback_now/readback_after_execute; callers have no pending/failure receipt, so this alone does not prove CPU consumers cannot continue with stale data. State teardown/pending-buffer lifetime and allocation-failure fallback remain untested. No title launch, shader dispatch, memory-saving claim, or attribution to the separate Game-Initcpu_writesfence0/wanted1 watchdog. All external resource guards stayed unchanged.Imported from ivall/xcl. Originally posted by KOLESNiii on 2026-11-28T01:10:10Z.
@pickles976 thanks, confirmed against the source:
wait_for(sparse.rs) made oneWaitForSingleObjecton the shared auto-reset event and oneGetCompletedValuecheck, and ignored the wait's result. So a wake left behind by a wait that had given up ended the next wait at once. The bug is older than these PRs (mainhas it too, where the caller just went on early), but here afalseholds a list back or skips the copy, so it matters more.Fixed in a new commit on #3062,
e9e84e87("D3D12.X: a sparse fence wait rechecks the fence after every wake"). #3063 is rebased onto it (now89bcf0d8).wait_forchecks the fence after every wake and waits again against the same deadline, until its value is reached or the bound is spent. A failed or timed-out wait ends it. The event is not reset (as you said, that does not protect against a late old registration). The warning now gives the time actually waited, not the bound.a_stale_wake_does_not_end_the_next_wait: it registers a value and reaches it from the CPU, leaving the wake on the event, then waits for the next value, which another thread signals 20 ms later. The wait must returntrueafter at least 10 ms.a_readback_the_wait_gave_up_on_leaves_the_cpu_view_as_it_wasnow seeds the GPU page with 0x3C. After the queue is released, the same readback must bring those bytes in (your retry assertion).Tested (RTX 2070 SUPER, driver 621.40, Windows 11 26300, debug tests): full suite
--no-fail-fast --test-threads=4: 1467 passed / 0 failed / 47 ignored / 25 SKIPPED ate9e84e87, and 1468 / 0 / 47 / 25 at89bcf0d8. The stale-wake test passed 3 of 3 on both heads, and the readback test 3 of 3 on89bcf0d8. With the old single wait put back, both failed 3 of 3: "the wait ended on a stale wake after 111–192 µs", and "a readback after the queue was released did not copy the GPU's bytes" (your failure). Smoke, 60 s on a retail game: 1490 frames ate9e84e87and 1497 at89bcf0d8, 0 removals, 0 crashes (both are in the PR descriptions).Not changed, as you noted: a real timeout still returns
()throughreadback_ranges/readback_now/readback_after_execute, so callers get no failure receipt. Teardown of a pending buffer and the allocation-failure fallback remain untested. Both are outside this PR.AI use: Claude Code (Claude Opus 5.5) checked the finding, wrote the fix, the tests and this reply at the account owner's request.
Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-28T01:45:16Z.
I checked the device-removed fence sentinel on head
89bcf0d8with a deterministic CPU-only harness using the exactState::wait_formethod and fake fence/event responses.ID3D12Fence::GetCompletedValuereturnsUINT64_MAXon device removal (Microsoft documentation).For a nonzero target, injecting that value at entry or after a wake returned true in both cases. Controls behaved as expected: pending timeout returned false; exact, past, and pending-then-completed values returned true.
The comparison treats the removal sentinel as completion. In
readback_ranges, a true result permits copying staging contents and updating sent hashes even though this return value does not establish GPU completion. This harness tested decision logic only; it did not induce a device removal or observe corrupted pixels.A simple global change to return false on the sentinel needs care: the allocation-failure path retries
wait_forin a loop. A distinct terminal removal result or a readback-specific guard could avoid confusing removal with an ordinary timeout.AI use: OpenAI Codex with GPT-6.2 Astra built and ran the harness; Codex reviewed and prepared this report.
Imported from ivall/xcl. Originally posted by KOLESNiii on 2026-11-28T03:02:06Z.
@andrewDoing thanks. Confirmed by reading
89bcf0d8:wait_for(sparse.rs:847) treatsGetCompletedValue() >= targetas reached, so after a device removal (UINT64_MAX) it returnstrue, andreadback_ranges(sparse.rs:1111) copies the readback buffer into the title's memory.I'm leaving it as it is in this PR:
main,wait_forreturns nothing, andreadback_rangescopies after every wait, whether the queue got there, the wait timed out or the device is gone. This PR stops the copy only after a timeout; removal behaves as onmain.wait_forreturningtrueon the sentinel is also what letswhile !self.wait_for(fv) {}(sparse.rs:898, when no new command list can be made) end on a removed device. Returningfalsethere would turn it into a hang.If a removal needs its own handling here, I'd add it as a separate change: a check of the sentinel in
readback_rangesbefore the copy, rather than a change towait_for. A device removal during a readback was not induced on hardware for this PR.AI use: Claude Code (Claude Opus 5.5) checked the finding against the code and wrote this reply.
Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-28T04:30:02Z.
I tested the suggested readback-local approach on top of
89bcf0d8, reusing the existinggpu::fence::completed_valueremoval check before staging bytes andsenthashes are published. The sharedwait_forbehavior remains unchanged, so the allocator retry path still exits on removal.In a test-only extension of the existing native sparse readback fixture, the real queue and device remained healthy. After a real completed GPU copy, an auxiliary D3D12 fence initialized to
UINT64_MAXwas substituted only for the final readback observation. With the guard, CPU bytes andsenthashes stayed unchanged; a subsequent normal observation copied the expected bytes. Removing only the guard failed the same fixture at the stale-publication assertion. Sparse and shared-fence tests on the candidate: 25 passed, 0 failed, 1 ignored timing benchmark, no explicit skips.This is a local candidate, not an actual device-removal test or a complete lifetime fix. A removal occurring after the final observation remains outside the check, and no retail behavior or performance was measured.
AI use: OpenAI Codex with GPT-6.2 Astra built and ran the test; Codex reviewed and prepared this report.
Pull request closed