D3D12.X: a resource's last Release waits for the queues to pass the work in flight #866

Manually merged
github merged 1 commit from gh-pr/866/head into gh-pr/866/base 2026-11-26 04:35:02 +00:00
Owner

@⁠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 UTC

The title's final Release of 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 with CORRUPTION: 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 Release returns.

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; the Release itself 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.rs res_release: the last reference goes to late_release::hold instead of D3D12; XCL's own bookkeeping for the resource is dropped then, as before.
  • present.rs note_execute: a drain with every submit.
  • sparse.rs queue(), title_textures.rs upload_queues(): the queues of XCL's own, for the fence values.
  • XCL_LATE_RELEASE=0 turns it off.

Tested

  • NVIDIA GeForce RTX 5090 (driver 621.14), Ryzen 9 9950X3D, Windows 11 build 26300, rustc 1.100.0, debug build for tests, release for the runs
  • cargo build --workspace, then cargo test --workspace -- --test-threads=4: 715 passed, 0 failed, 41 ignored; no SKIPPED tests on this adapter
  • An earlier version of this change (no wait in Release; resources only let go by the thread) failed readback_routing_tests::coherent_buffer_sanitizes_console_flags_and_state in the whole suite, twice out of two runs: VirtualFree of memory under an imported heap right after the last Release of its placed resource. That is why Release waits for idle queues; the suite passes with it.
  • A retail title with 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:

xcl-smoke v1
commit: beaa245ca04e212f064efc7cafcdce104bc5c0a2
gpu: NVIDIA GeForce RTX 5090
title: NYCMain
seconds: 60
exit: 0x0
frames shown: 1616 (PresentX 1616)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17204 MB

PR:

xcl-smoke v1
commit: e7da8a18afd45d41d37ec44056b5b21bc68b4727
gpu: NVIDIA GeForce RTX 5090
title: NYCMain
seconds: 60
exit: 0x0
frames shown: 1623 (PresentX 1623)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16397 MB

Not tested

  • AMD and Intel GPUs, Wine / vkd3d-proton.
  • The head commit itself with the debug layer on the retail title: the id 921 runs above were made with the earlier version (no wait in Release). The 60 s regression run above is of the head commit, and does not get as far as the title's world.
  • The title still loses its device later in the world for another reason (the debug layer names a command list executed after its allocator was reset, id 541, after a queue had stood still for seconds). This PR does not change that.
  • Heaps and other object kinds: only resources are held.
  • The remaining debug-layer reports about tile mappings while another queue writes (id 1047).

AI use

  • Claude Code, Claude Fable 5.2: found the cause from the debug layer's report, wrote the code, the tests and this description. The runs above were made on the hardware named.

🤖 Generated with Claude Code

**@⁠theaustinayers** on GitHub · 2026-11-24 07:02 UTC · [original](https://github.com/xcl-dev/xcl/pull/866) `theaustinayers:late-release` → `main` · +243 −1 · 6 files · 1 commits · merged 2026-11-24 07:05 UTC The title's final `Release` of 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 with `CORRUPTION: 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 `Release` returns. **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; the `Release` itself 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.rs` `res_release`: the last reference goes to `late_release::hold` instead of D3D12; XCL's own bookkeeping for the resource is dropped then, as before. - `present.rs` `note_execute`: a drain with every submit. - `sparse.rs` `queue()`, `title_textures.rs` `upload_queues()`: the queues of XCL's own, for the fence values. - `XCL_LATE_RELEASE=0` turns it off. **Tested** - NVIDIA GeForce RTX 5090 (driver 621.14), Ryzen 9 9950X3D, Windows 11 build 26300, rustc 1.100.0, debug build for tests, release for the runs - `cargo build --workspace`, then `cargo test --workspace -- --test-threads=4`: 715 passed, 0 failed, 41 ignored; no SKIPPED tests on this adapter - An earlier version of this change (no wait in `Release`; resources only let go by the thread) failed `readback_routing_tests::coherent_buffer_sanitizes_console_flags_and_state` in the whole suite, twice out of two runs: `VirtualFree` of memory under an imported heap right after the last `Release` of its placed resource. That is why `Release` waits for idle queues; the suite passes with it. - A retail title with `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: ``` xcl-smoke v1 commit: beaa245ca04e212f064efc7cafcdce104bc5c0a2 gpu: NVIDIA GeForce RTX 5090 title: NYCMain seconds: 60 exit: 0x0 frames shown: 1616 (PresentX 1616) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 17204 MB ``` PR: ``` xcl-smoke v1 commit: e7da8a18afd45d41d37ec44056b5b21bc68b4727 gpu: NVIDIA GeForce RTX 5090 title: NYCMain seconds: 60 exit: 0x0 frames shown: 1623 (PresentX 1623) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 16397 MB ``` **Not tested** - AMD and Intel GPUs, Wine / vkd3d-proton. - The head commit itself with the debug layer on the retail title: the id 921 runs above were made with the earlier version (no wait in `Release`). The 60 s regression run above is of the head commit, and does not get as far as the title's world. - The title still loses its device later in the world for another reason (the debug layer names a command list executed after its allocator was reset, id 541, after a queue had stood still for seconds). This PR does not change that. - Heaps and other object kinds: only resources are held. - The remaining debug-layer reports about tile mappings while another queue writes (id 1047). **AI use** - Claude Code, Claude Fable 5.2: found the cause from the debug layer's report, wrote the code, the tests and this description. The runs above were made on the hardware named. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:35:00 +00:00
github manually merged commit e7da8a18af into gh-pr/866/base 2026-11-26 04:35:02 +00:00
Author
Owner

@⁠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:

xcl-smoke v1
commit: e7da8a18afd45d41d37ec44056b5b21bc68b4727
gpu: NVIDIA GeForce RTX 3060 Ti
title: ScarlettGame
seconds: 90
exit: 0x0
frames shown: 2450 (PresentX 2450)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14497 MB

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.

**@⁠ryosen0** on GitHub · 2026-11-24 07:09 UTC · [original](https://github.com/xcl-dev/xcl/pull/866#issuecomment-7124683522) 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: ``` xcl-smoke v1 commit: e7da8a18afd45d41d37ec44056b5b21bc68b4727 gpu: NVIDIA GeForce RTX 3060 Ti title: ScarlettGame seconds: 90 exit: 0x0 frames shown: 2450 (PresentX 2450) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14497 MB ``` 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.
This discussion has been locked. Commenting is limited to contributors.
No description provided.