Merge pull request #1945 from kvark/view-parent

Store a reference to the device in texture views
This commit is contained in:
Connor Fitzgerald 2021-09-12 20:22:51 -04:00 committed by GitHub
commit e8c236cd71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 16 deletions

View File

@ -809,6 +809,7 @@ impl<A: HalApi> Device<A> {
value: id::Valid(texture_id),
ref_count: texture.life_guard.add_ref(),
},
device_id: texture.device_id.clone(),
desc: resource::HalTextureViewDescriptor {
format: hal_desc.format,
dimension: hal_desc.dimension,
@ -3294,15 +3295,13 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let mut token = Token::root();
let (last_submit_index, device_id) = {
let (texture_guard, mut token) = hub.textures.read(&mut token);
let (mut texture_view_guard, _) = hub.texture_views.write(&mut token);
match texture_view_guard.get_mut(texture_view_id) {
Ok(view) => {
let _ref_count = view.life_guard.ref_count.take();
let last_submit_index = view.life_guard.life_count();
let device_id = texture_guard[view.parent_id.value].device_id.value;
(last_submit_index, device_id)
(last_submit_index, view.device_id.value)
}
Err(InvalidId) => {
hub.texture_views

View File

@ -644,19 +644,12 @@ impl<A: HalApi, F: GlobalIdentityHandlerFactory> Hub<A, F> {
}
}
}
{
let textures = self.textures.data.read();
for element in self.texture_views.data.write().map.drain(..) {
if let Element::Occupied(texture_view, _) = element {
// the texture should generally be present, unless it's a surface
// texture, and we are in emergency shutdown.
if textures.contains(texture_view.parent_id.value.0) {
let texture = &textures[texture_view.parent_id.value];
let device = &devices[texture.device_id.value];
unsafe {
device.raw.destroy_texture_view(texture_view.raw);
}
}
for element in self.texture_views.data.write().map.drain(..) {
if let Element::Occupied(texture_view, _) = element {
let device = &devices[texture_view.device_id.value];
unsafe {
device.raw.destroy_texture_view(texture_view.raw);
}
}
}

View File

@ -296,7 +296,10 @@ impl HalTextureViewDescriptor {
#[derive(Debug)]
pub struct TextureView<A: hal::Api> {
pub(crate) raw: A::TextureView,
// The parent's refcount is held alive, but the parent may still be deleted
// if it's a surface texture. TODO: make this cleaner.
pub(crate) parent_id: Stored<TextureId>,
pub(crate) device_id: Stored<DeviceId>,
//TODO: store device_id for quick access?
pub(crate) desc: HalTextureViewDescriptor,
pub(crate) format_features: wgt::TextureFormatFeatures,