diff --git a/crates/victory-gpu/src/host.rs b/crates/victory-gpu/src/host.rs index d58ae41..2aa4178 100644 --- a/crates/victory-gpu/src/host.rs +++ b/crates/victory-gpu/src/host.rs @@ -4234,7 +4234,7 @@ impl Host { list.SetPipelineState(&work.pso); list.SetComputeRootUnorderedAccessView(3, work.differs.0.GetGPUVirtualAddress()); for (shadow, ranges) in &dirty { - let Some((_, Some(before), size)) = shadow.card_sides() else { + let (Some((_, Some(before), _)), size) = (shadow.card_sides(), shadow.card_hash_size()) else { continue; }; // No twin (it cost the card the copy's size again, @@ -4364,7 +4364,7 @@ impl Host { list.SetPipelineState(&work.pso); list.SetComputeRootUnorderedAccessView(3, work.differs.0.GetGPUVirtualAddress()); for r in plan.ranges.iter().filter(|r| r.compared) { - let Some((_, Some(before), size)) = r.shadow.card_sides() else { + let (Some((_, Some(before), _)), size) = (r.shadow.card_sides(), r.shadow.card_hash_size()) else { continue; }; list.SetComputeRootShaderResourceView(1, r.shadow.buffer.GetGPUVirtualAddress()); diff --git a/crates/victory-gpu/src/shadow.rs b/crates/victory-gpu/src/shadow.rs index 9851d79..43d1b76 100644 --- a/crates/victory-gpu/src/shadow.rs +++ b/crates/victory-gpu/src/shadow.rs @@ -224,12 +224,22 @@ fn card_limits() -> (u64, u64) { env_mb("VICTORY_CARD_BUFFERS_MIN_MB"), env_mb("VICTORY_CARD_BUFFERS_MB"), ); + // `VICTORY_CARD_BUFFERS_MIN_KB` (after fxceless c36971b2) says the + // least size in KiB, so that it can go under 1 MiB: 64 is every title + // buffer. Copies under 1 MiB are nearly all there are and few bytes; + // in the PC's memory every load, store and atomic a shader does on + // them crosses the bus. + if let Some(kib) = std::env::var("VICTORY_CARD_BUFFERS_MIN_KB").ok().and_then(|v| v.trim().parse::().ok()) + && kib > 0 + { + min_bytes = kib << 10; + } if card_all() { min_bytes = 0; } tracing::info!( vram_budget_mb = vram_budget.map(|b| b >> 20), - card_buffers_min_mb = min_bytes >> 20, + card_buffers_min_kb = min_bytes >> 10, card_buffers_max_mb = max_bytes >> 20, "card buffer limits" ); @@ -4225,10 +4235,25 @@ impl Shadow { /// it in the card's buffer (which may be longer than the copy), widened /// to 16 bytes. pub(crate) fn card_hashed(&self, piece: u32) -> (usize, usize) { - let size = self.card.as_ref().map_or(self.len, |c| c.size) as usize; + let size = self.card_hash_size() as usize; card_hashed_of(self.start as usize, size, piece as usize) } + /// The bytes of the copy the card's hashes cover: the title buffer's own, + /// rounded up to the hash's 16-byte step. The card's buffer is the title + /// buffer rounded up to 64 KiB, of which a title buffer of 288 bytes can + /// give nothing back but those (after fxceless c36971b2). + /// `VICTORY_CARD_HASH_LEN=0`: the whole buffer. + pub(crate) fn card_hash_size(&self) -> u64 { + static OWN: std::sync::OnceLock = std::sync::OnceLock::new(); + let size = self.card.as_ref().map_or(self.len, |c| c.size); + if *OWN.get_or_init(|| std::env::var_os("VICTORY_CARD_HASH_LEN").is_none_or(|v| v != "0")) { + self.len.next_multiple_of(16).min(size) + } else { + size + } + } + /// The walls trace (`crate::host::walls_trace`): a piece of `fetched` /// bytes of this copy came back from the card and `written` of them /// went into title memory. Summed per buffer and logged once a frame: