Repository navigation
Conversation
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`.
c4d2062 to
d99e868
Compare
Dukestar69
left a comment
There was a problem hiding this comment.
Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090):
- Widening tracked refreshes in
Shadow::widento 64 KiB page boundaries (clamped to the buffer and stopping short ofShadow::keptranges, withbusyranges still subtracted afterward) cleanly lets touched pages be taken whole and guarded instead of repeatedly re-copying partial pages, withTakenWholeBytes/TakenPartBytesdiagnostics counters matching. cargo test -p victory-gpu --lib shadow:: -- --test-threads=1(RTX 5090): 11 passed, 0 failed (includinga_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).
|
WARP verification report (test report only, no code changes)
AI use: Claude Code (Claude Sonnet 5.5) |
|
I tested a port of 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. |
|
I checked a scaling case for the kept-write lookup on 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 @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 |
|
Thanks @andrewpozdnakov7-jpg — reviewed and added as-is: 6d3e953 is now on the branch with your authorship. Checked here on an RTX 4060 Ti: |
|
Independent local verification on Windows 11 x64, Intel Arc B580 12 GB (12 cores), at this PR's head 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 |
|
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
Around 2-3 ms off preparing, inside the spread of the controls. Its two new AI-assisted (Claude); measured on my machine, no game data shared. |
AndyLatimer
left a comment
There was a problem hiding this comment.
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, checkhas_keptper 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 incopy_back_or_not(whenback == true),copy_back_marked, andupdate_tracked(for each copied/zeroed(a, b)span). - In
copy_back_marks, collect(Arc<Shadow>, usize)pairs forheldpages while holdingmarks(), dropMARKS, and callcopy.remember_kept(page, page + PAGE)beforecrate::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 failedcargo clippy -p victory-gpu --all-targets --locked -- -D warnings-> 0 warningscargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings-> 0 warningscargo xtask policy-> 191 files ok
Synthetic tests only; AI-assisted review.
…1), after upstream Marvisak#3289 (R55) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012yVGuwMXsHSx2BHbb9L2Yw
|
A local benchmark at
B is the pattern the description measures in the title: a page cut by a refresh stays changed on A shows the other side of the widening. When the refreshes are tiny and land on pages the title writes,
AI-assisted (Claude Code, Claude Opus 5.5 wrote and ran the local benchmark). |
…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
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::updatenow 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):
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_releasedandlists_share_a_table_and_copies_keep_their_viewsfail on main as well on this RTX 4060 Ti); clippy clean with and withoutdiagnostics.