First uploads of textures picked by index run on a copy queue of their own, their slots show them when they have (VICTORY_UPLOAD_AHEAD=1; off); blips found while the camera moves

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
localandClaude Opus 5.5 committed 2026-11-25 10:50:14 -06:00
1 parent af0013dd76
commit 1cfc476831
7 files changed
+654 -21

No files matched your search

+79 -4
View File
@@ -326,6 +326,13 @@ fn neutral_for(view: &View, at: D3D12_CPU_DESCRIPTOR_HANDLE) -> Option<ID3D12Res
static FLIPS: Mutex<Vec<Flip>> = Mutex::new(Vec::new());
/// Makes the slots whose new texture's upload has run
/// ([`HostHeap::texture_slots_flip`]); on any thread. Not if the heap is at
/// something else: the next texture pass does.
pub(crate) fn flip_now() {
let _ = super::with_view_heap(HostHeap::texture_slots_flip);
}
/// Since the start: slots made from their new view after its upload had run,
/// and those the title had written again by then.
pub(crate) static FLIPPED: [std::sync::atomic::AtomicU64; 2] = [const { std::sync::atomic::AtomicU64::new(0) }; 2];
@@ -1986,19 +1993,27 @@ impl HostHeap {
/// `handle` views, or something else: until then it shows the neutral
/// texture ([`show_after`]).
pub(crate) fn texture_slot_show_after(&self, list: &crate::host::HostList, index: u32, handle: u64) {
if self.show_later(index, handle) {
self.flip(list, index, handle, Some(crate::frame::current()));
}
}
/// What slot `index` shows until the texture the record at `handle` views
/// is shown. False: it shows it, or there is none.
fn show_later(&self, index: u32, handle: u64) -> bool {
use std::sync::atomic::Ordering::Relaxed;
let key = record_key(handle);
let view = view_at(key as u32, (key >> 32) as u32);
let (true, Some(view)) = (key != 0, view) else {
return;
return false;
};
{
let mut made = self.made.lock().unwrap_or_else(|e| e.into_inner());
let Some(&shown) = made.get(index as usize) else {
return;
return false;
};
if shown == key {
return;
return false;
}
// (As `mirror`.)
for stale in self.note_buffer(index, Some(&view), true) {
@@ -2023,7 +2038,21 @@ impl HostHeap {
self.keep(index, kept);
}
}
self.flip(list, index, handle, Some(crate::frame::current()));
true
}
/// [`HostHeap::texture_slot_show_after`] of a texture whose upload `job`
/// makes: shown when that has run.
pub(crate) fn texture_slot_show_ahead(&self, job: &crate::texture::ahead::Job, index: u32, handle: u64) {
if !self.show_later(index, handle) {
return;
}
let (heap, key) = (std::ptr::from_ref(self) as usize, record_key(handle));
let late = Some(crate::frame::current());
job.then(move || {
let flip = Flip { after: 0, heap, index, handle, key, late };
FLIPS.lock().unwrap_or_else(|e| e.into_inner()).push(flip);
});
}
/// [`HostHeap::mirror`] of a slot whose table a draw read: a texture made
@@ -2037,6 +2066,7 @@ impl HostHeap {
&& let Some(View::Shader(resource, _)) = placed_texture(&view).or(Some(view))
&& crate::resource::buffer_bytes(resource as crate::object::This).is_none()
&& crate::resource::host_resource(resource as crate::object::This).is_some_and(crate::pool::fresh)
&& !crate::texture::ahead::there(resource as crate::object::This)
{
return self.texture_slot_show_after(list, index, handle);
}
@@ -2101,8 +2131,14 @@ impl HostHeap {
#[cfg(feature = "diagnostics")]
note_before(f.index, *shown, if f.late.is_some() { "shown after its upload" } else { "flip" });
self.put(f.index);
#[cfg(feature = "diagnostics")]
let was = *shown;
*shown = f.key;
self.keep(f.index, kept);
#[cfg(feature = "diagnostics")]
if f.late.is_some() && was != 0 {
same_bytes(was, f.key);
}
if let Some(since) = f.late {
let frames = crate::frame::current().saturating_sub(since);
let n = LATE[0].fetch_add(1, Relaxed) + 1;
@@ -4085,6 +4121,45 @@ fn rewritten(kin: Kin, kept: bool) {
}
}
/// Diagnostics: whether a texture that a slot showed until its new one came
/// holds the new one's bytes (the title moved it), by the bytes their host
/// copies were filled from: equal, different, not known.
#[cfg(feature = "diagnostics")]
fn same_bytes(old: u64, new: u64) {
use std::sync::atomic::Ordering::Relaxed;
static SEEN: [std::sync::atomic::AtomicU64; 6] = [const { std::sync::atomic::AtomicU64::new(0) }; 6];
let view = |key: u64| view_at(key as u32, (key >> 32) as u32);
let (Some(old), Some(new)) = (view(old), view(new)) else {
return;
};
let held = |view: &View| {
let View::Placed(false, resource, desc) = view else {
return None;
};
let address = u64::from(desc[10]) | u64::from(desc[11]) << 32;
crate::resource::texture_held(crate::resource::texture_at_made(address, resource)?)
};
let class = match kin(&old, &new) {
Kin::Moved => 0,
Kin::Same | Kin::None => return,
_ => 3,
};
let which = match (held(&old), held(&new)) {
(Some(a), Some(b)) if a == b => 0,
(Some(a), Some(b)) if a.0 == b.0 => 1,
_ => 2,
};
SEEN[class + which].fetch_add(1, Relaxed);
let n: u64 = SEEN.iter().map(|n| n.load(Relaxed)).sum();
if n.is_multiple_of(1000) {
let seen: Vec<u64> = SEEN.iter().map(|n| n.load(Relaxed)).collect();
tracing::info!(
"slots that went on showing another texture until the new one came, since the start: of one of the same kind elsewhere {} had the new one's bytes, {} others, {} not known; of others {}, {}, {}",
seen[0], seen[1], seen[2], seen[3], seen[4], seen[5]
);
}
}
/// For `crate::popwatch`, since the start: slots made null as they were
/// written with another texture, such that kept the old one, slots given the
/// neutral texture, slots made null as their memory was another's.