diff --git a/crates/victory-gpu/src/copystat.rs b/crates/victory-gpu/src/copystat.rs index 6abd41b..292d995 100644 --- a/crates/victory-gpu/src/copystat.rs +++ b/crates/victory-gpu/src/copystat.rs @@ -37,6 +37,8 @@ pub(crate) enum C { TexWatched, TexHashed, TexChanged, + /// Changes of guarded textures the hash found and the guard did not see. + TexHot, /// Frames presented since the last line (what the line divides by). Frames, /// Calls of list methods that record into a host list, and the @@ -1060,7 +1062,7 @@ pub(crate) fn log(frames: f64) { {:.0} skipped {:.1} MB; {:.0} runs {:.1} ms; {:.0} queries {:.2} ms, moves {:.2} ms, \ {:.2} MB unmapped; {:.0} page faults; {:.0} watches {:.2} ms, {:.1} MB checked, {:.1} MB \ unchanged; {:.1} fallbacks; {:.0} guard faults; textures {:.1} MB watched and \ - changed, {:.1} MB hashed, {:.1} MB of them changed", + changed, {:.1} MB hashed, {:.1} MB of them changed, {:.1} changes the guard did not see", c[C::Submissions as usize], c[C::Copies as usize], mb(c[C::CopyBytes as usize]), @@ -1084,6 +1086,7 @@ pub(crate) fn log(frames: f64) { mb(c[C::TexWatched as usize]), mb(c[C::TexHashed as usize]), mb(c[C::TexChanged as usize]), + c[C::TexHot as usize], ); tracing::info!( "recording per frame ({frames:.0} frames): {:.0} list calls {:.1} ms (all recording \ diff --git a/crates/victory-gpu/src/texture.rs b/crates/victory-gpu/src/texture.rs index f815393..cbf5974 100644 --- a/crates/victory-gpu/src/texture.rs +++ b/crates/victory-gpu/src/texture.rs @@ -66,6 +66,31 @@ struct Last { asked: u64, /// The frame a partly mapped texture was last read in. partial: Option, + /// Until this frame a guarded texture is hashed at every check: its + /// first checks, and after the hash found a change the guard had not + /// seen ([`hot_textures`]). 0: not checked under the guard yet. + hot_until: u64, +} + +/// Frames a guarded texture is hashed at every check from its first check, +/// and after the hash found a change the guard did not see. +const HOT_FRAMES: u64 = 64; + +/// Whether a guarded texture whose memory the hash found changed although +/// the guard saw no write is hashed at every check for a while +/// ([`HOT_FRAMES`]), not every eighth frame. A title that writes such a +/// texture through another view of its pages (the guard sees none of it) +/// every frame, a video's frames in a ring of three, showed each one up +/// to eight frames late and in turns: the boot logo video and the loading +/// animation flickered between old and new pictures (fx-flicker run 1441: +/// the presented picture cycled through three, a new one every eight +/// frames). A texture also starts hot, for the ones written that way from +/// the start (the six-star screen of the first seconds, which the hash +/// never caught changing). `VICTORY_TEXTURE_HOT=0`: every eighth frame +/// only, as before. +fn hot_textures() -> bool { + static ON: std::sync::OnceLock = std::sync::OnceLock::new(); + *ON.get_or_init(|| std::env::var_os("VICTORY_TEXTURE_HOT").is_none_or(|v| v != "0")) } // SAFETY: the staging mapping is written only at submission, under @@ -647,17 +672,37 @@ impl Staging { // texture's address, so the textures take turns. // `VICTORY_TEXTURE_GUARD=0` hashes at every check, as before. static GUARD: std::sync::OnceLock = std::sync::OnceLock::new(); + // The guard saw no write: a change the hash finds came another way. + let mut blind = false; if *GUARD.get_or_init(|| std::env::var_os("VICTORY_TEXTURE_GUARD").is_none_or(|v| v != "0")) && let Some((now, written)) = waited(1, || crate::watch::writes(start, start + size, true)) { const HASH_EVERY: u64 = 8; let unwritten = last.asked != 0 && written.iter().all(|&(_, w)| w <= last.asked); last.asked = now; - let turn = crate::frame::current().wrapping_add((start >> 16) as u64).is_multiple_of(HASH_EVERY); - if unwritten && !turn { + let frame = crate::frame::current(); + let turn = frame + .wrapping_add((start >> 16) as u64) + .is_multiple_of(HASH_EVERY); + // A texture starts hot: one written that way from its first + // frames on changes before the hash has ever caught it. + if last.hot_until == 0 { + last.hot_until = frame + HOT_FRAMES; + } + let hot = hot_textures() && frame < last.hot_until; + if unwritten && !turn && !hot { return 0; } + blind = unwritten; } + // A change the guard did not see: hashed at every check for a while. + let found_blind = |last: &mut Last| { + if blind && hot_textures() { + last.hot_until = crate::frame::current() + HOT_FRAMES; + #[cfg(feature = "diagnostics")] + crate::copystat::add(crate::copystat::C::TexHot, 1); + } + }; // From here on the texture's memory may be read in place. Held until // that read is done: the runtime changes what title memory shows // only with this taken alone, so what `committed` finds mapped @@ -707,7 +752,9 @@ impl Staging { if changed { crate::copystat::add(crate::copystat::C::TexChanged, size as u64); } - let _ = changed; + if changed { + found_blind(last); + } return size; } if through_copy() { @@ -719,6 +766,7 @@ impl Staging { return size; } last.hash = Some(hash); + found_blind(last); self.detile(tiled); #[cfg(feature = "diagnostics")] crate::copystat::add(crate::copystat::C::TexChanged, size as u64); @@ -735,6 +783,7 @@ impl Staging { return size; } last.hash = Some(hash); + found_blind(last); self.detile(tiled); #[cfg(feature = "diagnostics")] crate::copystat::add(crate::copystat::C::TexChanged, size as u64);