mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-21 22:33:49 +00:00
use ManuallyDrop
for texture views of TextureClearMode
This commit is contained in:
parent
ce9c9b76f6
commit
1aaaec22f6
@ -971,7 +971,7 @@ impl<A: HalApi> Device<A> {
|
||||
array_layer_count: Some(1),
|
||||
},
|
||||
};
|
||||
clear_views.push(Some(
|
||||
clear_views.push(ManuallyDrop::new(
|
||||
unsafe { self.raw().create_texture_view(&raw_texture, &desc) }
|
||||
.map_err(DeviceError::from)?,
|
||||
));
|
||||
|
@ -9,7 +9,7 @@ When this texture is presented, we remove it from the device tracker as well as
|
||||
extract it from the hub.
|
||||
!*/
|
||||
|
||||
use std::{borrow::Borrow, sync::Arc};
|
||||
use std::{borrow::Borrow, mem::ManuallyDrop, sync::Arc};
|
||||
|
||||
#[cfg(feature = "trace")]
|
||||
use crate::device::trace::Action;
|
||||
@ -215,7 +215,7 @@ impl Global {
|
||||
&texture_desc,
|
||||
format_features,
|
||||
resource::TextureClearMode::Surface {
|
||||
clear_view: Some(clear_view),
|
||||
clear_view: ManuallyDrop::new(clear_view),
|
||||
},
|
||||
true,
|
||||
);
|
||||
|
@ -972,11 +972,11 @@ pub enum TextureClearMode<A: HalApi> {
|
||||
BufferCopy,
|
||||
// View for clear via RenderPass for every subsurface (mip/layer/slice)
|
||||
RenderPass {
|
||||
clear_views: SmallVec<[Option<A::TextureView>; 1]>,
|
||||
clear_views: SmallVec<[ManuallyDrop<A::TextureView>; 1]>,
|
||||
is_color: bool,
|
||||
},
|
||||
Surface {
|
||||
clear_view: Option<A::TextureView>,
|
||||
clear_view: ManuallyDrop<A::TextureView>,
|
||||
},
|
||||
// Texture can't be cleared, attempting to do so will cause panic.
|
||||
// (either because it is impossible for the type of texture or it is being destroyed)
|
||||
@ -1062,10 +1062,10 @@ impl<A: HalApi> Drop for Texture<A> {
|
||||
TextureClearMode::Surface {
|
||||
ref mut clear_view, ..
|
||||
} => {
|
||||
if let Some(view) = clear_view.take() {
|
||||
unsafe {
|
||||
self.device.raw().destroy_texture_view(view);
|
||||
}
|
||||
// SAFETY: We are in the Drop impl and we don't use clear_view anymore after this point.
|
||||
let raw = unsafe { ManuallyDrop::take(clear_view) };
|
||||
unsafe {
|
||||
self.device.raw().destroy_texture_view(raw);
|
||||
}
|
||||
}
|
||||
TextureClearMode::RenderPass {
|
||||
@ -1073,10 +1073,10 @@ impl<A: HalApi> Drop for Texture<A> {
|
||||
..
|
||||
} => {
|
||||
clear_views.iter_mut().for_each(|clear_view| {
|
||||
if let Some(view) = clear_view.take() {
|
||||
unsafe {
|
||||
self.device.raw().destroy_texture_view(view);
|
||||
}
|
||||
// SAFETY: We are in the Drop impl and we don't use clear_view anymore after this point.
|
||||
let raw = unsafe { ManuallyDrop::take(clear_view) };
|
||||
unsafe {
|
||||
self.device.raw().destroy_texture_view(raw);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -1129,7 +1129,7 @@ impl<A: HalApi> Texture<A> {
|
||||
TextureClearMode::None => {
|
||||
panic!("Given texture can't be cleared")
|
||||
}
|
||||
TextureClearMode::Surface { ref clear_view, .. } => clear_view.as_ref().unwrap(),
|
||||
TextureClearMode::Surface { ref clear_view, .. } => clear_view,
|
||||
TextureClearMode::RenderPass {
|
||||
ref clear_views, ..
|
||||
} => {
|
||||
@ -1140,7 +1140,7 @@ impl<A: HalApi> Texture<A> {
|
||||
} else {
|
||||
mip_level * desc.size.depth_or_array_layers
|
||||
} + depth_or_layer;
|
||||
clear_views[index as usize].as_ref().unwrap()
|
||||
&clear_views[index as usize]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user