From 8e9f11d618534e5d9deac73488fb0ccdf5b5c75d Mon Sep 17 00:00:00 2001 From: DiosET3RN0 <314449134+DiosET3RN0@users.noreply.github.com> Date: Fri, 27 Nov 2026 12:16:16 -0600 Subject: [PATCH] Up-copy check: what is known of copies that are gone is let go KNOWN (VICTORY_UPCOPY_CHECK) kept an entry per copy ever declared or fetched. The look at rest now keeps only the ids still in carded_copies(), before anything in it that can fail. A copy's id is never given to another copy, and nothing declares or fetches while the look runs (the submission lock is held). Co-Authored-By: Claude Fable 5.2 (cherry picked from commit 2e7e626eeb51a0482f29fec2fb16aa75259b849b) --- crates/victory-gpu/src/host/upcheck.rs | 36 +++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/crates/victory-gpu/src/host/upcheck.rs b/crates/victory-gpu/src/host/upcheck.rs index d82a0c9..63e8cd4 100644 --- a/crates/victory-gpu/src/host/upcheck.rs +++ b/crates/victory-gpu/src/host/upcheck.rs @@ -294,6 +294,14 @@ pub(super) fn fetched(copy: u64, at: usize) { known.entry(copy).or_default().fetched.insert(at / PIECE, crate::frame::current()); } +/// Keeps what is known of the copies `live` names and lets the rest go: an +/// id is never given to another copy, so what was known of a copy that is +/// gone is never asked for again. +fn forget_gone(known: &mut BTreeMap, live: impl IntoIterator) { + let live: std::collections::HashSet = live.into_iter().collect(); + known.retain(|copy, _| live.contains(copy)); +} + fn known(copy: u64, at: usize) -> String { let all = KNOWN.lock().unwrap_or_else(|e| e.into_inner()); let Some(known) = all.get(©) else { @@ -511,8 +519,15 @@ fn run(host: &Host, f: impl FnOnce(&ID3D12GraphicsCommandList)) -> Option<()> { /// The words that differ. fn look(host: &Host) -> Option { - let pass = pass(host)?; let copies = crate::shadow::carded_copies(); + // (Before anything that can fail. Nothing declares or fetches meanwhile: + // what is known of copies that are gone is let go, or `KNOWN` would keep + // an entry per copy ever written.) + { + let mut known = KNOWN.lock().unwrap_or_else(|e| e.into_inner()); + forget_gone(&mut known, copies.iter().map(|s| s.id())); + } + let pass = pass(host)?; // (copy, offset, bytes) let mut pieces: Vec<(std::sync::Arc, usize, usize)> = Vec::new(); for shadow in &copies { @@ -667,6 +682,25 @@ mod tests { assert_eq!((t.at, &t.was[..], &t.new[..]), (8, &was[3..11], &new[3..11])); } + #[test] + fn what_is_known_of_a_copy_that_is_gone_is_let_go() { + // (A map of its own: `KNOWN` is the process's.) + let mut known = BTreeMap::new(); + for copy in [3u64, 5, 8] { + let of: &mut Known = known.entry(copy).or_default(); + of.declared.push((0, 64)); + of.fetched.insert(0, copy); + } + // 5 is gone; 13 lives and nothing is known of it. + forget_gone(&mut known, [8, 3, 13]); + assert_eq!(known.keys().copied().collect::>(), [3, 8]); + for (copy, of) in &known { + assert_eq!((&of.declared[..], of.fetched.get(&0)), (&[(0, 64)][..], Some(copy))); + } + forget_gone(&mut known, []); + assert!(known.is_empty()); + } + /// The tests below want processes of their own with the relay on: each /// `VICTORY_RELAY=2 VICTORY_RELAY_COPY=1 VICTORY_UPCOPY_CHECK=1 cargo /// test -p victory-gpu --lib upcheck -- --ignored --test-threads=1