Textures from the first level viewed; equal uploads left out; bakes take textures as they are; kept by the card's real room

Placed textures are read, kept on the card and uploaded from the first level their views show (VICTORY_HELD_LEVELS=0: whole;
after victory-amd 4436f8f1's spans). An upload of the bytes a host copy holds is left out (VICTORY_TEXTURE_SAME=0). A slot
shows its new view once that view's upload has run. A decoration bake takes slots due a few frames later too and waits for
memory being remapped (VICTORY_BAKE_EXACT=0). Host copies go only past 88 % of the budget, the longest idle first
(VICTORY_TEXTURE_KEEP=1: the rule before). A slot rewritten with other filler words keeps its view.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
localandClaude Opus 5.5 committed 2026-11-25 02:56:28 -06:00
1 parent 320c93a30c
commit c00a0bbd79
6 files changed
+866 -45

No files matched your search

+85 -6
View File
@@ -95,6 +95,26 @@ fn early_budgets() -> (u64, u64) {
})
}
/// Whether a draw of the title's bake finds the textures it picks by index
/// as title memory has them at that moment (`VICTORY_BAKE_EXACT=0`: as the
/// pass leaves them, as before). The pass looks at a slot whose memory was
/// written or mapped a frame or two later, by when the rest of it has
/// landed, and at one uploaded whole a few frames later again, for a title
/// that fills memory unnoticed: a bake in between took the bytes from before
/// (another texture's), and what it bakes stays: coloured specks all over
/// the waitress's face for the whole diner scene (run n01), none in other
/// runs. So the pass ahead of a bake takes those slots too, and its uploads
/// wait for title memory that is being remapped (`crate::texture` `BAKING`).
fn bake_exact() -> bool {
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
*ON.get_or_init(|| std::env::var_os("VICTORY_BAKE_EXACT").is_none_or(|v| v != "0"))
}
/// Frames ahead the pass before a bake takes slots from that are due only
/// then ([`bake_exact`]): those of notices (1 and 2), and the first looks
/// again ([`RECHECK_FRAMES`]).
const BAKE_AHEAD: u64 = 12;
/// The pixel shaders of the title's decoration bake (the title:
/// `PS_BakeDecorations_*`), by the first 16 hex digits of their hash as the
/// frame listings print it. They draw into a 256x256 corner of 2048x2048
@@ -601,6 +621,7 @@ fn heap_recheck() -> bool {
}
/// Times a placed texture's slot was passed over because its memory is not
/// mapped.
pub(crate) static HEAP_TEXTURES_SAME: AtomicU64 = AtomicU64::new(0);
pub(crate) static HEAP_TEXTURES_AWAY: AtomicU64 = AtomicU64::new(0);
/// Slots the pass found up to date already: their texture is uploaded by
/// the draws that read it through a table (it has a staging buffer).
@@ -1820,7 +1841,9 @@ impl State {
}
let began = std::time::Instant::now();
PASS_BUDGET.set(Some(budget));
crate::texture::BAKING.set(bake && bake_exact());
self.heap_textures(list, heap, host);
crate::texture::BAKING.set(false);
PASS_BUDGET.set(None);
if bake {
BAKED_MS.fetch_add(began.elapsed().as_millis() as u64, Ordering::Relaxed);
@@ -1970,15 +1993,23 @@ impl State {
// wrote since the last pass are due again.
host.texture_slots_remapped(frame);
host.texture_slots_short(frame);
// Levels on demand: the slots of textures whose first level with
// memory changed since the last pass are made again from it.
// The slots of textures whose first level with memory (levels on
// demand), or whose host copy for one with more levels, changed since
// the last pass are made again from it; those whose new view's upload
// has run are made from that.
host.texture_views_remade();
host.texture_slots_flip();
// And with room, the textures whose upload left a held level
// without the card's memory are uploaded again.
if room {
host.texture_slots_waiting(frame);
}
let (due, census) = host.texture_slots_due(frame, 4096);
let baking = crate::texture::BAKING.get();
let (due, census) = if baking {
host.texture_slots_due(frame + BAKE_AHEAD, 1 << 16)
} else {
host.texture_slots_due(frame, 4096)
};
HEAP_TEXTURES_WAITING.store(census[0], Ordering::Relaxed);
for (count, now) in HEAP_TEXTURES_QUEUE.iter().zip(census) {
count.store(now, Ordering::Relaxed);
@@ -2068,7 +2099,16 @@ impl State {
}
let n = HEAP_TEXTURES_RECHECKED[1].fetch_add(1, Ordering::Relaxed);
if n < 200 || n.is_multiple_of(1000) {
// Whether its pages are the title's at other addresses
// too: what is written there is told of there alone.
let elsewhere = crate::inplace::shown_elsewhere(at as usize & !0xffff, (at + len) as usize);
let first = heap.handle(index).and_then(crate::descriptor::view).map_or(0, |view| match view {
View::Placed(false, _, desc) => crate::resource::first_mip(&desc),
_ => 0,
});
tracing::warn!(
first_level = first,
blocks_shown_elsewhere = elsewhere.len(),
slot = index,
address = format_args!("{at:#x}"),
bytes = len,
@@ -2082,7 +2122,8 @@ impl State {
let mut partly = None;
if let Some(View::Placed(false, resource, desc)) = heap.handle(index).and_then(crate::descriptor::view) {
let address = u64::from(desc[10]) | u64::from(desc[11]) << 32;
let len = crate::resource::placed_bytes(&resource).unwrap_or(1);
let first = crate::resource::first_mip(&desc);
let len = crate::resource::placed_bytes_from(&resource, first).unwrap_or(1);
let mapped = crate::texture::mapped_bytes(address as *const u8, len as usize);
if mapped == 0 {
HEAP_TEXTURES_AWAY.fetch_add(1, Ordering::Relaxed);
@@ -2155,7 +2196,15 @@ impl State {
);
}
}
let view = heap.handle(index).and_then(|handle| host.mirror(index, handle, true));
// A slot that shows the texture by an earlier view of it (one
// from another level) goes on doing so until the upload of what
// the new one shows has run.
let shows_other = !baking
&& crate::resource::held_only()
&& heap.handle(index).is_some_and(|handle| host.texture_slot_shows_other(index, handle));
let view = heap.handle(index).and_then(|handle| {
if shows_other { crate::descriptor::view(handle) } else { host.mirror(index, handle, true) }
});
let placed = view.as_ref().and_then(crate::descriptor::host::placed_texture);
let resource = match placed.as_ref().or(view.as_ref()) {
Some(&View::Shader(resource, _)) => resource as This,
@@ -2174,9 +2223,34 @@ impl State {
// through a table: they upload it, and check it at every
// submission that samples it.
let tabled = crate::texture::is_staged(resource);
// The host copy holds these very bytes: nothing to upload.
let first = match (&placed, &view) {
(Some(_), Some(View::Placed(_, _, desc))) => crate::resource::first_mip(desc),
_ => 0,
};
let same = !tabled && crate::texture::unchanged(resource, first);
if same {
HEAP_TEXTURES_SAME.fetch_add(1, Ordering::Relaxed);
if shows_other && let Some(handle) = heap.handle(index) {
let _ = host.mirror(index, handle, true);
}
let again = partly.map(|mapped| (frame + 1, mapped));
let memory = if again.is_none() && heap_recheck() { crate::texture::title_span(resource, first) } else { None };
match memory {
Some((at, len)) => {
let print = crate::texture::fingerprint(at, len);
host.texture_slot_recheck(index, write, frame + RECHECK_FRAMES[0], (at, len), print, 0, frame);
}
None => host.texture_slot_done(index, write, again),
}
continue;
}
if let Some(view) = &view {
readable(list, sampled.kind, view);
}
if shows_other && let Some(handle) = heap.handle(index) {
host.texture_slot_flip(list, index, handle);
}
// A texture view the host refuses removes the device: name it.
static GONE: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
if !GONE.load(Ordering::Relaxed)
@@ -3529,7 +3603,12 @@ fn readable(list: &HostList, kind: ResourceType, view: &View) {
&& let Some(t) = crate::resource::host_resource(*resource as This)
&& crate::texture::title_written(t)
{
crate::texture::upload(list, *resource as This, t);
// Of a texture the title placed, the levels the view shows.
let first = match (&placed, view) {
(Some(_), View::Shader(_, Some(desc))) => crate::resource::first_mip(desc),
_ => 0,
};
crate::texture::upload_from(list, *resource as This, first);
}
// A depth texture shaders also write: what they wrote, first.
list.twin_use(*resource as This, false, false);