VICTORY_SHOW_NEW_LATER=1: slots show a texture made while earlier lists run only once those ran (off)

Ported from Belobug/VIctory-Belobug-AMD 4cd2d13 and 91018a5, where it is on
by default. Every device loss with the texture pool in that fork's report
(n08, n11, n15, steps-ab2, start-3, a user's play-1125-2107 without ray
tracing) was a page fault at the first byte of a texture in a block made
that millisecond, its title slot changed "at once" (`mirror`) while lists
sent before read that slot by index; VICTORY_SHOW_AFTER covers only some
paths (a draw's table, the texture pass's own uploads). We run the pool.

With the switch, `HostHeap::mirror` holds a slot whose new view shows a
pooled texture made while a submission begun before it may still run
(`pool::begun_before`: the submissions begun when it was made, noted in
`pool::made_now`) on what it showed, or the neutral texture if that cannot
stand for it (`keep_shown`), and flips it when every such submission has
finished (`FLIPS`, `texture_slots_flip`); a slot held back is held once, not
again at each draw or pass that reads it (`NEW_PENDING`, 91018a5). A line
says how many slots were held back since the start (with the switch on).
Also an A/B switch in diag builds (VICTORY_AB).

Off by default (not behaviour-neutral: a slot shows its new texture one or
more submissions later); with it off, `made_now` notes nothing more than
before and nothing else changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
readmet3xt-labandClaude Opus 5.5 committed 2026-11-27 01:08:54 +05:30
1 parent 185bc4cc84
commit ee3fb5201a
3 files changed
+156 -4

No files matched your search

+99
View File
@@ -294,6 +294,55 @@ pub(crate) fn show_after() -> bool {
*ON.get_or_init(|| std::env::var_os("VICTORY_SHOW_AFTER").is_some_and(|v| v != "0"))
}
/// Whether a title slot that would show a texture made while submissions
/// begun before it may still run shows it only once those have finished
/// (`VICTORY_SHOW_NEW_LATER=1`; off: at once, as before). Also an A/B switch
/// in diag builds (`VICTORY_AB`).
///
/// Ported from Belobug/VIctory-Belobug-AMD 4cd2d13 and 91018a5, where it is
/// on by default: [`show_after`] leaves out slots made "at once" from a
/// draw's table, the texture pass's paths that are no upload of theirs, and
/// the heap's own look at buffer views; that fork's device losses with the
/// texture pool (steps-ab2, start-3, a user's play-1125-2107 without ray
/// tracing) were all page faults at the first byte of a texture in a block
/// made that millisecond, its slot changed "at once" while lists sent before
/// read that slot by index. `HostHeap::mirror` then holds such a slot on what
/// it showed (or the neutral texture) and flips it when every submission
/// begun before the texture was made has finished.
pub(crate) fn show_new_later() -> bool {
#[cfg(feature = "diagnostics")]
if let Some(on) = crate::ab::pick("VICTORY_SHOW_NEW_LATER") {
return on;
}
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
*ON.get_or_init(|| std::env::var_os("VICTORY_SHOW_NEW_LATER").is_some_and(|v| v == "1"))
}
/// Slots [`show_new_later`] holds back now: heap, slot, record. (A slot
/// held back is held once, not again at each draw that reads it.)
static NEW_PENDING: std::sync::LazyLock<Mutex<std::collections::HashSet<(usize, u32, u64)>>> =
std::sync::LazyLock::new(Default::default);
/// Slots held back by [`show_new_later`] since the start.
pub(crate) static NEW_LATER: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);
/// The submissions begun when the host texture `view` shows was made, if
/// one begun before that may still run (`crate::pool::begun_before`). The
/// host texture is made here if it is not yet, as [`make`] would.
fn begun_before(view: &View) -> Option<u64> {
// (Resolved first: the texture made here, a moment ago, is the case.)
let shader = match view {
View::Placed(false, resource, _) if resource[0] != 1 => placed_texture(view)?,
View::Shader(..) => view.clone(),
_ => return None,
};
let View::Shader(resource, _) = shader else {
return None;
};
let texture = crate::resource::host_resource(resource as crate::object::This)?;
crate::pool::begun_before(texture)
}
/// Slots shown late ([`show_after`]), the frames they waited, the longest;
/// those that were given the neutral texture meanwhile; those not shown any
/// more when their time came.
@@ -2853,6 +2902,15 @@ impl HostHeap {
*flips = wait;
ready
};
// Held back by `show_new_later`: no longer once flipped.
{
let mut pending = NEW_PENDING.lock().unwrap_or_else(|e| e.into_inner());
if !pending.is_empty() {
for f in &ready {
pending.remove(&(f.heap, f.index, f.key));
}
}
}
let mut flipped = 0;
let mut late_flipped = 0;
for f in ready {
@@ -3756,6 +3814,47 @@ impl HostHeap {
}
}
}
// A texture made while lists sent before it may still run: those
// read this slot by index, and must not find it ([`show_new_later`]).
// The slot shows what it showed (or the neutral texture), and the
// new view when they have all run.
if !later
&& !self.sampler
&& show_new_later()
&& is_texture_view(&view)
&& let Some(after) = begun_before(&view)
{
// Asked again (each draw that reads the slot, each pass)
// while it waits: nothing more to do.
let own = (std::ptr::from_ref(self) as usize, index, key);
if !NEW_PENDING.lock().unwrap_or_else(|e| e.into_inner()).insert(own) {
drop(held);
self.unmake_stale(index, stale);
return Some(view);
}
let old = view_at(shown as u32, (shown >> 32) as u32);
let kept = old.is_some_and(|old| match kin(&old, &view) {
Kin::Same => true,
kin => kin.kept(keep_shown()),
});
if shown == 0 || !kept {
#[cfg(feature = "diagnostics")]
note_before(index, shown, "neutral, new texture");
self.quick_is(index, 0);
self.made.set(index, 0);
let kept = neutral_for(&view, self.at(index));
self.put(index);
self.clear_twin(index);
self.keep(index, kept);
}
let late = Some(crate::frame::current());
let flip = Flip { after, heap: std::ptr::from_ref(self) as usize, index, handle, key, late };
FLIPS.lock().unwrap_or_else(|e| e.into_inner()).push(flip);
NEW_LATER.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
drop(held);
self.unmake_stale(index, stale);
return Some(view);
}
#[cfg(feature = "diagnostics")]
if !self.sampler && is_texture_view(&view) {
note_before(index, shown, if later { "null, waits" } else { "at once" });