Bake sources: leave out null views, say why a real one fails

The 588 "failed" bake sources of the first runs (3,720 sources in 256
bakes) were null views: slot 1 and others hold views of no resource,
which small numbers among the bake's words name all the time, and
is_texture_view counts them (no buffer behind them). They have no host
copy to make, so they were counted as refused. Now they are not
sources at all.

A real failure now says why (the first 64, a warning with the view):
the host refused the copy, the staging buffer was deferred, uploads are
refused after the host ran out of memory, or no upload was recorded (no
console layout, an XOR mode, no staging buffer). Whether an upload was
recorded is told by upload_from itself (UPLOAD_STAGED), and a source
whose upload the pass recorded on the bake's list already counts as
brought up to date (it was counted as failed or uploaded twice).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
readmet3xt-labandClaude Opus 5.5 committed 2026-11-26 17:08:48 +05:30
1 parent dfb76df595
commit 082ebaf3b8
2 files changed
+76 -22

No files matched your search

+55 -21
View File
@@ -250,6 +250,16 @@ fn bake_candidates(words: Vec<u32>, names_texture: impl Fn(u32) -> bool) -> Vec<
.collect() .collect()
} }
/// Says why a bake's source could not be brought up to date (the first
/// 64 times): the bake reads it as it stands.
fn bake_source_failed(index: u32, view: &View, why: &str) {
static SAID: AtomicU64 = AtomicU64::new(0);
if SAID.fetch_add(1, Ordering::Relaxed) < 64 {
let text: String = format!("{view:?}").chars().take(200).collect();
tracing::warn!(slot = index, frame = crate::frame::current(), "a decoration bake's source was not brought up to date: {why}; {text}");
}
}
/// Adds one bake's counts to [`BAKE_SOURCES`] and says them: every bake /// Adds one bake's counts to [`BAKE_SOURCES`] and says them: every bake
/// that found a source not up to date (the first 256), and the totals at /// that found a source not up to date (the first 256), and the totals at
/// bakes 1, 2, 4, 8 ... /// bakes 1, 2, 4, 8 ...
@@ -886,11 +896,14 @@ pub(crate) static HEAP_TEXTURES_PARTLY: [AtomicU64; 3] = [const { AtomicU64::new
/// last 5-second line, on: looks again at slots uploaded whole (a /// last 5-second line, on: looks again at slots uploaded whole (a
/// fingerprint of 48 KiB), asking how much of a texture's memory is mapped, /// fingerprint of 48 KiB), asking how much of a texture's memory is mapped,
/// asking whether a host copy holds what memory holds (a digest of all of /// asking whether a host copy holds what memory holds (a digest of all of
/// it), and making host copies and staging their uploads (`readable`); and /// it), staging uploads (`readable`); the passes in all; making host copies
/// the passes in all. The pass stops at `VICTORY_TEXTURE_STAGE_MS` (16 in /// (`resource::host_resource`: creation, residency); and making the slots'
/// views (`mirror`, the placed texture's resource). In the first runs with
/// the line (2026-11-26 16:52) the first four were a third of the passes'
/// time. The pass stops at `VICTORY_TEXTURE_STAGE_MS` (16 in
/// the launcher), and in play it ran 18-20 ms a frame for about 20 /// the launcher), and in play it ran 18-20 ms a frame for about 20
/// textures: these say what took the time. /// textures: these say what took the time.
pub(crate) static HEAP_TEXTURE_MICROS: [AtomicU64; 5] = [const { AtomicU64::new(0) }; 5]; pub(crate) static HEAP_TEXTURE_MICROS: [AtomicU64; 7] = [const { AtomicU64::new(0) }; 7];
/// `f`'s result, its time added to [`HEAP_TEXTURE_MICROS`]' place `slot`. /// `f`'s result, its time added to [`HEAP_TEXTURE_MICROS`]' place `slot`.
fn timed<T>(slot: usize, f: impl FnOnce() -> T) -> T { fn timed<T>(slot: usize, f: impl FnOnce() -> T) -> T {
@@ -2441,11 +2454,13 @@ impl State {
} }
} }
} }
// (Not a null view: slot 1 and others hold views of no resource,
// which small numbers among the words name all the time; they were
// the "failed" sources of the first runs, 588 of 3,720.)
bake_candidates(words, |w| { bake_candidates(words, |w| {
heap.handle(w) heap.handle(w).and_then(crate::descriptor::view).as_ref().is_some_and(|view| {
.and_then(crate::descriptor::view) crate::descriptor::host::is_texture_view(view) && !matches!(view, View::Shader(0, _))
.as_ref() })
.is_some_and(crate::descriptor::host::is_texture_view)
}) })
} }
@@ -2505,6 +2520,7 @@ impl State {
let Some(texture) = crate::resource::host_resource(resource) else { let Some(texture) = crate::resource::host_resource(resource) else {
// The host refused it (its creation failed). // The host refused it (its creation failed).
n[8] += 1; n[8] += 1;
bake_source_failed(index, &view, "the host has no copy of it (refused)");
continue; continue;
}; };
if !crate::texture::title_written(texture) || crate::texture::host_wrote(resource as usize) { if !crate::texture::title_written(texture) || crate::texture::host_wrote(resource as usize) {
@@ -2526,15 +2542,31 @@ impl State {
// another view; the texture has no host copy yet; its host copy // another view; the texture has no host copy yet; its host copy
// holds other bytes than its memory now. // holds other bytes than its memory now.
n[if !shown { 3 } else if !had_copy { 4 } else { 7 }] += 1; n[if !shown { 3 } else if !had_copy { 4 } else { 7 }] += 1;
// The pass recorded its upload on this list already (with
// `BAKING`: read exactly at submission): nothing more to do.
if crate::texture::upload_listed(list, resource, first) {
sync.publish.push((index, handle, key));
continue;
}
let was_staged = crate::texture::is_staged(resource); let was_staged = crate::texture::is_staged(resource);
let _ = crate::residency::take_staging_deferred(); let _ = crate::residency::take_staging_deferred();
crate::texture::UPLOAD_STAGED.set(false);
readable(list, ResourceType::Srv, &view); readable(list, ResourceType::Srv, &view);
let failed = crate::residency::take_staging_deferred() || crate::residency::upload_refused(); let why = if crate::residency::take_staging_deferred() {
Some("its staging buffer was deferred")
} else if crate::residency::upload_refused() {
Some("uploads are refused for a moment after the host ran out of memory")
} else if !crate::texture::UPLOAD_STAGED.get() {
Some("no upload was recorded (no console layout, an XOR mode, or no staging buffer)")
} else {
None
};
if !was_staged { if !was_staged {
crate::texture::unstage(resource); crate::texture::unstage(resource);
} }
if failed { if let Some(why) = why {
n[8] += 1; n[8] += 1;
bake_source_failed(index, &view, why);
continue; continue;
} }
if let Some(copy) = crate::resource::host_copy(resource) { if let Some(copy) = crate::resource::host_copy(resource) {
@@ -3104,23 +3136,25 @@ impl State {
&& !sync_bake && !sync_bake
&& crate::descriptor::host::show_after() && crate::descriptor::host::show_after()
&& heap.handle(index).is_some_and(|handle| !host.texture_slot_made_from(index, handle)); && heap.handle(index).is_some_and(|handle| !host.texture_slot_made_from(index, handle));
let (view, bake_key) = if sync_bake { let (view, bake_key) = timed(6, || {
match heap.handle(index).and_then(|handle| host.prepare_bake_slot(index, handle)) { if sync_bake {
Some((view, key)) => (Some(view), Some(key)), match heap.handle(index).and_then(|handle| host.prepare_bake_slot(index, handle)) {
None => (None, None), Some((view, key)) => (Some(view), Some(key)),
None => (None, None),
}
} else {
let view = heap.handle(index).and_then(|handle| {
if shows_other || late { crate::descriptor::view(handle) } else { host.mirror(index, handle, true) }
});
(view, None)
} }
} else { });
let view = heap.handle(index).and_then(|handle| {
if shows_other || late { crate::descriptor::view(handle) } else { host.mirror(index, handle, true) }
});
(view, None)
};
let at_once = || { let at_once = || {
if (late || bake_key.is_some()) && let Some(handle) = heap.handle(index) { if (late || bake_key.is_some()) && let Some(handle) = heap.handle(index) {
let _ = host.mirror(index, handle, true); let _ = host.mirror(index, handle, true);
} }
}; };
let placed = view.as_ref().and_then(crate::descriptor::host::placed_texture); let placed = timed(6, || view.as_ref().and_then(crate::descriptor::host::placed_texture));
if crate::residency::upload_refused() { if crate::residency::upload_refused() {
served = false; served = false;
break; break;
@@ -3133,7 +3167,7 @@ impl State {
continue; continue;
} }
}; };
let texture = crate::resource::host_resource(resource); let texture = timed(5, || crate::resource::host_resource(resource));
if crate::residency::upload_refused() { if crate::residency::upload_refused() {
served = false; served = false;
break; break;
+21 -1
View File
@@ -753,6 +753,25 @@ pub(crate) struct Digest(u128);
/// [`upload`] of the levels from `first` on, the ones a view shows: of a /// [`upload`] of the levels from `first` on, the ones a view shows: of a
/// texture the title placed there may be no memory of the larger ones, and /// texture the title placed there may be no memory of the larger ones, and
/// what lies there is another texture's. (After victory-amd 4436f8f1.) /// what lies there is another texture's. (After victory-amd 4436f8f1.)
/// Whether `list` has recorded [`upload_from`]'s upload of `resource`
/// from level `first` (or been asked to: see [`UPLOAD_STAGED`]).
pub(crate) fn upload_listed(list: &HostList, resource: This, first: u32) -> bool {
let first = if crate::resource::held_only() { first } else { 0 };
list.used(upload_key(resource, first))
}
/// The key [`upload_from`] asks `HostList::first_use` with.
fn upload_key(resource: This, first: u32) -> usize {
1 << 63 | (resource as usize) << 4 | first as usize & 15
}
thread_local! {
/// Set by [`upload_from`] when it found or made the texture's staging
/// buffer (its upload is recorded or checked at submission): for a
/// caller that must know the upload happened.
pub(crate) static UPLOAD_STAGED: std::cell::Cell<bool> = const { std::cell::Cell::new(false) };
}
pub(crate) fn upload_from(list: &HostList, resource: This, first: u32) { pub(crate) fn upload_from(list: &HostList, resource: This, first: u32) {
let first = if crate::resource::held_only() { first } else { 0 }; let first = if crate::resource::held_only() { first } else { 0 };
let host_written = HOST_WRITTEN let host_written = HOST_WRITTEN
@@ -767,7 +786,7 @@ pub(crate) fn upload_from(list: &HostList, resource: This, first: u32) {
} }
// Once a list for each first level; not again for one that the list's // Once a list for each first level; not again for one that the list's
// upload of larger ones held too. // upload of larger ones held too.
if !list.first_use(1 << 63 | (resource as usize) << 4 | first as usize & 15) { if !list.first_use(upload_key(resource, first)) {
return; return;
} }
if !list.first_use(resource as usize) && staged_from(resource) <= first { if !list.first_use(resource as usize) && staged_from(resource) <= first {
@@ -781,6 +800,7 @@ pub(crate) fn upload_from(list: &HostList, resource: This, first: u32) {
let Some(staging) = staging(resource, &copy, first) else { let Some(staging) = staging(resource, &copy, first) else {
return; return;
}; };
UPLOAD_STAGED.set(true);
use std::sync::atomic::Ordering::Relaxed; use std::sync::atomic::Ordering::Relaxed;
let baking = BAKING.get(); let baking = BAKING.get();
if baking { if baking {