D3D12.X: a resource's last Release waits for the queues to pass the work in flight #866
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!866
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/866/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?
@theaustinayers on GitHub · 2026-11-24 07:02 UTC · original
theaustinayers:late-release→main· +243 −1 · 6 files · 1 commits · merged 2026-11-24 07:05 UTCThe title's final
Releaseof a resource goes straight to D3D12 today. A retail title did that while a queue still had work on the resource: it counts its own finished frames, but XCL's submits are not the title's (texture uploads go out with a later submit, tile mappings on XCL's own queue). With the debug layer on, the run stopped during loading withCORRUPTION: An ID3D12Resource object … is referenced by GPU operations in-flight on Command Queue(id 921) on the title's render thread.XCL now keeps the last reference until every queue it knows of has passed a fence value signalled after the release. With nothing in flight the resource is still gone when
Releasereturns.What is in it
crates/xcl/src/hle/d3d12x/late_release.rs(new): batches of held resources, a fence value a queue for each batch, release once all queues are past it; a thread looks every 4 ms; theReleaseitself waits up to 300 µs so that idle queues let the resource go at once. Two tests (one on the GPU: a queue made to stand still keeps the resource held, and it goes once the queue moves).real.rsres_release: the last reference goes tolate_release::holdinstead of D3D12; XCL's own bookkeeping for the resource is dropped then, as before.present.rsnote_execute: a drain with every submit.sparse.rsqueue(),title_textures.rsupload_queues(): the queues of XCL's own, for the fence values.XCL_LATE_RELEASE=0turns it off.Tested
cargo build --workspace, thencargo test --workspace -- --test-threads=4: 715 passed, 0 failed, 41 ignored; no SKIPPED tests on this adapterRelease; resources only let go by the thread) failedreadback_routing_tests::coherent_buffer_sanitizes_console_flags_and_statein the whole suite, twice out of two runs:VirtualFreeof memory under an imported heap right after the lastReleaseof its placed resource. That is whyReleasewaits for idle queues; the suite passes with it.XCL_D3D12_DEBUG=1, on a build of main atbeaa245plus an earlier version of this change (the thread only, without the 300 µs wait): before, one run of two stopped at 50.7 s with id 921; with the change, no id 921 in two runs, and 356 last releases were held and all 356 released by 74 s.Regression run
main:
PR:
Not tested
Release). The 60 s regression run above is of the head commit, and does not get as far as the title's world.AI use
🤖 Generated with Claude Code
@ryosen0 on GitHub · 2026-11-24 07:09 UTC · original
Windows / RTX 3060 Ti 8 GB cross-check of
e7da8a1(Ryzen 7 9800X3D, driver 32.0.16.1742, Windows 11, release) on the other retail title, including a run into the loading phase where your id 921 fired:Official smoke:
Plus a 150 s run with scripted presses (25/35/45/55/65/80/95/110/125/140 s) that reaches the loading screens and the title's texture-upload churn (~4096 uploads left out, ≈1.75 GB of CPU writes through the sparse windows, 16k+ tiles mapped): clean, 4171 frames, 60 presents / 2 s throughout, 0 removals, 0 crashes. No debug layer here, so this shows the hold path doesn't disturb normal pacing on a second host — not that id 921 is gone (only a debug-layer run can show that).
Tests on this head:
cargo test --release -p xcl --lib late_release -- --test-threads=1→ 2 passed / 0 failed (both, including the GPU one — the queue-standstill hold and release).One question from the 8 GB side: this title's load phase intermittently ends in a device removal here (~1 in 6 runs,
0x887a0006, also seen by others on #541). Since your change holds resources past the title's own frame counting, do you expect any interaction with resources the title releases because it is shedding memory under pressure — i.e. could the hold delay a release the title relies on to free VRAM promptly? The 300 µs wait plus the 4 ms drain thread suggest the delay is bounded and tiny, but on a card at its budget that is the kind of thing worth a sentence in the description if you have a view.AI use: GPT-6.2 Astra (API model selector) in DSH built the head, ran the smoke, the 150 s run and the tests, and drafted this comment; the human contributor reviewed the numbers before posting.