Fix locking of device lifetime tracker on resource drop

This commit is contained in:
Dzmitry Malyshau 2020-10-13 18:37:07 -04:00
parent 7ac706f0a9
commit ecbf81f4c9
2 changed files with 31 additions and 28 deletions

View File

@ -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)
@ -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 {
@ -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 {

View File

@ -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