Skip to content

D3D12.X: the game's image keeps its aspect ratio in the window - #733

Open
MrCheese5 wants to merge 3 commits into
xcl-dev:mainfrom
MrCheese5:uw-b1-aspect
Open

MrCheese5 wants to merge 3 commits into
xcl-dev:mainfrom
MrCheese5:uw-b1-aspect

Conversation

@MrCheese5

@MrCheese5 MrCheese5 commented Nov 24, 2026 •

Copy link
Copy Markdown

Stacked on #555 and #732; only the top commit belongs here.

A 16:9 image in a window of another shape (a 21:9 or 16:10 screen) was stretched to fit it. The swap chain is now the size of the client area, and the image is placed in it according to scaling (xcl.toml, XCL_SCALING):

  • "fit" (the default): the aspect ratio is kept, with black bars
  • "integer": whole multiples only, falling back to fit in a smaller window
  • "stretch": the old behaviour

An image that lands 1:1 (3840x2160 in a 5120x2160 client area) is copied texel for texel into its place (Route::Place) after the bars are cleared. Other sizes go through #555's area filter, which now draws into a rectangle (a viewport plus an origin root constant), with the bars cleared to black. Without DXC, the old stretched copy stays.

This changes behaviour for everyone: a 16:9 image in a window of another shape now gets black bars instead of being stretched.

What is in it

  • crates/xcl/src/hle/d3d12x/present/downscale.rs: Scaling, place(), the new routes, the filter drawing into a rectangle; tests of place() for each scaling, the routes, and a GPU test that places a 1280x720 image 1:1 in 1680x720 (exact texels, black bars) and filters it into 1032x432 (against a CPU area filter)
  • crates/xcl/src/hle/d3d12x/present.rs: present_frame places the image; draw()
  • crates/xcl/src/config.rs, README.md: scaling

Tested

  • RTX 4090 (driver 621.14), i9-14900K, Windows 11 26200, Rust stable-x86_64-pc-windows-msvc, debug tests, release smoke runs
  • cargo test -p xcl --lib downscale: covered by the suite run below
  • cargo test --workspace -- --test-threads=1: 697 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: 8244a72a195d85dff35a5308c0e47535eff8c5ba
gpu: NVIDIA GeForce RTX 4090
title: Xbox
seconds: 60
exit: 0x0
frames shown: 819 (PresentX 819)
presents per 2 s (last 3): 37 35 37
device removals: 0
crashes: 0
peak commit: 15544 MB

Not tested

  • In a game, a window of another aspect ratio. The smoke run uses the default 16:9 window, so the default route is a plain copy.
  • AMD and wave64 GPUs.

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 3 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>
A 16:9 image in a window of another shape (a 21:9 or 16:10 screen) was
stretched to it. The swap chain is now the client area's size and the
image is placed in it by `scaling` (xcl.toml, XCL_SCALING):
- "fit" (default): the aspect ratio is kept, with black bars
- "integer": whole multiples only (falls back to fit in a smaller window)
- "stretch": the old behaviour

An image that lands 1:1 (3840x2160 in a 5120x2160 client area) is copied
texel for texel at its place (Route::Place, after clearing the bars).
Other sizes go through the area filter, which now draws into a rectangle
(viewport + an origin root constant) with the bars cleared to black.
Without DXC the old stretched copy stays.

Tests: place() for each scaling, the routes, and on the GPU a 1280x720
image placed 1:1 in 1680x720 (exact texels, black bars) and filtered
into 1032x432 (against a CPU area filter).

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

Copy link
Copy Markdown

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

Tested

  • Commit: 8244a72a195d85dff35a5308c0e47535eff8c5ba (pr-733, 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: 697 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 #733 (8244a72):

xcl-smoke v1
commit: 8244a72a195d85dff35a5308c0e47535eff8c5ba
gpu: NVIDIA GeForce RTX 3060 Ti
title: retail-1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1547 (PresentX 1547)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14712 MB

Not tested: Non-16:9 / ultrawide monitor scaling ("integer" / "stretch"), 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 8244a72a195d85dff35a5308c0e47535eff8c5ba on AMD RDNA4. I merged it onto current main 64b3f35 locally (clean merge), so the tree tested includes the stack under it (#555, #732).

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: 706 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 665 passed, 0 failed, 21 ignored
  • 0 SKIPPED; place_keeps_the_aspect_ratio, placed_image_between_black_bars and swap_chain_follows_the_window pass.

Review: The swap chain follows the client area and the image is placed by scaling (fit by default), with black bars outside it. I reviewed the top commit only.

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.

@JJAutoCompare

Copy link
Copy Markdown

Empirical test report (8244a72)

Hardware / environment

  • Tested 8244a72a195d85dff35a5308c0e47535eff8c5ba on STOR-WINLAB, Windows x64 build 26200, Session 0, AMD64 Family 23 Model 113. Cargo used the unoptimized test profile with debug info and incremental compilation disabled.
  • Rust 1.100.0 (0ef1bc386 2026-11-09) and DXC 1.9.2609.5 (01b62ad47). The D3D12 run held the Arc A770 test lock and set XCL_ADAPTER=A770. These fixtures request the default D3D12 device with WARP fallback, so the actual adapter and driver were unverified.

Commands and results

  • cargo test --workspace --no-run built all workspace test targets outside the Arc lock (exit 0). In the commands below, $xclTests is the xcl library test executable from that build. Both runs set RUST_TEST_NOCAPTURE=1.
  • With XCL_ADAPTER=NONE_CPU_ONLY outside the lock, ran & $xclTests --test-threads=1 place_keeps_the_aspect_ratio route_filters_only_when_the_window_is_smaller (exit 0).
  • With XCL_ADAPTER=A770 inside Invoke-ArcTest.ps1, ran & $xclTests --test-threads=1 downscale_matches_a_cpu_area_filter placed_image_between_black_bars swap_chain_follows_the_window (exit 101).
  • The log recorded 4 passed, 1 failed, 0 ignored, 0 SKIPPED markers. Both CPU fixtures passed. Two D3D12 fixtures passed and one failed.

Observed behavior

  • The CPU assertions passed for fit, integer and stretch placement and route selection.
  • Offscreen D3D12 readback matched the CPU area filter. A 1280×720 image in a 1680×720 target retained exact RGB values, and the filtered 768×432 image in a 1032×432 target matched the CPU reference within 1.5 RGB levels. Bars were black in both cases.
  • swap_chain_follows_the_window failed at the first 1280×720 frame in Session 0. CreateSwapChainForHwnd returned 0x887A0022 (DXGI_ERROR_NOT_CURRENTLY_AVAILABLE) before any resize checks were reached.

Not tested

  • Interactive window presentation and resizing, the full GPU workspace suite, and game smoke runs.

AI use

Verified with T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high). Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against pr733-focused.log and published.

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