Skip to content

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

Open
Decodere wants to merge 1 commit into
xcl-dev:mainfrom
Decodere:fix-615-present-compositor
Open

Decodere wants to merge 1 commit into
xcl-dev:mainfrom
Decodere:fix-615-present-compositor

Conversation

@Decodere

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 (+125/-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.

Part of #1452
Part of #1333

Tested

  • Failing-first on unmodified origin/main (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 (3f4a1291, WARP-backed CI-safe tests covering psos_for refcount on valid and failing formats, record rejection of DENY_SHADER_RESOURCE / MSAA / unsupported format / buffer / empty planes without state mutation, needs_compositor routing + single-plane [0.0, 0.0, 0.5, 0.5] sub-rect scaling readback, and raw_plane_words MAX_PLANES capping):
    • Debug (cargo test -p xcl --lib hle::d3d12x::present -- --test-threads=1 --nocapture): 11 passed; 0 failed; 0 ignored (0.07 s).
    • Release default RTX 4060 (cargo test --release -p xcl --lib hle::d3d12x::present -- --test-threads=1 --nocapture): 11 passed; 0 failed; 0 ignored (0.07 s).
    • Release WARP (XCL_ADAPTER=warp cargo test --release -p xcl --lib hle::d3d12x::present -- --test-threads=1 --nocapture): 11 passed; 0 failed; 0 ignored (0.07 s).
  • Full release workspace (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 the pre-existing origin/main (68a284a5) failure gpu::recomp::lower_dxil::tests::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 (21 no wave64, 3 per-lane wave32 refused, 3 no D3D12 debug layer / d3d12SDKLayers.dll, 1 no heap windows, 1 cannot disable driver cache; 0 skipped in hle::d3d12x::present).

Regression run
Paired 60 s RTX 4060 smoke (scripts/smoke.ps1 -Seconds 60) on base origin/main vs PR head (exercises the preserved full-rect single-plane PresentX fast path; 1593 vs 1557 frames = 102.3%, 0 device removals, 0 crashes):

Base (origin/main):

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:

xcl-smoke v1
commit: 3f4a12913cfb2ba21055471052a50cc47e02fa85
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1593 (PresentX 1593)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14010 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).
  • 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, full release workspace tests, 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)
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.

4 participants