From d77556c791599421f7c2d57524e5d62cc939e6ca Mon Sep 17 00:00:00 2001 From: local Date: Wed, 25 Nov 2026 03:23:33 -0600 Subject: [PATCH] Fewer empty staging blocks kept; the raw twins made are counted Run crash-1 held 5.2 GB of staging blocks (n02: 0.9): at most 8 empty ones stay (512 MB of the PC's memory). With the frame line: raw twins made per frame, and those that had to be views as the title's are. Co-Authored-By: Claude Opus 5.5 --- crates/victory-gpu/src/descriptor.rs | 8 ++++++++ crates/victory-gpu/src/descriptor/host.rs | 2 +- crates/victory-gpu/src/pool.rs | 22 +++++++++++++--------- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/crates/victory-gpu/src/descriptor.rs b/crates/victory-gpu/src/descriptor.rs index d4edf99..256b8e5 100644 --- a/crates/victory-gpu/src/descriptor.rs +++ b/crates/victory-gpu/src/descriptor.rs @@ -286,6 +286,14 @@ pub(crate) static SYNCED: [std::sync::atomic::AtomicU64; 6] = [const { std::sync /// Nothing while no heap page changed. #[cfg(windows)] pub(crate) fn sync_line(frames: f64) { + let [twins, as_is] = [0, 1].map(|i| host::TWINS[i].swap(0, std::sync::atomic::Ordering::Relaxed)); + if twins > 0 { + tracing::info!( + "raw twins of buffer views made per frame (VICTORY_RAW_VIEWS=0: none): {:.0}, of them {:.1} as the title's view is (it does not begin on 16 bytes)", + twins as f64 / frames, + as_is as f64 / frames + ); + } let [pages, looked, mirrored, micros, tabled, later] = [0, 1, 2, 3, 4, 5].map(|i| SYNCED[i].swap(0, std::sync::atomic::Ordering::Relaxed)); if pages == 0 { return; diff --git a/crates/victory-gpu/src/descriptor/host.rs b/crates/victory-gpu/src/descriptor/host.rs index 357ed9c..7bf1711 100644 --- a/crates/victory-gpu/src/descriptor/host.rs +++ b/crates/victory-gpu/src/descriptor/host.rs @@ -2542,7 +2542,7 @@ fn buffer_view_ok(format: DXGI_FORMAT, first: u64, count: u32, stride: u32, raw: .is_some_and(|end| end <= width) } -/// Raw twins ([`raw_twins`]) made since the start, and those of them that had +/// Raw twins ([`raw_twins`]) made since the last frame line, and those of them that had /// to be views as the title's slot has them (a raw view begins on 16 bytes). pub(crate) static TWINS: [std::sync::atomic::AtomicU64; 2] = [const { std::sync::atomic::AtomicU64::new(0) }; 2]; diff --git a/crates/victory-gpu/src/pool.rs b/crates/victory-gpu/src/pool.rs index 95ba178..f4d3b73 100644 --- a/crates/victory-gpu/src/pool.rs +++ b/crates/victory-gpu/src/pool.rs @@ -31,6 +31,9 @@ const BLOCK: u64 = 64 << 20; const SPARE: usize = 2; /// The same while the card has room ([`room`]): 4 GiB of them. const SPARE_KEPT: usize = 64; +/// The same of blocks of staging buffers, which are the PC's memory: run +/// crash-1 held 5.2 GB of them. +const STAGING_KEPT: usize = 8; /// How many are kept now. static SPARES: AtomicUsize = AtomicUsize::new(SPARE); @@ -125,13 +128,14 @@ struct Pool { blocks: Vec>>, /// Pieces given back, and when each may be used again. resting: VecDeque<(u64, Piece)>, - /// The empty blocks it was last told to keep. + /// The empty blocks it was last told to keep, and the most it keeps. spare: usize, + most: usize, } impl Pool { - const fn new() -> Pool { - Pool { blocks: Vec::new(), resting: VecDeque::new(), spare: 0 } + const fn new(most: usize) -> Pool { + Pool { blocks: Vec::new(), resting: VecDeque::new(), spare: 0, most } } /// A piece of `len` bytes and the memory it lies in, and whether that @@ -190,7 +194,7 @@ impl Pool { } } // (Without a piece given back too, once there is less room.) - let most = SPARES.load(Ordering::Relaxed); + let most = SPARES.load(Ordering::Relaxed).min(self.most); if any || most < self.spare { self.spare = most; let mut spare = 0; @@ -216,8 +220,8 @@ struct Upload(ID3D12Resource, *mut u8); // SAFETY: the mapping is written by the owners of its pieces, each its own. unsafe impl Send for Upload {} -static TEXTURES: Mutex> = Mutex::new(Pool::new()); -static STAGING: Mutex> = Mutex::new(Pool::new()); +static TEXTURES: Mutex> = Mutex::new(Pool::new(SPARE_KEPT)); +static STAGING: Mutex> = Mutex::new(Pool::new(STAGING_KEPT)); fn lock(m: &'static Mutex) -> std::sync::MutexGuard<'static, T> { m.lock().unwrap_or_else(|e| e.into_inner()) @@ -413,7 +417,7 @@ mod tests { #[test] fn pieces_never_overlap_and_rest_before_they_are_used_again() { - let mut pool: Pool = Pool::new(); + let mut pool: Pool = Pool::new(SPARE); let made = std::cell::Cell::new(0); let make = || { made.set(made.get() + 1); @@ -440,10 +444,10 @@ mod tests { pool.give(p, 20); } pool.rested(20 + REST); - assert_eq!(pool.blocks(), blocks.min(SPARES.load(Ordering::Relaxed))); + assert_eq!(pool.blocks(), blocks.min(SPARE)); // Too big for a block, and a block that cannot be made. assert!(pool.take(BLOCK, 65536, 30, make).is_none()); - let mut none: Pool = Pool::new(); + let mut none: Pool = Pool::new(SPARE); assert!(none.take(65536, 65536, 0, || None).is_none()); }