Merge branch 'local/next' into night/light

# Conflicts:
#	crates/victory-shader/src/emit/mod.rs
This commit is contained in:
local committed 2026-11-25 04:43:44 -06:00
commit ea375caa52
27 files changed
+3107 -163

No files matched your search

+120 -10
View File
@@ -95,6 +95,34 @@ 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"))
}
/// Whether a texture found changed with nothing to tell of it is looked at
/// again in the next frame (`VICTORY_RECHECK_SOON=0`: after four, as
/// before).
fn recheck_soon() -> bool {
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
*ON.get_or_init(|| std::env::var_os("VICTORY_RECHECK_SOON").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
@@ -283,6 +311,10 @@ pub(crate) struct State {
/// The records clamped in a batch, if later executions may still read
/// them ([`batches`]).
batch: Option<Batch>,
/// The user data bound last, of the last stage that has some (for the
/// report of a removed device, `crate::host::indirects`).
#[cfg(feature = "diagnostics")]
user: Vec<u32>,
/// What the host list has: pipeline, root signature, heaps.
host_pipeline: usize,
/// Graphics, compute.
@@ -601,6 +633,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).
@@ -1268,6 +1301,11 @@ impl State {
None => self.user_value(compute, u.slot, u.root, u.dword),
};
}
#[cfg(feature = "diagnostics")]
{
self.user.clear();
self.user.extend_from_slice(&values);
}
// SAFETY: an open list; `values` covers the parameter.
unsafe {
if compute {
@@ -1842,7 +1880,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);
@@ -1992,15 +2032,26 @@ 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 (mut due, census) = host.texture_slots_due(frame, if baking { 1 << 16 } else { 4096 });
// (Those that are due later after all that are due.)
let on_time = due.len();
if baking {
let known: std::collections::HashSet<u32> = due.iter().map(|&(index, _)| index).collect();
let (ahead, _) = host.texture_slots_due(frame + BAKE_AHEAD, 1 << 16);
due.extend(ahead.into_iter().filter(|(index, _)| !known.contains(index)));
}
HEAP_TEXTURES_WAITING.store(census[0], Ordering::Relaxed);
for (count, now) in HEAP_TEXTURES_QUEUE.iter().zip(census) {
count.store(now, Ordering::Relaxed);
@@ -2043,7 +2094,7 @@ impl State {
// drains; `VICTORY_TEXTURE_CATCHUP=0` keeps the plain budget.
static CATCHUP: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
let catchup = *CATCHUP.get_or_init(|| std::env::var_os("VICTORY_TEXTURE_CATCHUP").is_none_or(|v| v != "0"));
let (per_frame, span) = if catchup && due.len() >= 1024 { (per_frame * 3, span * 3) } else { (per_frame, span) };
let (per_frame, span) = if catchup && on_time >= 1024 { (per_frame * 3, span * 3) } else { (per_frame, span) };
// A run made early (`State::early_textures`) has a budget of its
// own: its bytes on top of what the frame has spent so far.
// (Not `most`: that is the longest wait between looks, used below.)
@@ -2077,6 +2128,12 @@ impl State {
// first look for the rest of the run. The look reads 48 KiB;
// only a changed texture is uploaded again.
// `VICTORY_HEAP_RECHECK=0`: uploaded once, as before.
// One found changed by such a look is looked at in the next frame
// again: the textures left that change unnoticed are ones the
// title paints all the time through another view of their pages
// (all their blocks are shown at other addresses too), and each
// was shown four frames late, over and over.
let mut again_in = RECHECK_FRAMES[0];
if let Some((at, len, print, looks, uploaded)) = host.texture_slot_checked(index) {
if crate::texture::fingerprint(at, len) == print {
HEAP_TEXTURES_RECHECKED[0].fetch_add(1, Ordering::Relaxed);
@@ -2088,9 +2145,21 @@ impl State {
}
continue;
}
if recheck_soon() {
again_in = 1;
}
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,
@@ -2104,7 +2173,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);
@@ -2177,7 +2247,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,
@@ -2196,9 +2274,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 + again_in, (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)
@@ -2254,7 +2357,7 @@ impl State {
// Whole and uploaded: looked at again (see above).
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);
host.texture_slot_recheck(index, write, frame + again_in, (at, len), print, 0, frame);
}
None => host.texture_slot_done(index, write, again),
}
@@ -2896,13 +2999,13 @@ impl State {
let used = entries.iter().find(|u| u.table_offset_dwords / 8 == k);
match crate::descriptor::view(table + u64::from(k) * 32) {
Some(View::Constant(address, size)) => {
let Some((gpu, to)) = list.scratch(u64::from(size)) else {
let Some((buffer, gpu, to)) = list.scratch_held(u64::from(size)) else {
host.make_null(index);
continue;
};
let slot = (std::ptr::from_ref(heap) as usize, index);
list.defer_constants(to, address as *const u8, size as usize, slot);
host.constant_at(index, gpu, size);
host.constant_at(index, &buffer, gpu, size);
}
Some(view) => {
host.make_at(index, &view);
@@ -3410,6 +3513,8 @@ impl State {
list.note_op(|| {
self.op_text(format!("indirect kind {kind} max {max} at {arguments:#x}"), kind == DISPATCH)
});
#[cfg(feature = "diagnostics")]
list.ran_indirect(p.pso.as_raw() as usize, &p.name, kind, max, &self.user);
if kind == MESH {
self.mesh_scissor(list, true);
}
@@ -3556,7 +3661,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);