Texture uploads wait for no mapping, ask no guards and hash cheaply; the sweep looks at a part; bakes pass once for what is new
A bake's uploads waited for the lock the runtime holds while it remaps, and a staging buffer a draw kept waited at every later refresh (29 to 239 ms a frame, all threads, run n04): gone, a read through the kernel gets every page. A staging buffer made for one upload asks neither the write watch nor the guards (VICTORY_TEXTURE_ONCE=0: as before). blake3 makes way for a 128-bit digest (0.035 against 0.2 ms a megabyte). While textures are kept for minutes the sweep looks at 8,192 a time (VICTORY_TEXTURE_SWEEP=whole). The pass before a bake is made again only for something new. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
708c13484c
commit
6b07e2e02d
5 files changed
+215
-38
No files matched your search
@@ -120,8 +120,14 @@ fn recheck_soon() -> bool {
|
||||
|
||||
/// 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;
|
||||
/// again ([`RECHECK_FRAMES`]), these at the frame's first bake alone (a
|
||||
/// look reads 48 KiB, and a frame bakes up to sixteen times).
|
||||
const BAKE_AHEAD: [u64; 2] = [12, 2];
|
||||
|
||||
/// What [`crate::descriptor::host::HostHeap::texture_news`] said when the
|
||||
/// pass before a bake last served all there was, plus one (0: it did not):
|
||||
/// until something is new, the next bakes of the frame need no pass.
|
||||
static BAKE_SERVED: AtomicU64 = AtomicU64::new(0);
|
||||
|
||||
/// The pixel shaders of the title's decoration bake (the title:
|
||||
/// `PS_BakeDecorations_*`), by the first 16 hex digits of their hash as the
|
||||
@@ -1844,6 +1850,12 @@ impl State {
|
||||
return;
|
||||
};
|
||||
let bake = bake && left > 0;
|
||||
if bake && !first && bake_exact() {
|
||||
let (writes, noted) = host.texture_news();
|
||||
if !noted && BAKE_SERVED.load(Ordering::Relaxed) == writes + 1 {
|
||||
return;
|
||||
}
|
||||
}
|
||||
let n = EARLY_TEXTURE_PASSES[usize::from(bake)].fetch_add(1, Ordering::Relaxed) + 1;
|
||||
if bake && n.is_power_of_two() {
|
||||
let [slots, due, ..] = HEAP_TEXTURES_QUEUE.each_ref().map(|c| c.load(Ordering::Relaxed));
|
||||
@@ -2027,7 +2039,9 @@ impl State {
|
||||
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);
|
||||
static AHEAD: AtomicU64 = AtomicU64::new(u64::MAX);
|
||||
let again = AHEAD.swap(frame, Ordering::Relaxed) == frame;
|
||||
let (ahead, _) = host.texture_slots_due(frame + BAKE_AHEAD[usize::from(again)], 1 << 16);
|
||||
due.extend(ahead.into_iter().filter(|(index, _)| !known.contains(index)));
|
||||
}
|
||||
HEAP_TEXTURES_WAITING.store(census[0], Ordering::Relaxed);
|
||||
@@ -2083,8 +2097,11 @@ impl State {
|
||||
None => (span, per_frame),
|
||||
};
|
||||
let began = std::time::Instant::now();
|
||||
BAKE_SERVED.store(0, Ordering::Relaxed);
|
||||
let mut served = true;
|
||||
for (index, write) in due {
|
||||
if SPENT.load(Ordering::Relaxed) >= bytes_at_most || began.elapsed() > span {
|
||||
served = false;
|
||||
break;
|
||||
}
|
||||
// A placed texture whose memory is not mapped (not streamed in
|
||||
@@ -2149,6 +2166,7 @@ impl State {
|
||||
}
|
||||
}
|
||||
let mut partly = None;
|
||||
let mut there = 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 first = crate::resource::first_mip(&desc);
|
||||
@@ -2162,6 +2180,7 @@ impl State {
|
||||
continue;
|
||||
}
|
||||
host.texture_slot_here(index);
|
||||
there = Some(mapped);
|
||||
if mapped < len {
|
||||
if mapped <= host.texture_slot_mapped(index) {
|
||||
HEAP_TEXTURES_PARTLY[0].fetch_add(1, Ordering::Relaxed);
|
||||
@@ -2275,7 +2294,11 @@ impl State {
|
||||
continue;
|
||||
}
|
||||
if let Some(view) = &view {
|
||||
// (What was found mapped of it a moment ago is not asked
|
||||
// again, unless the host copy may need more.)
|
||||
crate::texture::PICKING.set(Some(there.filter(|_| partly.is_none()).unwrap_or(u64::MAX)));
|
||||
readable(list, sampled.kind, view);
|
||||
crate::texture::PICKING.set(None);
|
||||
}
|
||||
if shows_other && let Some(handle) = heap.handle(index) {
|
||||
host.texture_slot_flip(list, index, handle);
|
||||
@@ -2291,7 +2314,7 @@ impl State {
|
||||
crate::host::log_removal_context();
|
||||
return;
|
||||
}
|
||||
let (bytes, whole) = crate::texture::staged(resource).unwrap_or((0, true));
|
||||
let (bytes, whole) = crate::texture::staged(resource, there.is_none()).unwrap_or((0, true));
|
||||
// Not all of it there: looked at again next frame, and from
|
||||
// then on as a slot with nothing new (a placed texture: until
|
||||
// more of it is mapped; a texture object at an address the
|
||||
@@ -2340,6 +2363,9 @@ impl State {
|
||||
None => host.texture_slot_done(index, write, again),
|
||||
}
|
||||
}
|
||||
if baking && served {
|
||||
BAKE_SERVED.store(host.texture_news().0 + 1, Ordering::Relaxed);
|
||||
}
|
||||
}
|
||||
|
||||
/// For the frame listing, after a dropped dispatch's line: its group
|
||||
|
||||
Reference in new issue
Block a user