Skip to content

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

Open
n-romanovich wants to merge 1 commit into
fxceless:mainfrom
n-romanovich:fix/1344-partial-page-stamps
Open

n-romanovich wants to merge 1 commit into
fxceless:mainfrom
n-romanovich:fix/1344-partial-page-stamps

Conversation

@n-romanovich

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

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).

aleksesipenko pushed a commit to aleksesipenko/VIctory-RTX that referenced this pull request Nov 27, 2026
…ans (#1388)

Port two CPU-side GPU prep and shadow-refresh improvements into `victory-gpu`
without touching rendering, shader, descriptor, texture, or DXR pipelines:

1. CPU prep wins (GPL-3.0 provenance: Peppacodes/playablegames-peppa #6 &
   fxceless/victory-fork #1146 by beamdotdev):
   - Add opt-in `VICTORY_LAND_ASIDE=1` (`victory-land-aside` worker thread
     with coalesced wakeups and process-lifetime `OnceLock` lifecycle matching
     `VICTORY_BURY_ASIDE`, off by default and A/B-flippable in diagnostics
     builds) while preserving `victory-rtx`'s relay fast path when off.
   - Fix `CARD_DIRTY_QUEUE` lock ordering by enqueuing inside `card.dirty.lock()`
     in `card_changed_runs`, store `(start, end, Weak<Shadow>)` in `CARDED` to
     range-filter `send_copied` before `Weak::upgrade()`, prune dead `CARDED`
     entries periodically in `card_dirty`, and add `VICTORY_CARD_TOUCHED` A/B
     switch support in diagnostics builds.
   - Expose `shadow::helper_priority` (`VICTORY_WIDE_PRIORITY`) and wire it
     into `land::Pool::help` for `victory-under` and `victory-records`.

2. Partial-page shadow spans (GPL-3.0 provenance: fxceless/victory-fork #1388):
   - Track per-page sub-64 KiB copied spans in `Shadow::partial`, lifting
     sub-page refreshes out of full-page re-uploads, promoting full-page
     coverage back to whole-page `copied` stamps, fixing `by_parts` multi-gap
     indexing, adding `watch::nothing_new_by` for `Shadow::nothing_new`,
     advancing owner partial stamps on clean landings in `Shadow::landed`, and
     clearing partial spans on whole-page refreshes / `merge_under_writes`.

Note: `fxceless/victory-fork #1385` (cross-shadow sibling propagation) was
intentionally omitted after review identified concurrency races in cross-thread
sibling mutation.

Provenance (GPL-3.0):
- Peppacodes/playablegames-peppa#6 (and fxceless/victory-fork#1146 / beamdotdev)
- fxceless/victory-fork#1388
@KyleS98

KyleS98 commented Nov 27, 2026

Copy link
Copy Markdown

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Repeated refreshes recopy unchanged spans at watched-page boundaries

3 participants