Texture queue census: slots waiting for a look again are not waiting for their memory

The census counted a slot uploaded whole and waiting for its looks again
(RECHECK_FRAMES 4, 12, 40, 120, 400 frames: in the queue up to 576 frames
after its upload) as "waiting for their memory", and its old write as "the
oldest". In coolfox-20261126-223059 at 17:02:04 the queue line said 19,277
waiting for their memory when the looks that had found memory not there
numbered 1,700 in the whole run (17:01:45: 6,842 vs 104; 17:01:59: 19,023 vs
471): nine in ten or more of them were uploaded textures waiting for a look
again, not streaming. They are counted apart now ("uploaded whole and waiting
to be looked at again"), and "the oldest" is of slots not uploaded yet.

A new 5-second line says how late first uploads are: slots served for the
first time at their first look, with the frames they had been due before the
pass took them (the pass's own lateness: its time cap), and slots served
after their memory was found not there, with the frames since their write
(streaming: mapping that came late).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
readmet3xt-labandClaude Opus 5.5 committed 2026-11-26 23:03:25 +05:30
1 parent 36c4c3746c
commit c1d1b4ee76
3 files changed
+100 -15

No files matched your search

+78 -9
View File
@@ -997,18 +997,23 @@ impl TextureQueue {
/// slots in the first gameplay area kept it 1-5 ms a pass, and the
/// title's recording threads, whose every descriptor copy notes its slot
/// here, waited that long behind it (run timeline, 2026-11-26).
fn due_and_census(&self, frame: u64) -> (Due, [u64; 5]) {
fn due_and_census(&self, frame: u64) -> (Due, [u64; 6]) {
let mut due = Due::default();
let mut c = [self.slots.len() as u64, 0, 0, 0, 0];
let mut c = [self.slots.len() as u64, 0, 0, 0, 0, 0];
for (&index, w) in &self.slots {
let again = w.checked.2 != 0;
if w.mapped > 0 {
c[3] += 1;
} else if again {
c[5] += 1;
} else if w.looks > 0 {
c[2] += 1;
}
if w.due <= frame {
c[1] += 1;
c[4] = c[4].max(frame.saturating_sub(w.written));
if !again {
c[4] = c[4].max(frame.saturating_sub(w.written));
}
let class = if w.looks > 0 || w.mapped > 0 { &mut due.again } else { &mut due.fresh };
class.push((w.written, index, w.write));
}
@@ -1148,25 +1153,66 @@ impl TextureQueue {
/// For the frame line (made with the slots due, by
/// [`TextureQueue::due_and_census`]): slots in the queue; of them due at `frame`;
/// waiting for their memory (looked at, never uploaded); uploaded in
/// part; and the frames the oldest due one has waited since its write.
/// part; the frames the oldest due one not uploaded yet has waited
/// since its write; and the slots uploaded whole that wait for a look
/// again ([`TextureQueue::recheck`]). (Those were counted as waiting
/// for their memory, and their writes as the oldest: 19,023 of a
/// cutscene's 19,277 "waiting for their memory" were such slots,
/// coolfox-20261126-223059 17:02:04, where 1,700 looks in all had found
/// memory not there.)
#[cfg(test)]
fn census(&self, frame: u64) -> [u64; 5] {
let mut c = [self.slots.len() as u64, 0, 0, 0, 0];
fn census(&self, frame: u64) -> [u64; 6] {
let mut c = [self.slots.len() as u64, 0, 0, 0, 0, 0];
for w in self.slots.values() {
let again = w.checked.2 != 0;
if w.mapped > 0 {
c[3] += 1;
} else if again {
c[5] += 1;
} else if w.looks > 0 {
c[2] += 1;
}
if w.due <= frame {
c[1] += 1;
c[4] = c[4].max(frame.saturating_sub(w.written));
if !again {
c[4] = c[4].max(frame.saturating_sub(w.written));
}
}
}
c
}
/// The pass serves slot `index` (as handed out with `write`) in
/// `frame`: if it was not served before (not uploaded in part, not
/// waiting for a look again), counted in [`SERVED`]: at its first look,
/// by the frames it was due and not taken; after looks that found its
/// memory not there, by the frames since its write.
fn note_served(&self, index: u32, write: u64, frame: u64) {
use std::sync::atomic::Ordering::Relaxed;
let Some(w) = self.slots.get(&index).filter(|w| w.write == write) else {
return;
};
if w.mapped > 0 || w.checked.2 != 0 {
return;
}
let (which, frames) = if w.looks == 0 {
(0, frame.saturating_sub(w.due.max(w.written)))
} else {
(3, frame.saturating_sub(w.written))
};
SERVED[which].fetch_add(1, Relaxed);
SERVED[which + 1].fetch_add(frames, Relaxed);
SERVED[which + 2].fetch_max(frames, Relaxed);
}
}
/// Slots of textures picked by index the pass served for the first time,
/// since the last 5-second line: at their first look, with the frames they
/// had been due before the pass took them (in all, and the most); after
/// looks that found their memory not there, with the frames since their
/// write (in all, and the most). ([`TextureQueue::note_served`].)
pub(crate) static SERVED: [std::sync::atomic::AtomicU64; 6] = [const { std::sync::atomic::AtomicU64::new(0) }; 6];
/// Whether `view` is of a texture the title may fill itself: a texture it
/// placed in memory, or a texture object.
pub(crate) fn is_texture_view(view: &View) -> bool {
@@ -1853,7 +1899,7 @@ impl HostHeap {
/// with its write number, in the order to serve them
/// ([`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]) {
pub(crate) fn texture_slots_due(&self, frame: u64, max: usize) -> (Vec<(u32, u64)>, [u64; 6]) {
let (due, census) = self.queue().due_and_census(frame);
(if max == 0 { Vec::new() } else { due.order(max) }, census)
}
@@ -1886,6 +1932,7 @@ impl HostHeap {
/// slot is written again.
pub(crate) fn texture_slot_done(&self, index: u32, write: u64, again: Option<(u64, u64)>) {
let mut textures = self.queue();
textures.note_served(index, write, crate::frame::current());
match again {
Some((frame, mapped)) => textures.partly(index, write, frame, mapped),
None => textures.done(index, write),
@@ -1905,6 +1952,7 @@ impl HostHeap {
uploaded: u64,
) {
let mut textures = self.queue();
textures.note_served(index, write, crate::frame::current());
textures.recheck(index, write, due, at, print, looks, uploaded);
}
@@ -5372,7 +5420,7 @@ mod tests {
// newest, oldest, newest, oldest, and so on
assert_eq!(order, [5, 10, 17, 11, 16, 12, 15, 13, 14]);
assert_eq!(q.due(9, 2).len(), 2);
assert_eq!(q.census(9), [9, 9, 0, 0, 8]);
assert_eq!(q.census(9), [9, 9, 0, 0, 8, 0]);
// Slot 17's memory is not mapped: again next frame, then in 2, 4, 4.
let write = |q: &TextureQueue, index: u32| q.due(u64::MAX, 100).iter().find(|d| d.0 == index).unwrap().1;
let w17 = write(&q, 17);
@@ -5417,6 +5465,27 @@ mod tests {
assert!(q.due(16, 100).iter().any(|d| d.0 == 98));
}
/// A slot uploaded whole that waits for a look again is counted apart:
/// not as waiting for its memory, and not as the oldest due slot.
#[test]
fn slots_waiting_for_a_look_again_are_not_waiting_for_their_memory() {
let mut q = TextureQueue::default();
q.written(1, 1, 0, false);
q.written(2, 5, 0, false);
let write = |q: &TextureQueue, index: u32| q.due(u64::MAX, 100).iter().find(|d| d.0 == index).unwrap().1;
let (w1, w2) = (write(&q, 1), write(&q, 2));
// Slot 1 uploaded whole at frame 10, looked at again from frame 14;
// slot 2's memory not there at frame 10.
q.recheck(1, w1, 14, (0x1_0000, 4096), 7, 0, 10);
q.later(2, w2, 10, 4);
let c = q.census(20);
assert_eq!((c[2], c[5]), (1, 1));
assert_eq!(c[4], 15, "the oldest is slot 2's write, not slot 1's");
for at in [0, 12, 20] {
assert_eq!(q.due_and_census(at).1, q.census(at));
}
}
/// Slots held back for lack of room on the card are not handed out
/// until their frame, keep their place, are not counted as waiting
/// for their memory, and all come back at once when the card has room;
+3 -2
View File
@@ -886,8 +886,9 @@ pub(crate) static HEAP_TEXTURES_AWAY: AtomicU64 = AtomicU64::new(0);
pub(crate) static HEAP_TEXTURES_TABLED: AtomicU64 = AtomicU64::new(0);
/// The queue of textures picked by index at the last pass
/// (`TextureQueue::census`): slots in it, due, waiting for their memory,
/// uploaded in part, and the frames the oldest due one has waited.
pub(crate) static HEAP_TEXTURES_QUEUE: [AtomicU64; 5] = [const { AtomicU64::new(0) }; 5];
/// uploaded in part, the frames the oldest due one has waited, and those
/// uploaded whole that wait for a look again.
pub(crate) static HEAP_TEXTURES_QUEUE: [AtomicU64; 6] = [const { AtomicU64::new(0) }; 6];
/// Since the start: looks at a slot uploaded in part that found no more of
/// its memory mapped; uploads of textures not all mapped; and of those,
/// the ones whose first page was not there (asked by the first page alone,
+19 -4
View File
@@ -8972,13 +8972,14 @@ impl Meter {
);
crate::tiles::status();
{
let [queued, due, away, partly, oldest] =
[0, 1, 2, 3, 4].map(|i| crate::draw::HEAP_TEXTURES_QUEUE[i].load(Ordering::Relaxed));
let [queued, due, away, partly, oldest, again] =
[0, 1, 2, 3, 4, 5].map(|i| crate::draw::HEAP_TEXTURES_QUEUE[i].load(Ordering::Relaxed));
let [same, parts, tails] =
[0, 1, 2].map(|i| crate::draw::HEAP_TEXTURES_PARTLY[i].load(Ordering::Relaxed));
tracing::info!(
"textures picked by index, the queue: {queued} slots, {due} of them due (the oldest written {oldest} frames ago), \
{away} waiting for their memory, {partly} uploaded in part; since the start: {} slots found uploaded already by \
"textures picked by index, the queue: {queued} slots, {due} of them due (the oldest not uploaded yet written \
{oldest} frames ago), {away} waiting for their memory, {partly} uploaded in part, {again} uploaded whole and \
waiting to be looked at again; since the start: {} slots found uploaded already by \
the draws that read them through tables, {} writes of tables' slots (due some frames later), {} slots taken out \
as read through a table, {parts} uploads of textures not all mapped ({tails} of them without their first page), \
{same} looks that found no more mapped; {} slots made stale by a newer view of other memory there, \
@@ -9025,6 +9026,20 @@ impl Meter {
crate::draw::HEAP_TEXTURE_BYTES.load(Ordering::Relaxed) >> 20
);
}
let served = crate::descriptor::host::SERVED.each_ref().map(|n| n.swap(0, Ordering::Relaxed));
if served[0] + served[3] > 0 {
tracing::info!(
"textures picked by index served for the first time in the last 5 seconds: {} at their first look, \
{:.1} frames after they were due ({} at most: the pass's own lateness), {} after their memory was \
found not there, {:.1} frames after their write ({} at most)",
served[0],
served[1] as f64 / served[0].max(1) as f64,
served[2],
served[3],
served[4] as f64 / served[3].max(1) as f64,
served[5]
);
}
if all > 0 || parts[7] > 0 {
let [queue, records, prints, ahead, shown, whole, checks, before] = parts;
let [n_frame, n_early, n_bake, t_frame, t_early, t_bake, at_time, at_bytes] = passes;