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:
1 parent
2f81d0c85b
commit
0b651fa9a8
5 files changed
+323
-80
No files matched your search
@@ -1759,6 +1759,21 @@ fn null_sampler(at: D3D12_CPU_DESCRIPTOR_HANDLE) {
|
||||
}
|
||||
|
||||
impl HostHeap {
|
||||
/// The queue of textures picked by index, locked; a wait for its lock
|
||||
/// is counted (`super::LOCK_WAITS`).
|
||||
fn queue(&self) -> std::sync::MutexGuard<'_, TextureQueue> {
|
||||
match self.textures.try_lock() {
|
||||
Ok(queue) => queue,
|
||||
Err(std::sync::TryLockError::Poisoned(e)) => e.into_inner(),
|
||||
Err(std::sync::TryLockError::WouldBlock) => {
|
||||
let started = std::time::Instant::now();
|
||||
let queue = self.textures.lock().unwrap_or_else(|e| e.into_inner());
|
||||
super::waited(0, started);
|
||||
queue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// `n` consecutive free dynamic slots (view heaps only), taken until
|
||||
/// [`HostHeap::release`]: the first's index.
|
||||
pub(crate) fn dynamic(&self, n: u32) -> Option<u32> {
|
||||
@@ -1839,14 +1854,14 @@ impl HostHeap {
|
||||
/// ([`TextureQueue::due`]), and the queue's counts
|
||||
/// ([`TextureQueue::census`]).
|
||||
pub(crate) fn texture_slots_due(&self, frame: u64, max: usize) -> (Vec<(u32, u64)>, [u64; 5]) {
|
||||
let (due, census) = self.textures.lock().unwrap_or_else(|e| e.into_inner()).due_and_census(frame);
|
||||
let (due, census) = self.queue().due_and_census(frame);
|
||||
(if max == 0 { Vec::new() } else { due.order(max) }, census)
|
||||
}
|
||||
|
||||
/// A number that changes when a slot is written or made due anew, and
|
||||
/// whether memory was noted since a pass last took the notes.
|
||||
pub(crate) fn texture_news(&self) -> (u64, bool) {
|
||||
let writes = self.textures.lock().unwrap_or_else(|e| e.into_inner()).writes;
|
||||
let writes = self.queue().writes;
|
||||
let noted = |ranges: &Mutex<Vec<(u64, u64)>>| !ranges.lock().unwrap_or_else(|e| e.into_inner()).is_empty();
|
||||
(writes, noted(&REMAPPED) || noted(&PAGE_WRITTEN) || noted(&BAKE_PAGE_WRITTEN))
|
||||
}
|
||||
@@ -1856,7 +1871,7 @@ impl HostHeap {
|
||||
/// look): for the card accounting line
|
||||
/// (`crate::resource::card_accounting`).
|
||||
pub(crate) fn texture_slots_all_due(&self, frame: u64) -> Vec<(u32, bool)> {
|
||||
let textures = self.textures.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let textures = self.queue();
|
||||
textures
|
||||
.slots
|
||||
.iter()
|
||||
@@ -1870,7 +1885,7 @@ impl HostHeap {
|
||||
/// that many bytes of its memory there, not all), or not until the
|
||||
/// slot is written again.
|
||||
pub(crate) fn texture_slot_done(&self, index: u32, write: u64, again: Option<(u64, u64)>) {
|
||||
let mut textures = self.textures.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let mut textures = self.queue();
|
||||
match again {
|
||||
Some((frame, mapped)) => textures.partly(index, write, frame, mapped),
|
||||
None => textures.done(index, write),
|
||||
@@ -1889,37 +1904,37 @@ impl HostHeap {
|
||||
looks: u8,
|
||||
uploaded: u64,
|
||||
) {
|
||||
let mut textures = self.textures.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let mut textures = self.queue();
|
||||
textures.recheck(index, write, due, at, print, looks, uploaded);
|
||||
}
|
||||
|
||||
/// See [`TextureQueue::checked`].
|
||||
pub(crate) fn texture_slot_checked(&self, index: u32) -> Option<(u64, u64, u64, u8, u64)> {
|
||||
self.textures.lock().unwrap_or_else(|e| e.into_inner()).checked(index)
|
||||
self.queue().checked(index)
|
||||
}
|
||||
|
||||
/// Nothing to upload at title slot `index` now (its memory is not
|
||||
/// mapped, or no more of it than before): looked at again after 1, 2,
|
||||
/// 4, ... frames, at most `most`.
|
||||
pub(crate) fn texture_slot_later(&self, index: u32, write: u64, frame: u64, most: u64) {
|
||||
let mut textures = self.textures.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let mut textures = self.queue();
|
||||
textures.later(index, write, frame, most);
|
||||
}
|
||||
|
||||
/// See [`TextureQueue::hold`].
|
||||
pub(crate) fn texture_slot_held(&self, index: u32, write: u64, due: u64) {
|
||||
self.textures.lock().unwrap_or_else(|e| e.into_inner()).hold(index, write, due);
|
||||
self.queue().hold(index, write, due);
|
||||
}
|
||||
|
||||
/// See [`TextureQueue::room`].
|
||||
pub(crate) fn texture_slots_room(&self, frame: u64) -> usize {
|
||||
self.textures.lock().unwrap_or_else(|e| e.into_inner()).room(frame)
|
||||
self.queue().room(frame)
|
||||
}
|
||||
|
||||
/// Bytes of title slot `index`'s memory that were mapped when it was
|
||||
/// last uploaded in part (0: not uploaded, or whole).
|
||||
pub(crate) fn texture_slot_mapped(&self, index: u32) -> u64 {
|
||||
self.textures.lock().unwrap_or_else(|e| e.into_inner()).mapped(index)
|
||||
self.queue().mapped(index)
|
||||
}
|
||||
|
||||
/// Takes the ranges of title memory the runtime mapped, unmapped or
|
||||
@@ -1947,7 +1962,7 @@ impl HostHeap {
|
||||
slots.sort_unstable();
|
||||
slots.dedup();
|
||||
slots.retain(|&slot| !self.tabled_lately(slot, frame));
|
||||
let mut textures = self.textures.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let mut textures = self.queue();
|
||||
for &slot in &slots {
|
||||
textures.changed(slot, frame, frame + 1);
|
||||
}
|
||||
@@ -1972,7 +1987,7 @@ impl HostHeap {
|
||||
slots.sort_unstable();
|
||||
slots.dedup();
|
||||
slots.retain(|&slot| !self.tabled_lately(slot, frame));
|
||||
let mut textures = self.textures.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let mut textures = self.queue();
|
||||
for &slot in &slots {
|
||||
textures.changed(slot, frame, frame + 1);
|
||||
}
|
||||
@@ -2032,7 +2047,7 @@ impl HostHeap {
|
||||
slots.sort_unstable();
|
||||
slots.dedup();
|
||||
slots.retain(|&slot| !self.tabled_lately(slot, frame));
|
||||
let mut textures = self.textures.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let mut textures = self.queue();
|
||||
slots.retain(|slot| textures.slots.get(slot).is_none_or(|w| w.mapped > 0 || w.checked.2 != 0));
|
||||
for &slot in &slots {
|
||||
textures.changed(slot, frame, frame);
|
||||
@@ -2053,7 +2068,7 @@ impl HostHeap {
|
||||
slots.dedup();
|
||||
slots.retain(|&slot| !self.tabled_lately(slot, frame));
|
||||
let held = slots.len();
|
||||
let mut textures = self.textures.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let mut textures = self.queue();
|
||||
// Uploaded before: out of the queue, or in it after an upload (in
|
||||
// part, or whole and being looked at again).
|
||||
slots.retain(|slot| textures.slots.get(slot).is_none_or(|w| w.mapped > 0 || w.checked.2 != 0));
|
||||
@@ -2143,7 +2158,7 @@ impl HostHeap {
|
||||
slots.sort_unstable();
|
||||
slots.dedup();
|
||||
slots.retain(|&slot| !self.tabled_lately(slot, frame));
|
||||
let mut textures = self.textures.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let mut textures = self.queue();
|
||||
for &slot in &slots {
|
||||
textures.changed(slot, frame, frame + 1);
|
||||
}
|
||||
@@ -2638,7 +2653,7 @@ impl HostHeap {
|
||||
if old != now | TABLED_READ {
|
||||
stamp.store(now | TABLED_READ, Relaxed);
|
||||
if tabled_out() {
|
||||
let mut textures = self.textures.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let mut textures = self.queue();
|
||||
if textures.slots.remove(&index).is_some() {
|
||||
TABLED_WRITES[1].fetch_add(1, Relaxed);
|
||||
}
|
||||
@@ -2674,7 +2689,7 @@ impl HostHeap {
|
||||
// Made now by a draw of this frame that read it through a table:
|
||||
// up to date.
|
||||
let read_now = seen && stamp == now | TABLED_READ;
|
||||
let mut textures = self.textures.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let mut textures = self.queue();
|
||||
if texture && !read_now {
|
||||
let due = if lately && !seen {
|
||||
TABLED_WRITES[0].fetch_add(1, std::sync::atomic::Ordering::Relaxed);
|
||||
@@ -2783,7 +2798,7 @@ impl HostHeap {
|
||||
};
|
||||
if !stale.is_empty() {
|
||||
STALE[0].fetch_add(stale.len() as u64, std::sync::atomic::Ordering::Relaxed);
|
||||
let mut textures = self.textures.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let mut textures = self.queue();
|
||||
for &(slot, _) in &stale {
|
||||
textures.remove(slot);
|
||||
}
|
||||
@@ -3411,7 +3426,7 @@ impl HostHeap {
|
||||
/// `index` at `frame`, in a few words (diagnostics).
|
||||
#[cfg(feature = "diagnostics")]
|
||||
pub(crate) fn texture_slot_state(&self, index: u32, frame: u64) -> String {
|
||||
let textures = self.textures.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let textures = self.queue();
|
||||
match textures.slots.get(&index) {
|
||||
None => "not queued".into(),
|
||||
Some(w) => format!(
|
||||
|
||||
Reference in new issue
Block a user