Skip to content

GPU: a refresh takes the whole pages it touches - #3289

Open
QalityDev wants to merge 2 commits into
Marvisak:mainfrom
QalityDev:pr/refresh-whole-pages
Open

QalityDev wants to merge 2 commits into
Marvisak:mainfrom
QalityDev:pr/refresh-whole-pages

Conversation

@QalityDev

@QalityDev QalityDev commented Nov 26, 2026 •

Copy link
Copy Markdown

A refresh of a range that cuts a 64 KiB page copied that part and left the page changed (Tracked::take), so every later refresh reaching it copied it again, whether or not the title had written it since. GTA VI refreshes small ranges inside its 174 MB GPU-heap buffer dozens of times per frame: on an RTX 4060 Ti, 410-550 MB of the 550-690 MB copied per frame came from such partial pages.

Shadow::update now widens the range to the whole pages it touches (cut to the copy). Taken whole, a page is guarded and copied again only once the title writes it. Ranges whose shaders' writes stay in the copy (keep_writes) are remembered and the widening stops short of them; ranges shaders are writing still go through the busy split. This generalises what #2172 does for marked UAV refreshes to every refresh.

Measured in the intro cutscene (diagnostics build):

  • before: copies 290-395 ms, 550-690 MB per frame; 700-730 ms/frame
  • after: copies 69-108 ms, 73-120 MB per frame; 380-445 ms/frame

New test a_partial_refresh_takes_the_whole_page; the copy-stats line reports bytes taken from whole and partial pages. On main 63bcca4: victory-gpu lib tests 230 passed (dynamic_slots_are_held_until_released and lists_share_a_table_and_copies_keep_their_views fail on main as well on this RTX 4060 Ti); clippy clean with and without diagnostics.

A refresh of a range that cuts a 64 KiB page copied that part and left
the page changed (`Tracked::take`), so every later refresh reaching it
copied it again, whether or not the title had written it since. The
world refreshes small ranges inside the title's 174 MB GPU-heap buffer
dozens of times per frame: on an RTX 4060 Ti, 410-550 MB of the
550-690 MB copied per frame came from such partial pages, against
100-140 MB from pages taken whole.

`Shadow::update` now widens the range to the pages it touches (cut to
the copy). Taken whole, a page is guarded and copied again only once
the title writes it. Ranges whose shaders' writes stay in the copy
(`keep_writes`) are remembered and the widening stops short of them;
ranges shaders are writing go through the existing busy split.

Measured in the intro cutscene (diagnostics build, the four heaviest
compute pipelines skipped to isolate CPU preparation):

  before: copies 290-395 ms, 550-690 MB per frame; 700-730 ms/frame
  after:  copies  69-108 ms,  73-120 MB per frame; 380-445 ms/frame

Diagnostics: the copy-stats line reports bytes taken from whole and
partial pages. New test `a_partial_refresh_takes_the_whole_page`;
On main 63bcca4: victory-gpu lib tests 230 passed (the two that fail,
dynamic_slots_are_held_until_released and
lists_share_a_table_and_copies_keep_their_views, fail on main as well
on this RTX 4060 Ti); clippy clean with and without `diagnostics`.
@QalityDev
QalityDev force-pushed the pr/refresh-whole-pages branch from c4d2062 to d99e868 Compare November 26, 2026 16:03

@Dukestar69 Dukestar69 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090):

  • Widening tracked refreshes in Shadow::widen to 64 KiB page boundaries (clamped to the buffer and stopping short of Shadow::kept ranges, with busy ranges still subtracted afterward) cleanly lets touched pages be taken whole and guarded instead of repeatedly re-copying partial pages, with TakenWholeBytes/TakenPartBytes diagnostics counters matching.
  • cargo test -p victory-gpu --lib shadow:: -- --test-threads=1 (RTX 5090): 11 passed, 0 failed (including a_partial_refresh_takes_the_whole_page).
  • cargo test -p victory-gpu --lib draw:: -- --test-threads=1 (RTX 5090): 20 passed, 0 failed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo clippy -p victory-gpu --features diagnostics --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

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

@oni-swr

oni-swr commented Nov 26, 2026

Copy link
Copy Markdown

WARP verification report (test report only, no code changes)

  • PR head: d99e868f
  • main: 63bcca43 (control); WARP software adapter forced with VICTORY_WARP=1 VICTORY_D3D12_WARP=1, --features diagnostics, d3d10warp.dll 10.0.26100.9818; dxil.dll 1.8.2502.11 (Windows Kit 10.0.26100.0, via VICTORY_DXIL). No physical GPU. Synthetic tests only, no game data.
  • Commands: cargo test -p victory-gpu --lib --features diagnostics --no-run -j 4, then the test binary with --exact <name> --test-threads 1 per test, then the whole lib suite.
  • New test shadow::tests::a_partial_refresh_takes_the_whole_page: passes on the PR (1 passed, 0.22 s).
  • Control: main plus only this test added (no source change). It fails on main at the written page, whole (left 16, right 65536): the refresh copies the 16 bytes asked for, not the page.
  • victory-gpu lib suite: PR 246 passed, 1 failed, 1 ignored; main plus the test 245 passed, 2 failed, 1 ignored (the new test and the failure below).
  • The one failure on both is frame::tests::waits_end_on_ticks_and_count_frames (left: 0, right: 1 at frame.rs:231). It also fails alone in its own process on the PR and on main, so it is not caused by this PR.
  • Not tested: physical GPU.

AI use: Claude Code (Claude Sonnet 5.5)

@Venom2054

Copy link
Copy Markdown

I tested a port of d99e868 on an RTX 5070 Ti with a tuned Series S profile. Two fresh launches used the same executable, save and warmed pipeline library. Only whole-page refresh changed. The port avoids widening across ranges previously written by a GPU shader because this fork can retain those writes.

At the stationary prison window, median copy volume fell from 75.0 to 55.4 MB per frame. The partial-page counter fell from 26.72 to 0.03 MB per frame. Write-watch time fell from 27.51 to 23.28 ms with 2,251 and 2,271 queries per frame, respectively. The runs issued 4,424 and 4,488 draws per frame.

Seven complete presentation batches per run covered 35.3 and 35.4 seconds. Presentation rate rose from 9.88 to 11.35 FPS (349 and 402 presents). Median frame time went from 101 to 85 ms and p90 from 142 to 120 ms. This is one pair of launches. A separate in-process toggle reproduced the reduction in copy volume. Disabling the change did not immediately restore the original volume because already refreshed pages stayed current.

Codex assisted with the port and measurements.

@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor

I checked a scaling case for the kept-write lookup on d99e868. Repeated overlapping declarations kept 131 entries for two disjoint regions, and widen walked the full set for each refresh. Follow-up 6d3e953 keeps the union of overlapping and adjacent ranges. Each lookup uses the nearest kept ranges to find the same boundaries.

The new regression gets two records, preserves both clipping boundaries, and keeps a request that overlaps a GPU write narrow. The original WARP kept-texel and whole-page tests pass. Full diagnostics on verified app-local Agility 1.620.2/WARP 1.0.22 had 249 passed, 0 failed, 1 ignored, including runtime identity. Strict Clippy in both configurations and asset policy passed.

I also built an optimized isolated benchmark from the two exact widen implementations. It first checked 2,500 mixed overlap insertions/lookups and 16,384 matching lookup results per disjoint-set size, then alternated nine timed runs. Median lookup time stayed at 19 ns with zero kept regions, went from 215 to 101 ns with 64 disjoint regions, and from 12.8 to 0.163 microseconds with 4,096. These are CPU lookup timings on synthetic ranges; a title trace would show how often a real buffer reaches those counts.

@QalityDev this is one commit directly on your head if the follow-up fits. Please retain its Git author on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <andrewpozdnakov7-jpg@users.noreply.github.com> if folding it into another commit. AI-assisted with Codex.

@QalityDev

Copy link
Copy Markdown
Author

Thanks @andrewpozdnakov7-jpg — reviewed and added as-is: 6d3e953 is now on the branch with your authorship. Checked here on an RTX 4060 Ti: shadow::/watch:: tests 27 passed (including overlapping_kept_writes_remember_their_union), strict Clippy clean with and without diagnostics.

@borosf

borosf commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Independent local verification on Windows 11 x64, Intel Arc B580 12 GB (12 cores), at this PR's head 6d3e953:

cargo test -p victory-gpu --lib --locked --no-fail-fast -- --test-threads=1
cargo clippy -p victory-gpu --all-targets --locked -- -D warnings
cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings

Result: victory-gpu lib: 2 known baseline failures only; the new a_partial_refresh_takes_the_whole_page test passed.

Both clippy runs exit 0 (-D warnings, both feature sets). The B580 baseline failures pristine main also hits are: victory-gpu descriptor::host::tests::dynamic_slots_are_held_until_released + memory::tests::lists_share_a_table_and_copies_keep_their_views (#1744/#1829); victory-shader emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros + emit::valu_tests::fspx_programs_run_with_the_hardwares_dot_products. No PR regressions.

Synthetic tests only; no game data used. Full log kept locally. — borosf

@neonbyte1

Copy link
Copy Markdown

Measured in game on an RTX 5090 (driver 620.73.04), Linux, GE-Proton11-14 Wine with its vkd3d-proton, GTA VI's opening prison yard, warm cache; base is main plus the unmerged PRs this setup needs (#3312, #3318, #2472 and others, listed in #3425). This PR merged on top, 600 s runs, medians of the last 30 frame-rate lines, against a control run of the same base taken next to it (frame times drift by up to ~25 ms between runs hours apart).

Frame Preparing Copy-back
control 402 ms 81 ms 53 ms
+ this PR 401 ms 78 ms 53 ms
+ this PR + #3343 404 ms 75.5 ms 51.9 ms (second control: 400 / 78 / 52)

Around 2-3 ms off preparing, inside the spread of the controls. Its two new shadow:: tests pass under Wine.

AI-assisted (Claude); measured on my machine, no game data shared.

@AndyLatimer AndyLatimer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed commit 6d3e953 (crates/victory-gpu/src/shadow.rs, rebased/merged cleanly onto 63bcca4). The core idea of guarding whole 64 KiB pages on partial refreshes makes sense, but two issues need addressing before merge:

1. Partial widening on pages with kept writes amplifies repeated refreshes, and self.kept is never pruned

watch::Tracked::take_split(from, to) only marks a 64 KiB page p as guarded (whole) when (p * PAGE).max(self.start) >= from && ((p + 1) * PAGE).min(self.end) <= to.

When self.kept contains e.g. [p + PAGE - 16, p + PAGE), Shadow::widen(p + 64, p + 80) clamps to (p, p + PAGE - 16) (65,520 bytes). Because that page is not covered whole, take_split leaves it unguarded/dirty, so every subsequent 16-byte refresh on that page re-copies 65,520 bytes instead of 16 bytes on main (up to ~4,095x amplification).

In addition, self.kept is never cleared once title memory and the host copy resync (update_tracked, copy_back_or_not with back == true, copy_back_marked), so a single keep_writes permanently prevents whole-page guarding on that page for the rest of the run.

Reproduced on 6d3e953 (RED):
shadow::tests::repeated_small_refreshes_beside_kept_writes_do_not_amplify_copies failed:

4 small refreshes beside kept write copied 262080 bytes (partial widening re-copies the page)

(Expected <= 64 bytes.)

2. Withheld copy_back_marks pages are not recorded in self.kept

In copy_back_marks, pages withheld in held call crate::memory::drop_withheld(page, PAGE) without recording [page, page + PAGE) via copy.remember_kept(page, page + PAGE). A later small refresh at another offset on that same page widens across the whole 64 KiB page and overwrites the withheld GPU writes with stale title memory.

Reproduced on 6d3e953 (RED):
shadow::tests::widened_refresh_preserves_withheld_marked_write_on_same_page failed:

assertion `left == right` failed: withheld marked GPU write on the same page was overwritten by widened refresh
  left: 0
 right: 221

(0xdd written at p + 4096 overwritten by a small refresh at p + 64..p + 80.)

Suggested fix & verification

  • In Shadow::widen, check has_kept per boundary page (first_start..first_end, last_start..last_end) so pages containing kept writes stay narrow while clean neighbor pages on multi-page refreshes still widen.
  • Add Shadow::forget_kept(from, to) and prune synced spans in copy_back_or_not (when back == true), copy_back_marked, and update_tracked (for each copied/zeroed (a, b) span).
  • In copy_back_marks, collect (Arc<Shadow>, usize) pairs for held pages while holding marks(), drop MARKS, and call copy.remember_kept(page, page + PAGE) before crate::memory::drop_withheld(page, PAGE).
Tested patch + regression tests (applies cleanly on 6d3e953)
diff --git a/crates/victory-gpu/src/shadow.rs b/crates/victory-gpu/src/shadow.rs
index 123f3ef..c13f409 100644
--- a/crates/victory-gpu/src/shadow.rs
+++ b/crates/victory-gpu/src/shadow.rs
@@ -433,40 +433,57 @@ impl Shadow {
         kept.insert(from, to);
     }
 
+    /// Removes `[from, to)` from the kept-writes union once title memory
+    /// and the host copy agree on those bytes again.
+    fn forget_kept(&self, from: usize, to: usize) {
+        if from >= to {
+            return;
+        }
+        let mut kept = self.kept.lock().unwrap_or_else(|e| e.into_inner());
+        if kept.is_empty() {
+            return;
+        }
+        if let Some((&start, &end)) = kept.range(..from).next_back()
+            && end > from
+        {
+            *kept.get_mut(&start).unwrap() = from;
+            if end > to {
+                kept.insert(to, end);
+                return;
+            }
+        }
+        while let Some((&start, &end)) = kept.range(from..to).next() {
+            kept.remove(&start);
+            if end > to {
+                kept.insert(to, end);
+                break;
+            }
+        }
+    }
+
     /// `[from, to)` (inside the buffer) grown to the 64 KiB pages it
-    /// touches, cut to the buffer and short of ranges holding shaders'
-    /// kept writes. A page only partly inside a refreshed range is copied
-    /// in part and stays changed ([`crate::watch::Tracked::take`]), so it
-    /// was copied again at every later refresh reaching it: in the world,
-    /// about 80% of the bytes copied per frame (400-550 MB of 550-690 MB on
-    /// an RTX 4060 Ti). Taken whole, it is
-    /// guarded and copied again only once the title writes it.
+    /// touches, cut to the buffer and skipping any leading or trailing page
+    /// that holds shaders' kept writes. A page only partly inside a refreshed
+    /// range is copied in part and stays changed
+    /// ([`crate::watch::Tracked::take`]), so it was copied again at every
+    /// later refresh reaching it: in the world, about 80% of the bytes
+    /// copied per frame (400-550 MB of 550-690 MB on an RTX 4060 Ti). Taken
+    /// whole, it is guarded and copied again only once the title writes it;
+    /// keeping a page with kept writes narrow avoids repeatedly copying the
+    /// rest of the page on every refresh.
     fn widen(&self, from: usize, to: usize) -> (usize, usize) {
-        if self.tracked.is_none() {
+        if self.tracked.is_none() || from >= to {
             return (from, to);
         }
         let (start, end) = (self.start as usize, (self.start + self.len) as usize);
-        let low = (from / PAGE * PAGE).max(start);
-        let high = to.div_ceil(PAGE).saturating_mul(PAGE).min(end);
+        let first_start = (from / PAGE * PAGE).max(start);
+        let first_end = (from / PAGE + 1).saturating_mul(PAGE).min(end);
+        let last_start = ((to - 1) / PAGE * PAGE).max(start);
+        let last_end = to.div_ceil(PAGE).saturating_mul(PAGE).min(end);
         let kept = self.kept.lock().unwrap_or_else(|e| e.into_inner());
-        if kept.len() <= 1 {
-            return match kept.first_key_value() {
-                Some((_, &end)) if end <= from => (low.max(end), high),
-                Some((&start, _)) if start >= to => (low, high.min(start)),
-                Some(_) => (from, to),
-                None => (low, high),
-            };
-        }
-        let before = kept.range(..from).next_back();
-        let after = kept.range(from..).next();
-        if before.is_some_and(|(_, &end)| end > from)
-            || after.is_some_and(|(&start, _)| start < to)
-        {
-            // Kept writes inside the range itself: as asked, no more.
-            return (from, to);
-        }
-        let low = before.map_or(low, |(_, &end)| low.max(end));
-        let high = after.map_or(high, |(&start, _)| high.min(start));
+        let has_kept = |a: usize, b: usize| kept.range(..b).next_back().is_some_and(|(_, &e)| e > a);
+        let low = if has_kept(first_start, first_end) { from } else { first_start };
+        let high = if has_kept(last_start, last_end) { to } else { last_end };
         (low, high)
     }
 
@@ -525,6 +542,7 @@ impl Shadow {
                 let whole: Vec<usize> = synced.into_iter().filter(|p| (first..last).contains(p)).collect();
                 t.taken(&whole);
             }
+            self.forget_kept(start + from, start + to);
         }
         // Every submitted step that declared the range is done with it (one
         // submission runs at a time), and the snapshot with the last range.
@@ -594,6 +612,7 @@ impl Shadow {
         if from == page && to == page + PAGE {
             t.taken(&[page / PAGE]);
         }
+        self.forget_kept(from, to);
         written.map_or(0, |_| n)
     }
 
@@ -697,11 +716,13 @@ impl Shadow {
         for (a, b) in runs {
             copied += self.copy(a, b);
             sync_before(a, b);
+            self.forget_kept(a, b);
         }
         for (a, b) in unmapped {
             // SAFETY: inside the mapping (`take_split` cuts to the buffer).
             unsafe { self.data.add(a - start).write_bytes(0, b - a) };
             sync_before(a, b);
+            self.forget_kept(a, b);
             #[cfg(feature = "diagnostics")]
             crate::copystat::add(crate::copystat::C::Unmapped, (b - a) as u64);
         }
@@ -711,6 +732,7 @@ impl Shadow {
             let started = std::time::Instant::now();
             copied += self.copy(a, b);
             sync_before(a, b);
+            self.forget_kept(a, b);
             #[cfg(feature = "diagnostics")]
             {
                 use crate::copystat::{C, add};
@@ -1000,8 +1022,12 @@ pub(crate) fn copy_back_marks(withheld: &[(Arc<Shadow>, usize, usize)], memory_w
     };
     // Held back: dropped from the copies (`crate::memory::drop_withheld`).
     if !held.is_empty() {
-        let m = marks();
-        for (_, page) in held.into_iter().filter_map(|n| page_of(&m, n)) {
+        let held_pages: Vec<(Arc<Shadow>, usize)> = {
+            let m = marks();
+            held.into_iter().filter_map(|n| page_of(&m, n)).collect()
+        };
+        for (copy, page) in held_pages {
+            copy.remember_kept(page, page + PAGE);
             crate::memory::drop_withheld(page, PAGE);
         }
     }
@@ -1528,12 +1554,12 @@ pub(crate) mod tests {
         // SAFETY: a byte of our pool.
         unsafe { ((p + 100) as *mut u8).write_volatile(8) };
         assert_eq!(copy.update(p + 64, 16), PAGE, "written again: copied again");
-        // Shaders' kept writes at the page's end: the refresh stops short.
+        // Shaders' kept writes on the page: the refresh stays narrow.
         copy.write_host((p + PAGE - 8) as u64, &[0xee]);
         copy.keep_writes(p + PAGE - 16, 16);
         // SAFETY: a byte of our pool.
         unsafe { ((p + 100) as *mut u8).write_volatile(9) };
-        assert_eq!(copy.update(p + 64, 16), PAGE - 16, "up to the kept writes");
+        assert_eq!(copy.update(p + 64, 16), 16, "stays narrow beside kept writes");
         assert_eq!(copy.read_host((p + PAGE - 8) as u64, 1)[0].to_le_bytes()[0], 0xee, "kept");
         unregister(p, p as u64);
     }
@@ -1557,7 +1583,8 @@ pub(crate) mod tests {
         copy.keep_writes(p + 3088, 16);
         copy.keep_writes(p + 2000, 8); // already covered
         copy.keep_writes(p + 8192, 16);
-        assert_eq!(copy.widen(p + 4096, p + 4112), (p + 3104, p + 8192));
+        assert_eq!(copy.widen(p + 4096, p + 4112), (p + 4096, p + 4112));
+        assert_eq!(copy.widen(p + 4096, p + PAGE + 16), (p + 4096, p + len));
         // Explicitly requested bytes that overlap a kept write stay narrow.
         assert_eq!(copy.widen(p + 2000, p + 2008), (p + 2000, p + 2008));
         assert_eq!(copy.widen(p + PAGE + 12, p + PAGE + 16), (p + PAGE, p + len));
@@ -1782,4 +1809,68 @@ pub(crate) mod tests {
         assert_eq!(pages(0x1_fff0, 0x20), 2, "a range across a page boundary");
         assert_eq!(pages(0x2_0000, 0x1_0000), 1);
     }
+
+    /// Repeated small refreshes on a page that also holds a kept GPU write
+    /// must not partially widen to `(page..kept_start)`, which leaves the page
+    /// unguarded and re-copies ~64 KiB on every call; and once the kept write
+    /// is synced back, whole-page guarding recovers.
+    #[test]
+    fn repeated_small_refreshes_beside_kept_writes_do_not_amplify_copies() {
+        let p = crate::watch::tests::pool(2);
+        let len = 2 * PAGE;
+        register(p, p as u64, len as u64);
+        let Some(copy) = find(p as u64, len as u64) else {
+            unregister(p, p as u64);
+            return; // no host GPU here
+        };
+        copy.update(p, len);
+        copy.write_host((p + PAGE - 8) as u64, &[0xee]);
+        copy.keep_writes(p + PAGE - 16, 16);
+        // SAFETY: a byte of our pool.
+        unsafe { ((p + 100) as *mut u8).write_volatile(9) };
+        let total: usize = (0..4).map(|_| copy.update(p + 64, 16)).sum();
+        assert!(
+            total <= 64,
+            "4 small refreshes beside kept write copied {total} bytes (partial widening re-copies the page)"
+        );
+        assert_eq!(copy.read_host((p + PAGE - 8) as u64, 1)[0].to_le_bytes()[0], 0xee, "kept");
+        // Once the kept range is refreshed (synced from title memory), the page can be taken whole again.
+        copy.update(p + PAGE - 16, 16);
+        // SAFETY: a byte of our pool.
+        unsafe { ((p + 100) as *mut u8).write_volatile(10) };
+        assert_eq!(copy.update(p + 64, 16), PAGE, "whole page guarded again after kept range synced");
+        assert_eq!(copy.update(p + 64, 16), 0, "clean once taken whole");
+        unregister(p, p as u64);
+    }
+
+    /// A title-memory write-marked page withheld at submission end (`held` ->
+    /// `drop_withheld`) still holds the GPU's kept writes in the copy: a small
+    /// refresh elsewhere on that page must not widen across the whole page and
+    /// overwrite them.
+    #[test]
+    fn widened_refresh_preserves_withheld_marked_write_on_same_page() {
+        let p = crate::watch::tests::pool(1);
+        register(p, p as u64, PAGE as u64);
+        let (Some(copy), Some(b)) = (find(p as u64, PAGE as u64), bitmap(true)) else {
+            unregister(p, p as u64);
+            return; // no host GPU here
+        };
+        copy.update(p, PAGE);
+        copy.write_host((p + 4096) as u64, &[0xdd]);
+        let base = copy.marks.expect("tracked memory gets mark bits") as usize;
+        let bits = b.data as *mut u32;
+        // SAFETY: a dword of the mapped title-memory mark bitmap.
+        unsafe { *bits.add(base / 32) |= 1 << (base % 32) };
+        copy_back_marks(&[], true);
+        // Title writes +100, then refreshes only +64..+80; the GPU's withheld write at +4096 must survive.
+        // SAFETY: a byte of our pool.
+        unsafe { ((p + 100) as *mut u8).write_volatile(0x33) };
+        copy.update(p + 64, 16);
+        assert_eq!(
+            copy.read_host((p + 4096) as u64, 1)[0].to_le_bytes()[0],
+            0xdd,
+            "withheld marked GPU write on the same page was overwritten by widened refresh"
+        );
+        unregister(p, p as u64);
+    }
 }

Verified locally (Windows 11, NVIDIA GeForce RTX 3060 Ti, Rust 1.98.1 MSVC):

  • cargo test -p victory-gpu --lib --locked -- shadow:: watch:: --test-threads=1 -> 29 passed, 0 failed
  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings -> 0 warnings
  • cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings -> 0 warnings
  • cargo xtask policy -> 191 files ok

Synthetic tests only; AI-assisted review.

@upipibi

upipibi commented Nov 27, 2026

Copy link
Copy Markdown

A local benchmark at 6d3e9539 against main 63bcca4 (same base), Windows 11, RTX 3070 PC, release. It is an ignored test in shadow::tests, not proposed: one 32 MiB copy over pool(512) memory, copy.update called directly, and the same random sequence on both trees, 30 frames, 3 runs each (identical every time).

scenario main this PR
A. 400 refreshes a frame of 16-256 B at random places, 16 random pages written by the "title" a frame 0.02 MB copied, 0.12-0.14 ms a frame 0.97 MB, 0.13-0.15 ms
B. your pattern: 400 refreshes a frame of 4-32 KiB over a hot set of 64 pages, 2 pages written a frame 2.84 MB, 0.27-0.28 ms 0.13 MB, 0.020 ms

B is the pattern the description measures in the title: a page cut by a refresh stays changed on main and is copied again at every later refresh. Here the PR copies 22× fewer bytes and is about 14× faster. That reproduces the effect away from the title.

A shows the other side of the widening. When the refreshes are tiny and land on pages the title writes, main copies only the asked bytes, while this PR copies the whole 64 KiB page once after each write. That is about 50× the bytes at no measurable cost here (both under 0.2 ms, the bytes still under 1 MB a frame). For a title that writes many pages each frame and refreshes only a few bytes of each, the cost would grow with the pages written. That is worth keeping in mind against the 410-550 MB the widening removes in the title. Not a reason to hold it, as far as these numbers go.

cargo test -p victory-gpu --lib shadow::tests:: at the PR head: 11 passed, 0 failed in each of 3 runs, a_partial_refresh_takes_the_whole_page and overlapping_kept_writes_remember_their_union included.

AI-assisted (Claude Code, Claude Opus 5.5 wrote and ran the local benchmark).

Xeltax added a commit to Xeltax/VIcky that referenced this pull request Nov 28, 2026
…OURCES), the texture pass's phase counters, and the queue/alias ports (VICTORY_FAIR_DUE, VICTORY_RELOOK_MS, VICTORY_WHOLE_PAGES, VICTORY_ALIAS_NOTICES, VICTORY_ALIAS_FULL_PRINT_KB, VICTORY_ALIAS_RECHECK_EVERY, VICTORY_ALIAS_COPY_AFTER_CPU); all off by default

Steps 1-3 of Fable's bake design (fable-2026-11-28-bake.md):
- phase counters of the pass over textures picked by index, always on, on
  the queue's 5-s line (snapshot, looks with prints / mapped / pending
  asks, mirror, uploads with staging and copies);
- VICTORY_FAIR_DUE=1 + VICTORY_RELOOK_MS (fxceless Marvisak#1246, Exopus-0x65f7ad0);
- VICTORY_WHOLE_PAGES=1: a refresh takes the whole 64 KiB pages it touches
  (Marvisak Marvisak#3289, QalityDev);
- VICTORY_BAKE_VERIFY=1: before each bake draw, settle DirectStorage writes
  (<= 200 ms), hash every recorded texture with a current view on the wide
  threads against its detiling's hash (mismatches due this frame), then
  drain the whole queue in rounds (TextureQueue::due_all, 2 GiB cap kept and
  logged); full once per bake frame, incremental after; one 'bake verify:'
  line per bake frame; Look::Stop logs. Turns the records on without EXACT;
- VICTORY_BAKE_SOURCES=1: the bake draw's small buffers and constants
  scanned for words naming texture views, verified first; the audit's bake
  line says 'of N candidate sources, D differ';
- alias ports: notices after our copies and writes projected onto alias
  mappings (TaynanGT fbfdd3e909, 03ecd2f876), whole prints and rechecks of
  aliased textures (kitty-core ae3cce8), alias copy after a CPU upload
  (Biskwit d59b637).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A4bpLmErkufJL3LGgfR561
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.

9 participants