use ::wgpu;
use super::super::PreparedWgpuContext;
use super::{ExportedTextureAlloc, ExternalSyncHandle};
pub(crate) struct MetalIoSurfaceGuard {
iosurface_ref: u64,
}
impl Drop for MetalIoSurfaceGuard {
fn drop(&mut self) {
if self.iosurface_ref != 0 {
unsafe extern "C" {
fn CFRelease(cf: *const core::ffi::c_void);
}
unsafe {
CFRelease(self.iosurface_ref as usize as *const core::ffi::c_void);
}
}
}
}
pub(crate) struct MetalSharedFence {
val: core::sync::atomic::AtomicU64,
}
impl MetalSharedFence {
pub(crate) fn new(_device: &wgpu::Device) -> Option<Self> {
Some(Self {
val: core::sync::atomic::AtomicU64::new(0),
})
}
pub(crate) fn export_handle(&self) -> ExternalSyncHandle {
ExternalSyncHandle::None
}
pub(crate) fn signal_on_device(&self, device: &wgpu::Device, value: u64) {
let _ = device.poll(wgpu::PollType::Poll);
self.val.store(value, core::sync::atomic::Ordering::Release);
}
pub(crate) fn completed_value(&self) -> u64 {
self.val.load(core::sync::atomic::Ordering::Acquire)
}
pub(crate) fn wait_cpu(&self, device: &wgpu::Device, value: u64, _timeout_ms: u32) -> bool {
let _ = device.poll(wgpu::PollType::wait_indefinitely());
self.val.load(core::sync::atomic::Ordering::Acquire) >= value
}
}
pub(crate) fn init_aligned_metal_context() -> Option<PreparedWgpuContext> {
PreparedWgpuContext::init_headless()
}
#[derive(Copy, Clone, Debug)]
pub struct MetalIoSurfaceDesc {
pub width: u32,
pub height: u32,
pub bytes_per_element: u32,
pub bytes_per_row: u32,
pub pixel_format_fourcc: u32, }
impl MetalIoSurfaceDesc {
#[inline]
pub const fn new_bgra8(width: u32, height: u32) -> Self {
let w = if width == 0 { 1 } else { width };
let h = if height == 0 { 1 } else { height };
let stride = (w * 4 + 63) & !63; Self {
width: w,
height: h,
bytes_per_element: 4,
bytes_per_row: stride,
pixel_format_fourcc: 0x4247_5241,
}
}
}
pub(crate) fn allocate_metal_shared_texture(
_device: &wgpu::Device,
width: u32,
height: u32,
_format: wgpu::TextureFormat,
) -> Option<ExportedTextureAlloc> {
let _desc = MetalIoSurfaceDesc::new_bgra8(width, height);
None
}