Exact texture refreshes read through the kernel before waiting

The uploads before a bake must read title memory as it is (`exact`), so
while the runtime remapped title memory they waited for it to finish,
even with VICTORY_TEXTURE_NO_WAIT=1: 808 of 866 ms of texture refreshes
a frame in a cutscene second (diag run 2026-11-26 15:58). Now such a
refresh reads the texture whole through the kernel first: that read
needs no lock, gets every byte as title memory holds it at that moment,
and fails where a page is away; only then does it wait, as before. The
frame line counts both. VICTORY_EXACT_NO_WAIT=0: always waits.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
readmet3xt-labandClaude Opus 5.5 committed 2026-11-26 16:44:17 +05:30
1 parent b3d49db34f
commit 3cb7b8f1d0
2 files changed
+69

No files matched your search

+9
View File
@@ -8776,6 +8776,15 @@ impl Meter {
with less than was mapped (looked at again)"
);
}
let [read, waited] =
[0, 1].map(|i| crate::texture::EXACT_UNLOCKED[i].swap(0, Ordering::Relaxed) as f64 / frames);
if read + waited > 0.0 {
tracing::info!(
"exact texture refreshes (uploads before a bake) that found title memory being remapped, per frame: \
{read:.1} read whole through the kernel without waiting, {waited:.1} waited (a page was not there) \
(VICTORY_EXACT_NO_WAIT=0: all wait)"
);
}
}
{
let [copies, joined] = [0, 1].map(|i| COPIES_JOINED[i].swap(0, Ordering::Relaxed) as f64 / frames);
+60
View File
@@ -401,6 +401,27 @@ fn fill_unlocked() -> bool {
/// got less than was mapped (their slots are looked at again).
pub(crate) static UNLOCKED: [std::sync::atomic::AtomicU64; 4] = [const { std::sync::atomic::AtomicU64::new(0) }; 4];
/// Since the last frame-rate line, exact refreshes (for a bake) that found
/// the runtime remapping title memory ([`exact_unlocked`]): read whole
/// through the kernel without waiting, and those that had to wait (a page
/// was not there).
pub(crate) static EXACT_UNLOCKED: [std::sync::atomic::AtomicU64; 2] = [const { std::sync::atomic::AtomicU64::new(0) }; 2];
/// Whether an exact refresh (the uploads before a bake, `BAKING`) that
/// finds the runtime remapping title memory first reads the texture whole
/// through the kernel, and waits for the remapping to end only if a page of
/// it is not there (`VICTORY_EXACT_NO_WAIT=0`: it always waits, as before).
/// A read through the kernel that succeeds got every byte as title memory
/// holds it at that moment, which is what waiting gave; it fails, rather
/// than reading something else, where a page is away. Waiting made the
/// texture refreshes of a cutscene second 866 ms a frame, 808 of them
/// waiting for title memory to hold still (diag run of 2026-11-26 15:58,
/// with `VICTORY_TEXTURE_NO_WAIT=1`, where only exact refreshes wait).
fn exact_unlocked() -> bool {
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
*ON.get_or_init(|| std::env::var_os("VICTORY_EXACT_NO_WAIT").is_none_or(|v| v != "0"))
}
/// Since the last frame-rate line, of texture refreshes on every thread, in
/// microseconds: waiting for the texture's own lock (another thread is
/// refreshing the same texture), asking the write watch and the guards,
@@ -1342,6 +1363,19 @@ impl Staging {
return self.refresh_unlocked(last, size);
};
mapped
} else if exact && exact_unlocked() {
match crate::watch::title_memory_reading_now() {
Some(mapped) => mapped,
None => match self.refresh_exact_unlocked(last, size) {
Some(read) => {
if read {
found_blind(last);
}
return size;
}
None => waited(2, crate::watch::title_memory_reading),
},
}
} else {
waited(2, crate::watch::title_memory_reading)
};
@@ -1447,6 +1481,32 @@ impl Staging {
}
}
/// An exact refresh (for a bake) that finds the runtime remapping
/// title memory ([`exact_unlocked`]): the texture is read whole through
/// the kernel, which needs no lock and fails if a page of it is not
/// there; read, it is what title memory holds now, as a read under the
/// lock would be. `Some(changed)` if read (and detiled if it changed),
/// `None` if a page was missing: then the refresh waits for the lock
/// as before.
fn refresh_exact_unlocked(&self, last: &mut Last, size: usize) -> Option<bool> {
use std::sync::atomic::Ordering::Relaxed;
let mut changed = false;
let read = with_read(size, |read| {
if !crate::host::read_into(self.memory, read) {
return false;
}
let hash = digest(read);
if last.hash != Some(hash) {
last.hash = Some(hash);
self.detile(read);
changed = true;
}
true
});
EXACT_UNLOCKED[usize::from(!read)].fetch_add(1, Relaxed);
read.then_some(changed)
}
/// The first filling of the staging buffer while the runtime is
/// remapping title memory, of a texture not all of which can be read:
/// with the pages that are there, zeros for the others, as a partly