Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix locking of device lifetime tracker on resource drop #984

Merged
merged 1 commit into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 29 additions & 26 deletions wgpu-core/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ impl<B: GfxBackend> Device<B> {

pub(crate) fn lock_life<'this, 'token: 'this>(
&'this self,
//TODO: fix this - the token has to be borrowed for the lock
token: &mut Token<'token, Self>,
) -> MutexGuard<'this, life::LifetimeTracker<B>> {
Self::lock_life_internal(&self.life_tracker, token)
Expand Down Expand Up @@ -1282,19 +1283,20 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {

let (device_guard, mut token) = hub.devices.read(&mut token);
let device = &device_guard[device_id];
let mut life_lock = device_guard[device_id].lock_life(&mut token);

if device.pending_writes.dst_buffers.contains(&buffer_id) {
life_lock.future_suspected_buffers.push(Stored {
value: id::Valid(buffer_id),
ref_count,
});
} else {
drop(ref_count);
life_lock
.suspected_resources
.buffers
.push(id::Valid(buffer_id));
{
let mut life_lock = device.lock_life(&mut token);
if device.pending_writes.dst_buffers.contains(&buffer_id) {
life_lock.future_suspected_buffers.push(Stored {
value: id::Valid(buffer_id),
ref_count,
});
} else {
drop(ref_count);
life_lock
.suspected_resources
.buffers
.push(id::Valid(buffer_id));
}
}

if wait {
Expand Down Expand Up @@ -1429,19 +1431,20 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {

let (device_guard, mut token) = hub.devices.read(&mut token);
let device = &device_guard[device_id];
let mut life_lock = device_guard[device_id].lock_life(&mut token);

if device.pending_writes.dst_textures.contains(&texture_id) {
life_lock.future_suspected_textures.push(Stored {
value: id::Valid(texture_id),
ref_count,
});
} else {
drop(ref_count);
life_lock
.suspected_resources
.textures
.push(id::Valid(texture_id));
{
let mut life_lock = device.lock_life(&mut token);
if device.pending_writes.dst_textures.contains(&texture_id) {
life_lock.future_suspected_textures.push(Stored {
value: id::Valid(texture_id),
ref_count,
});
} else {
drop(ref_count);
life_lock
.suspected_resources
.textures
.push(id::Valid(texture_id));
}
}

if wait {
Expand Down
4 changes: 2 additions & 2 deletions wgpu-core/src/device/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use crate::id;
use std::ops::Range;
#[cfg(feature = "trace")]
use std::io::Write as _;
use std::{borrow::Cow, ops::Range};
use std::{borrow::Cow, io::Write as _};

//TODO: consider a readable Id that doesn't include the backend

Expand Down