Skip to content

PE loader: render_resolution renders RAGE titles at the screen's aspect - #735

Open
MrCheese5 wants to merge 5 commits into
xcl-dev:mainfrom
MrCheese5:uw-c-render-resolution
Open

MrCheese5 wants to merge 5 commits into
xcl-dev:mainfrom
MrCheese5:uw-c-render-resolution

Conversation

@MrCheese5

@MrCheese5 MrCheese5 commented Nov 24, 2026 •

Copy link
Copy Markdown

Stacked on #555, #732, #733 and #734; only the top commit belongs here. It uses present::screen_size() from #734.

On a 21:9 screen the newer retail game still rendered 16:9, so it was pillarboxed. RAGE titles take their back buffer size from a mode table in read-only data: {w, h, 60, 1} × 5, the largest 3840x2160. With render_resolution ("native" by default, so nothing changes unless it is set; "WxH"; or "screen"; XCL_RENDER_RES), three things are patched when the executable is mapped. Each is found by its bytes, never by an address, and when a pattern is not found, a warning is logged and nothing is patched:

  • The table's largest mode becomes the render size.
  • A debug break after the full-size targets are allocated becomes a nop. It fires when their arena has more than 2 MB left over, and the normal path follows it.
  • The loads of the title's output size (3840x2160, the console's output; it sits next to the render size its setter writes) read the render size instead. Without this, the UI was laid out for the render size but drawn as if the screen were 4K: scaled by render/4K twice, with the bottom 17 % black and the right-hand prompts off the screen.

The arena does not grow (5120x2160 overran it by 22 MB, and 4416x1864 by 1.9 MB through 128x128 tile padding), so a size must fit 3840x2176 in tiles. "screen" picks the largest 128-aligned size within 2 % of the monitor's aspect ratio: 4224x1792 for 21:9, 4992x1408 for 32:9, 3456x2176 for 16:10, and no change for 16:9.

What is in it

  • crates/xcl/src/widescreen.rs: the render size from the setting and the three patches, with unit tests on synthetic bytes (render size settings, only the largest mode rewritten, the break becoming a nop, the output-size loads retargeted and others left alone, and nothing done without the setter)
  • crates/xcl/src/loader.rs: patch_image when the main executable is mapped, before page protections
  • crates/xcl/src/hle/d3d12x/present.rs: screen_size()
  • crates/xcl/src/config.rs, crates/xcl/src/lib.rs, README.md: render_resolution

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 widescreen: covered by the suite run below
  • cargo test --workspace -- --test-threads=1: 702 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).
  • An earlier run on this machine, with render_resolution = "screen" on a 5120x2160 monitor (the newer retail game's account screen, intro video and loading art): a 4224x1792 back buffer at 30 fps. The UI spans the full width with its prompts in the wide screen's corner, round icons stay round, and the video and art fill 21:9. The smoke run below is with the default "native", which patches nothing.

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: 0c43a53620aba918699412e4ba25c314b45a3b73
gpu: NVIDIA GeForce RTX 4090
title: Xbox
seconds: 60
exit: 0x0
frames shown: 841 (PresentX 841)
presents per 2 s (last 3): 37 36 37
device removals: 0
crashes: 0
peak commit: 15561 MB

Not tested

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 5 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>
…oice

At 125 % display scaling Windows enlarged the DPI-unaware XCL window, so
the game's image was drawn smaller and blurred back up.

- The process is per-monitor DPI aware (V2), set in host_main before the
  window exists. window_width / window_height are at 100 % and scaled by
  the monitor's DPI, and WM_DPICHANGED takes the size Windows suggests.
- `fullscreen` (XCL_FULLSCREEN): a borderless window over the monitor at
  its native resolution. Alt+Enter or F11 switches while running.
- `monitor` (XCL_MONITOR): "primary", a number from the list logged at
  start, or a device name. "auto" placement centres on a named monitor.

Test: pick_monitor() for each kind of setting.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On a 21:9 screen the newer retail game still rendered 16:9, so it was
pillarboxed. RAGE titles take their back buffer size from a mode table in
read-only data ({w, h, 60, 1} x 5, the largest 3840x2160). With
`render_resolution` ("native" by default, "WxH", or "screen";
XCL_RENDER_RES), three things are patched when the executable is mapped.
Each is found by its bytes, not by an address:

- The table's largest mode becomes the render size.
- A debug break after the full-size targets are allocated becomes a nop.
  It fires when their arena has more than 2 MB left over, and its normal
  path follows it.
- The loads of the title's output size (3840x2160, the console's output;
  it sits next to the render size its setter writes) read the render size
  instead. Without this the UI was laid out for the render size but drawn
  as if the screen were 4K: scaled by render/4K twice, with the bottom
  17 % black and the right-hand prompts off the screen.

The arena does not grow (5120x2160 overran it by 22 MB, 4416x1864 by
1.9 MB through 128x128 tile padding), so a size must fit 3840x2176 in
tiles. "screen" picks the largest 128-aligned size within 2 % of the
monitor's aspect ratio: 4224x1792 on a 5120x2160 monitor.

Measured on the newer retail game (account screen, intro video, loading
art; RTX 4090): a 4224x1792 back buffer at 30 fps, the UI spanning the
full width with its prompts in the wide screen's corner and round icons
(not stretched), and the video and art filling 21:9. The 3D projection
is not checked yet, because the world still stops at xcl-dev#505.

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

Copy link
Copy Markdown
Contributor

Test run and review of 0c43a53620aba918699412e4ba25c314b45a3b73 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
  • Commands & Results:
    • First cargo test --workspace -- --test-threads=4: 669 passed, 1 failed in src/lib.rs — hle::d3d12x::real::readback_routing_tests::coherent_buffer_sanitizes_console_flags_and_state panicked on VirtualFree(mem, 0, MEM_RELEASE) != 0 (real.rs:5388, an unrelated OpenExistingHeapFromAddress teardown timing flake on main).
    • Re-run standalone (coherent_buffer_sanitizes_console_flags_and_state): 1 passed, 0 failed.
    • Full workspace re-run (cargo test --workspace -- --test-threads=4): 711 passed, 0 failed, 41 ignored (downscale::tests::*, pick_monitor_by_setting, and all 4 widescreen::tests::* 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

  • Inherits #732 / #555's pre-Present q.Signal ordering in crates/xcl/src/hle/d3d12x/present.rs.
  • In crates/xcl/src/widescreen.rs: render_size("WxH", ...) returns Some((w, h)) and patch_image still rewrites the executable's mode table when !fits(w, h), logging only a warning afterward; patch_output_size (widescreen.rs:174) also subtracts 0x20 from disp32 with checked subtraction instead of wrapping_sub(0x20).

Not tested

  • 21:9 monitor / multi-monitor DPI scaling / Alt+Enter fullscreen interactively, retail executable binary patching via xcl run, AMD / wave64

AI use

  • Antigravity with Gemini 4 Hydrogen — merged 0c43a53 onto f4ce27c, audited widescreen.rs and the stacked changes, 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: 0c43a53620aba918699412e4ba25c314b45a3b73 (pr-735, 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: 702 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, default render_resolution = "native", 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 #735 (0c43a53):

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

Not tested: Ultrawide XCL_RENDER_RES=screen / WxH patching on a non-16:9 monitor, 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 0c43a53620aba918699412e4ba25c314b45a3b73 on AMD RDNA4. I merged it onto current main 64b3f35 locally (clean merge), so the tree tested includes the stack under it (#555, #732, #733, #734).

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: 711 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 670 passed, 0 failed, 21 ignored
  • 0 SKIPPED; all present / downscale tests pass, downscale_matches_a_cpu_area_filter included.

Review: Patching a RAGE title's mode table in read-only data to the screen's aspect is title-specific and needs a retail title to check, which I do not have; I can only report that the stack builds and the suite passes on AMD, and I reviewed the top commit's structure, not its patch offsets.

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