D3D12.X: a stalled sparse upload retries its unsent chunks and reuses no busy allocator #2821

Open
github-bot wants to merge 3 commits from github-bot/gh-2821 into main AGit
Owner

@⁠KOLESNiii on GitHub · 2026-11-26 14:29 UTC · original
KOLESNiii:d3d12x-sparse-ring-stall → main · +274 −39 · 1 files · 3 commits · open

Stacked on #1277; only the top two commits belong here. Part of #1833. This is S1 from the extraction plan in #2787.

#1277 (ExoCalibra) stops upload_dirty from looping forever, holding the sparse STATE lock, when the staging ring's oldest fence never advances. That loop blocked xcl-activity and every later title submit. This PR ports #2778's two follow-ups (bmjask):

  • Retry exactly the unsent part. When the ring wait times out, or there is no staging or upload slot, only the 64-byte chunks not yet submitted are marked for the next upload. Chunks already submitted in the same page are left alone. upload_dirty returns whether everything was submitted. A synchronous readback_now stops instead of copying stale GPU bytes over CPU memory when its upload did not go through.
  • No allocator reuse after a failed wait. begin_slot returns None instead of resetting an allocator the GPU may still be using, and checks Reset/Close results. The readback path stops before Reset or before writing to CPU memory when its wait, Close or Reset fails. Failed zero-fills go back to to_zero. The normal path is unchanged.

What is in it

  • D3D12.X: stop sparse upload_dirty ring wait when fence times out: #1277's commit, author kept. For current main, I added the two State fields main has since gained (quarantined, queue_fences) to its test's initializer. Without them the test does not compile. #1277 needs the same fix when it is rebased.
  • D3D12.X: stop stalled sparse ring reclaim cleanly (crates/xcl/src/hle/d3d12x/sparse.rs), ported from faea307a. The conflicts were resolved by hand: #2778's stall tracing span and its quarantine-fence helpers are left out. Tests: a_stalled_ring_retries_only_the_unsubmitted_dirty_suffix, a_stalled_upload_ring_returns_and_retries_exact_chunks.
  • D3D12.X: abort sparse allocator reuse after wait failure (same file), ported from 37271a3c. It keeps main's readback ExecuteCommandLists call, not #2778's native_queue_execute. The stalled-ring test also checks that a slot whose wait timed out is not reset.

Tested

  • NVIDIA GeForce RTX 2070 SUPER (driver 32.0.16.2140), AMD Ryzen 5 3600XT, Windows 11 build 26300, rustc 1.100.0, debug tests and a release smoke run
  • cargo test --workspace -- --test-threads=4 on 475341d1: 1438 passed, 0 failed, 47 ignored
  • 25 SKIPPED on this adapter: 24 recompiler GPU tests with no wave64 (or the wave32 per-lane form refused), and heap_window_out_of_memory_falls_back_to_the_switch_form with no heap windows
  • Each commit of the stack builds (cargo test -p xcl --lib --no-run on the first commit, the full suite on the head)

Regression run

main:

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

This PR:

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

The run never hit a stalled sparse fence, so it does not reach the new failure paths. It checks only that the normal upload path still works.

Not tested

  • A real stalled sparse queue on the retail title. The timeout paths are covered only by the unit tests, with a fence nothing signals.
  • Reset/Close failures. No test injects them.
  • AMD and Intel GPUs. The 47 ignored tests.

AI use

  • Claude Code (Claude Opus 5.5) chose this item from #2787, ported the two commits onto #1277 and resolved their conflicts, fixed the test initializer, ran the tests and smoke runs, and wrote this description. The source commits' own messages name the tools that wrote them (Codex, Antigravity).

🤖 Generated with Claude Code

**@⁠KOLESNiii** on GitHub · 2026-11-26 14:29 UTC · [original](https://github.com/xcl-dev/xcl/pull/2821) `KOLESNiii:d3d12x-sparse-ring-stall` → `main` · +274 −39 · 1 files · 3 commits · open Stacked on #1277; only the top two commits belong here. Part of #1833. This is S1 from the extraction plan in #2787. #1277 (ExoCalibra) stops `upload_dirty` from looping forever, holding the sparse `STATE` lock, when the staging ring's oldest fence never advances. That loop blocked `xcl-activity` and every later title submit. This PR ports #2778's two follow-ups (bmjask): - **Retry exactly the unsent part.** When the ring wait times out, or there is no staging or upload slot, only the 64-byte chunks not yet submitted are marked for the next upload. Chunks already submitted in the same page are left alone. `upload_dirty` returns whether everything was submitted. A synchronous `readback_now` stops instead of copying stale GPU bytes over CPU memory when its upload did not go through. - **No allocator reuse after a failed wait.** `begin_slot` returns `None` instead of resetting an allocator the GPU may still be using, and checks Reset/Close results. The readback path stops before Reset or before writing to CPU memory when its wait, Close or Reset fails. Failed zero-fills go back to `to_zero`. The normal path is unchanged. **What is in it** - `D3D12.X: stop sparse upload_dirty ring wait when fence times out`: #1277's commit, author kept. For current `main`, I added the two `State` fields `main` has since gained (`quarantined`, `queue_fences`) to its test's initializer. Without them the test does not compile. #1277 needs the same fix when it is rebased. - `D3D12.X: stop stalled sparse ring reclaim cleanly` (`crates/xcl/src/hle/d3d12x/sparse.rs`), ported from `faea307a`. The conflicts were resolved by hand: #2778's `stall` tracing span and its quarantine-fence helpers are left out. Tests: `a_stalled_ring_retries_only_the_unsubmitted_dirty_suffix`, `a_stalled_upload_ring_returns_and_retries_exact_chunks`. - `D3D12.X: abort sparse allocator reuse after wait failure` (same file), ported from `37271a3c`. It keeps `main`'s readback `ExecuteCommandLists` call, not #2778's `native_queue_execute`. The stalled-ring test also checks that a slot whose wait timed out is not reset. **Tested** - NVIDIA GeForce RTX 2070 SUPER (driver 32.0.16.2140), AMD Ryzen 5 3600XT, Windows 11 build 26300, rustc 1.100.0, debug tests and a release smoke run - `cargo test --workspace -- --test-threads=4` on `475341d1`: 1438 passed, 0 failed, 47 ignored - 25 `SKIPPED` on this adapter: 24 recompiler GPU tests with `no wave64` (or the wave32 per-lane form refused), and `heap_window_out_of_memory_falls_back_to_the_switch_form` with `no heap windows` - Each commit of the stack builds (`cargo test -p xcl --lib --no-run` on the first commit, the full suite on the head) **Regression run** `main`: ``` xcl-smoke v1 commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7 gpu: NVIDIA GeForce RTX 2070 SUPER title: retail game seconds: 60 exit: 0x0 frames shown: 1480 (PresentX 1480) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 17754 MB ``` This PR: ``` xcl-smoke v1 commit: 475341d1ee5b173dee4107562b2fd38a5fe73dc3 gpu: NVIDIA GeForce RTX 2070 SUPER title: retail game seconds: 60 exit: 0x0 frames shown: 1505 (PresentX 1505) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 16220 MB ``` The run never hit a stalled sparse fence, so it does not reach the new failure paths. It checks only that the normal upload path still works. **Not tested** - A real stalled sparse queue on the retail title. The timeout paths are covered only by the unit tests, with a fence nothing signals. - Reset/Close failures. No test injects them. - AMD and Intel GPUs. The 47 ignored tests. **AI use** - Claude Code (Claude Opus 5.5) chose this item from #2787, ported the two commits onto #1277 and resolved their conflicts, fixed the test initializer, ran the tests and smoke runs, and wrote this description. The source commits' own messages name the tools that wrote them (Codex, Antigravity). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
sparse::State::wait_for intentionally returns after 5 s with a warning if the sparse queue stalls, but upload_dirty wrapped wait_for in a while loop waiting for staging ring space. When the oldest in-flight fence failed to advance, reclaim_ring freed nothing and upload_dirty looped forever while holding the global STATE mutex, blocking xcl-activity (pool_bytes) and every submitting thread.

Return whether wait_for reached its target fence value, bail out of upload_dirty with a bounded warning on timeout so STATE is released, and add a GPU regression test reproducing a full staging ring with a stalled fence.

(cherry picked from commit 0f66820065)
The sparse upload ring retried a five-second fence wait forever while holding global sparse state. A stalled upload queue therefore blocked activity reporting and every later title submission permanently.\n\nAdapt #1277's bounded exit, but preserve correctness beyond the source patch: mark exactly the unsubmitted 64-byte chunk suffix for retry instead of leaving its sent hashes stale or invalidating already-submitted chunks in the same page. A synchronous readback aborts when its prerequisite upload did not complete, so it cannot overwrite CPU memory with stale GPU data.\n\nThe Windows GNU library/test cross-check passed with the existing warnings. Windows MSVC runtime, GPU execution, and smoke tests were not available here.\n\nSource diagnosis and timeout test: #1277 by ExoCalibra, assisted by Antigravity (Gemini 4 Neon).\n\nAssisted-by: Codex (GPT-5.6-sol)

(cherry picked from commit faea307a31)
Sparse upload and readback paths continued after a five-second fence timeout, resetting command allocators which the GPU could still be using and publishing readback staging bytes whose copy had not completed. Reset and Close failures were ignored as well.\n\nMake upload-slot acquisition fail closed, retry exact dirty or zero work, and abort readback before allocator reuse or CPU publication whenever its wait or command-list transition fails. The healthy asynchronous path is unchanged.\n\nThe Windows GNU library/test cross-check passed with the existing warnings. Windows MSVC runtime, GPU execution, and smoke tests were not available here.\n\nAssisted-by: Codex (GPT-5.6-sol)

(cherry picked from commit 37271a3c0e)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 14:31:07 +00:00
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2821/head:github-bot/gh-2821'
git switch 'github-bot/gh-2821'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2821'
git switch 'github-bot/gh-2821'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2821'
git switch 'github-bot/gh-2821'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2821'
git switch 'main'
git merge --squash 'github-bot/gh-2821'
git switch 'main'
git merge --ff-only 'github-bot/gh-2821'
git switch 'main'
git merge 'github-bot/gh-2821'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.