Streaming stores for the big copies of the preparing thread (snapshots, sends to card copies, refreshes) #98

Open
Joly0 wants to merge 3 commits from upstream-pr/98 into main
Joly0 commented 2026-11-26 03:23:40 +00:00 (Migrated from github.com)

Imported from avatarmanz/VIctory-7900XTX. Originally posted by Joly0 on 2026-11-26T03:23:40Z.


What

Three commits on c9c932c. Each copy path has its own switch, and both are off by default: unset, everything copies as before.

  • Snapshots and sends to the card's copies (VICTORY_STREAM_COPY=1 turns it on). The snapshots of the ranges shaders may write (about 90 MB a frame) and the bytes of copies in the card's memory sent through upload memory are written with AVX2 streaming stores when a copy is 4 KiB or more.
  • Refreshes (VICTORY_STREAM_REFRESH=1 turns it on). safecopy::copy_streaming works like safecopy::copy, with streaming stores. A fault goes to its failing exit, and a guard page it hits keeps its guard flag, through the same handler as the other copies (fa11650). Shadow::copy uses it for copies of 4 KiB and more. A copy that fails is done again the old way, and every other caller of copy_mapped is unchanged.
  • Off by default until the switches are measured on more than one PC, as asked in review.

Why

On the PC this was measured on, the limit is memory writes, not threads. Copies of 512 MB, with nothing else running:

1 thread 2–16 threads
read only 37 GB/s up to 55 GB/s
write only 23 GB/s ~23 GB/s
memcpy / rep movsb 14.5 GB/s ~15 GB/s
copy with streaming stores 24 GB/s ~24 GB/s

A plain copy reads every destination line before writing it. These destinations are not read by the CPU again soon: snapshots are compared only after the card has run, and upload memory and host copies are read by the card. So skipping that read is a good fit.

Measurements

Only one PC: RX 7800 XT 16 GB, i9-12900K, 32 GB DDR5-5200 (2 × 16), Windows 11, the settings of scripts\play.ps1. Each switch was flipped within one run with VICTORY_AB, so both sides saw the same scene.

  • On this branch (VICTORY_AB=10,VICTORY_STREAM_COPY,VICTORY_STREAM_REFRESH: all four combinations in turn, 240 s, no errors). In the stable part, about 4,900–5,100 draws, median frames were:

    • neither: 62.9 and 60.2 ms;
    • only VICTORY_STREAM_COPY: 60.9 and 59.2 ms;
    • only VICTORY_STREAM_REFRESH: 61.0 and 63.2 ms;
    • both: 58.3 ms.

    That is one or two phases per combination, so it is a rough picture; the refresh switch alone shows no clear gain there.

  • Earlier, before the rebase:

    • VICTORY_STREAM_COPY (VICTORY_AB=8,VICTORY_STREAM_COPY), about 900 draws: median frame 34.2 ms with it (35.2, 34.1, 34.0, 33.9, 34.0) and 37.3 ms without (37.8, 36.5, 36.8, 37.5, 37.7). The snapshots took 5.4–5.9 ms of the preparing thread instead of 7.0–7.9 ms.
    • VICTORY_STREAM_REFRESH (VICTORY_AB=10,VICTORY_STREAM_REFRESH), 3,000–6,000 draws: in each pair of neighbouring phases with similar draw counts, the refreshes took less with it (15.3 → 13.2, 17.0 → 14.8, 15.3 → 14.6, 27.0 → 22.8 ms) and the median frame was shorter (77.5 → 71.6, 67.8 → 66.2, 64.1 → 63.1, 81.5 → 78.2 ms). That is about 1–2 ms; most of a refresh's time is asking the write watch, not copying.

The gain may be smaller on a PC with more memory bandwidth, such as a 7900 XTX with 64 GB. One run with VICTORY_AB=10,VICTORY_STREAM_COPY,VICTORY_STREAM_REFRESH shows all four combinations there.

Tests

  • New tests:
    • shadow::wide_tests::a_streaming_copy_copies_the_range_and_nothing_beside: lengths and alignments of both sides, and no byte written outside the range. It streams whatever the switch says, and asserts that AVX2 is there.
    • safecopy::tests::streams_every_length_and_alignment.
    • safecopy::tests::a_stream_from_missing_memory_fails: a source page missing or not readable in the head, the blocks or the tail.
    • safecopy::tests::a_guard_page_fails_the_streaming_copy_and_stays_a_guard_page.
  • Each test fails when the code is broken on purpose:
    • dropping the tail fails both copy tests;
    • streaming one block too many fails the first one;
    • removing the streaming copy's failing exit crashes the test process (an access violation, and 0x80000001 for the guard test);
    • a short tail fails the missing-memory test.
  • cargo test -p victory-gpu --features diagnostics on WARP: 436 pass, which is main's 432 plus the 4 new ones. depth_bounds_pipeline_loads_and_filters_draws fails on main too. watch::port7_tests::no_write_is_lost_with_port_7 failed once in a full run and passed 3 of 3 alone, on main and on this branch. I did not run the whole workspace.
  • Clippy (--all-targets, with and without --all-features): 1 finding each, the same as main.

🤖 Generated with Claude Code

<!-- greyfinch-sync:avatarmanz/VIctory-7900XTX:issue:5503416478 --> Imported from [avatarmanz/VIctory-7900XTX](https://github.com/avatarmanz/VIctory-7900XTX/pull/98). Originally posted by [Joly0](https://github.com/Joly0) on 2026-11-26T03:23:40Z. --- ## What Three commits on `c9c932c`. Each copy path has its own switch, and **both are off by default**: unset, everything copies as before. - **Snapshots and sends to the card's copies** (`VICTORY_STREAM_COPY=1` turns it on). The snapshots of the ranges shaders may write (about 90 MB a frame) and the bytes of copies in the card's memory sent through upload memory are written with AVX2 streaming stores when a copy is 4 KiB or more. - **Refreshes** (`VICTORY_STREAM_REFRESH=1` turns it on). `safecopy::copy_streaming` works like `safecopy::copy`, with streaming stores. A fault goes to its failing exit, and a guard page it hits keeps its guard flag, through the same handler as the other copies (fa11650). `Shadow::copy` uses it for copies of 4 KiB and more. A copy that fails is done again the old way, and every other caller of `copy_mapped` is unchanged. - **Off by default** until the switches are measured on more than one PC, as asked in review. ## Why On the PC this was measured on, the limit is memory writes, not threads. Copies of 512 MB, with nothing else running: | | 1 thread | 2–16 threads | |---|---|---| | read only | 37 GB/s | up to 55 GB/s | | write only | 23 GB/s | ~23 GB/s | | `memcpy` / `rep movsb` | 14.5 GB/s | ~15 GB/s | | copy with streaming stores | 24 GB/s | ~24 GB/s | A plain copy reads every destination line before writing it. These destinations are not read by the CPU again soon: snapshots are compared only after the card has run, and upload memory and host copies are read by the card. So skipping that read is a good fit. ## Measurements Only one PC: RX 7800 XT 16 GB, i9-12900K, 32 GB DDR5-5200 (2 × 16), Windows 11, the settings of `scripts\play.ps1`. Each switch was flipped within one run with `VICTORY_AB`, so both sides saw the same scene. - **On this branch** (`VICTORY_AB=10,VICTORY_STREAM_COPY,VICTORY_STREAM_REFRESH`: all four combinations in turn, 240 s, no errors). In the stable part, about 4,900–5,100 draws, median frames were: - neither: 62.9 and 60.2 ms; - only `VICTORY_STREAM_COPY`: 60.9 and 59.2 ms; - only `VICTORY_STREAM_REFRESH`: 61.0 and 63.2 ms; - both: 58.3 ms. That is one or two phases per combination, so it is a rough picture; the refresh switch alone shows no clear gain there. - **Earlier, before the rebase:** - `VICTORY_STREAM_COPY` (`VICTORY_AB=8,VICTORY_STREAM_COPY`), about 900 draws: median frame 34.2 ms with it (35.2, 34.1, 34.0, 33.9, 34.0) and 37.3 ms without (37.8, 36.5, 36.8, 37.5, 37.7). The snapshots took 5.4–5.9 ms of the preparing thread instead of 7.0–7.9 ms. - `VICTORY_STREAM_REFRESH` (`VICTORY_AB=10,VICTORY_STREAM_REFRESH`), 3,000–6,000 draws: in each pair of neighbouring phases with similar draw counts, the refreshes took less with it (15.3 → 13.2, 17.0 → 14.8, 15.3 → 14.6, 27.0 → 22.8 ms) and the median frame was shorter (77.5 → 71.6, 67.8 → 66.2, 64.1 → 63.1, 81.5 → 78.2 ms). That is about 1–2 ms; most of a refresh's time is asking the write watch, not copying. The gain may be smaller on a PC with more memory bandwidth, such as a 7900 XTX with 64 GB. One run with `VICTORY_AB=10,VICTORY_STREAM_COPY,VICTORY_STREAM_REFRESH` shows all four combinations there. ## Tests - New tests: - `shadow::wide_tests::a_streaming_copy_copies_the_range_and_nothing_beside`: lengths and alignments of both sides, and no byte written outside the range. It streams whatever the switch says, and asserts that AVX2 is there. - `safecopy::tests::streams_every_length_and_alignment`. - `safecopy::tests::a_stream_from_missing_memory_fails`: a source page missing or not readable in the head, the blocks or the tail. - `safecopy::tests::a_guard_page_fails_the_streaming_copy_and_stays_a_guard_page`. - Each test fails when the code is broken on purpose: - dropping the tail fails both copy tests; - streaming one block too many fails the first one; - removing the streaming copy's failing exit crashes the test process (an access violation, and `0x80000001` for the guard test); - a short tail fails the missing-memory test. - `cargo test -p victory-gpu --features diagnostics` on WARP: 436 pass, which is main's 432 plus the 4 new ones. `depth_bounds_pipeline_loads_and_filters_draws` fails on main too. `watch::port7_tests::no_write_is_lost_with_port_7` failed once in a full run and passed 3 of 3 alone, on main and on this branch. I did not run the whole workspace. - Clippy (`--all-targets`, with and without `--all-features`): 1 finding each, the same as main. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
HrHd commented 2026-11-26 06:26:56 +00:00 (Migrated from github.com)

Imported from avatarmanz/VIctory-7900XTX. Originally posted by HrHd on 2026-11-26T06:26:56Z.


Took both commits of this onto the -Safe set of an 8 GB / 15.7 GB box and measured, with a 2 s process watcher rather than sampled looks:

  • OOM in the load is gone (no 0x8007000E at make_prelude), so the streaming copies do help there;
  • the run then ends anyway, at frame 3599-4092, with 0x8007000E from the fetch of what shaders wrote ("what shaders wrote to the card's memory could not be fetched") on -Safe, and with 0x887A0006 (device removed) on the fast path;
  • low card targets (VICTORY_CARD_WINDOWS_MB=4 VICTORY_MEMORY_CARD_MB=2048 VICTORY_KEEP_SNAPSHOTS_MB=4, with CARD_BUFFERS_MIN_MB=1) did not change that either way.

That matches #124's finding that the fast paths want more desktop VRAM than 8 GB and that the failure comes back whatever the switches; this PR still removes one of the two walls, so it looks worth having.

<!-- greyfinch-sync:avatarmanz/VIctory-7900XTX:comment:7184439197 --> Imported from [avatarmanz/VIctory-7900XTX](https://github.com/avatarmanz/VIctory-7900XTX/pull/98#issuecomment-7184439197). Originally posted by [HrHd](https://github.com/HrHd) on 2026-11-26T06:26:56Z. --- Took both commits of this onto the `-Safe` set of an 8 GB / 15.7 GB box and measured, with a 2 s process watcher rather than sampled looks: - OOM in the load is gone (no `0x8007000E` at `make_prelude`), so the streaming copies do help there; - the run then ends anyway, at frame 3599-4092, with `0x8007000E` from the fetch of what shaders wrote ("what shaders wrote to the card's memory could not be fetched") on `-Safe`, and with `0x887A0006` (device removed) on the fast path; - low card targets (`VICTORY_CARD_WINDOWS_MB=4 VICTORY_MEMORY_CARD_MB=2048 VICTORY_KEEP_SNAPSHOTS_MB=4`, with `CARD_BUFFERS_MIN_MB=1`) did not change that either way. That matches `#124`'s finding that the fast paths want more desktop VRAM than 8 GB and that the failure comes back whatever the switches; this PR still removes one of the two walls, so it looks worth having.
avatarmanz commented 2026-11-26 07:33:45 +00:00 (Migrated from github.com)

Imported from avatarmanz/VIctory-7900XTX. Originally posted by avatarmanz on 2026-11-26T07:33:45Z.


Left open: conflicts with main (safecopy.rs), and the streaming stores are on by default; needs a rebase and an in-game check on the 7900 XTX.

<!-- greyfinch-sync:avatarmanz/VIctory-7900XTX:comment:7185590233 --> Imported from [avatarmanz/VIctory-7900XTX](https://github.com/avatarmanz/VIctory-7900XTX/pull/98#issuecomment-7185590233). Originally posted by [avatarmanz](https://github.com/avatarmanz) on 2026-11-26T07:33:45Z. --- Left open: conflicts with main (safecopy.rs), and the streaming stores are on by default; needs a rebase and an in-game check on the 7900 XTX.
Joly0 commented 2026-11-26 16:57:19 +00:00 (Migrated from github.com)

Imported from avatarmanz/VIctory-7900XTX. Originally posted by Joly0 on 2026-11-26T16:57:19Z.


Rebased onto c9c932c, and the streaming copies are now off by default.

  • Conflict: the only conflict in safecopy.rs was in the tests (changed_records_are_found_and_taken landed where the streaming tests go); all of them are kept.

  • Guard pages (fa11650): the streaming copy is registered in failing_exit, so a guard page it hits gets its flag set again by the same handler as the other copies. A new test checks this: a_guard_page_fails_the_streaming_copy_and_stays_a_guard_page. Without the failing exit, the test process dies of the guard fault (0x80000001).

  • Off by default (new third commit): VICTORY_STREAM_COPY=1 and VICTORY_STREAM_REFRESH=1 turn them on; with both unset the copies are as before. The description above still says "on by default" and =0; read it with that in mind.

  • Checks on this branch:

    • cargo test -p victory-gpu --features diagnostics on WARP: 436 pass, which is main's 432 plus the 4 new ones. depth_bounds_pipeline_loads_and_filters_draws fails on main too. no_write_is_lost_with_port_7 failed once in a full run and passed 3 of 3 alone, on main and on this branch.
    • Clippy: 1 finding with and without --all-features, the same as main.
  • Game run: one 240 s run on an RX 7800 XT with VICTORY_AB=10,VICTORY_STREAM_COPY,VICTORY_STREAM_REFRESH, which cycles through all four combinations; no errors. In the stable part (about 4,900–5,100 draws), median frames were:

    • neither: 62.9 and 60.2 ms;
    • only the copy switch: 60.9 and 59.2 ms;
    • only the refresh switch: 61.0 and 63.2 ms;
    • both: 58.3 ms.

    That is one or two phases per combination, so it is a rough picture; the refresh switch alone shows no clear gain there.

The same VICTORY_AB setting should give the 7900 XTX check in a single run.

<!-- greyfinch-sync:avatarmanz/VIctory-7900XTX:comment:7198305728 --> Imported from [avatarmanz/VIctory-7900XTX](https://github.com/avatarmanz/VIctory-7900XTX/pull/98#issuecomment-7198305728). Originally posted by [Joly0](https://github.com/Joly0) on 2026-11-26T16:57:19Z. --- Rebased onto `c9c932c`, and the streaming copies are now off by default. - **Conflict:** the only conflict in `safecopy.rs` was in the tests (`changed_records_are_found_and_taken` landed where the streaming tests go); all of them are kept. - **Guard pages (fa11650):** the streaming copy is registered in `failing_exit`, so a guard page it hits gets its flag set again by the same handler as the other copies. A new test checks this: `a_guard_page_fails_the_streaming_copy_and_stays_a_guard_page`. Without the failing exit, the test process dies of the guard fault (`0x80000001`). - **Off by default (new third commit):** `VICTORY_STREAM_COPY=1` and `VICTORY_STREAM_REFRESH=1` turn them on; with both unset the copies are as before. The description above still says "on by default" and `=0`; read it with that in mind. - **Checks on this branch:** - `cargo test -p victory-gpu --features diagnostics` on WARP: 436 pass, which is main's 432 plus the 4 new ones. `depth_bounds_pipeline_loads_and_filters_draws` fails on main too. `no_write_is_lost_with_port_7` failed once in a full run and passed 3 of 3 alone, on main and on this branch. - Clippy: 1 finding with and without `--all-features`, the same as main. - **Game run:** one 240 s run on an RX 7800 XT with `VICTORY_AB=10,VICTORY_STREAM_COPY,VICTORY_STREAM_REFRESH`, which cycles through all four combinations; no errors. In the stable part (about 4,900–5,100 draws), median frames were: - neither: 62.9 and 60.2 ms; - only the copy switch: 60.9 and 59.2 ms; - only the refresh switch: 61.0 and 63.2 ms; - both: 58.3 ms. That is one or two phases per combination, so it is a rough picture; the refresh switch alone shows no clear gain there. The same `VICTORY_AB` setting should give the 7900 XTX check in a single run.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/98:upstream-pr/98'
git switch 'upstream-pr/98'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/98'
git switch 'upstream-pr/98'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/98'
git switch 'upstream-pr/98'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/98'
git switch 'main'
git merge --squash 'upstream-pr/98'
git switch 'main'
git merge --ff-only 'upstream-pr/98'
git switch 'main'
git merge 'upstream-pr/98'
git push origin 'main'
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
avatarmanz/VIctory-7900XTX!98
No description provided.