diff --git a/CHANGELOG.md b/CHANGELOG.md index c31f3ac77..3eef977e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -141,6 +141,7 @@ By @beholdnec in [#8505](https://github.com/gfx-rs/wgpu/pull/8505). - Add `metal::Queue::add_wait_event` / `add_signal_event` (with `remove_*` companions) to stage `MTLSharedEvent` waits/signals on the next `Queue::submit`, for GPU-side interop with foreign APIs. Waits run on an internal CB committed before user CBs. By @AdrianEddy in [#9483](https://github.com/gfx-rs/wgpu/pull/9483). - Unconditionally enable `Features::CLIP_DISTANCES`. By @ErichDonGubler in [#9270](https://github.com/gfx-rs/wgpu/pull/9270). - Added full support for mesh shaders, including in WGSL shaders. By @inner-daemons in [#8739](https://github.com/gfx-rs/wgpu/pull/8739). +- Added `DropCallback`s to Metal textures. By @jerzywilczek in [#9634](https://github.com/gfx-rs/wgpu/pull/9634). #### GLES diff --git a/wgpu-hal/src/lib.rs b/wgpu-hal/src/lib.rs index 8082ed120..0a4d12b47 100644 --- a/wgpu-hal/src/lib.rs +++ b/wgpu-hal/src/lib.rs @@ -339,15 +339,15 @@ pub type AtomicFenceValue = core::sync::atomic::AtomicU64; pub type AtomicFenceValue = portable_atomic::AtomicU64; /// A callback to signal that wgpu is no longer using a resource. -#[cfg(any(gles, vulkan))] +#[cfg(any(gles, vulkan, metal))] pub type DropCallback = Box; -#[cfg(any(gles, vulkan))] +#[cfg(any(gles, vulkan, metal))] pub struct DropGuard { callback: Option, } -#[cfg(all(any(gles, vulkan), any(native, Emscripten)))] +#[cfg(all(any(gles, vulkan, metal), any(native, Emscripten)))] impl DropGuard { fn from_option(callback: Option) -> Option { callback.map(Self::new) @@ -360,7 +360,7 @@ impl DropGuard { } } -#[cfg(any(gles, vulkan))] +#[cfg(any(gles, vulkan, metal))] impl Drop for DropGuard { fn drop(&mut self) { if let Some(cb) = self.callback.take() { @@ -369,7 +369,7 @@ impl Drop for DropGuard { } } -#[cfg(any(gles, vulkan))] +#[cfg(any(gles, vulkan, metal))] impl fmt::Debug for DropGuard { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("DropGuard").finish() diff --git a/wgpu-hal/src/metal/device.rs b/wgpu-hal/src/metal/device.rs index d488116cd..c811f115a 100644 --- a/wgpu-hal/src/metal/device.rs +++ b/wgpu-hal/src/metal/device.rs @@ -25,7 +25,7 @@ use objc2_metal::{ use parking_lot::{Condvar, Mutex, RwLock}; use super::{adapter::VERTEX_BUFFER_SLOT_START, conv, PassthroughShader, ShaderModuleSource}; -use crate::{auxil::map_naga_stage, TlasInstance}; +use crate::{auxil::map_naga_stage, DropCallback, DropGuard, TlasInstance}; type DeviceResult = Result; @@ -389,6 +389,7 @@ impl super::Device { array_layers: u32, mip_levels: u32, copy_size: crate::CopyExtent, + drop_callback: Option, ) -> super::Texture { super::Texture { raw, @@ -397,6 +398,7 @@ impl super::Device { array_layers, mip_levels, copy_size, + _drop_guard: DropGuard::from_option(drop_callback), } } @@ -568,6 +570,7 @@ impl crate::Device for super::Device { mip_levels: desc.mip_level_count, array_layers: desc.array_layer_count(), copy_size: desc.copy_extent(), + _drop_guard: None, }) }) } diff --git a/wgpu-hal/src/metal/mod.rs b/wgpu-hal/src/metal/mod.rs index a8d51e14b..e0decffc2 100644 --- a/wgpu-hal/src/metal/mod.rs +++ b/wgpu-hal/src/metal/mod.rs @@ -858,6 +858,10 @@ pub struct Texture { array_layers: u32, mip_levels: u32, copy_size: crate::CopyExtent, + + // The `drop_guard` field must be the last field of this struct so it is dropped last. + // Do not add new fields after it. + _drop_guard: Option, } impl Texture { diff --git a/wgpu-hal/src/metal/surface.rs b/wgpu-hal/src/metal/surface.rs index 1b08c53d4..b3637325e 100644 --- a/wgpu-hal/src/metal/surface.rs +++ b/wgpu-hal/src/metal/surface.rs @@ -181,6 +181,7 @@ impl crate::Surface for super::Surface { height: extent.height, depth: 1, }, + _drop_guard: None, }, drawable: ProtocolObject::from_retained(drawable), present_with_transaction: render_layer.presentsWithTransaction(),