Textures picked by index are looked at again after their upload (characters' skin and hair without colour in most launches)

A texture a shader picks by index was uploaded once, when the title wrote
its view, and again only if the view was rewritten or the runtime told of
a remap. The title often fills the texture's memory only afterwards (its
streaming reads land later), so the host copy kept what the memory held at
the first look for the rest of the run: zeros. Which textures lost that
race changed from launch to launch; the main character's face came out
black and her hair pale in about three launches of four.

Now a texture uploaded whole is looked at again after 4, 12, 40, 120 and
400 frames (a fingerprint of 48 KiB of its memory); a changed one is
uploaded again and the looks start over. One test launch re-uploaded more
than 6,000 textures this way. VICTORY_HEAP_RECHECK=0 turns it off.

Known gap: the fingerprint samples the start, middle and end of the
memory, so a texture whose other parts arrive later is still missed.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
fxcelessandClaude Fable 5.2 committed 2026-11-24 19:29:47 -05:00
1 parent 31714deb2d
commit a803c87c48
3 files changed
+146 -3

No files matched your search

+60 -1
View File
@@ -333,6 +333,21 @@ pub(crate) static HEAP_TEXTURES_WAITING: AtomicU64 = AtomicU64::new(0);
/// Passes that made no texture because the card had no room
/// (`crate::resource::room`), for the memory line.
pub(crate) static HEAP_TEXTURES_FULL: AtomicU64 = AtomicU64::new(0);
/// Frames after a whole upload of a texture picked by index at which its
/// memory is looked at again, each counted from the look before.
const RECHECK_FRAMES: [u64; 5] = [4, 12, 40, 120, 400];
/// Looks at uploaded textures picked by index that found the memory as it
/// was, and that found it changed (uploaded again), since the start.
pub(crate) static HEAP_TEXTURES_RECHECKED: [AtomicU64; 2] = [AtomicU64::new(0), AtomicU64::new(0)];
/// Whether textures picked by index are looked at again after their upload
/// (`VICTORY_HEAP_RECHECK=0`: no).
fn heap_recheck() -> bool {
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
*ON.get_or_init(|| std::env::var_os("VICTORY_HEAP_RECHECK").is_none_or(|v| v != "0"))
}
/// Times a placed texture's slot was passed over because its memory is not
/// mapped.
pub(crate) static HEAP_TEXTURES_AWAY: AtomicU64 = AtomicU64::new(0);
@@ -1530,6 +1545,38 @@ impl State {
// every 120 frames, changed or not; and asked by its first
// page alone, one whose first page is the one missing counted
// as not there.)
// A slot uploaded whole is looked at again a few times
// (`RECHECK_FRAMES`): the title writes a texture's view, and
// may fill the texture's memory itself only afterwards, with
// no descriptor write and nothing from the runtime to tell of
// it. The host copy then kept what the memory held at the
// 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.
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);
match RECHECK_FRAMES.get(usize::from(looks) + 1) {
Some(wait) => {
host.texture_slot_recheck(index, write, frame + wait, (at, len), print, looks + 1, uploaded)
}
None => host.texture_slot_done(index, write, None),
}
continue;
}
let n = HEAP_TEXTURES_RECHECKED[1].fetch_add(1, Ordering::Relaxed);
if n < 200 || n.is_multiple_of(1000) {
tracing::warn!(
slot = index,
address = format_args!("{at:#x}"),
bytes = len,
frames_after_upload = frame.saturating_sub(uploaded),
looks,
changed = n + 1,
"a texture picked by index changed after its upload with nothing to tell of it: uploaded again"
);
}
}
let mut partly = None;
if let Some(View::Placed(false, resource, desc)) = heap.handle(index).and_then(crate::descriptor::view) {
let address = u64::from(desc[10]) | u64::from(desc[11]) << 32;
@@ -1633,11 +1680,23 @@ impl State {
// yet, makes it anew. (Kept for those until now: every partly
// streamed texture of the heap held a staging buffer of its full
// size for good.)
let memory = if again.is_none() && heap_recheck() {
crate::texture::staged_memory(resource)
} else {
None
};
crate::texture::unstage(resource);
SPENT.fetch_add(bytes, Ordering::Relaxed);
HEAP_TEXTURE_BYTES.fetch_add(bytes, Ordering::Relaxed);
HEAP_TEXTURES.fetch_add(1, Ordering::Relaxed);
host.texture_slot_done(index, write, again);
match memory {
// 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);
}
None => host.texture_slot_done(index, write, again),
}
}
}