Repository navigation
D3D12.X: a resource's last Release waits for the queues to pass the work in flight - #866
Conversation
…ork in flight A retail title's final Release of a resource went straight to D3D12 while a queue still had work on it: the title 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). The debug layer stopped the run with "CORRUPTION: An ID3D12Resource object is referenced by GPU operations in-flight on Command Queue" (id 921) on the title's render thread. The last reference is now held: each batch of held resources gets a fence value signalled on every queue XCL knows of (the title's, the tile-mapping one, the upload ones) and is released once all of them have passed it. With no work in flight the queues pass that value at once, and the Release itself waits up to 300 us for it: the resource is gone when it returns, as before (a title, and a test here, frees the memory under an imported heap right after the last Release of its resource - held, the pages were still pinned). Otherwise a thread of its own lets the batch go, looking every 4 ms. XCL's own bookkeeping for the resource is dropped at the title's last Release, as before. Measured on the retail title with the debug layer on (RTX 5090): id 921 no longer reported; 356 last releases held and all 356 released by 74 s. XCL_LATE_RELEASE=0 turns it off. Assisted-by: Claude Code (Claude Fable 5.2)
|
Windows / RTX 3060 Ti 8 GB cross-check of 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: One question from the 8 GB side: this title's load phase intermittently ends in a device removal here (~1 in 6 runs, 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. |
Part of xcl-dev#248. Re-scoped onto upstream/main after xcl-dev#288 and xcl-dev#866: drops xcl-dev#269 overlap retirement (covered by xcl-dev#288) and unsafe mid-device MADE eviction (D3D12 descriptors hold no COM reference). Scopes real::MADE by device, returns an owned COM ID3D12Resource from resource_at held across descriptor creation, releases device-owned MADE entries and title_textures state on dev_release (routed through xcl-dev#866 late_release), clears released queues from vram::Pages::waited, and adds title-texture counts to XCL_ACTIVITY. Assisted-by: T3 Code / Antigravity (gemini-pro-orchestrator-neon)
`coherent_buffer_sanitizes_console_flags_and_state` failed now and then in the whole suite (`VirtualFree` returned 0 at its end) and passed alone. The device it makes is the one other tests adopted: D3D12 has one device per adapter. On that device its placed resource is XCL's, and since e7da8a1 (xcl-dev#866) a last `Release` is held until the queues XCL knows of are past their work; `Release` waits 300 us for that. With other tests' work in flight the resource goes a few ms later, and until then the imported heap pins the pages: `VirtualFree` fails with ERROR_INVALID_PARAMETER. The test now frees the memory with `free_imported`, which retries `VirtualFree` until the held release has gone (10 s at most). `imported_heap_memory_frees_after_a_held_release` makes the case on purpose: an adopted device, a known queue that waits on a fence, so the release is held and `VirtualFree` fails; then the queue goes on and the memory is freed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The 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 at beaa245 plus 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