D3D12.X: multi-plane PresentX Compositor::record leaks DXGI back-buffer COM ref into RTVS (breaking ResizeBuffers) and strips _SRGB from concrete plane SRVs #2446

Open
opened 2026-11-25 19:30:14 +00:00 by microwave805 · 3 comments
microwave805 commented 2026-11-25 19:30:14 +00:00 (Migrated from github.com)
Contributor

Imported from ivall/xcl. Originally posted by microwave805 on 2026-11-25T19:30:14Z.


Static audit on main @ c7e1799 found two bugs in the newly merged multi-plane PresentX compositor (#615) in crates/xcl/src/hle/d3d12x/present.rs. (Note: open PR #2418 addresses root_sig ManuallyDrop release and upfront plane validation, but does not fix either bug below.)

1. [Critical] Compositor::record leaks a COM ref to the DXGI back buffer into global RTVS, permanently breaking ResizeBuffers and leaking old swap chains

  • Where: crates/xcl/src/hle/d3d12x/present.rs:208-221 (note_rtv), 261-266 (note_rt0), 848, 862 (Compositor::record), 976 (ResizeBuffers), 1061, and real.rs:551-552, 2867, 6806
  • Root cause: Presenter::dev wraps the adopted Kind::Device (real::device_raw()), whose CreateRenderTargetView vtable slot is unconditionally hooked by real::dev_create_rtv (real.rs:2867). Every multi-plane frame, Compositor::record (present.rs:848) calls dev.CreateRenderTargetView(dst, Some(&rtv_desc), rtv_cpu) on the DXGI swap-chain back buffer bb. dev_create_rtv (real.rs:6806) calls present::note_rtv(handle, res), which checks only if !enabled() — not IN_PRESENT — calls add_ref(bb), and pins (rtv_cpu.ptr, bb) in global RTVS forever. (list.OMSetRenderTargets at present.rs:862 similarly hits cl_om_set_render_targets → note_rt0, polluting LISTS.)
  • Trigger: Any multi-plane title that later changes plane count, resolution, or format (e.g. 2-plane UI + scene menu → 1-plane gameplay): DXGI requires all outstanding references to swap-chain back buffers to be released before ResizeBuffers. Because RTVS still holds an AddRef on the last composited bb, sc.ResizeBuffers (present.rs:976) fails with DXGI_ERROR_INVALID_CALL (0x887A0001), ensure_swapchain returns false, and present_now stops presenting permanently. On queue switch (*guard = None at present.rs:1061), the old swap chain's back buffer leaks forever. (Missed by compositor_blends_ui_plane_over_scene_plane because it uses an unadopted raw WARP device.)
  • Fix: Guard note_rtv (present.rs:209) and note_rt0 (present.rs:262) with if !enabled() || IN_PRESENT.with(|c| c.get()) { return; }.

2. [High] Compositor::record strips _SRGB from concrete *_UNORM_SRGB plane SRVs

  • Where: crates/xcl/src/hle/d3d12x/present.rs:854 (with present.rs:269-277)
  • Root cause: Compositor::record sets each plane SRV's format to swap_format(desc.Format).unwrap_or(desc.Format). swap_format (present.rs:271-272) maps R8G8B8A8_UNORM_SRGB → R8G8B8A8_UNORM and B8G8R8A8_UNORM_SRGB → B8G8R8A8_UNORM. In D3D12, viewing a concrete (non-typeless) *_UNORM_SRGB texture with a *_UNORM SRV is invalid (CREATESHADERRESOURCEVIEW_INVALIDFORMAT).
  • Trigger: Any multi-plane PresentX frame whose scene or UI plane resource has concrete format R8G8B8A8_UNORM_SRGB or B8G8R8A8_UNORM_SRGB.
  • Fix: Use a plane_srv_format(f) helper at present.rs:854 that converts only *_TYPELESS formats to concrete formats and preserves concrete *_UNORM_SRGB formats as desc.Format.

AI use

  • Antigravity (Gemini 4 Neon): static code audit on main @ c7e1799 and issue drafting.
<!-- greyfinch-sync:ivall/xcl:issue:6612105704 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/2456). Originally posted by [microwave805](https://github.com/microwave805) on 2026-11-25T19:30:14Z. --- Static audit on `main @ c7e1799` found two bugs in the newly merged multi-plane `PresentX` compositor (#615) in `crates/xcl/src/hle/d3d12x/present.rs`. *(Note: open PR #2418 addresses `root_sig` `ManuallyDrop` release and upfront plane validation, but does not fix either bug below.)* ### 1. [Critical] `Compositor::record` leaks a COM ref to the DXGI back buffer into global `RTVS`, permanently breaking `ResizeBuffers` and leaking old swap chains - **Where:** `crates/xcl/src/hle/d3d12x/present.rs:208-221` (`note_rtv`), `261-266` (`note_rt0`), `848, 862` (`Compositor::record`), `976` (`ResizeBuffers`), `1061`, and `real.rs:551-552, 2867, 6806` - **Root cause:** `Presenter::dev` wraps the adopted `Kind::Device` (`real::device_raw()`), whose `CreateRenderTargetView` vtable slot is unconditionally hooked by `real::dev_create_rtv` (`real.rs:2867`). Every multi-plane frame, `Compositor::record` (`present.rs:848`) calls `dev.CreateRenderTargetView(dst, Some(&rtv_desc), rtv_cpu)` on the DXGI swap-chain back buffer `bb`. `dev_create_rtv` (`real.rs:6806`) calls `present::note_rtv(handle, res)`, which checks only `if !enabled()` — **not** `IN_PRESENT` — calls `add_ref(bb)`, and pins `(rtv_cpu.ptr, bb)` in global `RTVS` forever. (`list.OMSetRenderTargets` at `present.rs:862` similarly hits `cl_om_set_render_targets` → `note_rt0`, polluting `LISTS`.) - **Trigger:** Any multi-plane title that later changes plane count, resolution, or format (e.g. 2-plane UI + scene menu → 1-plane gameplay): DXGI requires all outstanding references to swap-chain back buffers to be released before `ResizeBuffers`. Because `RTVS` still holds an `AddRef` on the last composited `bb`, `sc.ResizeBuffers` (`present.rs:976`) fails with `DXGI_ERROR_INVALID_CALL` (`0x887A0001`), `ensure_swapchain` returns `false`, and `present_now` stops presenting permanently. On queue switch (`*guard = None` at `present.rs:1061`), the old swap chain's back buffer leaks forever. *(Missed by `compositor_blends_ui_plane_over_scene_plane` because it uses an unadopted raw WARP device.)* - **Fix:** Guard `note_rtv` (`present.rs:209`) and `note_rt0` (`present.rs:262`) with `if !enabled() || IN_PRESENT.with(|c| c.get()) { return; }`. ### 2. [High] `Compositor::record` strips `_SRGB` from concrete `*_UNORM_SRGB` plane SRVs - **Where:** `crates/xcl/src/hle/d3d12x/present.rs:854` (with `present.rs:269-277`) - **Root cause:** `Compositor::record` sets each plane SRV's format to `swap_format(desc.Format).unwrap_or(desc.Format)`. `swap_format` (`present.rs:271-272`) maps `R8G8B8A8_UNORM_SRGB` → `R8G8B8A8_UNORM` and `B8G8R8A8_UNORM_SRGB` → `B8G8R8A8_UNORM`. In D3D12, viewing a concrete (non-typeless) `*_UNORM_SRGB` texture with a `*_UNORM` SRV is invalid (`CREATESHADERRESOURCEVIEW_INVALIDFORMAT`). - **Trigger:** Any multi-plane `PresentX` frame whose scene or UI plane resource has concrete format `R8G8B8A8_UNORM_SRGB` or `B8G8R8A8_UNORM_SRGB`. - **Fix:** Use a `plane_srv_format(f)` helper at `present.rs:854` that converts only `*_TYPELESS` formats to concrete formats and preserves concrete `*_UNORM_SRGB` formats as `desc.Format`. ### AI use - Antigravity (Gemini 4 Neon): static code audit on `main @ c7e1799` and issue drafting.
Creaa commented 2026-11-25 20:08:44 +00:00 (Migrated from github.com)
Author
Contributor

Imported from ivall/xcl. Originally posted by Creaa on 2026-11-25T19:44:32Z.


Taking the back-buffer reference and render-target tracking part. I will keep compositor-owned render targets out of the title tracking tables during presentation and test both paths. The separate sRGB view-format issue remains open. AI use: OpenAI Codex (GPT-6).

<!-- greyfinch-sync:ivall/xcl:comment:7172706034 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/2456#issuecomment-7172706034). Originally posted by [Creaa](https://github.com/Creaa) on 2026-11-25T19:44:32Z. --- Taking the back-buffer reference and render-target tracking part. I will keep compositor-owned render targets out of the title tracking tables during presentation and test both paths. The separate sRGB view-format issue remains open. AI use: OpenAI Codex (GPT-6).
CryingLaughing commented 2026-11-27 03:28:57 +00:00 (Migrated from github.com)
Author
Contributor

Imported from ivall/xcl. Originally posted by CryingLaughing on 2026-11-27T03:28:57Z.


For item 2, I reapplied the archived sRGB follow-ups on current main 8b957bec6f82495aec940944c6bf47faa02db590. Both refreshed heads merge cleanly into that revision and retain main’s shader-startup documentation. The stack preserves ramon-victor’s #2537 SRV change and its authorship, replayed as a262974c624c29beabc7d0a2e4e7f4c313f28cfc. #2537 remains upstream’s prerequisite. Upstream SRV change

Refreshed fork head Focused native results
f8c3c4fb6bc46b9a97da101d9301cff658562aa3 All-UNORM and all-sRGB pairs both matched. The fractional sRGB pixel was [137, 161, 0, 255].
92217cad04fd69bab29e9874fce59de2a57db0a5 All five matching and mixed RGBA/BGRA pairs matched the fixture. A transparent UNORM overlay over an sRGB primary preserved [188, 128, 0, 255].

The serial offscreen runs each reported 1 passed, 0 failed, 0 ignored, and zero capability skips on a GeForce RTX 4080 with driver 621.01. Hardware and toolchain were Windows 11 25H2 build 26200.9974, Core i5-13600K, Rust 1.100.0 x64 MSVC and DXC 1.8.2502.11. A test-only overlay selects the physical adapter, confirms its device LUID, and logs pixel readbacks. The production code and original fixture assertions match each clean head.

cargo test -p xcl --lib --locked --offline -j 3 --no-run --message-format=json
$env:XCL_ADAPTER = '4080'
$env:XCL_NETWORK = '0'
& $testExecutable hle::d3d12x::present::frame_dump_tests::compositor_blends_ui_plane_over_scene_plane --exact --nocapture --test-threads=1

Both old heads and their matched smoke evidence are preserved. These refreshed heads still need their own same-title retail smoke. Xbox’s intended behavior for an opaque UNORM midtone over an sRGB primary also remains unverified. Output-encoding head · Primary-plane head · Mixed-format review

AI use

  • OpenAI Codex assisted with the original follow-ups and synthetic tests. Codex (GPT-6 family, exact serving variant unavailable) reapplied the patches, adapted the measurement fixture, ran the local checks, and drafted this report. The SRV prerequisite and linked independent checks are credited to their authors.

Clean-head workspace checks

The exact two clean heads also passed cargo build --workspace --locked --offline -j 3 and cargo test --workspace --locked --offline -j 3 --no-fail-fast -- --test-threads=1 --show-output with XCL_ADAPTER=4080 XCL_NETWORK=0. Each serial suite reported 1,447 passed, 0 failed, 47 ignored, with the same 29 explicit capability skips. These were 21 wave64 cases, three unsupported instructions, three D3D12 debug-layer cases, one driver-cache control, and one heap-window case. The stock compositor fixture also passed in each clean suite.

For the output-encoding follow-up, a same-title, same-duration retail pair using scripts/smoke.ps1 on clean upstream main 8b957bec6f82495aec940944c6bf47faa02db590 and clean output head f8c3c4fb6bc46b9a97da101d9301cff658562aa3 would supply the remaining retail evidence. If an independent runner can provide this comparison, the two raw xcl-smoke v1 blocks can be posted here.

<!-- greyfinch-sync:ivall/xcl:comment:7209022966 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/2456#issuecomment-7209022966). Originally posted by [CryingLaughing](https://github.com/CryingLaughing) on 2026-11-27T03:28:57Z. --- For item 2, I reapplied the archived sRGB follow-ups on current main `8b957bec6f82495aec940944c6bf47faa02db590`. Both refreshed heads merge cleanly into that revision and retain main’s shader-startup documentation. The stack preserves ramon-victor’s #2537 SRV change and its authorship, replayed as `a262974c624c29beabc7d0a2e4e7f4c313f28cfc`. #2537 remains upstream’s prerequisite. [Upstream SRV change](https://github.com/xcl-dev/xcl/pull/2537) | Refreshed fork head | Focused native results | | --- | --- | | `f8c3c4fb6bc46b9a97da101d9301cff658562aa3` | All-UNORM and all-sRGB pairs both matched. The fractional sRGB pixel was `[137, 161, 0, 255]`. | | `92217cad04fd69bab29e9874fce59de2a57db0a5` | All five matching and mixed RGBA/BGRA pairs matched the fixture. A transparent UNORM overlay over an sRGB primary preserved `[188, 128, 0, 255]`. | The serial offscreen runs each reported **1 passed, 0 failed, 0 ignored, and zero capability skips** on a GeForce RTX 4080 with driver 621.01. Hardware and toolchain were Windows 11 25H2 build 26200.9974, Core i5-13600K, Rust 1.100.0 x64 MSVC and DXC 1.8.2502.11. A test-only overlay selects the physical adapter, confirms its device LUID, and logs pixel readbacks. The production code and original fixture assertions match each clean head. ```powershell cargo test -p xcl --lib --locked --offline -j 3 --no-run --message-format=json $env:XCL_ADAPTER = '4080' $env:XCL_NETWORK = '0' & $testExecutable hle::d3d12x::present::frame_dump_tests::compositor_blends_ui_plane_over_scene_plane --exact --nocapture --test-threads=1 ``` Both old heads and their matched smoke evidence are preserved. These refreshed heads still need their own same-title retail smoke. Xbox’s intended behavior for an opaque UNORM midtone over an sRGB primary also remains unverified. [Output-encoding head](https://github.com/CryingLaughing/xcl/commit/f8c3c4fb6bc46b9a97da101d9301cff658562aa3) · [Primary-plane head](https://github.com/CryingLaughing/xcl/commit/92217cad04fd69bab29e9874fce59de2a57db0a5) · [Mixed-format review](https://github.com/xcl-dev/xcl/pull/2811#issuecomment-7197643616) **AI use** - OpenAI Codex assisted with the original follow-ups and synthetic tests. Codex (GPT-6 family, exact serving variant unavailable) reapplied the patches, adapted the measurement fixture, ran the local checks, and drafted this report. The SRV prerequisite and linked independent checks are credited to their authors. **Clean-head workspace checks** The exact two clean heads also passed `cargo build --workspace --locked --offline -j 3` and `cargo test --workspace --locked --offline -j 3 --no-fail-fast -- --test-threads=1 --show-output` with `XCL_ADAPTER=4080 XCL_NETWORK=0`. Each serial suite reported **1,447 passed, 0 failed, 47 ignored**, with the same 29 explicit capability skips. These were 21 wave64 cases, three unsupported instructions, three D3D12 debug-layer cases, one driver-cache control, and one heap-window case. The stock compositor fixture also passed in each clean suite. For the output-encoding follow-up, a same-title, same-duration retail pair using `scripts/smoke.ps1` on clean upstream main `8b957bec6f82495aec940944c6bf47faa02db590` and clean output head `f8c3c4fb6bc46b9a97da101d9301cff658562aa3` would supply the remaining retail evidence. If an independent runner can provide this comparison, the two raw `xcl-smoke v1` blocks can be posted here.
Hash-0x commented 2026-11-30 13:11:57 +00:00 (Migrated from github.com)
Author
Contributor

Imported from ivall/xcl. Originally posted by Hash-0x on 2026-11-30T13:11:57Z.


On item 2: on this hardware a UNORM SRV on a concrete R8G8B8A8_UNORM_SRGB texture is valid, so current main is not doing anything undefined here. What differs is the space the planes are blended in.

I did not run XCL. I reproduced the compositor's steps (present.rs#L1243: linear sampler at 1:1, premultiplied ONE / INV_SRC_ALPHA) in my own D3D12 test bench, wave64-prefix-test, with my own shaders and synthetic data, and read back each stage. The compositing rows of --output at commit 16ba46b reproduce it.

View format

  • D3D12_FEATURE_DATA_D3D12_OPTIONS3::CastingFullyTypedFormatSupported is TRUE on both adapters tested.
  • Debug layer: 0 errors and 0 warnings with the UNORM view. As a control, an R32_FLOAT view of the same texture is rejected ("not a fully qualified format within the same family").
  • An adapter without that feature would still be a problem; I had none to test.

Readback, two R8G8B8A8_UNORM_SRGB planes, base byte 188 under a black plane with alpha 0 / 128 / 255:

SRV -> RTV sampled 188 (RTX / WARP) alpha 0 alpha 128 alpha 255
UNORM -> UNORM (main) 0.737 / 0.737 188 94 0
sRGB -> UNORM (#2537 alone) 0.504 / 0.503 128 64 0
sRGB -> sRGB (as in #2763 / #2811) 0.504 / 0.503 188 137 0
sRGB, re-encoded in the shader -> UNORM 0.504 / 0.503 188 94 0

The stored bytes are the same on both adapters. Each row is also checked over 262,144 random pixels against a CPU reference.

  • This agrees with the blocking review on #2537: the SRV change alone darkens the picture.
  • Rows 1 and 4 store the same bytes; only the sampled value tells them apart. For 1:1 compositing, re-encoding in the shader therefore gives what main gives today.
  • So the open question is whether the console blends its display planes encoded (94) or in linear (137). A PC GPU cannot answer that. Is there a console readback or public documentation for it?

Tested: GeForce RTX 4070 SUPER (driver 32.0.16.2124) and WARP, Windows 11 Pro 26300. 50 identical runs on the GPU and 2 on WARP.

Not tested: XCL itself, a retail title, scaled planes, other GPUs.

AI use

  • Claude Code (Claude Opus 5.5) wrote the test, ran it and drafted this comment.
<!-- greyfinch-sync:ivall/xcl:comment:7279496402 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/issues/2456#issuecomment-7279496402). Originally posted by [Hash-0x](https://github.com/Hash-0x) on 2026-11-30T13:11:57Z. --- On item 2: on this hardware a UNORM SRV on a concrete `R8G8B8A8_UNORM_SRGB` texture is valid, so current `main` is not doing anything undefined here. What differs is the space the planes are blended in. I did not run XCL. I reproduced the compositor's steps ([present.rs#L1243](https://github.com/xcl-dev/xcl/blob/9dfbe3ea6653a9c76ef3ea0d66187a4b5407483b/crates/xcl/src/hle/d3d12x/present.rs#L1243): linear sampler at 1:1, premultiplied `ONE / INV_SRC_ALPHA`) in my own D3D12 test bench, [wave64-prefix-test](https://github.com/Hash-0x/wave64-prefix-test), with my own shaders and synthetic data, and read back each stage. The compositing rows of `--output` at commit [`16ba46b`](https://github.com/Hash-0x/wave64-prefix-test/commit/16ba46b388dfdca1d64f7f87f5f90165f1dec9e5) reproduce it. **View format** - `D3D12_FEATURE_DATA_D3D12_OPTIONS3::CastingFullyTypedFormatSupported` is TRUE on both adapters tested. - Debug layer: 0 errors and 0 warnings with the UNORM view. As a control, an `R32_FLOAT` view of the same texture is rejected ("not a fully qualified format within the same family"). - An adapter without that feature would still be a problem; I had none to test. **Readback**, two `R8G8B8A8_UNORM_SRGB` planes, base byte 188 under a black plane with alpha 0 / 128 / 255: | SRV -> RTV | sampled 188 (RTX / WARP) | alpha 0 | alpha 128 | alpha 255 | |---|---|---|---|---| | UNORM -> UNORM (`main`) | 0.737 / 0.737 | 188 | 94 | 0 | | sRGB -> UNORM (#2537 alone) | 0.504 / 0.503 | 128 | 64 | 0 | | sRGB -> sRGB (as in #2763 / #2811) | 0.504 / 0.503 | 188 | 137 | 0 | | sRGB, re-encoded in the shader -> UNORM | 0.504 / 0.503 | 188 | 94 | 0 | The stored bytes are the same on both adapters. Each row is also checked over 262,144 random pixels against a CPU reference. - This agrees with the blocking review on #2537: the SRV change alone darkens the picture. - Rows 1 and 4 store the same bytes; only the sampled value tells them apart. For 1:1 compositing, re-encoding in the shader therefore gives what `main` gives today. - So the open question is whether the console blends its display planes encoded (94) or in linear (137). A PC GPU cannot answer that. Is there a console readback or public documentation for it? **Tested:** GeForce RTX 4070 SUPER (driver 32.0.16.2124) and WARP, Windows 11 Pro 26300. 50 identical runs on the GPU and 2 on WARP. **Not tested:** XCL itself, a retail title, scaled planes, other GPUs. **AI use** - Claude Code (Claude Opus 5.5) wrote the test, ran it and drafted this comment.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl#2446
No description provided.