GPU tests: replay a world frame's copies of title memory (benchmark for the copy PRs) #1743

Closed
github-bot wants to merge 2 commits from gh-pr/1743/head into gh-pr/1743/base
Owner

@⁠marquezinii on GitHub · 2026-11-24 21:48 UTC · original
marquezinii:tests/world-frame-copies → main · +292 −0 · 2 files · 2 commits · closed without merging

Copy PRs keep competing for the same part of a world frame, the copies into and out of title memory (#400: 300–400 ms "preparing" and 50–150 ms "copying back" per frame at 1 fps; on some forks seconds). Each PR measures them with a fixture of its own, so they can't be compared. This adds one benchmark that any of them can be run against, on one machine, without the title.

What

shadow::world_bench::world_frame_copies (ignored by default) replays 6 frames of 36 submissions on a 174 MB write-watched heap, with what #400 and the forks' counters say world frames do:

  • Each submission declares 24 shader-written ranges out of 64 overlapping views of the heap (64 KiB to 64 MiB). Passes declare the same big ranges again and again.
  • Before each declared range, a refresh of 1–128 MiB, about 25 GB asked per frame, of which ~540 MB changed.
  • The title writes 256 places between submissions. The GPU writes 4 places in the declared ranges while the title writes the 8 bytes after each.

It goes through update, writing and copy_back, the calls the submission path makes, and prints the time of each part per frame. The pattern is seeded, so it is the same in every build. Each declared range is refreshed before it is declared, as gpu_writes asks.

Two modes, the two ways Host::execute handles shader-written ranges:

  • world_frame_copies: snapshots each declared range before the submission (memory that is not tracked).
  • world_frame_copies_marked: arms the declared ranges (writing(.., true)), sets the written-pages bit of each GPU write as a shader does, and runs copy_back_marks before the per-range copy-backs (tracked memory, since cd94d35/940d32f).

It also asserts what copy-back must keep: the GPU's bytes reach title memory, and the title's writes during the run are not overwritten. A change that is fast but wrong fails.

cargo test --release -p victory-gpu world_frame_copies -- --ignored --nocapture --test-threads 1

On main at 940d32f, RTX 5070, release, median frame of 5:

mode refresh snapshots / arming copy-back total
snapshots 77–88 ms 377–501 ms 198–219 ms 748–758 ms
marked pages 79–84 ms 3.1–3.7 ms 6.6–8.0 ms 86.6–92.6 ms

The marked mode checks the same things, with one exception that it prints instead of asserting. A GPU write is kept out of title memory when it lands on a page that no declared range covers whole and that the title wrote since its copy last took it: 6 of up to 864 writes in this pattern. More on that in the comments.

Test-only: no change outside the new file and its mod line.

Results on the open copy PRs (snapshot mode, before the marked path)

Each PR merged alone onto ffe310e with this file added. RTX 5070 host device, Ryzen with other work running (so expect the spread), release build. The cells give the median frame of each run, in ms.

build runs median frame per run snapshots copy-back
main 6 2472–4282 1544–2514 830–1535
#1267 6 798–1155 221–291 490–758
#497 4 1126–2763 440–893 576–1589
#124 6 1989–2960 1376–2179 520–997
#1322 2 2443–2467 1508–1648 687–767
#322 2 2063–2697 1447–2068 493–706
#436, #393, #435, #1656, #1215, #1186, #261, #1124, #1024 2 each 2516–5124 within or above main's range within or above main's range

The snapshots and copy-back columns are frame 3 of each run.

  • #1267 is the only one well outside main's range, about 2.5–3x shorter. Its snapshots, one copy per declared byte instead of the whole union again at each widening, take the largest part from ~2 s to ~0.25 s. #497 goes the same way at page granularity, with more spread.
  • With #1267, copy-back becomes the largest part (0.5–0.75 s here). That is the overlapping ranges' pieces being compared once per range. #124 and #991 target exactly that, but #124 conflicts with #1267 and #991 does not compile merged onto ffe310e.
  • All builds pass the checks: none puts back stale bytes in this pattern.
  • Wall time only. The pattern is made up: these say which change moves which part, not what fps the title gets.

Tested

  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings, with and without --all-features, passes on 940d32f.
  • The benchmark passed on every build in the table (#991 not built, see above).

Not tested: the title; AMD hosts; a quiet machine (the spread above is between runs of the same build).

**@⁠marquezinii** on GitHub · 2026-11-24 21:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/1743) `marquezinii:tests/world-frame-copies` → `main` · +292 −0 · 2 files · 2 commits · closed without merging Copy PRs keep competing for the same part of a world frame, the copies into and out of title memory (#400: 300–400 ms "preparing" and 50–150 ms "copying back" per frame at 1 fps; on some forks seconds). Each PR measures them with a fixture of its own, so they can't be compared. This adds one benchmark that any of them can be run against, on one machine, without the title. ## What `shadow::world_bench::world_frame_copies` (ignored by default) replays 6 frames of 36 submissions on a 174 MB write-watched heap, with what #400 and the forks' counters say world frames do: - Each submission declares 24 shader-written ranges out of 64 overlapping views of the heap (64 KiB to 64 MiB). Passes declare the same big ranges again and again. - Before each declared range, a refresh of 1–128 MiB, about 25 GB asked per frame, of which ~540 MB changed. - The title writes 256 places between submissions. The GPU writes 4 places in the declared ranges while the title writes the 8 bytes after each. It goes through `update`, `writing` and `copy_back`, the calls the submission path makes, and prints the time of each part per frame. The pattern is seeded, so it is the same in every build. Each declared range is refreshed before it is declared, as `gpu_writes` asks. Two modes, the two ways `Host::execute` handles shader-written ranges: - `world_frame_copies`: snapshots each declared range before the submission (memory that is not tracked). - `world_frame_copies_marked`: arms the declared ranges (`writing(.., true)`), sets the written-pages bit of each GPU write as a shader does, and runs `copy_back_marks` before the per-range copy-backs (tracked memory, since cd94d35/940d32f). It also asserts what copy-back must keep: the GPU's bytes reach title memory, and the title's writes during the run are not overwritten. A change that is fast but wrong fails. ```powershell cargo test --release -p victory-gpu world_frame_copies -- --ignored --nocapture --test-threads 1 ``` On `main` at `940d32f`, RTX 5070, release, median frame of 5: | mode | refresh | snapshots / arming | copy-back | total | |---|---|---|---|---| | snapshots | 77–88 ms | 377–501 ms | 198–219 ms | **748–758 ms** | | marked pages | 79–84 ms | 3.1–3.7 ms | 6.6–8.0 ms | **86.6–92.6 ms** | The marked mode checks the same things, with one exception that it prints instead of asserting. A GPU write is kept out of title memory when it lands on a page that no declared range covers whole and that the title wrote since its copy last took it: 6 of up to 864 writes in this pattern. More on that in the comments. Test-only: no change outside the new file and its `mod` line. ## Results on the open copy PRs (snapshot mode, before the marked path) Each PR merged alone onto `ffe310e` with this file added. RTX 5070 host device, Ryzen with other work running (so expect the spread), release build. The cells give the median frame of each run, in ms. | build | runs | median frame per run | snapshots | copy-back | |---|---|---|---|---| | `main` | 6 | 2472–4282 | 1544–2514 | 830–1535 | | #1267 | 6 | **798–1155** | **221–291** | 490–758 | | #497 | 4 | 1126–2763 | 440–893 | 576–1589 | | #124 | 6 | 1989–2960 | 1376–2179 | 520–997 | | #1322 | 2 | 2443–2467 | 1508–1648 | 687–767 | | #322 | 2 | 2063–2697 | 1447–2068 | 493–706 | | #436, #393, #435, #1656, #1215, #1186, #261, #1124, #1024 | 2 each | 2516–5124 | within or above `main`'s range | within or above `main`'s range | The snapshots and copy-back columns are frame 3 of each run. - **#1267 is the only one well outside `main`'s range**, about 2.5–3x shorter. Its snapshots, one copy per declared byte instead of the whole union again at each widening, take the largest part from ~2 s to ~0.25 s. #497 goes the same way at page granularity, with more spread. - With #1267, copy-back becomes the largest part (0.5–0.75 s here). That is the overlapping ranges' pieces being compared once per range. #124 and #991 target exactly that, but #124 conflicts with #1267 and #991 does not compile merged onto `ffe310e`. - All builds pass the checks: none puts back stale bytes in this pattern. - Wall time only. The pattern is made up: these say which change moves which part, not what fps the title gets. ## Tested - `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings`, with and without `--all-features`, passes on `940d32f`. - The benchmark passed on every build in the table (#991 not built, see above). **Not tested:** the title; AMD hosts; a quiet machine (the spread above is between runs of the same build).
An ignored benchmark that runs the refreshes, snapshots and copy-back of
36 submissions on a made-up 174 MB heap, shaped as world frames were
measured to be (#400): dozens of overlapping shader-written views per
submission, refreshes asking for ~25 GB a frame of which a few percent
changed. It prints the time of each part per frame, so builds that
change the copies can be compared on one machine without the title.

It also checks that bytes the GPU wrote reach title memory and that
bytes the title wrote while the GPU ran are kept.
Shadow::writing takes `marked` now. The benchmark passes it and gains
world_frame_copies_marked, which arms the declared ranges, marks the
pages the GPU writes and runs copy_back_marks before the per-range
copy-backs, as Host::execute does for tracked memory.

Each declared range is now refreshed before it is declared, as
gpu_writes asks. Without that the marked mode lost GPU writes that the
real path does not.

In the marked mode, GPU writes on pages that no declared range covers
whole are counted and printed instead of asserted. Shadow::update takes
whole pages only, so such a page stays changed once the title writes it,
and copy_back_marked keeps the title's bytes there.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:43:28 +00:00
github-bot closed this pull request 2026-11-26 04:43:28 +00:00
Author
Owner

@⁠marquezinii on GitHub · 2026-11-24 22:02 UTC · original

The red check is not this change. main itself (70564ae, its run) fails the same two victory-shader tests: emit::synthetic_tests::gathers_at_a_level_match_the_hardware and permutes_read_the_lane_named_and_zero_from_lanes_left_out. This PR only adds an ignored test in victory-gpu.

**@⁠marquezinii** on GitHub · 2026-11-24 22:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/1743#issuecomment-7145722072) The red check is not this change. `main` itself (`70564ae`, [its run](https://github.com/Marvisak/VIctory/actions?query=branch%3Amain)) fails the same two `victory-shader` tests: `emit::synthetic_tests::gathers_at_a_level_match_the_hardware` and `permutes_read_the_lane_named_and_zero_from_lanes_left_out`. This PR only adds an ignored test in `victory-gpu`.
Author
Owner

@⁠aycow on GitHub · 2026-11-24 22:17 UTC · original

I ran your unchanged 174 MiB synthetic replay on Windows AMD with the GPU crate at opt-level 3, comparing exact 332152b on ffe310e and its clean cherry-pick on 70564ae (db1aca3, preserving your authorship). Five measured frames after warm-up gave median total CPU copy time 1,522.1 → 654.5 ms, snapshot 912.1 → 343.4 ms, copyback 515.5 → 222.0 ms, and refresh 94.5 → 87.3 ms. The checks passed and corresponding frames reported identical copied-back bytes. These samples measure the updated declared-range path. The separate 131,072-run fragmented replay remains a different case.

AI-assisted using Codex.

**@⁠aycow** on GitHub · 2026-11-24 22:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/1743#issuecomment-7146043705) I ran your unchanged 174 MiB synthetic replay on Windows AMD with the GPU crate at opt-level 3, comparing exact 332152b on ffe310e and its clean cherry-pick on 70564ae (db1aca3, preserving your authorship). Five measured frames after warm-up gave median total CPU copy time 1,522.1 → 654.5 ms, snapshot 912.1 → 343.4 ms, copyback 515.5 → 222.0 ms, and refresh 94.5 → 87.3 ms. The checks passed and corresponding frames reported identical copied-back bytes. These samples measure the updated declared-range path. The separate 131,072-run fragmented replay remains a different case. AI-assisted using Codex.
Author
Owner

@⁠0xkn0wh3r3 on GitHub · 2026-11-25 03:12 UTC · original

On current main (940d32f) this benchmark still measures the declared-range snapshot path. Since cd94d35 / 940d32f, tracked memory takes the marked-page path instead, and that path is about 9× cheaper on the same pattern. Numbers are on #400; the short version, on an RTX 5070 Ti (release, 5 counted frames):

  • Snapshot path: median 711 ms per frame (refresh 70–78 ms, snapshots 338–465 ms, copy-back 185–226 ms).
  • Marked path: median 76 ms per frame (refresh 67–71 ms, arming 2.6–3.0 ms, copy-back 5.0–5.2 ms).

Two notes for running it on main:

  • Shadow::writing takes a third argument now. false keeps what the benchmark measures.
  • A marked variant needed three changes to the loop. The benchmark then counts GPU writes lost to the unarmed-page shortcut instead of asserting on them: 6 over the run, all from title writes on pages only partly inside a declared range.
// per declared range: refresh it, then arm it (as Host::execute does)
f.refreshed += time(&mut f.refresh, || shadow.update(address, len));
time(&mut f.snapshots, || shadow.writing(address, len, true));

// per GPU write: set its page's bit
let (bit, _) = shadow.mark_entry(at as u64).expect("marked");
let words = bitmap().unwrap().data as *mut u32;
// SAFETY: a dword of the mapped bitmap.
unsafe { *words.add(bit as usize / 32) |= 1 << (bit % 32) };

// after the submission, before the per-range copy_back calls
time(&mut f.copy_back, || copy_back_marks(&[]));

Comparing the copy PRs in both modes would show which ones still matter for tracked memory.

**@⁠0xkn0wh3r3** on GitHub · 2026-11-25 03:12 UTC · [original](https://github.com/Marvisak/VIctory/pull/1743#issuecomment-7151689681) On current `main` (`940d32f`) this benchmark still measures the declared-range snapshot path. Since cd94d35 / 940d32f, tracked memory takes the marked-page path instead, and that path is about 9× cheaper on the same pattern. Numbers are on #400; the short version, on an RTX 5070 Ti (release, 5 counted frames): - **Snapshot path:** median 711 ms per frame (refresh 70–78 ms, snapshots 338–465 ms, copy-back 185–226 ms). - **Marked path:** median 76 ms per frame (refresh 67–71 ms, arming 2.6–3.0 ms, copy-back 5.0–5.2 ms). Two notes for running it on `main`: - `Shadow::writing` takes a third argument now. `false` keeps what the benchmark measures. - A marked variant needed three changes to the loop. The benchmark then counts GPU writes lost to the unarmed-page shortcut instead of asserting on them: 6 over the run, all from title writes on pages only partly inside a declared range. ```rust // per declared range: refresh it, then arm it (as Host::execute does) f.refreshed += time(&mut f.refresh, || shadow.update(address, len)); time(&mut f.snapshots, || shadow.writing(address, len, true)); // per GPU write: set its page's bit let (bit, _) = shadow.mark_entry(at as u64).expect("marked"); let words = bitmap().unwrap().data as *mut u32; // SAFETY: a dword of the mapped bitmap. unsafe { *words.add(bit as usize / 32) |= 1 << (bit % 32) }; // after the submission, before the per-range copy_back calls time(&mut f.copy_back, || copy_back_marks(&[])); ``` Comparing the copy PRs in both modes would show which ones still matter for tracked memory.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 03:36 UTC · original · edited 2026-11-25 07:27 UTC

Automated triage for the maintainers.

Merge candidate. Update after your reply: 005e263 fixes the Shadow::writing(.., marked) call, so the file builds on main. It adds world_frame_copies_marked, which arms the declared ranges, sets each GPU write's bit through mark_entry/bitmap(), and runs copy_back_marks(&[]) before the per-range copy-backs. Both benchmarks are #[ignore]d, seeded, test-only (#[cfg(test)] mod world_bench in shadow.rs), and assert that GPU writes reach title memory and that the title's own writes survive.

The finding in your reply looks real and is worth its own issue or PR. I read the code the same way: Shadow::update takes only pages it refreshed whole (the "taken, unless it holds the page in part" comment in shadow.rs), so copy_back_marked keeps the title's page when a marked GPU write lands on a partly covered edge page that the title also wrote. The benchmark counts and prints those cases instead of asserting, which is the right call while main has the gap.

CI: failing, but in victory-hle's modules::dstorage::tests::a_page_list_filled_after_its_request_starts, which this PR does not touch. The victory-gpu tests pass.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 03:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/1743#issuecomment-7152079807) · edited 2026-11-25 07:27 UTC <!-- victory-triage v1 head=005e263f847d491babd1ec3172884bf0ff8e1a2f verdict=merge-candidate at=2026-11-25T07:27:19Z --> Automated triage for the maintainers. **Merge candidate.** Update after your reply: `005e263` fixes the `Shadow::writing(.., marked)` call, so the file builds on `main`. It adds `world_frame_copies_marked`, which arms the declared ranges, sets each GPU write's bit through `mark_entry`/`bitmap()`, and runs `copy_back_marks(&[])` before the per-range copy-backs. Both benchmarks are `#[ignore]`d, seeded, test-only (`#[cfg(test)] mod world_bench` in `shadow.rs`), and assert that GPU writes reach title memory and that the title's own writes survive. The finding in your reply looks real and is worth its own issue or PR. I read the code the same way: `Shadow::update` takes only pages it refreshed whole (the "taken, unless it holds the page in part" comment in `shadow.rs`), so `copy_back_marked` keeps the title's page when a marked GPU write lands on a partly covered edge page that the title also wrote. The benchmark counts and prints those cases instead of asserting, which is the right call while `main` has the gap. CI: failing, but in `victory-hle`'s `modules::dstorage::tests::a_page_list_filled_after_its_request_starts`, which this PR does not touch. The `victory-gpu` tests pass. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠marquezinii on GitHub · 2026-11-25 03:58 UTC · original

Updated in 005e263 (rebased on 940d32f), thanks @⁠0xkn0wh3r3 for the sketch:

  • writing gets the third argument, so it builds on main again.
  • New world_frame_copies_marked, built from your loop: it arms the ranges, marks each GPU write's page, and runs copy_back_marks(&[]) before the per-range copy-backs. On an RTX 5070 the snapshot mode's median frame is 748–758 ms and the marked mode's is 86.6–92.6 ms, the same ~9× you measured.

About the writes the marked mode loses. Part of it came from the benchmark itself. It refreshed some other range of the heap before declaring each range, but never the declared range, which gpu_writes asks for. With that refresh added (both modes now do it), 6 losses remain over the run, out of up to 864 GPU writes. I printed where each one landed:

  • None of the 6 pages is covered whole by any declared range of its submission. They are edge pages, since the views start on 256 bytes and pages are 64 KiB.
  • The title wrote each of those pages since the copy last took it. The benchmark writes the 8 bytes after every GPU write, plus 256 random places per submission.

That matches the code. Shadow::update only takes pages it refreshed whole ("taken, unless it holds the page in part"), so an edge page the title has written stays changed, and the guard never saves its bytes. copy_back_marked then sees saved == None && changed and keeps the title's page, because it can't tell the shaders' bytes from stale ones in the part that wasn't refreshed. The snapshot path doesn't have this problem, because it compares byte by byte against its snapshot.

So on main, a shader write through a marked view can stay out of title memory when it lands in the partly covered first or last page of a declared range, and the title touched that page during the frame. The benchmark counts these cases and prints them instead of asserting, so it passes on main and shows the number. If you'd rather it fail until this is fixed, it's a one-line change.

One way to fix it, which I haven't tried: when writing(.., true) arms a range, save the copy's bytes of its partial edge pages that are changed. That's at most two pages per range. copy_back_marked would then compare against those bytes as it does for a saved page. I can open that as a separate PR if it looks right.

**@⁠marquezinii** on GitHub · 2026-11-25 03:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/1743#issuecomment-7152405102) Updated in 005e263 (rebased on `940d32f`), thanks @⁠0xkn0wh3r3 for the sketch: - `writing` gets the third argument, so it builds on `main` again. - New `world_frame_copies_marked`, built from your loop: it arms the ranges, marks each GPU write's page, and runs `copy_back_marks(&[])` before the per-range copy-backs. On an RTX 5070 the snapshot mode's median frame is 748–758 ms and the marked mode's is 86.6–92.6 ms, the same ~9× you measured. **About the writes the marked mode loses.** Part of it came from the benchmark itself. It refreshed some other range of the heap before declaring each range, but never the declared range, which `gpu_writes` asks for. With that refresh added (both modes now do it), 6 losses remain over the run, out of up to 864 GPU writes. I printed where each one landed: - None of the 6 pages is covered whole by any declared range of its submission. They are edge pages, since the views start on 256 bytes and pages are 64 KiB. - The title wrote each of those pages since the copy last took it. The benchmark writes the 8 bytes after every GPU write, plus 256 random places per submission. That matches the code. `Shadow::update` only takes pages it refreshed whole ("taken, unless it holds the page in part"), so an edge page the title has written stays changed, and the guard never saves its bytes. `copy_back_marked` then sees `saved == None && changed` and keeps the title's page, because it can't tell the shaders' bytes from stale ones in the part that wasn't refreshed. The snapshot path doesn't have this problem, because it compares byte by byte against its snapshot. So on `main`, a shader write through a marked view can stay out of title memory when it lands in the partly covered first or last page of a declared range, and the title touched that page during the frame. The benchmark counts these cases and prints them instead of asserting, so it passes on `main` and shows the number. If you'd rather it fail until this is fixed, it's a one-line change. One way to fix it, which I haven't tried: when `writing(.., true)` arms a range, save the copy's bytes of its partial edge pages that are changed. That's at most two pages per range. `copy_back_marked` would then compare against those bytes as it does for a saved page. I can open that as a separate PR if it looks right.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 22:02 UTC · original

Automated triage for the maintainers, second look (a review against current main, with builds and tests where they could change the verdict).

Closing because it no longer compiles on main (bitmap() now takes a memory: bool, and copy_back_marks takes (withheld, memory_withheld)), and #2134 covers the same ground more faithfully: it replays a frame's volumes through Host::execute itself instead of calling the Shadow methods on an invented pattern.

If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.

**@⁠Marvisak** on GitHub · 2026-11-25 22:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/1743#issuecomment-7175855627) Automated triage for the maintainers, second look (a review against current `main`, with builds and tests where they could change the verdict). Closing because it no longer compiles on `main` (`bitmap()` now takes a `memory: bool`, and `copy_back_marks` takes `(withheld, memory_withheld)`), and #2134 covers the same ground more faithfully: it replays a frame's volumes through `Host::execute` itself instead of calling the `Shadow` methods on an invented pattern. If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1743
No description provided.