diff --git a/crates/metal2vulkan-runtime/src/memory.rs b/crates/metal2vulkan-runtime/src/memory.rs index 77762717b..ed058beba 100644 --- a/crates/metal2vulkan-runtime/src/memory.rs +++ b/crates/metal2vulkan-runtime/src/memory.rs @@ -2713,16 +2713,15 @@ impl Memory { } /// The block `pool`, its blocks of `bytes`, lacks of the one it keeps made ahead - /// (`memory/ready.rs`), `held` the bytes of each block made, being made and still to make: + /// (`memory/ready.rs`), `held` the bytes of the blocks made, being made and still to make: /// counted in bytes together with its room ([`Pool::room`]), one where those held and its /// room come to less than a block. So a block just taken from them, which leaves the pool a /// whole block of room, is made again as soon as a placement takes any of that room, not only /// once the pool lacks room for a whole block: the room left then is less than the next /// creation calls' placements may take before the making ends (a 31.6 MiB texture after a /// 64 MiB block was taken). - fn lacking(&mut self, pool: (Holds, u32), bytes: u64, held: &[u64]) -> Vec { - let have: u64 = held.iter().sum(); - match self.pool(pool.0, pool.1).room().saturating_add(have) < bytes { + fn lacking(&mut self, pool: (Holds, u32), bytes: u64, held: u64) -> Vec { + match self.pool(pool.0, pool.1).room().saturating_add(held) < bytes { true => vec![bytes], false => Vec::new(), } @@ -2743,11 +2742,8 @@ impl Memory { /// [`lacking`](Self::lacking)): one it lacks made after the blocks its thread still makes, or /// on a new thread, once a burst of the device's queue uses ended. fn keep_ahead(&mut self, pool: (Holds, u32), bytes: u64) { - let held = match self.readying_at(pool) { - Some(at) => self.readying[at].held(), - None => Vec::new(), - }; - let lacking = self.lacking(pool, bytes, &held); + let held = (self.readying_at(pool)).map_or(0, |at| self.readying[at].outstanding_bytes()); + let lacking = self.lacking(pool, bytes, held); if lacking.is_empty() { return; } diff --git a/crates/metal2vulkan-runtime/src/memory/ready.rs b/crates/metal2vulkan-runtime/src/memory/ready.rs index 9121e4c60..3f5937af7 100644 --- a/crates/metal2vulkan-runtime/src/memory/ready.rs +++ b/crates/metal2vulkan-runtime/src/memory/ready.rs @@ -362,16 +362,6 @@ impl Readying { lock(&self.shared.state).will_hold(least) } - /// The bytes of each of its blocks made and not yet added, being made, and still to make. - pub(super) fn held(&self) -> Vec { - let state = lock(&self.shared.state); - let made = state.made.iter().map(|made| made.block.size); - (made - .chain(state.making) - .chain(state.to_make.iter().copied())) - .collect() - } - /// The bytes of each of its blocks made and not yet added, for the crate's device tests. #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] pub(super) fn made(&self) -> Vec { @@ -379,11 +369,13 @@ impl Readying { state.made.iter().map(|made| made.block.size).collect() } - /// What it holds against its heap's budget of kept empty blocks: the bytes of [`held`]. - /// - /// [`held`]: Self::held + /// What it holds against its heap's budget of kept empty blocks: the bytes of its blocks made + /// and not yet added, being made, and still to make. Summed under its lock, no list of them + /// made: every creation call that keeps room in its pool asks it (`Memory::keep_ahead`). pub(super) fn outstanding_bytes(&self) -> u64 { - self.held().iter().sum() + let state = lock(&self.shared.state); + let made: u64 = state.made.iter().map(|made| made.block.size).sum(); + made + state.making.unwrap_or(0) + state.to_make.iter().sum::() } /// Its smallest block made and not yet added of `least` bytes or more, taken.