GPU: record per-span stamps for partial watched-page refreshes #1388

Open
n-romanovich wants to merge 1 commit from upstream-pr/1388 into main
n-romanovich commented 2026-11-26 22:19:14 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by n-romanovich on 2026-11-26T22:19:14Z.


Fixes #1344.

Previously, Shadow::copy_stale only updated copied[page - base] when a refresh covered the entire 64 KiB page (within the shadow buffer). Partial or unaligned refreshes left the page unstamped, causing repeated refreshes of the same unchanged span to re-copy boundary bytes on every frame.

Changes in crates/victory-gpu/src/shadow.rs:

  • Track sorted, non-overlapping per-page partial byte spans (lo, hi, stamp) in Shadow::partial alongside Shadow::copied.
  • In copy_stale / copy_stale_with, prune any partial spans invalidated by a newer CPU write (stamp < write), copy only the uncovered gaps (including when VICTORY_DIRTY_4K subpage filtering is active), and promote to a whole-page stamp when a full page is refreshed.
  • Keep partial stamps in sync in Shadow::wrote_own.
  • Add unit tests in shadow::stale_tests covering unaligned cross-boundary refreshes, consecutive refreshes skipping unchanged bytes, CPU write invalidation, overlapping extensions, promotion to whole-page stamps, and VICTORY_DIRTY_4K interaction.

Verified locally:

  • cargo test --locked -p victory-gpu --lib shadow (34 passed, 0 failed)
  • cargo test --locked -p victory-gpu --features diagnostics --lib shadow (34 passed, 0 failed)
  • cargo test --locked -p victory-gpu --lib (226 passed, 0 failed, 6 ignored)
  • cargo build --release --locked -p victory
<!-- greyfinch-sync:fxceless/victory-fork:issue:5517919687 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1388). Originally posted by [n-romanovich](https://github.com/n-romanovich) on 2026-11-26T22:19:14Z. --- Fixes #1344. Previously, `Shadow::copy_stale` only updated `copied[page - base]` when a refresh covered the entire 64 KiB page (within the shadow buffer). Partial or unaligned refreshes left the page unstamped, causing repeated refreshes of the same unchanged span to re-copy boundary bytes on every frame. Changes in `crates/victory-gpu/src/shadow.rs`: - Track sorted, non-overlapping per-page partial byte spans `(lo, hi, stamp)` in `Shadow::partial` alongside `Shadow::copied`. - In `copy_stale` / `copy_stale_with`, prune any partial spans invalidated by a newer CPU write (`stamp < write`), copy only the uncovered gaps (including when `VICTORY_DIRTY_4K` subpage filtering is active), and promote to a whole-page stamp when a full page is refreshed. - Keep `partial` stamps in sync in `Shadow::wrote_own`. - Add unit tests in `shadow::stale_tests` covering unaligned cross-boundary refreshes, consecutive refreshes skipping unchanged bytes, CPU write invalidation, overlapping extensions, promotion to whole-page stamps, and `VICTORY_DIRTY_4K` interaction. Verified locally: - `cargo test --locked -p victory-gpu --lib shadow` (34 passed, 0 failed) - `cargo test --locked -p victory-gpu --features diagnostics --lib shadow` (34 passed, 0 failed) - `cargo test --locked -p victory-gpu --lib` (226 passed, 0 failed, 6 ignored) - `cargo build --release --locked -p victory`
Filip722 commented 2026-11-26 23:07:41 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Filip722 on 2026-11-26T23:07:41Z.


All four focused stale-page tests passed under GE-Proton11-14 on Bazzite 44 with an RTX 5060 Laptop. I also replayed the same Series S checkpoint from identical initial caches on the same local integration of main and #257, with #1388 as the app source change.

The patched run reached the cell and recorded 206 distinct presents over 54 seconds at 3.82 FPS, with 965 MiB minimum free VRAM and no pending pipelines. Camera movement responded to input. The unpatched run reached the matched view and hit the local GPU headroom stop at 618 MiB free before completing the window. This pair establishes a working Proton run with the patch. A complete control window is still needed for an FPS or CPU-copy comparison.

Assisted by Codex (GPT-6.2-Sol High).

<!-- greyfinch-sync:fxceless/victory-fork:comment:7205277617 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1388#issuecomment-7205277617). Originally posted by [Filip722](https://github.com/Filip722) on 2026-11-26T23:07:41Z. --- All four focused stale-page tests passed under GE-Proton11-14 on Bazzite 44 with an RTX 5060 Laptop. I also replayed the same Series S checkpoint from identical initial caches on the same local integration of main and #257, with #1388 as the app source change. The patched run reached the cell and recorded 206 distinct presents over 54 seconds at 3.82 FPS, with 965 MiB minimum free VRAM and no pending pipelines. Camera movement responded to input. The unpatched run reached the matched view and hit the local GPU headroom stop at 618 MiB free before completing the window. This pair establishes a working Proton run with the patch. A complete control window is still needed for an FPS or CPU-copy comparison. Assisted by Codex (GPT-6.2-Sol High).
KyleS98 commented 2026-11-27 02:53:42 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by KyleS98 on 2026-11-27T02:53:42Z.


An in-game data point from a setup where nearly every buffer refresh is the case this PR is about, plus a profile that says where the rest of the time is.

Setup. RTX 3090 Ti 24 GB, Ryzen 9 9950X3D, Windows 11 26200. main 1f5d17a with #798 (the Series S profile needs it) and #1414 with VICTORY_TABLED_ALL=1. With that switch the once-a-frame pass over buffer views no longer refreshes each copy's whole span, so the draws' own refreshes are what is left: small ranges on 64 KiB pages the copy never takes whole. This PR's commit cherry-picked cleanly on top. Series S profile, the prologue's cell, hands-off, 5.5 minutes a run, two runs each way, the last four readings of the frame line.

per frame without with this PR
title memory the refreshes read ("copies" on the frame line) 69–80 MB 53–58 MB
the time of it, submitting thread 19–28 ms 20–25 ms
frame 54–61 and 59–64 ms 53–59 and 55–59 ms (the second with the sampler running)
sent up to copies in the card's memory 38–39 MB in 2,450–2,930 ranges 40 MB in 2,750 ranges
exceptions, device loss none none

The picture in the cell is the same (four frames of each side by side).

So it does what it says: about a quarter fewer bytes read, with no fault I could find. The time does not follow the bytes, and the profile says why. Built-in sampler over 60 s of the cell, with this PR, submitting thread, ms a frame:

ms a frame
Shadow::update (all refreshes) 15.1
of it watch::writes (the asking) 9.4 (11.4 with its other callers)
of it Shadow::copy_stale (the copying) 4.4

The asking is paid once per range, whether the range then copies anything or not. watch::nothing_noted cannot answer for these ranges: it gives up on a page the copy has never taken whole (taken.contains(&0), and its comment says so: "so is, at every refresh, a page the copy's refreshes only ever hold in part"). For the same reason VICTORY_LIGHT_REFRESH=1 does not get past it here (one run with it on top: 54–57 ms).

A possible next step, not written: the spans this PR keeps are what nothing_noted is missing. A range whose pages are either taken whole or covered by spans stamped at or after the journal's last write of the page could be answered there with nothing asked. I am glad to run it here if someone writes it.

Two things I did not explain. What goes up to the copies in the card's memory did not change with this PR in these runs (38–39 against 40 MB a frame), so the reads it saves are not in what is sent there; I have not looked into which copies they belong to. And on another tree (#994's head with #868 and others, same card and scene) VICTORY_COPY_CHANGED=1 took what goes up from 27.8 to 6.2 MB a frame with the frame unchanged (45–47 ms both ways): there most of it was bytes written again with the same values, and the time was not in the sending either.

Numbers and text only. AI-assisted (Claude Code, Claude Fable 5.2).

<!-- greyfinch-sync:fxceless/victory-fork:comment:7208525238 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1388#issuecomment-7208525238). Originally posted by [KyleS98](https://github.com/KyleS98) on 2026-11-27T02:53:42Z. --- An in-game data point from a setup where nearly every buffer refresh is the case this PR is about, plus a profile that says where the rest of the time is. **Setup.** RTX 3090 Ti 24 GB, Ryzen 9 9950X3D, Windows 11 26200. `main` `1f5d17a` with #798 (the Series S profile needs it) and #1414 with `VICTORY_TABLED_ALL=1`. With that switch the once-a-frame pass over buffer views no longer refreshes each copy's whole span, so the draws' own refreshes are what is left: small ranges on 64 KiB pages the copy never takes whole. This PR's commit cherry-picked cleanly on top. Series S profile, the prologue's cell, hands-off, 5.5 minutes a run, two runs each way, the last four readings of the frame line. | per frame | without | with this PR | |---|---:|---:| | title memory the refreshes read ("copies" on the frame line) | 69–80 MB | 53–58 MB | | the time of it, submitting thread | 19–28 ms | 20–25 ms | | frame | 54–61 and 59–64 ms | 53–59 and 55–59 ms (the second with the sampler running) | | sent up to copies in the card's memory | 38–39 MB in 2,450–2,930 ranges | 40 MB in 2,750 ranges | | exceptions, device loss | none | none | The picture in the cell is the same (four frames of each side by side). So it does what it says: about a quarter fewer bytes read, with no fault I could find. The time does not follow the bytes, and the profile says why. Built-in sampler over 60 s of the cell, with this PR, submitting thread, ms a frame: | | ms a frame | |---|---:| | `Shadow::update` (all refreshes) | 15.1 | | of it `watch::writes` (the asking) | 9.4 (11.4 with its other callers) | | of it `Shadow::copy_stale` (the copying) | 4.4 | The asking is paid once per range, whether the range then copies anything or not. `watch::nothing_noted` cannot answer for these ranges: it gives up on a page the copy has never taken whole (`taken.contains(&0)`, and its comment says so: "so is, at every refresh, a page the copy's refreshes only ever hold in part"). For the same reason `VICTORY_LIGHT_REFRESH=1` does not get past it here (one run with it on top: 54–57 ms). **A possible next step, not written:** the spans this PR keeps are what `nothing_noted` is missing. A range whose pages are either taken whole or covered by spans stamped at or after the journal's last write of the page could be answered there with nothing asked. I am glad to run it here if someone writes it. Two things I did not explain. What goes up to the copies in the card's memory did not change with this PR in these runs (38–39 against 40 MB a frame), so the reads it saves are not in what is sent there; I have not looked into which copies they belong to. And on another tree (#994's head with #868 and others, same card and scene) `VICTORY_COPY_CHANGED=1` took what goes up from 27.8 to 6.2 MB a frame with the frame unchanged (45–47 ms both ways): there most of it was bytes written again with the same values, and the time was not in the sending either. Numbers and text only. AI-assisted (Claude Code, Claude Fable 5.2).
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/1388:upstream-pr/1388'
git switch 'upstream-pr/1388'

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/1388'
git switch 'upstream-pr/1388'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1388'
git switch 'upstream-pr/1388'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1388'
git switch 'main'
git merge --squash 'upstream-pr/1388'
git switch 'main'
git merge --ff-only 'upstream-pr/1388'
git switch 'main'
git merge 'upstream-pr/1388'
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
fxceless/victory-fork!1388
No description provided.