From 5371c96108aab85d6da9d6ed7783c7c5e348539f Mon Sep 17 00:00:00 2001 From: David Lin Date: Sat, 14 Oct 2017 11:44:15 +0800 Subject: [PATCH 1/4] initial work --- ash/Cargo.toml | 4 ++++ ash/src/entry.rs | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ash/Cargo.toml b/ash/Cargo.toml index 40837a5..1474cd3 100644 --- a/ash/Cargo.toml +++ b/ash/Cargo.toml @@ -14,5 +14,9 @@ shared_library = "0.1.5" lazy_static = "0.2.1" libc = "0.2.26" +[features] +default = [] +moltenvk = [] + [package.metadata.release] no-dev-version = true diff --git a/ash/src/entry.rs b/ash/src/entry.rs index 0e59883..9cebc8d 100644 --- a/ash/src/entry.rs +++ b/ash/src/entry.rs @@ -15,7 +15,7 @@ fn get_path() -> &'static Path { Path::new("vulkan-1.dll") } -#[cfg(all(unix, not(target_os = "android")))] +#[cfg(all(unix, not(any(feature = "moltenvk", target_os = "android"))))] fn get_path() -> &'static Path { Path::new("libvulkan.so.1") } @@ -25,6 +25,11 @@ fn get_path() -> &'static Path { Path::new("libvulkan.so") } +#[cfg(all(feature = "moltenvk", any(target_os = "macos", target_os = "ios")))] +fn get_path() -> &'static Path { + Path::new("libMoltenVK.dylib") +} + lazy_static!{ static ref VK_LIB: Result = DynamicLibrary::open(Some(get_path())); } From a38820fe6797e1f369f4b0b31b5b7be568235da2 Mon Sep 17 00:00:00 2001 From: David Lin Date: Sat, 14 Oct 2017 12:06:01 +0800 Subject: [PATCH 2/4] add native types --- ash/src/vk.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/ash/src/vk.rs b/ash/src/vk.rs index f30734a..d8ba04d 100644 --- a/ash/src/vk.rs +++ b/ash/src/vk.rs @@ -270,6 +270,8 @@ pub mod types { vk_bitflags_wrapped!(SwapchainCreateFlagsKHR, 0b0, Flags); vk_bitflags_wrapped!(DisplayModeCreateFlagsKHR, 0b0, Flags); vk_bitflags_wrapped!(DisplaySurfaceCreateFlagsKHR, 0b0, Flags); + vk_bitflags_wrapped!(IOSSurfaceCreateFlagsMVK, 0b0, Flags); + vk_bitflags_wrapped!(MacOSSurfaceCreateFlagsMVK, 0b0, Flags); pub const VK_MAX_PHYSICAL_DEVICE_NAME_SIZE: size_t = 256; pub const VK_UUID_SIZE: size_t = 16; @@ -308,6 +310,10 @@ pub mod types { pub const VK_KHR_DISPLAY_EXTENSION_NAME: &'static str = "VK_KHR_display"; pub const VK_EXT_DEBUG_REPORT_SPEC_VERSION: uint32_t = 3; pub const VK_EXT_DEBUG_REPORT_EXTENSION_NAME: &'static str = "VK_EXT_debug_report"; + pub const VK_MVK_IOS_SURFACE_SPEC_VERSION: uint32_t = 2; + pub const VK_MVK_IOS_SURFACE_EXTENSION_NAME: &'static str = "VK_MVK_ios_surface"; + pub const VK_MVK_MACOS_SURFACE_SPEC_VERSION: uint32_t = 2; + pub const VK_MVK_MACOS_SURFACE_EXTENSION_NAME: &'static str = "VK_MVK_macos_surface"; #[derive(Debug, Clone)] #[repr(C)] @@ -2556,6 +2562,23 @@ pub mod types { } } + #[derive(Debug, Clone)] + #[repr(C)] + pub struct IOSSurfaceCreateInfoMVK { + pub s_type: StructureType, + pub p_next: *const c_void, + pub flags: IOSSurfaceCreateFlagsMVK, + pub p_view: *const c_void, + } + + #[derive(Debug, Clone)] + #[repr(C)] + pub struct MacOSSurfaceCreateInfoMVK { + pub s_type: StructureType, + pub p_next: *const c_void, + pub flags: MacOSSurfaceCreateFlagsMVK, + pub p_view: *const c_void, + } /// Temporary Hard-Coded union hack; will be automatically generated when actual unions become stable #[repr(C)] @@ -2741,6 +2764,8 @@ pub mod types { DisplayModeCreateInfoKhr = 1000002000, DisplaySurfaceCreateInfoKhr = 1000002001, DebugReportCallbackCreateInfoExt = 1000011000, + IOSSurfaceCreateInfoMvk = 1000122000, + MacOSSurfaceCreateInfoMvk = 1000123000, } #[repr(C)] @@ -5104,4 +5129,24 @@ pub mod cmds { p_surface: *mut SurfaceKHR, ) -> Result; } + + vk_functions!{ + IOSSurfaceFn, + "vkCreateIOSSurfaceMVK", create_ios_surface_mvk( + instance: Instance, + p_create_info: *const IOSSurfaceCreateInfoMVK, + p_allocator: *const AllocationCallbacks, + p_surface: *mut SurfaceKHR, + ) -> Result; +} + + vk_functions!{ + MacOSSurfaceFn, + "vkCreateMacOSSurfaceMVK", create_macos_surface_mvk( + instance: Instance, + p_create_info: *const MacOSSurfaceCreateInfoMVK, + p_allocator: *const AllocationCallbacks, + p_surface: *mut SurfaceKHR, + ) -> Result; +} } From 85c3054fbbd388fe0ca2d7177132b48d096ff4a9 Mon Sep 17 00:00:00 2001 From: David Lin Date: Sat, 14 Oct 2017 12:12:05 +0800 Subject: [PATCH 3/4] add extension wrapper --- ash/src/extensions/ios_surface.rs | 53 +++++++++++++++++++++++++++++ ash/src/extensions/macos_surface.rs | 53 +++++++++++++++++++++++++++++ ash/src/extensions/mod.rs | 4 +++ 3 files changed, 110 insertions(+) create mode 100644 ash/src/extensions/ios_surface.rs create mode 100644 ash/src/extensions/macos_surface.rs diff --git a/ash/src/extensions/ios_surface.rs b/ash/src/extensions/ios_surface.rs new file mode 100644 index 0000000..2e4bd45 --- /dev/null +++ b/ash/src/extensions/ios_surface.rs @@ -0,0 +1,53 @@ +#![allow(dead_code)] +use prelude::*; +use std::mem; +use vk; +use std::ffi::CStr; +use RawPtr; +use version::{EntryV1_0, InstanceV1_0}; + +#[derive(Clone)] +pub struct IOSSurface { + handle: vk::Instance, + ios_surface_fn: vk::IOSSurfaceFn, +} + +impl IOSSurface { + pub fn new( + entry: &E, + instance: &I, + ) -> Result> { + let surface_fn = vk::IOSSurfaceFn::load(|name| unsafe { + mem::transmute(entry.get_instance_proc_addr( + instance.handle(), + name.as_ptr(), + )) + })?; + Ok(IOSSurface { + handle: instance.handle(), + ios_surface_fn: surface_fn, + }) + } + + pub fn name() -> &'static CStr { + CStr::from_bytes_with_nul(b"VK_MVK_IOS_surface\0").expect("Wrong extension string") + } + + pub unsafe fn create_ios_surface_mvk( + &self, + create_info: &vk::IOSSurfaceCreateInfoMVK, + allocation_callbacks: Option<&vk::AllocationCallbacks>, + ) -> VkResult { + let mut surface = mem::uninitialized(); + let err_code = self.ios_surface_fn.create_ios_surface_mvk( + self.handle, + create_info, + allocation_callbacks.as_raw_ptr(), + &mut surface, + ); + match err_code { + vk::Result::Success => Ok(surface), + _ => Err(err_code), + } + } +} diff --git a/ash/src/extensions/macos_surface.rs b/ash/src/extensions/macos_surface.rs new file mode 100644 index 0000000..92a1bbc --- /dev/null +++ b/ash/src/extensions/macos_surface.rs @@ -0,0 +1,53 @@ +#![allow(dead_code)] +use prelude::*; +use std::mem; +use vk; +use std::ffi::CStr; +use RawPtr; +use version::{EntryV1_0, InstanceV1_0}; + +#[derive(Clone)] +pub struct MacOSSurface { + handle: vk::Instance, + macos_surface_fn: vk::MacOSSurfaceFn, +} + +impl MacOSSurface { + pub fn new( + entry: &E, + instance: &I, + ) -> Result> { + let surface_fn = vk::MacOSSurfaceFn::load(|name| unsafe { + mem::transmute(entry.get_instance_proc_addr( + instance.handle(), + name.as_ptr(), + )) + })?; + Ok(MacOSSurface { + handle: instance.handle(), + macos_surface_fn: surface_fn, + }) + } + + pub fn name() -> &'static CStr { + CStr::from_bytes_with_nul(b"VK_MVK_macos_surface\0").expect("Wrong extension string") + } + + pub unsafe fn create_macos_surface_mvk( + &self, + create_info: &vk::MacOSSurfaceCreateInfoMVK, + allocation_callbacks: Option<&vk::AllocationCallbacks>, + ) -> VkResult { + let mut surface = mem::uninitialized(); + let err_code = self.macos_surface_fn.create_macos_surface_mvk( + self.handle, + create_info, + allocation_callbacks.as_raw_ptr(), + &mut surface, + ); + match err_code { + vk::Result::Success => Ok(surface), + _ => Err(err_code), + } + } +} diff --git a/ash/src/extensions/mod.rs b/ash/src/extensions/mod.rs index 761b363..b95213e 100644 --- a/ash/src/extensions/mod.rs +++ b/ash/src/extensions/mod.rs @@ -8,6 +8,8 @@ pub use self::mir_surface::MirSurface; pub use self::xcb_surface::XcbSurface; pub use self::wayland_surface::WaylandSurface; pub use self::android_surface::AndroidSurface; +pub use self::macos_surface::MacOSSurface; +pub use self::ios_surface::IOSSurface; mod swapchain; mod display_swapchain; @@ -19,3 +21,5 @@ mod mir_surface; mod android_surface; mod wayland_surface; mod xcb_surface; +mod macos_surface; +mod ios_surface; From 63c859a4620977597d06e9584cb1828998908bf5 Mon Sep 17 00:00:00 2001 From: David Lin Date: Sat, 14 Oct 2017 13:43:02 +0800 Subject: [PATCH 4/4] remove moltenvk feature --- ash/Cargo.toml | 1 - ash/src/entry.rs | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/ash/Cargo.toml b/ash/Cargo.toml index 1474cd3..59e2933 100644 --- a/ash/Cargo.toml +++ b/ash/Cargo.toml @@ -16,7 +16,6 @@ libc = "0.2.26" [features] default = [] -moltenvk = [] [package.metadata.release] no-dev-version = true diff --git a/ash/src/entry.rs b/ash/src/entry.rs index 9cebc8d..d9511e5 100644 --- a/ash/src/entry.rs +++ b/ash/src/entry.rs @@ -15,7 +15,7 @@ fn get_path() -> &'static Path { Path::new("vulkan-1.dll") } -#[cfg(all(unix, not(any(feature = "moltenvk", target_os = "android"))))] +#[cfg(all(unix, not(any(target_os = "macos", target_os = "ios", target_os = "android"))))] fn get_path() -> &'static Path { Path::new("libvulkan.so.1") } @@ -25,7 +25,7 @@ fn get_path() -> &'static Path { Path::new("libvulkan.so") } -#[cfg(all(feature = "moltenvk", any(target_os = "macos", target_os = "ios")))] +#[cfg(any(target_os = "macos", target_os = "ios"))] fn get_path() -> &'static Path { Path::new("libMoltenVK.dylib") }