Skip to content

D3D12.X: harden PresentX compositor and single-plane sub-rect scaling - #2418

Open
Decodere wants to merge 2 commits into
xcl-dev:mainfrom
Decodere:fix-615-present-compositor
Open

Decodere wants to merge 2 commits into
xcl-dev:mainfrom
Decodere:fix-615-present-compositor

Conversation

@Decodere

@Decodere Decodere commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What is in it
Follow-up hardening to #615's PresentX multi-plane compositor in crates/xcl/src/hle/d3d12x/present.rs (+135/-6 lines, single file):

  • Release ManuallyDrop<Option<ID3D12RootSignature>> via ManuallyDrop::into_inner(pd.pRootSignature) after CreateGraphicsPipelineState in Compositor::psos_for on both success and failure paths, fixing a 2-ref COM leak on self.root_sig per RTV format.
  • Validate target dimensions, non-empty plane list, and all active planes upfront in Compositor::record (D3D12_RESOURCE_DIMENSION_TEXTURE2D, SampleDesc.Count == 1, no D3D12_RESOURCE_FLAG_DENY_SHADER_RESOURCE, and swap_format(desc.Format).is_some()) before compiling PSOs, mutating RTV/SRV descriptors, or recording draws, returning false cleanly so present_now falls back to plane-0 copy.
  • Cap plane_count to MAX_PLANES in present_x_frame's raw-word logging helper (raw_plane_words), matching extract_planes and avoiding overflow or oversized reads on large guest counts.
  • Route single-plane PresentX frames with a non-full uv_rect != [0.0, 0.0, 1.0, 1.0] through Compositor via needs_compositor (with plane-0 copy fallback) so single-plane dynamic-resolution sub-rects scale to fill the target, while keeping the full-rect 1-plane CopyResource fast path intact.
  • Follow-up #[cfg(test)]-only fix (b80aa57c, 0 production lines changed vs 3f4a1291): switch the psos_for failure-path test format from DXGI_FORMAT_BC1_UNORM (which vkd3d-proton accepts as a NULL color attachment) to DXGI_FORMAT_R8G8B8A8_UINT (blending on an integer RTV format with SV_Target0 returns E_INVALIDARG on both Windows D3D12/WARP and vkd3d-proton), check the success-path root_sig refcount before the failure-path check, and serialize the three WARP Compositor::new tests with a test-only Mutex because D3D12's process-wide WARP singleton device deduplicates identical ID3D12RootSignature COM objects across parallel test threads.

Part of #1452
Part of #1333

Tested

  • Failing-first on unmodified base commit 68a284a5: cargo test -p xcl --lib hle::d3d12x::present -- --test-threads=1 --nocapture failed 2 of 11 (compositor_psos_for_preserves_root_sig_refcount leaked ID3D12RootSignature refs 7 != 3; compositor_record_rejects_unreadable_planes_without_mutating_state returned true and mutated compositor state on invalid planes).
  • Post-fix hle::d3d12x::present on head b80aa57ca11950951114ce12ba05f2e9b8b37518 (0 new warnings in present.rs under rustc and cargo clippy --tests -p xcl):
    • Debug parallel (cargo test -p xcl --lib hle::d3d12x::present:: -- --nocapture, 3x runs): 11 passed; 0 failed; 0 ignored (0.04 s–0.05 s, 0 skipped).
    • Release parallel (cargo test --release -p xcl --lib hle::d3d12x::present:: -- --nocapture, 3x runs): 11 passed; 0 failed; 0 ignored (0.04 s–0.05 s, 0 skipped).
    • Release clean build (cargo build --release -p xcl): exit 0 (1m 56s, 0 new warnings in present.rs).
  • Full release workspace on identical production diff (3f4a1291, cargo test --release --workspace --no-fail-fast -- --test-threads=4 --nocapture, RTX 4060): 23 test binaries, 1291 passed; 1 failed; 46 ignored (sole failure is pre-existing 68a284a5 failure a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier, tracked by Tests: the bridged mask write checks for no barrier past the first branch #2379; 29 pre-existing SKIPPED lines on this RTX 4060 host, 0 skipped in hle::d3d12x::present).

Regression run
Paired 60 s RTX 4060 smoke (scripts/smoke.ps1 -Seconds 60) on base 68a284a5 vs PR head b80aa57c (exercises the preserved full-rect single-plane PresentX fast path; 1536 vs 1557 frames = 98.7%, 13977 vs 14017 MB peak commit, 0 device removals, 0 crashes):

Base (68a284a5):

xcl-smoke v1
commit: 68a284a596bd558b6bd9db6eedda6d6aa178c360
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1557 (PresentX 1557)
presents per 2 s (last 3): 59 61 60
device removals: 0
crashes: 0
peak commit: 14017 MB

PR head (b80aa57c):

xcl-smoke v1
commit: b80aa57ca11950951114ce12ba05f2e9b8b37518
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1536 (PresentX 1536)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13977 MB

Not tested

  • Live retail title presenting multiple PresentX planes or a single-plane dynamic-resolution pSourceRect (the smoke title uses a full-rect single plane; single-plane sub-rect scaling, refcount cleanup, and invalid-plane fallback are covered by WARP unit tests).
  • Wine/Proton (vkd3d-proton) execution directly on this host (DXGI_FORMAT_R8G8B8A8_UINT blend rejection on SV_Target0 was checked against vkd3d-proton's libs/vkd3d/state.c validation and tested on native Windows WARP).
  • D3D12 debug layer (d3d12SDKLayers.dll not installed on this host).

AI use
Written and verified with Google Antigravity (Gemini 4 Neon). All changes were validated locally with failing-first WARP tests, parallel Debug and Release hle::d3d12x::present:: runs, full release workspace tests on the identical production diff (3f4a1291), and paired 60 s RTX 4060 smoke runs.

Follow-up hardening to xcl-dev#615's PresentX multi-plane compositor:
- Release `ManuallyDrop<Option<ID3D12RootSignature>>` after
  `CreateGraphicsPipelineState` in `Compositor::psos_for` on both success
  and failure paths so `self.root_sig` does not leak 2 COM references per
  RTV format.
- Validate all active planes upfront in `Compositor::record` (non-empty,
  `TEXTURE2D`, `SampleDesc.Count == 1`, no `DENY_SHADER_RESOURCE`, and
  supported `swap_format`) before creating PSOs/descriptors or recording
  draws so invalid planes fall back cleanly to plane-0 copy.
- Cap `plane_count` to `MAX_PLANES` in `present_x_frame`'s raw-word
  logging helper to match `extract_planes` and avoid overflow/over-read on
  large counts.
- Route single-plane `PresentX` frames with a non-full `uv_rect` through
  `Compositor` (with plane-0 copy fallback) while preserving the full-rect
  `CopyResource` fast path.

Part of xcl-dev#1452
Part of xcl-dev#1333

Assisted-by: Google Antigravity (Gemini 4 Neon)
@Aniseto

Aniseto commented Nov 25, 2026

Copy link
Copy Markdown

Ran the PresentX compositor tests at 3f4a129:

Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, wave32 only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09) MSVC 14.44.35207, DXC 1.9.2609.5, debug build.

XCL_ADAPTER=nvidia cargo test -p xcl --lib hle::d3d12x::present -- --test-threads=1 --nocapture
11 passed; 0 failed; 0 ignored; 1237 filtered out      (exit 0)

All eleven tests pass here, including the three new ones for the root-signature refcount, invalid-plane rejection and single-plane [0, 0, 0.5, 0.5] sub-rect scaling. As the description says, these are WARP-backed tests, so they do not measure the real adapter's PresentX path.

What this adds: the thread has no report from another machine. This host has a different GPU/driver (RTX 5070 Ti, 32.0.16.2124) and DXC 1.9.2609.5 from the author's RTX 4060 run, but the tests themselves use WARP on both.

Not tested: a live retail title presenting multiple planes or a dynamic-resolution sub-rect, the D3D12 debug layer, the full workspace suite, a paired 60 s smoke run, AMD and Intel GPUs, release profile, title data.

AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.

@Decodere Decodere closed this Nov 25, 2026
@Decodere Decodere reopened this Nov 25, 2026
@Decodere Decodere closed this Nov 25, 2026
@Decodere Decodere reopened this Nov 25, 2026
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 25, 2026
…#2414, xcl-dev#2415

Integrates per-draw mirror sync fast path (xcl-dev#2437), PresentX compositor
hardening (xcl-dev#2418), XAudio2 GetState buffer context fix (xcl-dev#2410), and Wine
test fixes (xcl-dev#2414, xcl-dev#2415).

Assisted-by: Antigravity (Gemini 4 Neon)
@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: 1 real failure, deterministic (also fails --test-threads=1, 1219/1):
gpu::recomp::lower_dxil::tests::a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier
  assertion failed: group barriers in the program (lower_dxil.rs:1155)

The lowered program is missing an expected group barrier (or emits one where none is expected). Needs a fix before merge.

— Devin

@Decodere

Copy link
Copy Markdown
Contributor Author

Thanks for testing! That gpu::recomp::lower_dxil::tests::a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier failure comes from a pre-#2420 main base (#2074) and was fixed on main in #2420 (c56e7448).

This PR (#2418) only touches crates/xcl/src/hle/d3d12x/present.rs, and CI Build and test on current main is green (0 failures).

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No concrete correctness defect found. The COM ownership and validation ordering look sound, and the single-plane UV path is covered. Nonblocking validation gap: the new sub-rect test is square-to-square RGBA8 only. Please consider an accepted non-square destination/target aspect ratio or another accepted format to validate the compositor scaling path more broadly.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 25, 2026
…#2414, xcl-dev#2415

Integrates per-draw mirror sync fast path (xcl-dev#2437), PresentX compositor
hardening (xcl-dev#2418), XAudio2 GetState buffer context fix (xcl-dev#2410), and Wine
test fixes (xcl-dev#2414, xcl-dev#2415).

Assisted-by: Antigravity (Gemini 4 Neon)
@ClosetPie107

Copy link
Copy Markdown

Independent test report under Wine/Proton (not native Windows) for head 3f4a1291.

Setup

  • AMD Radeon RX 9070 (RDNA4, RADV GFX1201, Mesa 26.3.1), Ryzen 5 9600X, CachyOS Linux 7.3.5
  • Proton Experimental experimental-11.0-20261112, vkd3d-proton master ec207194 with a local patch dropping the lpVtbl checks in d3d12_command_allocator_from_iface / d3d12_command_list_from_iface, DXC 1.9.2609.5, Rust 1.96.0, x86_64-pc-windows-gnu
  • Head merged onto main 83b00818, test commit d6eb56bf

Tests (debug, XCL_REQUIRE_GPU=wave64, --test-threads=1)

  • hle::d3d12x::present::: 14 passed, 1 failed (main: 13 passed, 0 failed). compositor_scales_single_plane_sub_rect passes. compositor_releases_root_sig_and_rejects_invalid_planes fails at present.rs:1886, assertion failed: comp.psos_for(&dev, DXGI_FORMAT_BC1_UNORM).is_none(): vkd3d-proton creates a graphics pipeline with a BC1 render-target format instead of refusing it. So the assertion holds only where the runtime refuses that format, and the rest of the test (the root signature reference count, the plane checks) does not run here. Perhaps the failing format could be one every runtime refuses, or the reference-count check could come before it.
  • cargo test --workspace --no-fail-fast -- --test-threads=4, lib binary: 1321 passed, 10 failed, 27 ignored (main the same run: 1320 passed, 9 failed, 27 ignored): main's 9 and the test above.

Retail title, 300 s (release, from a copy of the same warm-cache snapshot; XCL_DIRECT_DXIL=1 XCL_PREPARE=1 XCL_PSO_PRELOAD=1 XCL_PSO_WAIT_MS=50 XCL_TEXTURE_LEVEL_PAGES=1 XCL_COHERENT_MB=1024 VKD3D_CONFIG=ignore_shared_fence, A pressed every 10 s)

  • 1 run: exit 0, no crash, no device removal, 1,965 presents. main, 4 runs: all clean, 1,892–2,122.

Not tested

  • Native Windows, NVIDIA/Intel
  • Whether this title presents with a sub-rect

AI use

  • Claude Code (Claude Opus 5.5) wrote the test scripts, ran the tests and runs on this machine and wrote this report.

@Decodere

Copy link
Copy Markdown
Contributor Author

Thanks for testing this on RX 9070 / vkd3d-proton and catching the DXGI_FORMAT_BC1_UNORM assumption in compositor_releases_root_sig_and_rejects_invalid_planes!

Pushed follow-up #[cfg(test)]-only commit b80aa57c (+12/-2 lines in crates/xcl/src/hle/d3d12x/present.rs, 0 production lines changed vs 3f4a1291):

  • Checked the DXGI_FORMAT_R8G8B8A8_UNORM success-path root_sig refcount before exercising the failure path.
  • Replaced DXGI_FORMAT_BC1_UNORM with DXGI_FORMAT_R8G8B8A8_UINT: because psos_for builds a blended PSO (BlendEnable = true) whose pixel shader writes SV_Target0, integer RTV blending returns E_INVALIDARG on both Windows D3D12/WARP and vkd3d-proton (libs/vkd3d/state.c), while also exercising cleanup of the first (opaque) PSO plus ManuallyDrop::into_inner(pd.pRootSignature).
  • Serialized the three WARP Compositor::new tests with a test-only Mutex (COMPOSITOR_TEST_LOCK), since D3D12's process-wide WARP singleton device deduplicates identical ID3D12RootSignature COM objects and could otherwise shift comp.root_sig refcounts under parallel cargo test.

Verified locally on Windows 11 / RTX 4060 (3x parallel Debug + 3x parallel Release hle::d3d12x::present:: 11 passed; 0 failed; 0 ignored, plus fresh 60 s smoke on b80aa57c). Wine/Proton was not run directly on this host, so re-testing b80aa57c on RADV / vkd3d-proton would confirm the fix end-to-end.

(AI disclosure: Google Antigravity / Gemini 4 Neon inspected the vkd3d-proton validation path, wrote the #[cfg(test)]-only fix, and ran the local Windows verification.)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants