Skip to content

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

Backlog

Description

@microwave805

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.

Activity

  1. Creaa commented on Nov 25, 2026

    @Creaa
    Contributor

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

  2. CryingLaughing commented on Nov 27, 2026

    @CryingLaughing

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions