Skip to content

D3D12.X: free late_release's held set when GPU fences stall - #3365

Draft
Dremaus wants to merge 1 commit into
xcl-dev:mainfrom
Dremaus:d3d12x/late-release-backpressure
Draft

Dremaus wants to merge 1 commit into
xcl-dev:mainfrom
Dremaus:d3d12x/late-release-backpressure

Conversation

@Dremaus

@Dremaus Dremaus commented Nov 29, 2026 •

Copy link
Copy Markdown

When the GPU stalls (a hang or an impending removal), XCL's late_release cannot retire the title's
freed resources — it holds the last reference to each (and to held pipelines/heaps) until the owning
queue's fence passes the batch, and a stalled queue never advances its fence. The held set then grows
without bound until the WDDM kernel pool is exhausted and the device resets
(DXGI_ERROR_DEVICE_RESET), masking whatever actually wedged the GPU.

This frees a sealed batch held past STALL_FORCE (5 s) with no fence progress, instead of holding it
forever. It is gated on a true stall (time since the batch was sealed), never on a high count —
under a mere lag the resources are still in flight, so freeing them would be a use-after-free. The
result: a wedged / memory-undersized host fails gracefully (clean OOM or slowdown) and the real cause
stays observable, instead of a kernel-memory DEVICE_RESET.

Context: diagnosed running a 16 GB-console title on an 8 GB laptop GPU — the title exhausts VRAM +
system RAM and wedges; before this, the late_release backlog turned that shortfall into an
0x887A0007 reset at ~200 s instead of a clean failure.

What is in it

  • crates/xcl/src/hle/d3d12x/late_release.rs: Batch.sealed_at; in Held::drain, after the
    fence-completion pop, a stall-only force-free of the oldest batches past STALL_FORCE, with a
    one-time warning. New unit test a_stalled_batch_is_freed_after_the_timeout (ages a sealed batch
    past the timeout without a real 5 s wait).

Tested

  • The change's own tests pass, run directly on the GPU — cargo test -p xcl --lib late_release:
    5 passed, 0 failed, 0 ignored, incl. the new a_stalled_batch_is_freed_after_the_timeout.
    Hardware: NVIDIA RTX 4060 Laptop GPU, driver 617.14; Windows 11 26200; rustc 1.100.0; debug.
  • cargo test --workspace --no-fail-fast -- --test-threads=4: the integration and test-title
    binaries pass (139 passed, 0 failed, 20 ignored, 25 SKIPPED — no wave64 / no XCL_SAMPLE_* /
    no heap windows). The main xcl --lib binary aborted under full parallel GPU+DXC load with an
    unrelated Invalid bitcode signature / abnormal exit (0x80004005) — a GPU/DXC test, not this
    CPU-only late_release change (it reproduces only in the heavy parallel run on a host that had been
    VRAM/RAM-exhausted by the GTA6 sessions, never in isolation). A clean full---lib count on an
    unstressed host is still pending.

Regression run

  • Pending (retail scripts/smoke.ps1). The new code path only triggers on a genuine ≥ 5 s fence
    stall, so a short smoke run on a healthy title shows no behaviour change.

Not tested

  • A clean full xcl --lib count on an unstressed host; the retail smoke comparison; AMD.

AI use

  • Claude Code, Claude Opus 4.8 — wrote the change and the test.

🤖 Generated with Claude Code

late_release holds the last reference to every resource (and the pipelines
and heaps it owns) the title frees, releasing it once each queue's fence
passes the batch. On a wedged or removed GPU the fences stop advancing, so
nothing is freed and the held set grows without bound until the WDDM kernel
pool is exhausted and the device resets (DXGI_ERROR_DEVICE_RESET) - masking
the real cause.

A sealed batch held past STALL_FORCE (5 s) with no fence progress is now let
go without waiting. Safe: a GPU that is not progressing will not touch the
memory, and a lost device makes the references moot. Only on a true stall,
never on a high count alone - under a lag (fences advancing, just behind) the
resources are still in flight and freeing them would be a use-after-free.
This turns the kernel-OOM reset into a graceful slowdown and keeps the real
fault observable.

Found running a 16 GB-console title on an 8 GB GPU: memory exhaustion wedges
the GPU, fences stall, and the late_release backlog then OOMs into a reset
instead of a clean out-of-memory failure.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Nov 29, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Review (head 715f5ac, diff read, not a merge-check; draft, conflicts with main, PR description red):

  • This can free resources the GPU is still using. The new loop (late_release.rs ~110) lets a sealed batch go once 5 s have passed since it was sealed. It never looks at whether its fences moved. The comment at ~24-29 rules out exactly this: "never on a high count alone: under a lag ... freeing them would be a use-after-free". Two cases reach it:

    • a queue that is progressing but more than 5 s behind, plausible on the 8 GB card in the description while it pages VRAM;
    • a queue waiting on a fence the title signals later from the CPU.

    Then resources are released or recycled (recycle_ready), shared-heap views are nulled and Dead::Unmap tiles leave the shared pages while the queue will still write to them. Recording each batch's completed fence values and treating it as stalled only when none of them changed for 5 s would match the comment.

  • The removal case is already covered. On a removed device GetCompletedValue returns UINT64_MAX, so the existing loop frees everything. A real hang ends in a TDR, which is a removal. So the new path only fires while the device is alive, which is when freeing is unsafe.

  • The conflict isn't just textual. d783592 split drain into begin_seal / end_seal / take_gone, and drain is now test-only. A naive rebase leaves the new loop in test code only. It has to go into take_gone, with sealed_at set in end_seal.

  • The test only ages the batch artificially. Nothing checks that a lagging but moving queue keeps its batch, which is the case that matters.

Fine: the test fails without the change and skips without a GPU. #3125 is related and goes the other way (keeping resources when retirement fences fail).

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

@Dremaus

Dremaus commented Dec 1, 2026 via email

Copy link
Copy Markdown
Author

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head 715f5ac

No other open PR makes this change.
late_release.rs Held::drain: the new loop frees every sealed batch whose sealed_at is older than STALL_FORCE (5 s). It never checks whether the batch's fences have stopped advancing, though the comment says it acts "only on a true stall, never under a lag". A queue that is just behind by 5 s (heavy paging on an oversubscribed card, the case described) or is waiting on a fence the CPU signals later (the pattern the new test builds) gets its resources released while the GPU can still use them, which is the use-after-free the comment rules out.
The test only checks that an aged batch is freed, not that a progressing queue keeps its batch. The branch also conflicts with main, which has since changed late_release.rs a lot.
Recommendation: close (bad: frees in-flight resources on age alone, without the progress check it claims).

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants