From a221ca1c12725e4c9f78e0bbc04f06e68335b922 Mon Sep 17 00:00:00 2001 From: Layl <2385329-layl@users.noreply.gitlab.com> Date: Wed, 8 Jan 2020 01:17:58 +0100 Subject: [PATCH] Fix cmd buffer cleanup not always using lowest active index --- wgpu-core/src/command/allocator.rs | 2 +- wgpu-core/src/device.rs | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/wgpu-core/src/command/allocator.rs b/wgpu-core/src/command/allocator.rs index 92ac46d27d..2c5c9eaa14 100644 --- a/wgpu-core/src/command/allocator.rs +++ b/wgpu-core/src/command/allocator.rs @@ -35,7 +35,7 @@ impl CommandPool { if index < lowest_active_index { let cmd_buf = self.pending.swap_remove(i); log::trace!( - "recycling comb submitted in {} when {} is done", + "recycling comb submitted in {} when {} is lowest active", index, lowest_active_index, ); diff --git a/wgpu-core/src/device.rs b/wgpu-core/src/device.rs index c140641c6d..4ad66bdc2b 100644 --- a/wgpu-core/src/device.rs +++ b/wgpu-core/src/device.rs @@ -1546,11 +1546,12 @@ impl> Global { ref_count: device.life_guard.ref_count.clone(), }; - // The first entry in the active list should have the lowest index + // Find the pending entry with the lowest active index. If none can be found that means + // everything in the allocator can be cleaned up, so std::usize::MAX is correct. let lowest_active_index = device.pending.lock() - .active.get(0) - .map(|active| active.index) - .unwrap_or(0); + .active + .iter() + .fold(std::usize::MAX, |v, active| active.index.min(v)); let mut comb = device .com_allocator