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:
1 parent
185bc4cc84
commit
ee3fb5201a
3 files changed
+156
-4
No files matched your search
@@ -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" });
|
||||
|
||||
@@ -9192,6 +9192,13 @@ impl Meter {
|
||||
parts[7].saturating_sub(due_by_memory + remade + due_list),
|
||||
);
|
||||
}
|
||||
if crate::descriptor::host::show_new_later() {
|
||||
tracing::info!(
|
||||
"slots of textures made while lists sent before them ran, shown once those had run \
|
||||
(VICTORY_SHOW_NEW_LATER=1), since the start: {}",
|
||||
crate::descriptor::host::NEW_LATER.load(Ordering::Relaxed)
|
||||
);
|
||||
}
|
||||
// The queue's lock by place (`crate::descriptor::queue_site`).
|
||||
let lock = crate::descriptor::QUEUE_LOCK.each_ref().map(|row| row.each_ref().map(|n| n.swap(0, Ordering::Relaxed)));
|
||||
let [taken, waited, held, skipped] = lock;
|
||||
|
||||
@@ -568,11 +568,57 @@ pub(crate) fn fresh(texture: &ID3D12Resource) -> bool {
|
||||
|
||||
fn made_now(texture: &ID3D12Resource) {
|
||||
let now = now();
|
||||
let mut recent = RECENT.lock().unwrap_or_else(|e| e.into_inner());
|
||||
while recent.front().is_some_and(|r| r.1 + 1000 < now) {
|
||||
recent.pop_front();
|
||||
let raw = texture.as_raw() as usize;
|
||||
{
|
||||
let mut recent = RECENT.lock().unwrap_or_else(|e| e.into_inner());
|
||||
while recent.front().is_some_and(|r| r.1 + 1000 < now) {
|
||||
recent.pop_front();
|
||||
}
|
||||
recent.push_back((raw, now));
|
||||
}
|
||||
recent.push_back((texture.as_raw() as usize, now));
|
||||
if !crate::descriptor::host::show_new_later() {
|
||||
return;
|
||||
}
|
||||
let begun = crate::host::submissions().0;
|
||||
NEWEST_BEGUN.fetch_max(begun, Ordering::Relaxed);
|
||||
let mut unseen = UNSEEN.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let finished = crate::host::submissions().1;
|
||||
// Those every submission begun before them has left behind are no
|
||||
// one's concern any more (and a raw pointer may come again).
|
||||
unseen.retain(|_, b| *b > finished);
|
||||
unseen.insert(raw, begun);
|
||||
}
|
||||
|
||||
/// Pooled textures made while submissions begun before them may still run:
|
||||
/// the submissions begun when each was made (with
|
||||
/// `crate::descriptor::host::show_new_later` only). Ported from
|
||||
/// Belobug/VIctory-Belobug-AMD 4cd2d13.
|
||||
static UNSEEN: std::sync::LazyLock<Mutex<std::collections::HashMap<usize, u64>>> = std::sync::LazyLock::new(Default::default);
|
||||
/// The newest of those numbers (nothing to look up once it has finished).
|
||||
static NEWEST_BEGUN: AtomicU64 = AtomicU64::new(0);
|
||||
|
||||
/// Whether a texture was made in a block while a submission begun before
|
||||
/// it may still run ([`begun_before`]).
|
||||
fn any_unseen() -> bool {
|
||||
NEWEST_BEGUN.load(Ordering::Relaxed) > crate::host::submissions().1
|
||||
}
|
||||
|
||||
/// The submissions begun when `texture` was made in a block, if one of
|
||||
/// those may still be on the card: lists already sent then must not find it
|
||||
/// in a slot they read by index (`crate::descriptor::host::show_new_later`).
|
||||
/// Every device loss with the pool in the report of
|
||||
/// Belobug/VIctory-Belobug-AMD (runs n08, n11, n15, steps-ab2, start-3 and a
|
||||
/// user's play-1125-2107) was a page fault at the first byte of a texture
|
||||
/// made that very millisecond, its title slot changed "at once" while lists
|
||||
/// sent before it read that slot by index.
|
||||
pub(crate) fn begun_before(texture: &ID3D12Resource) -> Option<u64> {
|
||||
if !any_unseen() {
|
||||
return None;
|
||||
}
|
||||
let finished = crate::host::submissions().1;
|
||||
let raw = texture.as_raw() as usize;
|
||||
let unseen = UNSEEN.lock().unwrap_or_else(|e| e.into_inner());
|
||||
unseen.get(&raw).copied().filter(|&begun| begun > finished)
|
||||
}
|
||||
|
||||
/// Makes `texture` give `piece` back when the last reference to it goes.
|
||||
|
||||
Reference in new issue
Block a user