688: Fix recycling of command buffers r=kvark a=kvark

**Connections**
Fixes https://github.com/gfx-rs/wgpu-rs/issues/333

**Description**
We used `lowest_common_submission()` for figuring out when to reset command buffers, but it returns !0 when there are no active submissions. Instead, we are using the exising "last done" semantics here, which works better.

**Testing**
Tested on wgpu-rs examples.

Co-authored-by: Dzmitry Malyshau <dmalyshau@mozilla.com>
This commit is contained in:
bors[bot] 2020-05-31 15:54:41 +00:00 committed by GitHub
commit 1a569ebe89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 21 deletions

11
Cargo.lock generated
View File

@ -473,7 +473,6 @@ dependencies = [
"raw-window-handle",
"smallvec",
"winapi 0.3.8",
"x11",
]
[[package]]
@ -1510,16 +1509,6 @@ dependencies = [
"winapi-build",
]
[[package]]
name = "x11"
version = "2.18.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77ecd092546cb16f25783a5451538e73afc8d32e242648d54f4ae5459ba1e773"
dependencies = [
"libc",
"pkg-config",
]
[[package]]
name = "x11-dl"
version = "2.18.5"

View File

@ -24,14 +24,14 @@ struct CommandPool<B: hal::Backend> {
}
impl<B: hal::Backend> CommandPool<B> {
fn maintain(&mut self, lowest_active_index: SubmissionIndex) {
fn maintain(&mut self, last_done_index: SubmissionIndex) {
for i in (0..self.pending.len()).rev() {
if self.pending[i].1 < lowest_active_index {
if self.pending[i].1 <= last_done_index {
let (cmd_buf, index) = self.pending.swap_remove(i);
log::trace!(
"recycling comb submitted in {} when {} is lowest active",
"recycling comb submitted in {} when {} is last done",
index,
lowest_active_index,
last_done_index,
);
self.recycle(cmd_buf);
}
@ -185,7 +185,7 @@ impl<B: hal::Backend> CommandAllocator<B> {
let mut inner = self.inner.lock();
inner
.pools
.get_mut(&thread::current().id())
.get_mut(&self.internal_thread_id)
.unwrap()
.pending
.push((raw, submit_index));
@ -202,11 +202,11 @@ impl<B: hal::Backend> CommandAllocator<B> {
.extend(cmd_buf.raw.into_iter().map(|raw| (raw, submit_index)));
}
pub fn maintain(&self, device: &B::Device, lowest_active_index: SubmissionIndex) {
pub fn maintain(&self, device: &B::Device, last_done_index: SubmissionIndex) {
let mut inner = self.inner.lock();
let mut remove_threads = Vec::new();
for (thread_id, pool) in inner.pools.iter_mut() {
pool.maintain(lowest_active_index);
pool.maintain(last_done_index);
if pool.total == pool.available.len() {
assert!(pool.pending.is_empty());
remove_threads.push(*thread_id);

View File

@ -234,6 +234,7 @@ impl<B: hal::Backend> LifetimeTracker<B> {
/// 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.
#[cfg(feature = "replay")]
pub fn lowest_active_submission(&self) -> SubmissionIndex {
self.active
.iter()

View File

@ -312,12 +312,11 @@ impl<B: GfxBackend> Device<B> {
);
life_tracker.triage_mapped(global, token);
life_tracker.triage_framebuffers(global, &mut *self.framebuffers.lock(), token);
let _last_done = life_tracker.triage_submissions(&self.raw, force_wait);
let last_done = life_tracker.triage_submissions(&self.raw, force_wait);
let callbacks = life_tracker.handle_mapping(global, &self.raw, &self.trackers, token);
life_tracker.cleanup(&self.raw, &self.mem_allocator, &self.desc_allocator);
self.com_allocator
.maintain(&self.raw, life_tracker.lowest_active_submission());
self.com_allocator.maintain(&self.raw, last_done);
callbacks
}