From bb720dd7262c3014066a25c847b4f4902a2a20c3 Mon Sep 17 00:00:00 2001 From: msiglreith Date: Wed, 15 Apr 2020 22:35:48 +0200 Subject: [PATCH] Add metal surface extension (#288) --- ash/src/extensions/ext/metal_surface.rs | 56 +++++++++++++++++++++++++ ash/src/extensions/ext/mod.rs | 2 + 2 files changed, 58 insertions(+) create mode 100644 ash/src/extensions/ext/metal_surface.rs diff --git a/ash/src/extensions/ext/metal_surface.rs b/ash/src/extensions/ext/metal_surface.rs new file mode 100644 index 0000000..e3ff554 --- /dev/null +++ b/ash/src/extensions/ext/metal_surface.rs @@ -0,0 +1,56 @@ +#![allow(dead_code)] +use crate::prelude::*; +use crate::version::{EntryV1_0, InstanceV1_0}; +use crate::vk; +use crate::RawPtr; +use std::ffi::CStr; +use std::mem; + +#[derive(Clone)] +pub struct MetalSurface { + handle: vk::Instance, + metal_surface_fn: vk::ExtMetalSurfaceFn, +} + +impl MetalSurface { + pub fn new(entry: &E, instance: &I) -> MetalSurface { + let surface_fn = vk::ExtMetalSurfaceFn::load(|name| unsafe { + mem::transmute(entry.get_instance_proc_addr(instance.handle(), name.as_ptr())) + }); + MetalSurface { + handle: instance.handle(), + metal_surface_fn: surface_fn, + } + } + + pub fn name() -> &'static CStr { + vk::ExtMetalSurfaceFn::name() + } + + #[doc = ""] + pub unsafe fn create_metal_surface( + &self, + create_info: &vk::MetalSurfaceCreateInfoEXT, + allocation_callbacks: Option<&vk::AllocationCallbacks>, + ) -> VkResult { + let mut surface = mem::zeroed(); + let err_code = self.metal_surface_fn.create_metal_surface_ext( + self.handle, + create_info, + allocation_callbacks.as_raw_ptr(), + &mut surface, + ); + match err_code { + vk::Result::SUCCESS => Ok(surface), + _ => Err(err_code), + } + } + + pub fn fp(&self) -> &vk::ExtMetalSurfaceFn { + &self.metal_surface_fn + } + + pub fn instance(&self) -> vk::Instance { + self.handle + } +} diff --git a/ash/src/extensions/ext/mod.rs b/ash/src/extensions/ext/mod.rs index eba690f..1885933 100644 --- a/ash/src/extensions/ext/mod.rs +++ b/ash/src/extensions/ext/mod.rs @@ -1,7 +1,9 @@ pub use self::debug_marker::DebugMarker; pub use self::debug_report::DebugReport; pub use self::debug_utils::DebugUtils; +pub use self::metal_surface::MetalSurface; mod debug_marker; mod debug_report; mod debug_utils; +mod metal_surface;