D3D12.X: shrink the game image to the window with an area filter #555

Closed
github-bot wants to merge 1 commit from gh-pr/555/head into gh-pr/555/base
Owner

@⁠simnJS on GitHub · 2026-11-24 01:43 UTC · original
present-area-filter → main · +669 −31 · 2 files · 1 commits · closed without merging

A window smaller than the title's image showed jagged text and thin lines. The title presents 3840x2160; present.rs copied that image into a swap chain of the same size (DXGI_SCALING_STRETCH) and DWM shrank it to the XCL window (1280x720 by default) with one bilinear tap per window pixel, which skips texels at 3x or 1.5x. Now, when the client area is smaller than the image, the swap chain takes the client size and XCL draws the image into it with an area filter (each texel weighted by the area it covers, in linear light). A window as large as the image keeps the copy; a minimized one shows nothing; without DXC the copy stays, with one log line.

Fixes #554

Rebased on main 9ce2070 (merges cleanly with cb868b2 too). Since the first push: swap_chain_follows_the_window waits for its last frame before dropping its presenter – dropping it with the filter's draw still on the GPU hung the device every GPU test of the process shares (DXGI_ERROR_DEVICE_HUNG), which failed title_textures / vram tests in most --test-threads=4 runs; 6 of 6 green with the wait.

What is in it

  • D3D12.X: shrink the game image to the window with an area filter (one commit):
    • crates/xcl/src/hle/d3d12x/present/downscale.rs (new): route (Copy / Filter / Skip), Scaler (full-screen triangle, area-filter pixel shader with its root signature, compiled with dxc::compile_cached), the tests.
    • crates/xcl/src/hle/d3d12x/present.rs: present_frame (the per-frame work of present_now, so a test can drive it), the swap chain at the client size, client_size, scaler_ready, a logged and throttled ResizeBuffers refusal that still shows the frame at the current size, one present: line for the route.
    • The filter's render-target view of a back buffer is forgotten in note_rtv at once: the adopted device's CreateRenderTargetView hook keeps a reference to every view's resource, and one held swap chain buffer made every ResizeBuffers fail (DXGI_ERROR_INVALID_CALL).
  • Size: +669 / -31, of which about 400 lines are tests (two GPU tests with a CPU area-filter reference and a hidden test window).

Tested

  • NVIDIA GeForce RTX 4080 SUPER (driver 621.01, 32-lane waves), AMD Ryzen 9 7950X3D, 63 GB; Windows 11 Pro build 26300; Rust 1.99.1 (stable-x86_64-pc-windows-msvc); DXC 1.8.2502.11 (Windows SDK 10.0.26100.0).
  • scripts/test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4, debug) on 57a13c1: 687 passed, 0 failed, 41 ignored.
  • SKIPPED on this adapter (no wave64): gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask, gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware.
  • New tests: route_filters_only_when_the_window_is_smaller; downscale_matches_a_cpu_area_filter (1-pixel lines and a checker, 3840x2160 and 1920x1080 into 1280x720, within 1.5 of 255; fails by 73 with the sRGB decode removed from the shader); swap_chain_follows_the_window (adopted device, hidden window: 1280x720, 1920x1080, 800x450, minimized, 1280x720, and a refused resize that still shows the frame; fails at 1920x1080 with 0x887A0001 without the note_rtv line).
  • Retail title 1.0.2.1, 1280x720 window: present: 3840x2160 image in a 1280x720 client area – area filter into a swap chain of the client size; menu text is clean where main's is jagged (checked against a full-size XCL_FRAME_DUMP_FULL=1 dump of the same screen).
  • Resizes on the retail title (release build of 7550904, the same runtime code on the previous base): a script resized the window during a 70 s run (1920x1080, 800x450, maximized 2560x1369, 800x450, 1280x720, minimized, restored). Each size logged present: swap chain WxH, no ResizeBuffers refusal, no device removal; 1682 of 1802 PresentX were shown, the other 120 during the 4 s minimized. Without the note_rtv line: 635 of 1156.

Regression run

xcl-smoke v1
commit: 9ce2070eccf436d7bd38601c90407da447df34f3
gpu: NVIDIA GeForce RTX 4080 SUPER
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1568 (PresentX 1568)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14799 MB
xcl-smoke v1
commit: 57a13c110e1f5e81f7e8409968630cd28eb6a339
gpu: NVIDIA GeForce RTX 4080 SUPER
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1556 (PresentX 1556)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15215 MB

Same title for 60 s, XCL_NETWORK=0, a 1280x720 window (the PR's run uses the filter), the title's save folder emptied before each run.

Not tested

  • AMD and Intel GPUs, Windows 10.
  • HDR: the swap chain stays in the default sRGB colour space; with an HDR10 / PQ swap chain (#238) the filter would have to leave the sRGB curve out.
  • FP16 (scRGB) and _SRGB source formats on a real title (handled in the shader and the view, no title seen using them).
  • A client area larger than the image (the copy path, unchanged) and DPI changes when the window moves between monitors.
  • README.md is not changed; #450 also changes present.rs.

AI use

  • Claude Code with Claude Opus 5.5: traced the cause on the retail title (frame dumps, a comparison of bilinear and area-filter shrinks), wrote the code and the tests (Claude Code worker sessions, Claude Opus 5.5), found the test's device hang, ran the test suite, the resize script and the regression runs, and wrote this description and #554.
**@⁠simnJS** on GitHub · 2026-11-24 01:43 UTC · [original](https://github.com/xcl-dev/xcl/pull/555) `present-area-filter` → `main` · +669 −31 · 2 files · 1 commits · closed without merging A window smaller than the title's image showed jagged text and thin lines. The title presents 3840x2160; `present.rs` copied that image into a swap chain of the same size (`DXGI_SCALING_STRETCH`) and DWM shrank it to the XCL window (1280x720 by default) with one bilinear tap per window pixel, which skips texels at 3x or 1.5x. Now, when the client area is smaller than the image, the swap chain takes the client size and XCL draws the image into it with an area filter (each texel weighted by the area it covers, in linear light). A window as large as the image keeps the copy; a minimized one shows nothing; without DXC the copy stays, with one log line. Fixes #554 Rebased on main 9ce2070 (merges cleanly with cb868b2 too). Since the first push: `swap_chain_follows_the_window` waits for its last frame before dropping its presenter – dropping it with the filter's draw still on the GPU hung the device every GPU test of the process shares (`DXGI_ERROR_DEVICE_HUNG`), which failed `title_textures` / `vram` tests in most `--test-threads=4` runs; 6 of 6 green with the wait. **What is in it** - `D3D12.X: shrink the game image to the window with an area filter` (one commit): - `crates/xcl/src/hle/d3d12x/present/downscale.rs` (new): `route` (Copy / Filter / Skip), `Scaler` (full-screen triangle, area-filter pixel shader with its root signature, compiled with `dxc::compile_cached`), the tests. - `crates/xcl/src/hle/d3d12x/present.rs`: `present_frame` (the per-frame work of `present_now`, so a test can drive it), the swap chain at the client size, `client_size`, `scaler_ready`, a logged and throttled `ResizeBuffers` refusal that still shows the frame at the current size, one `present:` line for the route. - The filter's render-target view of a back buffer is forgotten in `note_rtv` at once: the adopted device's `CreateRenderTargetView` hook keeps a reference to every view's resource, and one held swap chain buffer made every `ResizeBuffers` fail (`DXGI_ERROR_INVALID_CALL`). - Size: +669 / -31, of which about 400 lines are tests (two GPU tests with a CPU area-filter reference and a hidden test window). **Tested** - NVIDIA GeForce RTX 4080 SUPER (driver 621.01, 32-lane waves), AMD Ryzen 9 7950X3D, 63 GB; Windows 11 Pro build 26300; Rust 1.99.1 (stable-x86_64-pc-windows-msvc); DXC 1.8.2502.11 (Windows SDK 10.0.26100.0). - `scripts/test.ps1` (`cargo build --workspace` + `cargo test --workspace -- --test-threads=4`, debug) on 57a13c1: 687 passed, 0 failed, 41 ignored. - SKIPPED on this adapter (no wave64): `gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware`. - New tests: `route_filters_only_when_the_window_is_smaller`; `downscale_matches_a_cpu_area_filter` (1-pixel lines and a checker, 3840x2160 and 1920x1080 into 1280x720, within 1.5 of 255; fails by 73 with the sRGB decode removed from the shader); `swap_chain_follows_the_window` (adopted device, hidden window: 1280x720, 1920x1080, 800x450, minimized, 1280x720, and a refused resize that still shows the frame; fails at 1920x1080 with 0x887A0001 without the `note_rtv` line). - Retail title 1.0.2.1, 1280x720 window: `present: 3840x2160 image in a 1280x720 client area – area filter into a swap chain of the client size`; menu text is clean where main's is jagged (checked against a full-size `XCL_FRAME_DUMP_FULL=1` dump of the same screen). - Resizes on the retail title (release build of 7550904, the same runtime code on the previous base): a script resized the window during a 70 s run (1920x1080, 800x450, maximized 2560x1369, 800x450, 1280x720, minimized, restored). Each size logged `present: swap chain WxH`, no `ResizeBuffers` refusal, no device removal; 1682 of 1802 PresentX were shown, the other 120 during the 4 s minimized. Without the `note_rtv` line: 635 of 1156. **Regression run** ``` xcl-smoke v1 commit: 9ce2070eccf436d7bd38601c90407da447df34f3 gpu: NVIDIA GeForce RTX 4080 SUPER title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1568 (PresentX 1568) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14799 MB ``` ``` xcl-smoke v1 commit: 57a13c110e1f5e81f7e8409968630cd28eb6a339 gpu: NVIDIA GeForce RTX 4080 SUPER title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1556 (PresentX 1556) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15215 MB ``` Same title for 60 s, `XCL_NETWORK=0`, a 1280x720 window (the PR's run uses the filter), the title's save folder emptied before each run. **Not tested** - AMD and Intel GPUs, Windows 10. - HDR: the swap chain stays in the default sRGB colour space; with an HDR10 / PQ swap chain (#238) the filter would have to leave the sRGB curve out. - FP16 (scRGB) and _SRGB source formats on a real title (handled in the shader and the view, no title seen using them). - A client area larger than the image (the copy path, unchanged) and DPI changes when the window moves between monitors. - `README.md` is not changed; #450 also changes `present.rs`. **AI use** - Claude Code with Claude Opus 5.5: traced the cause on the retail title (frame dumps, a comparison of bilinear and area-filter shrinks), wrote the code and the tests (Claude Code worker sessions, Claude Opus 5.5), found the test's device hang, ran the test suite, the resize script and the regression runs, and wrote this description and #554.
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)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:25:33 +00:00
github-bot closed this pull request 2026-11-26 04:25:33 +00:00
Author
Owner

@⁠alpz1000 on GitHub · 2026-11-24 02:53 UTC · original · edited 2026-11-24 02:57 UTC

Independent Present/downscale check of 57a13c110e1f5e81f7e8409968630cd28eb6a339 on RTX 3060 12 GB, driver 610.88 (32.0.16.1088), Intel i5-8400, Windows 11 Home 26200.9974, Rust 1.100.0 x86_64-pc-windows-msvc, SDK DXC 1.9.2602.17, debug. XCL_ADAPTER=3060.

Tested: cargo test --locked -p xcl --lib d3d12x::present:: -- --test-threads=4 --nocapture passed 9/9 with no skips, including GPU/CPU area-filter comparison and the hidden-window swap-chain resize test. I then ran the same filter in six fresh processes with four test threads. All six passed all nine, with no skip or device-hung messages.

Not tested: full workspace concurrency with texture/VRAM tests, visual retail gameplay, or other adapters.

AI use: OpenAI Codex (GPT-6) ran the local tests and drafted this report.

Follow-up: parallel GPU test groups. Same RTX 3060 and toolchain. I ran cargo test --locked -p xcl --lib -- --test-threads=4 --nocapture d3d12x::present::downscale::tests d3d12x::title_textures::tests d3d12x::vram::tests three times per revision, with XCL_ADAPTER=3060.

  • Base 9ce2070eccf436d7bd38601c90407da447df34f3: 3/3 clean, 15 tests per run. It has no downscale tests.
  • PR head 57a13c110e1f5e81f7e8409968630cd28eb6a339: 2/3 clean, 18 tests in each successful run. Run 3 exited with D3D12 device removal 0x887a0006. swap_chain_follows_the_window had already reported ok. The next relevant line was the placed-texture test's 512 unreleased 1 MiB textures over 16 MiB memory summary, then device removal before that test completed.

This shows an intermittent device hang with the combined test groups on this setup. The base comparison does not isolate the cause because it lacks the three added tests. No retail files or full workspace run. Codex ran the checks and summarized the logs.

**@⁠alpz1000** on GitHub · 2026-11-24 02:53 UTC · [original](https://github.com/xcl-dev/xcl/pull/555#issuecomment-7120576418) · edited 2026-11-24 02:57 UTC Independent Present/downscale check of `57a13c110e1f5e81f7e8409968630cd28eb6a339` on RTX 3060 12 GB, driver 610.88 (32.0.16.1088), Intel i5-8400, Windows 11 Home 26200.9974, Rust 1.100.0 x86_64-pc-windows-msvc, SDK DXC 1.9.2602.17, debug. `XCL_ADAPTER=3060`. **Tested**: `cargo test --locked -p xcl --lib d3d12x::present:: -- --test-threads=4 --nocapture` passed **9/9** with no skips, including GPU/CPU area-filter comparison and the hidden-window swap-chain resize test. I then ran the same filter in six fresh processes with four test threads. All six passed all nine, with no skip or device-hung messages. **Not tested**: full workspace concurrency with texture/VRAM tests, visual retail gameplay, or other adapters. **AI use**: OpenAI Codex (GPT-6) ran the local tests and drafted this report. **Follow-up: parallel GPU test groups.** Same RTX 3060 and toolchain. I ran `cargo test --locked -p xcl --lib -- --test-threads=4 --nocapture d3d12x::present::downscale::tests d3d12x::title_textures::tests d3d12x::vram::tests` three times per revision, with `XCL_ADAPTER=3060`. - Base `9ce2070eccf436d7bd38601c90407da447df34f3`: **3/3 clean**, 15 tests per run. It has no downscale tests. - PR head `57a13c110e1f5e81f7e8409968630cd28eb6a339`: **2/3 clean**, 18 tests in each successful run. Run 3 exited with D3D12 device removal `0x887a0006`. `swap_chain_follows_the_window` had already reported ok. The next relevant line was the placed-texture test's `512 unreleased 1 MiB textures over 16 MiB` memory summary, then device removal before that test completed. This shows an intermittent device hang with the combined test groups on this setup. The base comparison does not isolate the cause because it lacks the three added tests. No retail files or full workspace run. Codex ran the checks and summarized the logs.
Author
Owner

@⁠Chrysana on GitHub · 2026-11-24 03:04 UTC · original

Test report for 57a13c1 on AMD RDNA4, which Not tested lists: the shrunk image is visibly smoother on this card, and the runs show no regression.

Setup: AMD Radeon RX 9070 XT 16 GB, driver 32.0.32015.2008, Ryzen 7 9800X3D, 31 GB RAM, Windows 11 25H2 build 26200.9974, rustc 1.100.0 x86_64-pc-windows-msvc, DXC 1.9.2602.17. Retail title 1.0.2.1 (presents 3840x2160), XCL's window not resized. Debug build for the tests, release builds for the runs.

Tests: cargo test --workspace --no-fail-fast -- --test-threads=4 at 57a13c1: 687 passed, 0 failed, 41 ignored. SKIPPED: the two debug-layer tests (the D3D12 debug layer isn't installed here).

By eye: I watched eight runs: main and this PR merged onto main back to back, then six more, knowing which build each was. The menu's button-prompt text was smooth and anti-aliased in all three runs with this change (merged onto main twice, and at its own head) and jagged in the five without it (main twice, another PR merged onto main twice, and that PR's head).

Title runs: scripts/smoke.ps1 -Game <folder> -Seconds 60 with XCL_PRESS_A_AT=14,17,21, same saved state. 57a13c1 merged onto main 18c105a (clean, local merge 2873e09, not pushed):

build frames peak commit draws per 2 s at the end
main 18c105a 1170, 1183 15428, 15441 MB 1250–1263
57a13c1 merged onto 18c105a 1182, 1189 15445, 15434 MB 1256–1261
57a13c1 (its own base 9ce2070) 1530 16014 MB 1279–1320

On 18c105a the title reaches its first menu a little later, so the scripted presses (last at 21 s) come too early and the runs stay in the menus (a manual press goes on). The head's own base reaches the intro video. No crash or device removal in any run.

Regression run:

main:

xcl-smoke v1
commit: 18c105af86929d6ae26c44096c85b66f1644e743
gpu: AMD Radeon RX 9070 XT
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1183 (PresentX 1183)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15441 MB

PR merged onto main:

xcl-smoke v1
commit: 2873e096ba7514b7b7e1b4d33771f6509ab83542
gpu: AMD Radeon RX 9070 XT
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1182 (PresentX 1182)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15445 MB

PR head:

xcl-smoke v1
commit: 57a13c110e1f5e81f7e8409968630cd28eb6a339
gpu: AMD Radeon RX 9070 XT
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1530 (PresentX 1531)
presents per 2 s (last 3): 59 60 60
device removals: 0
crashes: 0
peak commit: 16014 MB

Not tested: a resized or minimized window; a window larger than the image; HDR; moving between monitors; no pixel-level comparison (by eye only).

AI use: Claude Code with Claude Opus 5.5 built the commits, ran the tests and the title runs, and wrote this report. The visual comparison was done by me.

**@⁠Chrysana** on GitHub · 2026-11-24 03:04 UTC · [original](https://github.com/xcl-dev/xcl/pull/555#issuecomment-7120746678) Test report for `57a13c1` on **AMD RDNA4**, which **Not tested** lists: **the shrunk image is visibly smoother on this card**, and the runs show no regression. **Setup:** AMD Radeon RX 9070 XT 16 GB, driver 32.0.32015.2008, Ryzen 7 9800X3D, 31 GB RAM, Windows 11 25H2 build 26200.9974, rustc 1.100.0 `x86_64-pc-windows-msvc`, DXC 1.9.2602.17. Retail title 1.0.2.1 (presents 3840x2160), XCL's window not resized. Debug build for the tests, release builds for the runs. **Tests:** `cargo test --workspace --no-fail-fast -- --test-threads=4` at `57a13c1`: 687 passed, 0 failed, 41 ignored. `SKIPPED`: the two debug-layer tests (the D3D12 debug layer isn't installed here). **By eye:** I watched eight runs: `main` and this PR merged onto `main` back to back, then six more, knowing which build each was. The menu's button-prompt text was **smooth and anti-aliased in all three runs with this change** (merged onto `main` twice, and at its own head) and jagged in the five without it (`main` twice, another PR merged onto `main` twice, and that PR's head). **Title runs:** `scripts/smoke.ps1 -Game <folder> -Seconds 60` with `XCL_PRESS_A_AT=14,17,21`, same saved state. `57a13c1` merged onto `main` `18c105a` (clean, local merge `2873e09`, not pushed): | build | frames | peak commit | draws per 2 s at the end | |---|---|---|---| | `main` `18c105a` | 1170, 1183 | 15428, 15441 MB | 1250–1263 | | **`57a13c1` merged onto `18c105a`** | **1182, 1189** | 15445, 15434 MB | 1256–1261 | | `57a13c1` (its own base `9ce2070`) | 1530 | 16014 MB | 1279–1320 | On `18c105a` the title reaches its first menu a little later, so the scripted presses (last at 21 s) come too early and the runs stay in the menus (a manual press goes on). The head's own base reaches the intro video. No crash or device removal in any run. **Regression run:** `main`: ``` xcl-smoke v1 commit: 18c105af86929d6ae26c44096c85b66f1644e743 gpu: AMD Radeon RX 9070 XT title: retail-title seconds: 60 exit: 0x0 frames shown: 1183 (PresentX 1183) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15441 MB ``` PR merged onto `main`: ``` xcl-smoke v1 commit: 2873e096ba7514b7b7e1b4d33771f6509ab83542 gpu: AMD Radeon RX 9070 XT title: retail-title seconds: 60 exit: 0x0 frames shown: 1182 (PresentX 1182) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15445 MB ``` PR head: ``` xcl-smoke v1 commit: 57a13c110e1f5e81f7e8409968630cd28eb6a339 gpu: AMD Radeon RX 9070 XT title: retail-title seconds: 60 exit: 0x0 frames shown: 1530 (PresentX 1531) presents per 2 s (last 3): 59 60 60 device removals: 0 crashes: 0 peak commit: 16014 MB ``` **Not tested:** a resized or minimized window; a window larger than the image; HDR; moving between monitors; no pixel-level comparison (by eye only). **AI use:** Claude Code with Claude Opus 5.5 built the commits, ran the tests and the title runs, and wrote this report. The visual comparison was done by me.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.