Skip to content

D3D12.X: a sparse list still in flight after its bounded wait is held, not reset - #3062

Closed
KOLESNiii wants to merge 2 commits into
xcl-dev:mainfrom
KOLESNiii:port/c16-sparse-pending
Closed

KOLESNiii wants to merge 2 commits into
xcl-dev:mainfrom
KOLESNiii:port/c16-sparse-pending

Conversation

@KOLESNiii

@KOLESNiii KOLESNiii commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

The sparse queue's wait (wait_for) gives up after 5 s and goes on. begin_slot and the readback path then Reset the allocator and list of the submission the wait gave up on, while the GPU may still be executing it. D3D12 does not allow that. Retail runs on other machines log the timeout (sparse: the queue has not reached fence value … after 5 s) five or more times a run: #675, #505, #846, #646.

Now a pair that is still in flight after the wait is held until the queue has passed its submission, and a new pair takes its place. Part of #3011 (C16); the mechanism follows Vice-Tay b06fdd5.

What is in it

  • crates/xcl/src/hle/d3d12x/sparse.rs:
    • wait_for returns whether the fence was reached. The bound (5 s) is unchanged.
    • New hold_pending: the old allocator and list go to held_lists with the fence value of their last submission, and a new pair replaces them. If no new pair can be made, it waits without a bound instead of resetting.
    • begin_slot (upload slots) and the readback list use it. reclaim_ring drops held pairs once the fence has passed.
    • Test a_slot_still_in_flight_after_the_wait_is_held_not_reset. It holds the queue on an unsignalled fence (queue.Wait), submits a slot, comes round to it again with a 20 ms bound, and checks that the slot got a new allocator and that the old one goes once the queue is released. A test-only override of the bound (wait_ms) keeps it short.
  • Second commit, sparse.rs: wait_for checks the fence after every wake and waits again against the same deadline. The sparse fence waits share one auto-reset event, so a wake left behind by a wait that gave up ended the next wait at once, and it reported "not reached" without waiting (found by pickles976 on D3D12.X: a sparse readback its wait gave up on is not copied into title memory #3063; main has the same single wait). The timeout warning now gives the time actually waited. Test a_stale_wake_does_not_end_the_next_wait: a wake is left on the event, then a wait for the next value, signalled from another thread 20 ms later, must return true after at least 10 ms.
  • THIRD_PARTY.md: a row for Vice-Tay. No code is taken from it, only the mechanism (a submission whose bounded wait timed out stays pending until its fence has passed), reimplemented here.

This makes the lifetime of the lists safe, not the bytes. After a timed-out wait, flush_and_copy still copies the readback buffer into title memory; #3063 (stacked on this one) leaves that copy out. The upload staging ring was already safe: its space is freed only for completed fences.

Tested

  • NVIDIA GeForce RTX 2070 SUPER 8 GB (32-lane waves), driver 621.40; AMD Ryzen 5 3600XT; 32 GB; Windows 11 Home 26300; rustc 1.100.0 MSVC; tests in debug, smoke in release.
  • cargo build --workspace then cargo test --workspace --no-fail-fast -- --test-threads=4 at e9e84e87: 1467 passed, 0 failed, 47 ignored; 25 SKIPPED (no wave64 on this adapter, and one "no heap windows").
  • cargo test -p xcl --lib sparse:: at e9e84e87: 19 passed, 0 failed, 1 ignored (early_commit_timing, ignored on main too). a_stale_wake_does_not_end_the_next_wait alone: passed 3 of 3.
  • Without the fixes, the new tests fail. Without the hold in begin_slot: "an allocator the GPU may still execute was reset for reuse". With the old single wait: "the wait ended on a stale wake after 111–192 µs", 3 of 3.

Regression run
Both 60 s, XCL_PREPARE=0 (full shader preparation does not finish in time on this machine), XCL_PRESS_AT=25:A, a new empty XCL_DXIL_CACHE for each run, the same retail game.

main:

xcl-smoke v1
commit: 6089122a1c96dff16e93b6fdf04c8ed20cfb6102
gpu: NVIDIA GeForce RTX 2070 SUPER
title: retail game
seconds: 60
exit: 0x0
frames shown: 1287 (PresentX 1287)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16057 MB

This PR:

xcl-smoke v1
commit: e9e84e87e1da60ae3d69f6652741f536e48b4ef5
gpu: NVIDIA GeForce RTX 2070 SUPER
title: retail game
seconds: 60
exit: 0x0
frames shown: 1490 (PresentX 1491)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15877 MB

Not tested

AI use

  • Claude Code with Claude Opus 5.5 compared the two trees, wrote the changes, the tests and this description, and ran the tests and the smoke runs on the hardware above. Claude Opus 5.5 sub-agents reviewed the diff (Rust and D3D12 reviews; no blocking findings).

Credit: the mechanism is Taynan Piza's (Vice-Tay #307, b06fdd5).

🤖 Generated with Claude Code

…, not reset

The sparse queue's wait (wait_for) gives up after 5 s and goes on.
begin_slot and the readback path then Reset the allocator and list of
the submission the wait gave up on, while the GPU may still execute it,
which D3D12 does not allow. Retail runs on other machines log the
timeout ("sparse: the queue has not reached fence value ... after 5 s")
five or more times a run (xcl-dev#675, xcl-dev#505, xcl-dev#846, xcl-dev#646).

wait_for now says whether the fence was reached. When it was not, the
allocator and list go to held_lists with the fence value of their last
submission, a new pair takes their place, and reclaim_ring drops held
pairs once the queue has passed that value. If no new pair can be made,
the wait goes on without a bound instead of resetting.

The mechanism follows Vice-Tay b06fdd5 (GPL-3.0-or-later): a submission
whose bounded wait timed out stays pending until its fence has passed.
No code is taken from it (THIRD_PARTY.md). C16 of xcl-dev#3011.

This makes the lists' lifetime safe, not the readback bytes: after a
timed-out wait, flush_and_copy still copies the readback buffer into
title memory (a separate change).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The sparse queue's fence waits share one auto-reset event. When a wait
gives up and its value is reached later, the event stays signalled, and
the next wait woke at once, checked the fence once and reported that the
queue had not got there, without waiting. With xcl-dev#3062 and xcl-dev#3063 that
answer holds a list back or skips a readback copy that would have been
fine 20 ms later; before them the caller went on early.

wait_for now checks the fence after every wake and waits again against
the same deadline until its value is reached or the bound is spent. The
timeout warning gives the time actually waited, not the bound.

Found by pickles976 in a review of xcl-dev#3063 (stale wake consumed by the
next wait). The new test leaves such a wake on the event and fails
without the change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@andrewDoing

Copy link
Copy Markdown
Contributor

I checked the previously untested native D3D12 debug-layer path on RTX 5070 / NVIDIA 616.92 at head e9e84e87, using a test-only fixture with two consecutive bounded sparse-queue waits and controlled gates. Three fresh-process runs passed without skips or debug-layer errors.

While the sparse queue was blocked, both 20 ms waits timed out. XCL retained both pending allocator/list pairs and used a distinct replacement for each subsequent recording. Releasing the first gate advanced the fence from 0 to 1 and reclaimed only the first pair; releasing the second advanced it to 3 and reclaimed the remaining pair.

This tests the synthetic allocator lifetime and reclamation path under a stalled queue. It does not test retail stalls, physical memory savings, or readback contents.

AI use: OpenAI Codex with GPT-6.2 Astra built and ran the checks; Codex reviewed and prepared this report.

@KOLESNiii KOLESNiii closed this Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants