diff --git a/crates/victory-gpu/src/draw.rs b/crates/victory-gpu/src/draw.rs index 653d221..e5fd151 100644 --- a/crates/victory-gpu/src/draw.rs +++ b/crates/victory-gpu/src/draw.rs @@ -110,6 +110,14 @@ fn bake_exact() -> bool { *ON.get_or_init(|| std::env::var_os("VICTORY_BAKE_EXACT").is_none_or(|v| v != "0")) } +/// Whether a texture found changed with nothing to tell of it is looked at +/// again in the next frame (`VICTORY_RECHECK_SOON=0`: after four, as +/// before). +fn recheck_soon() -> bool { + static ON: std::sync::OnceLock = std::sync::OnceLock::new(); + *ON.get_or_init(|| std::env::var_os("VICTORY_RECHECK_SOON").is_none_or(|v| v != "0")) +} + /// Frames ahead the pass before a bake takes slots from that are due only /// then ([`bake_exact`]): those of notices (1 and 2), and the first looks /// again ([`RECHECK_FRAMES`]). @@ -2014,11 +2022,14 @@ impl State { host.texture_slots_waiting(frame); } let baking = crate::texture::BAKING.get(); - let (due, census) = if baking { - host.texture_slots_due(frame + BAKE_AHEAD, 1 << 16) - } else { - host.texture_slots_due(frame, 4096) - }; + let (mut due, census) = host.texture_slots_due(frame, if baking { 1 << 16 } else { 4096 }); + // (Those that are due later after all that are due.) + let on_time = due.len(); + if baking { + let known: std::collections::HashSet = due.iter().map(|&(index, _)| index).collect(); + let (ahead, _) = host.texture_slots_due(frame + BAKE_AHEAD, 1 << 16); + due.extend(ahead.into_iter().filter(|(index, _)| !known.contains(index))); + } HEAP_TEXTURES_WAITING.store(census[0], Ordering::Relaxed); for (count, now) in HEAP_TEXTURES_QUEUE.iter().zip(census) { count.store(now, Ordering::Relaxed); @@ -2061,7 +2072,7 @@ impl State { // drains; `VICTORY_TEXTURE_CATCHUP=0` keeps the plain budget. static CATCHUP: std::sync::OnceLock = std::sync::OnceLock::new(); let catchup = *CATCHUP.get_or_init(|| std::env::var_os("VICTORY_TEXTURE_CATCHUP").is_none_or(|v| v != "0")); - let (per_frame, span) = if catchup && due.len() >= 1024 { (per_frame * 3, span * 3) } else { (per_frame, span) }; + let (per_frame, span) = if catchup && on_time >= 1024 { (per_frame * 3, span * 3) } else { (per_frame, span) }; // A run made early (`State::early_textures`) has a budget of its // own: its bytes on top of what the frame has spent so far. // (Not `most`: that is the longest wait between looks, used below.) @@ -2095,6 +2106,12 @@ impl State { // first look for the rest of the run. The look reads 48 KiB; // only a changed texture is uploaded again. // `VICTORY_HEAP_RECHECK=0`: uploaded once, as before. + // One found changed by such a look is looked at in the next frame + // again: the textures left that change unnoticed are ones the + // title paints all the time through another view of their pages + // (all their blocks are shown at other addresses too), and each + // was shown four frames late, over and over. + let mut again_in = RECHECK_FRAMES[0]; if let Some((at, len, print, looks, uploaded)) = host.texture_slot_checked(index) { if crate::texture::fingerprint(at, len) == print { HEAP_TEXTURES_RECHECKED[0].fetch_add(1, Ordering::Relaxed); @@ -2106,6 +2123,9 @@ impl State { } continue; } + if recheck_soon() { + again_in = 1; + } let n = HEAP_TEXTURES_RECHECKED[1].fetch_add(1, Ordering::Relaxed); if n < 200 || n.is_multiple_of(1000) { // Whether its pages are the title's at other addresses @@ -2248,7 +2268,7 @@ impl State { match memory { Some((at, len)) => { let print = crate::texture::fingerprint(at, len); - host.texture_slot_recheck(index, write, frame + RECHECK_FRAMES[0], (at, len), print, 0, frame); + host.texture_slot_recheck(index, write, frame + again_in, (at, len), print, 0, frame); } None => host.texture_slot_done(index, write, again), } @@ -2315,7 +2335,7 @@ impl State { // Whole and uploaded: looked at again (see above). Some((at, len)) => { let print = crate::texture::fingerprint(at, len); - host.texture_slot_recheck(index, write, frame + RECHECK_FRAMES[0], (at, len), print, 0, frame); + host.texture_slot_recheck(index, write, frame + again_in, (at, len), print, 0, frame); } None => host.texture_slot_done(index, write, again), } diff --git a/crates/victory-gpu/src/list.rs b/crates/victory-gpu/src/list.rs index 140b755..84aa3a3 100644 --- a/crates/victory-gpu/src/list.rs +++ b/crates/victory-gpu/src/list.rs @@ -1023,6 +1023,25 @@ extern "system" fn copy_texture_region( // A depth texture shaders also write: what they wrote, first (the // source above too). list.twin_use(dst.resource, false, true); + // The first copy into a texture of the title's: what it does not + // write is what title memory holds, as on the console. (The host + // copy is cut from a block and held whatever lay there, and no + // upload is made once a copy wrote it: the atlas the title copies + // its baked decorations into, a 2048x2048 BC3 texture of which a + // bake writes 256x256 at most, was drawn over a character's face + // with other textures' bytes wherever nothing was baked, runs n01 and + // textures-1.) + static OVER: std::sync::OnceLock = std::sync::OnceLock::new(); + if *OVER.get_or_init(|| std::env::var_os("VICTORY_COPY_OVER_TITLE").is_none_or(|v| v != "0")) + && crate::texture::title_written(to) + && !crate::texture::host_wrote(dst.resource as usize) + { + crate::texture::upload(list, dst.resource, to); + // (Done before the title's copy writes over it.) + if list.used(dst.resource as usize) { + ensure_state(list, dst.resource, COPY_SOURCE); + } + } // A destination made level by level gets the level's memory ahead // of this list (`crate::tiles`): the title's bake copies each level // of its result into a block-compressed texture of that kind, and diff --git a/crates/victory-gpu/src/resource.rs b/crates/victory-gpu/src/resource.rs index dc3de0d..d207e40 100644 --- a/crates/victory-gpu/src/resource.rs +++ b/crates/victory-gpu/src/resource.rs @@ -1430,6 +1430,30 @@ pub(crate) fn alias_of(this: This) -> Option { && o.desc.flags & DEPTH == 0 && target_format(o.desc.format) == o.desc.format && element(o.desc.format).is_some_and(|e| e.1 == 1 && Some(e) == element(r.desc.format)); + if !same && r.desc.sample_count <= 1 { + // What shaders wrote there is on the card in the other texture; this + // one is filled from title memory, which they never reached. Each + // kind of pair is said once. + static SAID: std::sync::Mutex> = + std::sync::Mutex::new(std::collections::BTreeSet::new()); + let pair = [ + r.desc.width as u32, + r.desc.height, + r.desc.format, + o.desc.width as u32, + o.desc.height, + o.desc.format, + ]; + let mut said = SAID.lock().unwrap_or_else(|e| e.into_inner()); + if said.len() < 64 && said.insert(pair) { + tracing::warn!( + view = ?this, + texture = ?other, + "a placed texture lies where a texture the host writes does, and is not like it (width, height, format of each): {pair:?}, levels {} and {}, layers {} and {}", + r.desc.mip_levels, o.desc.mip_levels, r.desc.depth_or_array_size, o.desc.depth_or_array_size + ); + } + } same.then_some(other) }