GPU: a marked page goes back at its first access (VICTORY_LAZY_COPY_BACK) #3118

Open
github-bot wants to merge 5 commits from github-bot/gh-3118 into main AGit
Owner

@⁠borosf on GitHub · 2026-11-26 08:44 UTC · original
borosf:vibe/lazy-copy-back-842ca5 → main · +348 −9 · 3 files · 5 commits · open

Summary

  • After a submission, Shadow::copy_back_marked brings every page its shaders marked as written back into title memory — on the card that is 60–127 ms a frame, 95 % of it waiting (FIND-33: the snapshot's pages fetched, and the waits around them; the host-side merge is 2.4–2.9 ms, the write 0.4–0.5 ms). The world marks ~2,250 pages a frame; most are never read by title code before a later pass overwrites them.
  • With VICTORY_LAZY_COPY_BACK=1 (opt-in, off by default — behavior is unchanged without it), a marked page leaves the submission sealed no-access. The first read faults that one page back; the first write faults it back and then lands as the title's own over it (the merge happens underneath, as eager copy-back would have); a page nothing touched is written by the next submission's copy-back and never holds the critical path.
  • The wait is a small ledger in the guard state (watch): sealed pages holding their copy alive, and the vectored handler — which today services write faults — also taking read faults on those pages, servicing exactly one page each time. Arming is one VirtualProtect per run of pages.
  • Only pages that can safely wait are armed: guarded, held whole by one copy, no alias showing them elsewhere, not already waiting. Everything else — partial pages, aliased pages, withheld ranges — goes back eagerly, unchanged.
  • Ordering is preserved against every path that could reach a sealed page without faulting: refreshes drain their range first (Shadow::update, copy_back, copy_back_page), writes the guards do not see drain before they mark (watch::writing — kernel reads, DirectStorage), and remaps, retakes and new aliases drop the wait and unseal (title_memory_remapped, retake, title_memory_aliased). In-process reads of a sealed page fault into the handler and service transparently.
  • The arming counts its seals and both refusal kinds (guard state, host), and a test failure names the stage — on hardware that refuses the seal the feature stays a no-op, falling back to eager copy-back.
  • Composes with #3069 (write-beside changes how pages go back, this when), #3102 (shared memory placement — the ledger is per virtual page regardless of backing), and #2914 (drains are per-range, re-entrant through remove-before-service).

Verification

  • CI (Windows clippy -D warnings, cargo test --workspace --locked); with the switch off the suite is unchanged.
  • New synthetic test marked_pages_leave_the_submission_and_go_back_at_their_first_access drives the real fault handler on the Intel Arc B580: the submission leaves pages sealed (asserted via VirtualQuery, arming counters (3, 0, 0) — sealed, none refused), a read_volatile faults the GPU's byte back and the page is guarded again, a write_volatile merges underneath and lands on top, an untouched page is written by the next copy-back, and the ledger ends empty.
  • Intel Arc B580, Windows 11: cargo clippy -p victory-gpu --all-targets --locked -- -D warnings clean; cargo test -p victory-gpu --lib --locked green except the two known Intel heap-cap failures (#1744) pristine main also fails.
  • No game data used. Synthetic tests only.

claiming: FIND-33 — lazy copy-back on read (marked pages go back at their first access), the 95 %-wait copy-back stall (#1633 comment, per the ledger)

**@⁠borosf** on GitHub · 2026-11-26 08:44 UTC · [original](https://github.com/Marvisak/VIctory/pull/3118) `borosf:vibe/lazy-copy-back-842ca5` → `main` · +348 −9 · 3 files · 5 commits · open ## Summary - After a submission, `Shadow::copy_back_marked` brings every page its shaders marked as written back into title memory — on the card that is 60–127 ms a frame, **95 % of it waiting** (FIND-33: the snapshot's pages fetched, and the waits around them; the host-side merge is 2.4–2.9 ms, the write 0.4–0.5 ms). The world marks ~2,250 pages a frame; most are never read by title code before a later pass overwrites them. - With `VICTORY_LAZY_COPY_BACK=1` (opt-in, off by default — behavior is unchanged without it), a marked page leaves the submission **sealed no-access**. The first *read* faults that one page back; the first *write* faults it back and then lands as the title's own over it (the merge happens underneath, as eager copy-back would have); a page nothing touched is written by the next submission's copy-back and never holds the critical path. - The wait is a small ledger in the guard state (`watch`): sealed pages holding their copy alive, and the vectored handler — which today services write faults — also taking read faults on those pages, servicing exactly one page each time. Arming is one `VirtualProtect` per run of pages. - Only pages that can safely wait are armed: guarded, held whole by one copy, no alias showing them elsewhere, not already waiting. Everything else — partial pages, aliased pages, withheld ranges — goes back eagerly, unchanged. - Ordering is preserved against every path that could reach a sealed page without faulting: refreshes drain their range first (`Shadow::update`, `copy_back`, `copy_back_page`), writes the guards do not see drain before they mark (`watch::writing` — kernel reads, DirectStorage), and remaps, retakes and new aliases drop the wait and unseal (`title_memory_remapped`, `retake`, `title_memory_aliased`). In-process reads of a sealed page fault into the handler and service transparently. - The arming counts its seals and both refusal kinds (guard state, host), and a test failure names the stage — on hardware that refuses the seal the feature stays a no-op, falling back to eager copy-back. - Composes with #3069 (write-beside changes *how* pages go back, this *when*), #3102 (shared memory placement — the ledger is per virtual page regardless of backing), and #2914 (drains are per-range, re-entrant through remove-before-service). ## Verification - CI (Windows clippy `-D warnings`, `cargo test --workspace --locked`); with the switch off the suite is unchanged. - New synthetic test `marked_pages_leave_the_submission_and_go_back_at_their_first_access` drives the real fault handler on the Intel Arc B580: the submission leaves pages sealed (asserted via `VirtualQuery`, arming counters `(3, 0, 0)` — sealed, none refused), a `read_volatile` faults the GPU's byte back and the page is guarded again, a `write_volatile` merges underneath and lands on top, an untouched page is written by the next copy-back, and the ledger ends empty. - Intel Arc B580, Windows 11: `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings` clean; `cargo test -p victory-gpu --lib --locked` green except the two known Intel heap-cap failures (#1744) pristine main also fails. - No game data used. Synthetic tests only. claiming: FIND-33 — lazy copy-back on read (marked pages go back at their first access), the 95 %-wait copy-back stall (#1633 comment, per the ledger)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:46:38 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 08:48 UTC · original · approved these changes

Verified on RTX 5090 & WARP against origin/main (63bcca4):

  • cargo test -p victory-gpu --lib shadow:: -- --test-threads=1: 11/11 passed on RTX 5090 and WARP (including marked_pages_leave_the_submission_and_go_back_at_their_first_access).
  • cargo test -p victory-gpu --lib watch:: -- --test-threads=1: 15/15 passed.
  • cargo test -p victory-gpu --lib draw:: -- --test-threads=1: 20/20 passed on RTX 5090.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Clean opt-in VICTORY_LAZY_COPY_BACK mechanism deferring marked-page copy-backs until first CPU access.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 08:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/3118#pullrequestreview-6070950233) · **approved these changes** Verified on RTX 5090 & WARP against `origin/main` (`63bcca4`): - `cargo test -p victory-gpu --lib shadow:: -- --test-threads=1`: 11/11 passed on RTX 5090 and WARP (including `marked_pages_leave_the_submission_and_go_back_at_their_first_access`). - `cargo test -p victory-gpu --lib watch:: -- --test-threads=1`: 15/15 passed. - `cargo test -p victory-gpu --lib draw:: -- --test-threads=1`: 20/20 passed on RTX 5090. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Clean opt-in `VICTORY_LAZY_COPY_BACK` mechanism deferring marked-page copy-backs until first CPU access. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
This pull request can be merged automatically.
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/3118/head:github-bot/gh-3118'
git switch 'github-bot/gh-3118'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3118'
git switch 'github-bot/gh-3118'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3118'
git switch 'github-bot/gh-3118'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3118'
git switch 'main'
git merge --squash 'github-bot/gh-3118'
git switch 'main'
git merge --ff-only 'github-bot/gh-3118'
git switch 'main'
git merge 'github-bot/gh-3118'
git push origin 'main'
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!3118
No description provided.