Skip to content

D3D12.X: a presenter waits for its last present before it is released - #732

Open
MrCheese5 wants to merge 2 commits into
xcl-dev:mainfrom
MrCheese5:uw-a-presenter-wait
Open

MrCheese5 wants to merge 2 commits into
xcl-dev:mainfrom
MrCheese5:uw-a-presenter-wait

Conversation

@MrCheese5

@MrCheese5 MrCheese5 commented Nov 24, 2026 •

Copy link
Copy Markdown

Stacked on #555; only the top commit belongs here. It fixes a lifetime issue in #555's presenter, so it could also be folded into #555.

Dropping a Presenter released the swap chain, the scaler's descriptor heaps and the title's image while the command list of its last present could still be running on the GPU. #555's swap_chain_follows_the_window drops its presenter right after the last present_frame. When that list is still running, the device is suspended (0x887A0005) and the GPU tests that run after it in the same process fail. That depends on timing, so it happens intermittently. Drop now waits for the presenter's fence: 2 s at most, and not after a failed Signal, when the presenter is already disabled.

On main without #555, a presenter is dropped only when the present queue changes, and that path already waits for the fence. So the fix belongs on top of #555.

What is in it

  • crates/xcl/src/hle/d3d12x/present.rs: Drop for Presenter waits for the last present

Tested

  • RTX 4090 (driver 621.14), i9-14900K, Windows 11 26200, Rust stable-x86_64-pc-windows-msvc, debug tests, release smoke runs
  • No new test: D3D12.X: shrink the game image to the window with an area filter #555's swap_chain_follows_the_window already reproduces the failure, intermittently
  • cargo test --workspace -- --test-threads=1: 695 passed, 0 failed, 41 ignored; SKIPPED: gpu_geometry_wave32_prefix_count_over_a_mask (no wave64), gpu_wave32_program_in_wave64_hardware (no wave64)
  • Single-threaded on purpose: with --test-threads=4, GPU tests on this machine hang or lose the device tonight on main too (bdab194 and 91f9a5e; bdab194 had passed with 4 threads earlier the same night, and the driver logs GPU errors). Single-threaded, main 91f9a5e passes (cargo test -p xcl --lib -- --test-threads=1: 647 passed, 0 failed).

Regression run
Both runs use a fresh data root of their own and the default settings (a 1280x720 window, nothing new turned on), so this shows that nothing else changes.

xcl-smoke v1
commit: 91f9a5e9f03156ea82dc55a18f7704862da7a5db
gpu: NVIDIA GeForce RTX 4090
title: Xbox
seconds: 60
exit: 0x0
frames shown: 811 (PresentX 811)
presents per 2 s (last 3): 37 34 36
device removals: 0
crashes: 0
peak commit: 15536 MB
xcl-smoke v1
commit: b7900d0010b2b808ec3c77243f25c8fe40dbe6eb
gpu: NVIDIA GeForce RTX 4090
title: Xbox
seconds: 60
exit: 0x0
frames shown: 786 (PresentX 786)
presents per 2 s (last 3): 35 35 35
device removals: 0
crashes: 0
peak commit: 15653 MB

Not tested

  • I did not reproduce the intermittent device suspension on this machine for this PR. The evidence for the race is the code path above, plus failures seen while testing a tree with more GPU tests on it.

AI use

  • Claude Code with Claude Opus 5.5: wrote the code, the tests and this description; the hardware checks above are runs on the machine named under Tested.

🤖 Generated with Claude Code

simnJS and others added 2 commits November 24, 2026 03:26
Text and thin lines of a retail title looked jagged in the XCL window.
Root cause: the title presents 3840x2160, present.rs copied it into a
swap chain of the same size (DXGI_SCALING_STRETCH) and DWM shrank it to
the window (1280x720 by default) with a single bilinear tap per pixel:
at 3x or 1.5x it skips texels, so strokes get uneven and edges
stair-step. A full-size frame dump of the same frame is clean.

When the window's client area is smaller than the image on either side,
the swap chain now takes the client size (ResizeBuffers on resize) and a
full-screen triangle draws the image into it: its pixel shader averages
the whole footprint of each window pixel (area filter, exact partial
texel weights), in linear light - 8/10-bit UNORM decoded and encoded
with the sRGB curve (the swap chain's default colour space), an _SRGB
source through its view, FP16 (scRGB) as is. A window as large as the
image keeps the copy; a minimized one (0x0) shows nothing and keeps its
swap chain. Without DXC (or a pipeline the device refuses) the copy
stays, with one log line. Frame dumps still read the title's own image.
One "present:" line names the route and the sizes.

Resizes: the presenter draws on the title's adopted device, whose
CreateRenderTargetView hook (note_rtv) keeps a reference to every view's
resource; the filter's view of a back buffer would hold one swap chain
buffer and make every ResizeBuffers fail (DXGI_ERROR_INVALID_CALL), so
Scaler::record forgets its own view at once. A refused ResizeBuffers is
logged once per size and asked for again twice a second; the frame is
still shown, drawn at the swap chain's current size. present_now's
per-frame work is present_frame, so a test can drive it.

Tests: the route decision; a GPU test drawing 1-pixel lines and a
checker from 3840x2160 and 1920x1080 into 1280x720 against a CPU area
filter (within 1.5 of 255); a GPU test on an adopted device with a
hidden window: frames at 1280x720, 1920x1080, 800x450 (each new back
buffer matches the CPU filter), minimized, 1280x720 again, and a refused
resize that still shows the frame.

Assisted-by: Claude Code (Claude Opus 5.5)
Dropping a Presenter released the swap chain, the scaler's descriptor
heaps and the title's image while its last present's command list could
still be running on the GPU. swap_chain_follows_the_window drops its
presenter right after the last present_frame; when the list was still
running, the device was suspended (0x887A0005) and the GPU tests that
ran after it failed. That happens intermittently and depends on timing.
The drop now waits for the presenter's fence (2 s at most; not after a
failed Signal, when the presenter is disabled).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@RandomGithub12309

Copy link
Copy Markdown
Contributor

Test run and review of b7900d0010b2b808ec3c77243f25c8fe40dbe6eb merged cleanly onto main (f4ce27c):

Tested

  • Hardware: NVIDIA GeForce RTX 5050 Laptop GPU (driver 32.0.16.2114, wave32, SM 6.6), Intel Core Ultra 7 255HX (20 cores), Windows 11 Build 26300, rustc 1.100.0 stable-x86_64-pc-windows-msvc, debug build
  • Command: cargo build --workspace + cargo test --workspace -- --test-threads=4
  • Result: 704 passed, 0 failed, 41 ignored (hle::d3d12x::present::downscale::tests::route_filters_only_when_the_window_is_smaller, downscale_matches_a_cpu_area_filter, and swap_chain_follows_the_window pass)
  • SKIPPED: gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask, gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware (no wave64)

Review

  • Drop for Presenter still waits on a fence signaled before sc.Present: In #555's base commit (present_frame in crates/xcl/src/hle/d3d12x/present.rs), q.Signal(&p.fence, p.value) still runs before sc.Present(0, DXGI_PRESENT(0)). Because DXGI's Present submits internal queue work referencing the swap-chain back buffer afterward, waiting for self.value in Drop can return before DXGI's Present work finishes unless Signal moves after Present or Drop signals a drain fence before waiting.

Not tested

  • AMD / wave64, Intel GPU, D3D12 debug layer (0x887A002D unavailable on this host), retail title (xcl-smoke)

AI use

  • Antigravity with Gemini 4 Hydrogen — merged b7900d0 onto f4ce27c, audited the diff, ran the workspace suite, and wrote this report.

@LocranKing

Copy link
Copy Markdown

Tested on Windows 11 + NVIDIA GeForce RTX 3060 Ti (8 GB, wave32).

Tested

  • Commit: b7900d0010b2b808ec3c77243f25c8fe40dbe6eb (pr-732, clean tree)
  • Hardware / software: Windows 11 Home Build 26200, AMD Ryzen 5 5500, 31.8 GB RAM, NVIDIA GeForce RTX 3060 Ti (8024 MiB VRAM, driver 32.0.16.2101), rustc 1.100.0 (x86_64-pc-windows-msvc, MSVC 14.44.35207), DXC 1.9.2602.17 (SDK 10.0.26100.0), --release
  • cargo test --workspace --release --no-fail-fast -- --test-threads=4: 695 passed, 0 failed, 41 ignored, exit 0; 2 (no wave64) skipped (gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware)

Regression run (scripts/smoke.ps1, 60 s, XCL_NETWORK=0, title folder name redacted)

main (64b3f35):

xcl-smoke v1
commit: 64b3f35599bb7102f55d640e1a791e7d6dd3b175
gpu: NVIDIA GeForce RTX 3060 Ti
title: retail-1.0.2.1
seconds: 60
exit: 0x0
frames shown: 544 (PresentX 545)
presents per 2 s (last 3): 22 22 21
device removals: 0
crashes: 0
peak commit: 15491 MB

PR #732 (b7900d0):

xcl-smoke v1
commit: b7900d0010b2b808ec3c77243f25c8fe40dbe6eb
gpu: NVIDIA GeForce RTX 3060 Ti
title: retail-1.0.2.1
seconds: 60
exit: 0x0
frames shown: 539 (PresentX 539)
presents per 2 s (last 3): 22 20 21
device removals: 0
crashes: 0
peak commit: 15485 MB

Not tested: Debug build, XCL_SAMPLE_* tests on this branch, AMD / wave64 hardware.

AI use: Antigravity (Gemini 4 Hydrogen) ran the build, tests, and smoke runs and drafted this report from the command outputs.

@MesshM

MesshM commented Nov 24, 2026

Copy link
Copy Markdown

Test run of b7900d0010b2b808ec3c77243f25c8fe40dbe6eb on AMD RDNA4. I merged it onto current main 64b3f35 locally (clean merge), so the tree tested includes the stack under it (#555).

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug
  • cargo build --workspace + cargo test --workspace -- --test-threads=4 on the merge: 704 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 663 passed, 0 failed, 21 ignored
  • 0 SKIPPED; the present tests pass.

Review: Waiting for the last present's fence before the presenter's swap chain, scaler heaps and image are released closes the lifetime gap described. Since it fixes #555's own presenter, folding it into #555 (as the description offers) would keep #555 from landing with the gap.

Not tested: no retail title or regression run (I have no unpacked game), no XCL_SAMPLE_* tests, release build; the PR's head on its old base was not run, only its merge onto main.

Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.

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