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

Open
opened 2026-11-26 05:31:20 +00:00 by github-bot · 1 comment
Owner

@⁠microwave805 on GitHub · 2026-11-25 19:30 UTC · original

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.
**@⁠microwave805** on GitHub · 2026-11-25 19:30 UTC · [original](https://github.com/xcl-dev/xcl/issues/2456) 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:31:20 +00:00
Author
Owner

@⁠Creaa on GitHub · 2026-11-25 19:44 UTC · original

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).

**@⁠Creaa** on GitHub · 2026-11-25 19:44 UTC · [original](https://github.com/xcl-dev/xcl/issues/2456#issuecomment-7172706034) 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).
This discussion has been locked. Commenting is limited to contributors.
No description provided.