perf: transient windows leave out pages that hold what they last sent (VICTORY_WINDOW_SKIP_SAME) #340

Merged
Skyfrye merged 2 commits from upstream-pr/340 into main 2026-11-26 14:21:30 +00:00
Skyfrye commented 2026-11-26 08:25:28 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by Skyfrye on 2026-11-26T08:25:28Z.


Change

VICTORY_WINDOW_SKIP_SAME, a new switch whose default (unset) sends what was sent before. With VICTORY_CARD_WINDOW_UPLOAD=1 (in the launcher's set) a window outside buffers keeps no CPU side, only its card buffer ("transient"). Every page the write watch or the guards call written is copied into pooled upload memory and sent up whole, without comparing it to anything. In the world that is about 70 MB a frame. A page that was written can still hold the same bytes as before: the title rewrites constant data.

Each transient window now keeps a 64-bit print per 4 KiB page of the bytes it last sent for that page (Card::prints, 8 bytes a page, made at the window's first copy: 8 KiB for a 4 MiB window). The print is page_print, an XXH3-style accumulate over eight lanes with keys that depend on position. It adds no crate (xxh3 is not in the tree, and blake3 is far too slow at 4 KiB) and runs at about 40 GB/s on one core.

VICTORY_WINDOW_SKIP_SAME What is sent What is compared
unset (default) everything, as before one 4 KiB page in 16 (picked by its address, the same pages each time) is read again and compared; the counts are multiplied by 16, an estimate
1 only the 4 KiB pages whose print is not the one last sent every page: title memory is read 256 KiB at a time into a buffer of the thread's, printed, and each run of other pages goes into a chunk of its own
0 everything nothing (the code path as before)

A new line comes with the frame-rate line, only while VICTORY_CARD_WINDOW_UPLOAD=1: title memory transient windows took per frame: N MB sent up, L MB left out; of what they took, S MB held the bytes the window last sent for their 4 KiB page, O MB other bytes, U MB nothing to compare with (VICTORY_WINDOW_SKIP_SAME=...). U covers pages never sent before, pages taken only in part, and windows that shaders are said to write. The ram line's window upload: part also gives the prints' memory.

Why the card side still holds a page that was left out:

  • Only the window's own sends write its card buffer, and Host::card_before copies them in the order they were copied. The dirty and masked-patch path, the merges and the copy-backs already skip transient windows.
  • A declared shader write to a transient window (unordered access, a title buffer copy on the card, title memory by address) is already a bug that is counted and logged (Shadow::transient_written). Such a window compares nothing from then on and sends everything it takes.
  • A page taken only in part loses its print, because the card then holds bytes from two reads. A window made again starts with no prints. The print is taken from the exact bytes that are sent, never from a second read.
  • The prints stay locked from the read until the chunks are noted, so with refreshes running in parallel, a print is always the one of the last chunk noted for its page.

Remaining risk: two different pages with the same 64-bit print (about 2^-64 per compare) would leave the older bytes on the card until the title writes the page again.

The default does not change. Unset only samples and sends everything as before, and the launcher's set is not touched. 1 is for whoever wants to try it.

Linked issue: none.

Verification

Windows 11 26300, Rust 1.98.1 (MSVC), on upstream main at c4c93bd, from third_party/victory:

cargo build --locked --release -p victory                                          -> Finished, no new warning
VICTORY_D3D12_WARP=1 cargo test --locked -p victory-gpu --lib -- --test-threads=1  -> 187 passed, 3 failed

The 3 failures are those of main: spans_say_the_next_start_and_the_lowest_level_viewed, warp_card_fetch_copies_flagged_pieces_to_their_slots, warp_card_patch_writes_the_masked_bytes_and_no_others. 4 new tests, CPU only (shadow::window_same_tests). None of them builds without this change:

  • a_print_changes_with_any_change_of_the_page: every single-bit flip, word swap, stripe swap and block swap of a page changes its print.
  • a_page_is_the_same_only_after_the_same_bytes_were_taken_whole: same, other, nothing to compare with, and a page taken in part keeps no print.
  • the_card_side_holds_the_titles_bytes_with_the_same_pages_left_out: a model of a window against a fake card side. It runs fixed cases and then 300 random rounds of writes, set-backs and partial ranges, and after each refresh checks that the card side equals title memory over the refreshed range and that only the pages that changed were sent. With the same pages sent again (a temporary mutant in window_copy) it fails: 1,048,576 bytes sent where 0 were expected.
  • one_page_in_sixteen_is_compared_and_counted_sixteen_times: the sample without the switch.

In the world of GTA VI (my own copy), running as a Series S (--console series-s, 1280x720), launcher set with #308 and VICTORY_INDIRECT_RAW=3, the same exe both ways, runs of 300 s alternating:

VICTORY_WINDOW_SKIP_SAME fps (median of the last minute)
unset 18.5 (machine 54 % loaded, not trustworthy), 20.1
1 20.7, 21.2

Of the bytes the transient windows took per frame, 67-73 MB held what the window last sent for their 4 KiB page, 0.9 MB differed, and 3.6-4.1 MB had nothing to compare with. With 1, those ~70 MB a frame were left out. No exception and no device lost in the 4 runs. With a single trustworthy run without the switch, the frame-rate gain is small (20.1 fps against 20.7 and 21.2). The firm part is the bytes left out.

The exe of these runs was built from the branch this PR comes from. That branch has the same skip code on top of a wider counter line and another switch that is off by default (VICTORY_REFRESH_4K, not set in these runs). This PR carries only the skip and the windows' part of that line.

Oracle and test data

No game file. The counts and frame rates come from my own runs of my copy of the game. The tests use generated bytes.

Checklist

  • The PR covers a single reviewable behaviour (transient windows leave out the 4 KiB pages that hold what they last sent, behind a switch that is off by default).
  • A test fails without this change and passes with it.
  • The commands and results of each check are given above.
  • An unimplemented function returns an error (E_NOTIMPL), never a fake success. (Nothing unimplemented here.)
  • README: not touched.
  • No game, console or SDK file, no key, no dump, no download link.
  • Findings drawn from a title: frame rates and byte counts of my own runs; no title code.
  • Code taken from another project: none (the print follows the shape of XXH3's accumulate; no code from it).

AI assistance: written with Claude Code. Claude Opus 5.5 subagents designed and wrote the change and its tests, ported it onto main for this PR and wrote this description. Claude Opus 5.5 (coordinating) ran the game A/B.

🤖 Generated with Claude Code

<!-- greyfinch-sync:LooperSalty/AnyXboxX:issue:6622542217 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/340). Originally posted by [Skyfrye](https://github.com/Skyfrye) on 2026-11-26T08:25:28Z. --- ## Change `VICTORY_WINDOW_SKIP_SAME`, a new switch whose default (unset) sends what was sent before. With `VICTORY_CARD_WINDOW_UPLOAD=1` (in the launcher's set) a window outside buffers keeps no CPU side, only its card buffer ("transient"). Every page the write watch or the guards call written is copied into pooled upload memory and sent up whole, without comparing it to anything. In the world that is about 70 MB a frame. A page that was written can still hold the same bytes as before: the title rewrites constant data. Each transient window now keeps a 64-bit print per 4 KiB page of the bytes it last sent for that page (`Card::prints`, 8 bytes a page, made at the window's first copy: 8 KiB for a 4 MiB window). The print is `page_print`, an XXH3-style accumulate over eight lanes with keys that depend on position. It adds no crate (xxh3 is not in the tree, and blake3 is far too slow at 4 KiB) and runs at about 40 GB/s on one core. | `VICTORY_WINDOW_SKIP_SAME` | What is sent | What is compared | |---|---|---| | unset (default) | everything, as before | one 4 KiB page in 16 (picked by its address, the same pages each time) is read again and compared; the counts are multiplied by 16, an estimate | | `1` | only the 4 KiB pages whose print is not the one last sent | every page: title memory is read 256 KiB at a time into a buffer of the thread's, printed, and each run of other pages goes into a chunk of its own | | `0` | everything | nothing (the code path as before) | A new line comes with the frame-rate line, only while `VICTORY_CARD_WINDOW_UPLOAD=1`: `title memory transient windows took per frame: N MB sent up, L MB left out; of what they took, S MB held the bytes the window last sent for their 4 KiB page, O MB other bytes, U MB nothing to compare with (VICTORY_WINDOW_SKIP_SAME=...)`. U covers pages never sent before, pages taken only in part, and windows that shaders are said to write. The ram line's `window upload:` part also gives the prints' memory. Why the card side still holds a page that was left out: - Only the window's own sends write its card buffer, and `Host::card_before` copies them in the order they were copied. The dirty and masked-patch path, the merges and the copy-backs already skip transient windows. - A declared shader write to a transient window (unordered access, a title buffer copy on the card, title memory by address) is already a bug that is counted and logged (`Shadow::transient_written`). Such a window compares nothing from then on and sends everything it takes. - A page taken only in part loses its print, because the card then holds bytes from two reads. A window made again starts with no prints. The print is taken from the exact bytes that are sent, never from a second read. - The prints stay locked from the read until the chunks are noted, so with refreshes running in parallel, a print is always the one of the last chunk noted for its page. Remaining risk: two different pages with the same 64-bit print (about 2^-64 per compare) would leave the older bytes on the card until the title writes the page again. The default does not change. Unset only samples and sends everything as before, and the launcher's set is not touched. `1` is for whoever wants to try it. Linked issue: none. ## Verification Windows 11 26300, Rust 1.98.1 (MSVC), on upstream `main` at `c4c93bd`, from `third_party/victory`: ``` cargo build --locked --release -p victory -> Finished, no new warning VICTORY_D3D12_WARP=1 cargo test --locked -p victory-gpu --lib -- --test-threads=1 -> 187 passed, 3 failed ``` The 3 failures are those of `main`: `spans_say_the_next_start_and_the_lowest_level_viewed`, `warp_card_fetch_copies_flagged_pieces_to_their_slots`, `warp_card_patch_writes_the_masked_bytes_and_no_others`. 4 new tests, CPU only (`shadow::window_same_tests`). None of them builds without this change: - `a_print_changes_with_any_change_of_the_page`: every single-bit flip, word swap, stripe swap and block swap of a page changes its print. - `a_page_is_the_same_only_after_the_same_bytes_were_taken_whole`: same, other, nothing to compare with, and a page taken in part keeps no print. - `the_card_side_holds_the_titles_bytes_with_the_same_pages_left_out`: a model of a window against a fake card side. It runs fixed cases and then 300 random rounds of writes, set-backs and partial ranges, and after each refresh checks that the card side equals title memory over the refreshed range and that only the pages that changed were sent. With the same pages sent again (a temporary mutant in `window_copy`) it fails: 1,048,576 bytes sent where 0 were expected. - `one_page_in_sixteen_is_compared_and_counted_sixteen_times`: the sample without the switch. In the world of GTA VI (my own copy), running as a Series S (`--console series-s`, 1280x720), launcher set with #308 and `VICTORY_INDIRECT_RAW=3`, the same exe both ways, runs of 300 s alternating: | `VICTORY_WINDOW_SKIP_SAME` | fps (median of the last minute) | |---|---| | unset | 18.5 (machine 54 % loaded, not trustworthy), 20.1 | | `1` | 20.7, 21.2 | Of the bytes the transient windows took per frame, 67-73 MB held what the window last sent for their 4 KiB page, 0.9 MB differed, and 3.6-4.1 MB had nothing to compare with. With `1`, those ~70 MB a frame were left out. No exception and no device lost in the 4 runs. With a single trustworthy run without the switch, the frame-rate gain is small (20.1 fps against 20.7 and 21.2). The firm part is the bytes left out. The exe of these runs was built from the branch this PR comes from. That branch has the same skip code on top of a wider counter line and another switch that is off by default (`VICTORY_REFRESH_4K`, not set in these runs). This PR carries only the skip and the windows' part of that line. ## Oracle and test data No game file. The counts and frame rates come from my own runs of my copy of the game. The tests use generated bytes. ## Checklist - [x] The PR covers a single reviewable behaviour (transient windows leave out the 4 KiB pages that hold what they last sent, behind a switch that is off by default). - [x] A test fails without this change and passes with it. - [x] The commands and results of each check are given above. - [x] An unimplemented function returns an error (`E_NOTIMPL`), never a fake success. (Nothing unimplemented here.) - [x] README: not touched. - [x] No game, console or SDK file, no key, no dump, no download link. - [x] Findings drawn from a title: frame rates and byte counts of my own runs; no title code. - [x] Code taken from another project: none (the print follows the shape of XXH3's accumulate; no code from it). AI assistance: written with Claude Code. Claude Opus 5.5 subagents designed and wrote the change and its tests, ported it onto `main` for this PR and wrote this description. Claude Opus 5.5 (coordinating) ran the game A/B. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Skyfrye commented 2026-11-26 10:43:57 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by Skyfrye on 2026-11-26T10:43:57Z.


Back to draft: do not merge. Looking at the window (Series X, first cutscene, build = main c4c93bd + #308 + this PR, VICTORY_INDIRECT_RAW=3): with VICTORY_WINDOW_SKIP_SAME=1 a rectangle of multicoloured noise covers a character's face; the same build and scene without the switch draws the face correctly. So a page left out is not always one the card already holds (the comparison with what the window last sent misses something, likely what the card side holds after other writes). Also, the frame rates in the description were measured with --console series-s, which draws only the UI (the 3D scene is black, see #338), so they do not show a gain. I judged those runs by the frame log alone; that was wrong.

🤖 Generated with Claude Code

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7189759891 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/340#issuecomment-7189759891). Originally posted by [Skyfrye](https://github.com/Skyfrye) on 2026-11-26T10:43:57Z. --- Back to draft: do not merge. Looking at the window (Series X, first cutscene, build = main c4c93bd + #308 + this PR, `VICTORY_INDIRECT_RAW=3`): with `VICTORY_WINDOW_SKIP_SAME=1` a rectangle of multicoloured noise covers a character's face; the same build and scene without the switch draws the face correctly. So a page left out is not always one the card already holds (the comparison with what the window last sent misses something, likely what the card side holds after other writes). Also, the frame rates in the description were measured with `--console series-s`, which draws only the UI (the 3D scene is black, see #338), so they do not show a gain. I judged those runs by the frame log alone; that was wrong. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
KainanP commented 2026-11-26 10:55:35 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by KainanP on 2026-11-26T10:55:35Z.


Test report for #340 on three adapters.

Merges cleanly onto current main. Setup: current origin/main (afa30ce) merged with this PR, Windows 11, cargo test --locked in third_party/victory. Nothing under third_party/victory changed since c4c93bd, so the main column is c4c93bd's run. Adapters: RTX 4060 Laptop (DXGI 0), Intel UHD 8086:a78b (16-lane waves, no FP64), WARP. The hardware adapter is picked by name through a local, uncommitted test hook and confirmed in its log; WARP for victory-gpu is --features diagnostics + VICTORY_D3D12_WARP=1. victory-gpu runs with --test-threads=1.

victory-gpu --lib main main + #340
RTX 4060 Laptop 183 passed, main's 3 failed 187 passed, main's 3 failed
Intel UHD 183 passed, main's 3 failed 187 passed, main's 3 failed
WARP 196 passed, main's 3 failed 200 passed, main's 3 failed

"main's 3" = descriptor::host::tests::spans_say_the_next_start_and_the_lowest_level_viewed, indirect::tests::warp_card_fetch_copies_flagged_pieces_to_their_slots, indirect::tests::warp_card_patch_writes_the_masked_bytes_and_no_others. They fail on all three adapters on main too. The 4 new shadow::window_same_tests pass everywhere (CPU only). No new failure, no new warning.

Notes from reading the diff:

  • The default (unset) is Sample, not the old path. Each transient window gets a prints table at its first copy, and after each copy one page in 16 is read again and printed. So the bytes sent change only with 1, but unset adds CPU work and memory to the launcher's set (it has VICTORY_CARD_WINDOW_UPLOAD=1). 0 is the old path. If the sample only feeds the new line, a default of 0 (sample on request) would make "the default does not change" literally true.
  • In Sample the print comes from a second read (window_sample → read_into) after copy_mapped into the chunk, so the title can write between them. That only skews the counts: Sample never leaves a page out, and the mode is read once. The description's "never from a second read" holds for 1 only.
  • In Skip, a copy_mapped read that fails leaves scratch with the previous block's bytes (the buffer is thread-local and not cleared). The page is then printed and sent with those bytes. Before, the chunk held "whatever", so this is not worse, but now the print records those bytes as sent. Zeroing the block before the read, or setting the page's print to 0 when the read fails, would keep the print honest.
  • prints stays locked across windowup::alloc and the chunk copies for the whole range. That serializes two refreshes of one window, which is what keeps the order right. One line saying so in copy_to_chunks_skipping would stop a later change from narrowing the lock.

AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7190022804 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/340#issuecomment-7190022804). Originally posted by [KainanP](https://github.com/KainanP) on 2026-11-26T10:55:35Z. --- Test report for #340 on three adapters. Merges cleanly onto current main. Setup: current `origin/main` (afa30ce) merged with this PR, Windows 11, `cargo test --locked` in `third_party/victory`. Nothing under `third_party/victory` changed since c4c93bd, so the main column is c4c93bd's run. Adapters: RTX 4060 Laptop (DXGI 0), Intel UHD 8086:a78b (16-lane waves, no FP64), WARP. The hardware adapter is picked by name through a local, uncommitted test hook and confirmed in its log; WARP for victory-gpu is `--features diagnostics` + `VICTORY_D3D12_WARP=1`. victory-gpu runs with `--test-threads=1`. | `victory-gpu --lib` | main | main + #340 | |---|---|---| | RTX 4060 Laptop | 183 passed, main's 3 failed | 187 passed, main's 3 failed | | Intel UHD | 183 passed, main's 3 failed | 187 passed, main's 3 failed | | WARP | 196 passed, main's 3 failed | 200 passed, main's 3 failed | "main's 3" = `descriptor::host::tests::spans_say_the_next_start_and_the_lowest_level_viewed`, `indirect::tests::warp_card_fetch_copies_flagged_pieces_to_their_slots`, `indirect::tests::warp_card_patch_writes_the_masked_bytes_and_no_others`. They fail on all three adapters on main too. The 4 new `shadow::window_same_tests` pass everywhere (CPU only). No new failure, no new warning. Notes from reading the diff: - The default (unset) is `Sample`, not the old path. Each transient window gets a prints table at its first copy, and after each copy one page in 16 is read again and printed. So the bytes sent change only with `1`, but unset adds CPU work and memory to the launcher's set (it has `VICTORY_CARD_WINDOW_UPLOAD=1`). `0` is the old path. If the sample only feeds the new line, a default of `0` (sample on request) would make "the default does not change" literally true. - In `Sample` the print comes from a second read (`window_sample` → `read_into`) after `copy_mapped` into the chunk, so the title can write between them. That only skews the counts: `Sample` never leaves a page out, and the mode is read once. The description's "never from a second read" holds for `1` only. - In `Skip`, a `copy_mapped` read that fails leaves `scratch` with the previous block's bytes (the buffer is thread-local and not cleared). The page is then printed and sent with those bytes. Before, the chunk held "whatever", so this is not worse, but now the print records those bytes as sent. Zeroing the block before the read, or setting the page's print to 0 when the read fails, would keep the print honest. - `prints` stays locked across `windowup::alloc` and the chunk copies for the whole range. That serializes two refreshes of one window, which is what keeps the order right. One line saying so in `copy_to_chunks_skipping` would stop a later change from narrowing the lock. _AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this._
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
LooperSalty/AnyXboxX!340
No description provided.