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

Open
github-bot wants to merge 3 commits from github-bot/gh-98 into main AGit
Owner

@⁠Joly0 on GitHub · 2026-11-26 03:23 UTC · original
Joly0:pr/streaming-copies → main · +306 −7 · 3 files · 3 commits · open

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

**@⁠Joly0** on GitHub · 2026-11-26 03:23 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/98) `Joly0:pr/streaming-copies` → `main` · +306 −7 · 3 files · 3 commits · open ## 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)
On this PC (i9-12900K, two DDR5-5200 modules) writes are what is scarce:
512 MB copied 14.5 GB/s on one thread and no more on sixteen, written alone
23 GB/s, copied with streaming stores 24 GB/s; reads 37 GB/s on one thread,
55 on several. So spreading copies over more threads, or running two of them
side by side, wins nothing (tried: the snapshots beside the work on copies in
the card's memory, about 1.5 ms, no frame gain), and a copy that does not read
its destination first does.

Copies of 4 KiB and more whose destination the CPU does not read again soon go
with AVX2 streaming stores: the snapshots of ranges shaders may write (about
90 MB a frame) and the bytes of copies in the card's memory sent through upload
memory. A test copies at many alignments and lengths and checks the bytes
beside the range; dropping the tail or streaming a block too many fails it.

RX 7800 XT, VICTORY_AB=8,VICTORY_STREAM_COPY, one run, the same scene of about
900 draws: median frame 34.2 ms with the switch (35.2, 34.1, 34.0, 33.9, 34.0)
and 37.3 without (37.8, 36.5, 36.8, 37.5, 37.7), p90 lower too; the snapshots
5.4-5.9 ms of the preparing thread's time instead of 7.0-7.9.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A refresh copies the pages the title wrote into the host copy's CPU side,
which the card reads and the CPU does not read again soon; the copy is the
fault-safe one of crate::safecopy, a rep movsb, which on this PC moves
14-15 GB/s on one thread and no more on several, against 24 GB/s with
streaming stores (the plain copy reads each destination line before it
writes it).

safecopy::copy_streaming: as copy, the bytes up to the destination's next
32-byte boundary and the rest with rep movsb, the blocks between with AVX2
loads and streaming stores, fenced; a fault anywhere in it goes to its
failing exit as copy's does. Shadow::copy uses it for copies of 4 KiB and
more (host::copy_streamed); what fails is copied again as before, and every
other caller of copy_mapped (scratch pages compared at once, title memory)
copies as before. Tests: every length and alignment, and a source page
missing or not readable in the head, the blocks or the tail; without the
failing exit the test process dies, with a short tail a test fails.

RX 7800 XT, VICTORY_AB=10,VICTORY_STREAM_REFRESH, one run in a scene of
3,000-6,000 draws: in each pair of neighbouring phases with like draws the
refreshes took less with the switch (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): about
1-2 ms, smaller than the snapshots' gain; the refreshes' time is mostly
asking and checking, not copying.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:32:10 +00:00
Author
Owner

@⁠HrHd on GitHub · 2026-11-26 06:26 UTC · original

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.

**@⁠HrHd** on GitHub · 2026-11-26 06:26 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/98#issuecomment-7184439197) 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.
Author
Owner

@⁠avatarmanz on GitHub · 2026-11-26 07:33 UTC · original

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.

**@⁠avatarmanz** on GitHub · 2026-11-26 07:33 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/98#issuecomment-7185590233) 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.
github-bot force-pushed github-bot/gh-98 from 9a3006bb52 to 0d87742f23 2026-11-26 16:59:37 +00:00 Compare
Author
Owner

@⁠Joly0 on GitHub · 2026-11-26 16:57 UTC · original

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.

**@⁠Joly0** on GitHub · 2026-11-26 16:57 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/98#issuecomment-7198305728) 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 can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/98/head:github-bot/gh-98'
git switch 'github-bot/gh-98'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-98'
git switch 'github-bot/gh-98'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-98'
git switch 'github-bot/gh-98'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-98'
git switch 'main'
git merge --squash 'github-bot/gh-98'
git switch 'main'
git merge --ff-only 'github-bot/gh-98'
git switch 'main'
git merge 'github-bot/gh-98'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.