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

+40
View File
@@ -814,6 +814,46 @@ pub(crate) fn unstage(resource: This) {
}
}
/// Where a staged title texture's memory is: address and bytes.
pub(crate) fn staged_memory(resource: This) -> Option<(u64, u64)> {
let map = STAGING.lock().unwrap_or_else(|e| e.into_inner());
let (at, len) = map.as_ref()?.get(&(resource as usize))?.memory();
Some((at as u64, len as u64))
}
/// A fingerprint of the title memory `[at, at + len)`, never 0: of all of
/// it up to 48 KiB, else of 16 KiB at its start, its middle and its end
/// (a texture streams in whole mips; the small ones lie first). Read
/// through the kernel, so pages not there count as zeros.
pub(crate) fn fingerprint(at: u64, len: u64) -> u64 {
const WINDOW: usize = 16 << 10;
thread_local! {
static READ: std::cell::RefCell<Vec<u8>> = const { std::cell::RefCell::new(Vec::new()) };
}
let len = len as usize;
let mut hasher = blake3::Hasher::new();
READ.with(|read| {
let mut read = read.borrow_mut();
read.resize(3 * WINDOW, 0);
let mut take = |from: usize, bytes: usize| {
read[..bytes].fill(0);
crate::host::copy_mapped(read.as_mut_ptr(), (at as usize + from) as *const u8, bytes, false);
hasher.update(&read[..bytes]);
};
if len <= 3 * WINDOW {
take(0, len);
} else {
take(0, WINDOW);
take((len / 2) & !0xfff, WINDOW);
take(len - WINDOW, WINDOW);
}
});
let hash = hasher.finalize();
let mut first = [0u8; 8];
first.copy_from_slice(&hash.as_bytes()[..8]);
u64::from_le_bytes(first) | 1
}
/// Whether a title texture has a staging buffer: a list recorded its
/// upload, and the lists that sample it check it at submission.
pub(crate) fn is_staged(resource: This) -> bool {