Texture pass: tell its "rest" apart (5-second line), waits for its locks

The pass over textures picked by index logged 846 of 1,408 ms (cutscene,
coolfox-20261126-223059) as "the rest". A second line now splits it:
telling the queue what came of each slot, reading the slots' records,
fingerprints after uploads and same-looks, handing first uploads to the
copy queue ahead, slots shown after their upload / flipped / made at once,
asking whether a staged texture's memory is all there, other checks; the
waits for the queue's and the views table's locks (by the pass and by other
threads, counted only when the lock was held: try_lock first); the work
before the loops (not in "all"); passes by kind (frame, early, bake) with
their time and how many stopped at their time or bytes; and the slots taken
by outcome.

The existing parts are summed in nanoseconds now: in microseconds each short
call lost what it took below the next whole one.

The pass reads the slot's view once for its placed and object checks (it
read it twice).

pass_costs (ignored test, a measurement): on this PC asking whether 1/4/16
MB of resident memory is all there takes 18/23/111 us, 0.9-15 ms when the
pages were trimmed from the working set; a fingerprint 3-7 us.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
readmet3xt-labandClaude Opus 5.5 committed 2026-11-26 22:56:37 +05:30
1 parent 2f81d0c85b
commit 0b651fa9a8
5 files changed
+323 -80

No files matched your search

+42 -2
View File
@@ -13,6 +13,28 @@ use crate::resource::{Memory, PAGEABLE_IIDS};
#[cfg(windows)]
pub(crate) mod host;
thread_local! {
/// Set while this thread runs the pass over textures picked by index
/// (`crate::draw::State::heap_textures`): its waits for the locks below
/// are counted apart from other threads' ([`LOCK_WAITS`]).
pub(crate) static IN_TEXTURE_PASS: std::cell::Cell<bool> = const { std::cell::Cell::new(false) };
}
/// Nanoseconds threads waited for a lock another thread held, since the
/// last 5-second line: the queue of textures picked by index's
/// (`host::TextureQueue`) by the texture pass's thread and by the others
/// (the threads that note slot writes in it), then the table of views'
/// ([`VIEWS`]) likewise. Only waits are counted: a lock taken at once costs
/// nothing here (`try_lock` first).
pub(crate) static LOCK_WAITS: [std::sync::atomic::AtomicU64; 4] = [const { std::sync::atomic::AtomicU64::new(0) }; 4];
/// A wait for lock `which` (0: the texture queue's, 1: the views table's)
/// that began at `started` is over: counted in [`LOCK_WAITS`].
pub(crate) fn waited(which: usize, started: std::time::Instant) {
let other = usize::from(!IN_TEXTURE_PASS.get());
LOCK_WAITS[2 * which + other].fetch_add(started.elapsed().as_nanos() as u64, std::sync::atomic::Ordering::Relaxed);
}
const HEAP_IIDS: [Iid; 4] = [
guid(
0x8efb471d,
@@ -1051,11 +1073,29 @@ fn words_for(view: View) -> [u32; 2] {
}
fn views_read() -> std::sync::RwLockReadGuard<'static, Views> {
VIEWS.read().unwrap_or_else(|e| e.into_inner())
match VIEWS.try_read() {
Ok(views) => views,
Err(std::sync::TryLockError::Poisoned(e)) => e.into_inner(),
Err(std::sync::TryLockError::WouldBlock) => {
let started = std::time::Instant::now();
let views = VIEWS.read().unwrap_or_else(|e| e.into_inner());
waited(1, started);
views
}
}
}
fn views_write() -> std::sync::RwLockWriteGuard<'static, Views> {
VIEWS.write().unwrap_or_else(|e| e.into_inner())
match VIEWS.try_write() {
Ok(views) => views,
Err(std::sync::TryLockError::Poisoned(e)) => e.into_inner(),
Err(std::sync::TryLockError::WouldBlock) => {
let started = std::time::Instant::now();
let views = VIEWS.write().unwrap_or_else(|e| e.into_inner());
waited(1, started);
views
}
}
}
/// For the memory line: the distinct views kept ([`Views`]), those of them