Texture uploads wait for no mapping, ask no guards and hash cheaply; the sweep looks at a part; bakes pass once for what is new

A bake's uploads waited for the lock the runtime holds while it remaps, and a staging buffer a draw kept waited at every later
refresh (29 to 239 ms a frame, all threads, run n04): gone, a read through the kernel gets every page. A staging buffer made for
one upload asks neither the write watch nor the guards (VICTORY_TEXTURE_ONCE=0: as before). blake3 makes way for a 128-bit digest
(0.035 against 0.2 ms a megabyte). While textures are kept for minutes the sweep looks at 8,192 a time (VICTORY_TEXTURE_SWEEP=whole).
The pass before a bake is made again only for something new.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
localandClaude Opus 5.5 committed 2026-11-25 05:14:38 -06:00
1 parent 708c13484c
commit 6b07e2e02d
5 files changed
+215 -38

No files matched your search

+34 -4
View File
@@ -1180,7 +1180,7 @@ pub(crate) struct HostTexture {
/// What a host copy was filled with last: the first level of it and the
/// hash of the title memory it was read from.
#[cfg(windows)]
pub(crate) type Holds = std::sync::Mutex<Option<(u32, blake3::Hash)>>;
pub(crate) type Holds = std::sync::Mutex<Option<(u32, crate::texture::Digest)>>;
/// [`HostTexture::serial`] of the last one made.
#[cfg(windows)]
@@ -2051,15 +2051,37 @@ pub(crate) fn let_go_idle() {
}
by_age.sort_unstable();
}
let every = all.iter().copied().filter(|_| most == u64::MAX);
for at in every.chain(by_age.iter().map(|&(_, at)| at)) {
// Without one, while textures are kept for minutes, a part of them at
// each look, the next one at the next: a play has over 100,000
// (`VICTORY_TEXTURE_SWEEP=whole`: all each time, as before).
const PART: usize = 8192;
static FROM: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
static WHOLE: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
let whole = *WHOLE.get_or_init(|| std::env::var_os("VICTORY_TEXTURE_SWEEP").is_some_and(|v| v == "whole"));
let part = if most != u64::MAX {
0
} else if whole || idle_ms < 60_000 {
usize::MAX
} else {
PART
};
let from = if part == PART { FROM.load(Relaxed) } else { 0 };
let mut looked = 0;
let began = std::time::Instant::now();
for at in all.range(from..).take(part).copied().chain(by_age.iter().map(|&(_, at)| at)) {
if bytes >= most {
break;
}
looked += 1;
if part == PART {
FROM.store(if looked == PART { at + 1 } else { 0 }, Relaxed);
}
// SAFETY: a texture leaves the table before it is freed, under the
// lock held here (`Drop for Resource`).
let r = unsafe { &*(at as *const Resource) };
if !fills(&r.desc) || crate::texture::host_wrote(at) {
// (Without its lock first: most were used lately or have none.)
let used = r.host.used.load(Relaxed);
if used == 0 || !fills(&r.desc) || !crate::host::long_ago(used, idle_ms, IDLE_FRAMES) || crate::texture::host_wrote(at) {
continue;
}
let gone = {
@@ -2091,6 +2113,9 @@ pub(crate) fn let_go_idle() {
crate::host::retire(host);
}
}
SWEPT_US[0].fetch_add(1, Relaxed);
SWEPT_US[1].fetch_add(began.elapsed().as_micros() as u64, Relaxed);
SWEPT_US[2].fetch_max(began.elapsed().as_micros() as u64, Relaxed);
if went > 0 {
crate::host::trail(|| {
format!(
@@ -2102,6 +2127,11 @@ pub(crate) fn let_go_idle() {
}
}
/// Since the start: looks of [`let_go_idle`], their microseconds, and the
/// longest one's.
#[cfg(windows)]
pub(crate) static SWEPT_US: [std::sync::atomic::AtomicU64; 3] = [const { std::sync::atomic::AtomicU64::new(0) }; 3];
/// For the memory line: the host copies the sweep never lets go
/// ([`let_go_idle`] takes only copies of textures the title fills that the
/// host never copied into), by what would say they are dead weight. A