Skip to content

D3D12.X: XCL_OVERLAY draws fps / stats into the shown frame - #450

Open
ryosen0 wants to merge 2 commits into
xcl-dev:mainfrom
ryosen0:stats-overlay
Open

ryosen0 wants to merge 2 commits into
xcl-dev:mainfrom
ryosen0:stats-overlay

Conversation

@ryosen0

@ryosen0 ryosen0 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

XCL_OVERLAY=1 draws a small stats panel into the top-left corner of the frame XCL shows: the title's fps and frame time, draws and dispatches per second, the process's commit and the adapter's video memory, refreshed once a second. Off unless asked for.

What is in it

  • hle/overlay.rs: the sample-to-text formatting, a 5x7 bitmap font (only the characters the lines use) and the panel rendered on the CPU into BGRA/RGBA pixels matching the back buffer's format, rows padded to a 256-byte pitch. 5 unit tests.
  • present.rs: after the game-image copy, the panel is copied from a small upload buffer into the back buffer at (8, 8) on XCL's own command list - part of the image, so it survives the flip-model swap chain and shows in screenshots and recordings. (A child window was tried first: the flip presentation draws over it - it never appears.) No extra window, no GDI, no input taken, none of the title's resources touched. 8-bit back buffers only; 10-bit / fp16 frames draw nothing.
  • host.rs logs one line when enabled; README.md documents the variable.
  • cd41749 fixes the two problems upipibi found by reading the copy: the copy locations cloned into ManuallyDrop (one leaked back-buffer reference per overlay frame — ResizeBuffers then fails — and every recreated panel buffer stayed alive); now they borrow via transmute_copy as readback_copy does. The placed footprint's RowPitch was w * 4, almost never a multiple of D3D12_TEXTURE_DATA_PITCH_ALIGNMENT; overlay::panel now pads its rows to 256 and the footprint uses the same panel_row_pitch. Tests panel_rows_are_at_a_256_byte_pitch and panel_row_pitch_is_256_aligned fail without the change.

Tested

  • RTX 3060 Ti 8 GB (wave32), Ryzen 7 9800X3D, driver 32.0.16.1742, Windows 11.
  • cargo test --workspace --no-fail-fast -- --test-threads=1 on 093f600: 709 passed, 0 failed, 41 ignored; 2 GPU SKIPPED (no wave64 on this adapter).
  • Retail runs with XCL_OVERLAY=1 (panel visible, verified by PrintWindow capture in the earlier round): clean exit, steady 60 presents / 2 s.

Regression run
Main at the branch's merge-base (e50836b, current main — includes #762 translated cache, #713 full symbols, #771 Discord invite):

xcl-smoke v1
commit: e50836bdf6f5c026f281d545ed86fb2f07ba6e6a
gpu: NVIDIA GeForce RTX 3060 Ti
title: ScarlettGame
seconds: 90
exit: 0x0
frames shown: 2417 (PresentX 2417)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14601 MB

This PR (093f600, rebased onto e50836b; only a README conflict with #762's bullet, both bullets kept):

xcl-smoke v1
commit: 093f6002a78f85742532eea7b9ec27b4971e1a18
gpu: NVIDIA GeForce RTX 3060 Ti
title: ScarlettGame
seconds: 90
exit: 0x0
frames shown: 2398 (PresentX 2398)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14468 MB

Not tested

  • 10-bit / fp16 back buffers (the overlay draws nothing there by design), other GPUs, wave64 hardware.
  • A ResizeBuffers / mode change with the overlay on (the leak fix removes the known blocker; no runtime resize repro was run). The debug-layer rejection of the unaligned pitch was not reproduced on this machine (Graphics Tools not installed); the alignment fix is verified by the unit tests and code reading.

AI use
GPT-6.2 Astra (API model selector) in DSH wrote the code and the fixes, ran the builds, tests and runs, and wrote this description; the human contributor watched the runs and reviewed the change. The two fixes follow upipibi's read-only review, credited in the commit message.

@TheHoracio

Copy link
Copy Markdown
Contributor

Test report on AMD RDNA3: RX 7800 XT (16 GB, wave32 and wave64), driver 32.0.32015.7029, Ryzen 7 9800X3D, Windows 11 Pro 10.0.26300, Rust 1.100.0 MSVC, DXC 1.9.2602.17, debug build. No retail data was used.

Tested: the PR head 057eabd as it is (on its base 2997c9a).

  • cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4: 680 passed, 0 failed, 41 ignored, no SKIPPED tests.
  • The four new hle::overlay tests pass: every_character_the_lines_produce_has_a_glyph, lines_show_the_rate_over_the_interval, panel_is_opaque_with_green_text_in_the_formats_channel_order, zero_frames_is_zero_fps_not_a_division_by_zero.

Not tested: the overlay drawn on screen (XCL_OVERLAY=1 on a title), a regression run, a release build, the head merged onto current main.

AI use: Claude Code ran the commands and drafted this comment; the runs are real runs on the hardware above.

@upipibi

upipibi commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Two problems in the overlay copy at bac87c3, found by reading the code (not run):

1. A reference leaks on every overlay frame, and ResizeBuffers then fails (present.rs:744, :749)
pResource: ManuallyDrop::new(Some(bb.clone())) AddRefs the back buffer, and the ManuallyDrop means that reference is never released. The same happens to the overlay buffer at :749. The other copy locations in this file use transmute_copy (:559, :905-906) to avoid exactly this. While XCL_OVERLAY is on, every back buffer gains one reference per frame. DXGI's ResizeBuffers fails while any back-buffer reference is outstanding, so the first resize or mode change after the overlay has drawn makes ensure_swapchain fail, and the window stops presenting. Every recreated overlay buffer (the panel changes width with its text) also stays alive. Using transmute_copy(&bb) / transmute_copy(tex), as at :905, fixes both.

2. RowPitch isn't 256-aligned (present.rs:754)
RowPitch: w * 4 with w = 16 + 12 * cols (overlay.rs panel) gives 64 + 48 * cols bytes, which is almost never a multiple of D3D12_TEXTURE_DATA_PITCH_ALIGNMENT (256). A placed footprint needs a 256-aligned pitch; the debug layer (XCL_D3D12_DEBUG=1) rejects the copy, and behaviour without it is undefined (NVIDIA tolerates it). Padding each row in panel()/overlay_copy to align_up(w * 4, 256) fixes it.

Also on merge order: besides #674, this PR conflicts textually in present.rs with #711, #732, #733, #604, #555, #615, #734 and #735 (each of those merges cleanly into main).

AI-assisted (Claude Code), read-only review.

@ryosen0

ryosen0 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

@upipibi both findings confirmed in the code and fixed in cd41749 — thank you, the reference leak was real and exactly as you described:

  1. Borrowed copy locations. ManuallyDrop::new(Some(bb.clone())) / (tex.clone()) → transmute_copy(&bb) / transmute_copy(tex), the same pattern as readback_copy at :905. One leaked back-buffer reference per overlay frame (and every recreated panel buffer alive) is gone.
  2. 256-aligned pitch. overlay::panel now pads each row to (w*4).div_ceil(256)*256 (transparent padding, outside the copied box), and the footprint uses the same panel_row_pitch(w). Tests: panel_rows_are_at_a_256_byte_pitch (pixel-level, over render_panel with given lines — fails without the padding) and panel_row_pitch_is_256_aligned (every font-producible width 16+12*cols).

Measured on the RTX 3060 Ti: full suite 691 passed, 0 failed, 41 ignored (--test-threads=1); smoke blocks (merge-base cb868b2 + head cd41749) refreshed in the description, both steady 60 presents / 2 s. Not run: a runtime ResizeBuffers repro with the overlay on, and the debug-layer rejection (no Graphics Tools on this machine) — both stated in Not tested.

On merge order: noted, the present.rs textual conflicts with #711/#732/#733/#604/#555/#615/#734/#735 will need a rebase after whichever lands first; happy to rebase on request.

AI use: GPT-6.2 Astra (API model selector) in DSH wrote the fixes and their tests, ran the suite and smokes, and drafted this reply; the human contributor reviewed the diff before posting.

@MesshM

MesshM commented Nov 24, 2026

Copy link
Copy Markdown

Test run of bac87c3db56e40969409aa873e4c817e70bab2ef on AMD RDNA4. I merged it onto current main 64b3f35 locally (clean merge).

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: 705 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 664 passed, 0 failed, 21 ignored
  • 0 SKIPPED; the overlay tests pass, zero_frames_is_zero_fps_not_a_division_by_zero included (the overlay itself was not drawn: no title).

Review: Off unless XCL_OVERLAY=1. I did not check @upipibi's reference-leak point, which needs the copy path to run; this run only shows the suite is green on RDNA4.

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.

XCL_OVERLAY=1 copies a small stats panel (fps, frame time, draws and
dispatches per second, process commit, adapter video memory; refreshed
once a second) into the top-left corner of the presented frame on XCL's
own command list, after the game-image copy. A 5x7 bitmap font rendered
on the CPU into an upload buffer: no extra window, no GDI, no input
taken, none of the title's resources touched. Part of the image, so it
survives the flip-model swap chain (a child window is hidden by it) and
shows in screenshots and recordings. 8-bit back buffers only.

Assisted-by: DSH (GPT-6.2 Astra)
Two problems upipibi found by reading the overlay copy: the copy locations cloned the back buffer and the panel buffer into ManuallyDrop, so every overlay frame leaked one reference on the back buffer (DXGI ResizeBuffers then fails while a reference is outstanding) and every recreated panel buffer stayed alive; and the placed footprint's RowPitch was w*4 (64 + 48*cols), almost never a multiple of D3D12_TEXTURE_DATA_PITCH_ALIGNMENT (256), which the debug layer rejects. The copy locations now borrow via transmute_copy as readback_copy does; overlay::panel pads its rows to a 256-byte pitch (transparent padding) and the footprint uses the same panel_row_pitch. Tests: panel_rows_are_at_a_256_byte_pitch (render_panel over given lines; fails without the padding), panel_row_pitch_is_256_aligned.

Assisted-by: DSH (GPT-6.2 Astra)
@ryosen0

ryosen0 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (e50836b) — head is now 093f600. The only conflict was README.md against #762's translated-cache bullet; both bullets kept.

Fresh measurements on this machine (RTX 3060 Ti, Ryzen 7 9800X3D):

  • suite on 093f600: 709 passed, 0 failed, 41 ignored (2 GPU SKIPPED, no wave64);
  • paired 90 s smokes: main e50836b 2417 frames / 14601 MB peak, head 093f600 (XCL_OVERLAY=1) 2398 frames / 14468 MB peak — both steady 60 presents / 2 s, clean exit, no device removals. Blocks in the description updated.

AI use: GPT-6.2 Astra (API model selector) in DSH did the rebase, ran the suite and smokes, and drafted this comment; the human contributor reviewed the numbers before posting.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main — needs a rebase before it can be tested.

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