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

Open
github-bot wants to merge 1 commit from github-bot/gh-2418 into main AGit
Owner

@⁠Decodere on GitHub · 2026-11-25 18:19 UTC · original
Decodere:fix-615-present-compositor → main · +125 −6 · 1 files · 1 commits · open

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

**@⁠Decodere** on GitHub · 2026-11-25 18:19 UTC · [original](https://github.com/xcl-dev/xcl/pull/2418) `Decodere:fix-615-present-compositor` → `main` · +125 −6 · 1 files · 1 commits · open **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 #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 #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 #1452
Part of #1333

Assisted-by: Google Antigravity (Gemini 4 Neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:30:19 +00:00
Author
Owner

@⁠Aniseto on GitHub · 2026-11-25 18:40 UTC · original

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.

**@⁠Aniseto** on GitHub · 2026-11-25 18:40 UTC · [original](https://github.com/xcl-dev/xcl/pull/2418#issuecomment-7171234166) 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.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 19:47 UTC · original

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

**@⁠DavidM1911** on GitHub · 2026-11-25 19:47 UTC · [original](https://github.com/xcl-dev/xcl/pull/2418#issuecomment-7172773460) 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
Author
Owner

@⁠Decodere on GitHub · 2026-11-25 19:53 UTC · original

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

**@⁠Decodere** on GitHub · 2026-11-25 19:53 UTC · [original](https://github.com/xcl-dev/xcl/pull/2418#issuecomment-7172905149) 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).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2418/head:github-bot/gh-2418'
git switch 'github-bot/gh-2418'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2418'
git switch 'github-bot/gh-2418'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2418'
git switch 'github-bot/gh-2418'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2418'
git switch 'main'
git merge --squash 'github-bot/gh-2418'
git switch 'main'
git merge --ff-only 'github-bot/gh-2418'
git switch 'main'
git merge 'github-bot/gh-2418'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.