From c96525dbb29daa12bc224813a3e64745520fae29 Mon Sep 17 00:00:00 2001 From: local Date: Wed, 25 Nov 2026 15:43:00 -0600 Subject: [PATCH] A root constant buffer not 256-byte aligned is copied into scratch memory once for the draws of a list that bind it (from Belobug 84ea9c12, romainhedouin) Until the list next writes title memory, as for refreshes: up to 64 KiB of fill less for every repeat. How often this title binds one was not measured. Co-Authored-By: Claude Opus 5.5 --- crates/victory-gpu/src/draw.rs | 4 +--- crates/victory-gpu/src/host.rs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/crates/victory-gpu/src/draw.rs b/crates/victory-gpu/src/draw.rs index 2641d9c..04aa40e 100644 --- a/crates/victory-gpu/src/draw.rs +++ b/crates/victory-gpu/src/draw.rs @@ -713,9 +713,7 @@ fn root_view(list: &HostList, address: u64, srv: bool) -> Option { crate::book::root(gpu, len); return Some(gpu); } - let (gpu, to) = list.scratch(len)?; - list.defer_fill(to, address as *const u8, len as usize); - Some(gpu) + list.fill_scratch(address as *const u8, len) } macro_rules! once { diff --git a/crates/victory-gpu/src/host.rs b/crates/victory-gpu/src/host.rs index da8f6da..1d83029 100644 --- a/crates/victory-gpu/src/host.rs +++ b/crates/victory-gpu/src/host.rs @@ -2190,6 +2190,9 @@ struct Deferred { /// memory (host copy, address, bytes): declaring them again would /// change nothing. gpu_written: std::collections::HashSet<(usize, usize, usize), std::hash::BuildHasherDefault>, + /// Scratch memory [`HostList::fill_scratch`] fills since the list last + /// wrote title memory (source, bytes): its host address. + filled: std::collections::HashMap<(usize, usize), u64, std::hash::BuildHasherDefault>, /// Textures whose contents the list brings up to date. textures: std::collections::HashSet, /// Bottom-of-pipe writes, done once the list has run: address, what, @@ -2230,6 +2233,7 @@ impl Deferred { fn title_written(&mut self) { self.refreshed.clear(); self.gpu_written.clear(); + self.filled.clear(); } } @@ -6676,6 +6680,21 @@ impl HostList { .push(Step::Fill(dst as usize, src as usize, len, None)); } + /// The host address of `len` bytes of scratch memory that hold the title + /// memory at `src` as of the list's submission: one fill for every ask + /// until the list next writes title memory. + pub(crate) fn fill_scratch(&self, src: *const u8, len: u64) -> Option { + let key = (src as usize, len as usize); + let known = self.deferred().filled.get(&key).copied(); + if known.is_some() { + return known; + } + let (gpu, to) = self.scratch(len)?; + self.defer_fill(to, src, len as usize); + self.deferred().filled.insert(key, gpu); + Some(gpu) + } + /// As [`HostList::defer_fill`], for upload memory that only `slot` (a /// title heap's address, and the slot) shows. pub(crate) fn defer_constants(&self, dst: *mut u8, src: *const u8, len: usize, slot: (usize, u32)) {