mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-29 09:34:09 +01:00
Add DropGuards to Metal Textures (#9634)
This commit is contained in:
1 parent
019bce9139
commit
792ec39c99
5 files changed
+15
-6
No files matched your search
@@ -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
|
||||
|
||||
|
||||
+5
-5
@@ -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<dyn FnOnce() + Send + Sync + 'static>;
|
||||
|
||||
#[cfg(any(gles, vulkan))]
|
||||
#[cfg(any(gles, vulkan, metal))]
|
||||
pub struct DropGuard {
|
||||
callback: Option<DropCallback>,
|
||||
}
|
||||
|
||||
#[cfg(all(any(gles, vulkan), any(native, Emscripten)))]
|
||||
#[cfg(all(any(gles, vulkan, metal), any(native, Emscripten)))]
|
||||
impl DropGuard {
|
||||
fn from_option(callback: Option<DropCallback>) -> Option<Self> {
|
||||
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()
|
||||
|
||||
@@ -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<T> = Result<T, crate::DeviceError>;
|
||||
|
||||
@@ -389,6 +389,7 @@ impl super::Device {
|
||||
array_layers: u32,
|
||||
mip_levels: u32,
|
||||
copy_size: crate::CopyExtent,
|
||||
drop_callback: Option<DropCallback>,
|
||||
) -> 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,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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<crate::DropGuard>,
|
||||
}
|
||||
|
||||
impl Texture {
|
||||
|
||||
@@ -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(),
|
||||
|
||||
Reference in new issue
Block a user