Merge pull request #36 from davll/moltenvk
Add MoltenVK support on macOS/iOS
This commit is contained in:
commit
fe16c135f3
|
@ -14,5 +14,8 @@ shared_library = "0.1.5"
|
||||||
lazy_static = "0.2.1"
|
lazy_static = "0.2.1"
|
||||||
libc = "0.2.26"
|
libc = "0.2.26"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = []
|
||||||
|
|
||||||
[package.metadata.release]
|
[package.metadata.release]
|
||||||
no-dev-version = true
|
no-dev-version = true
|
||||||
|
|
|
@ -15,7 +15,7 @@ fn get_path() -> &'static Path {
|
||||||
Path::new("vulkan-1.dll")
|
Path::new("vulkan-1.dll")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(unix, not(target_os = "android")))]
|
#[cfg(all(unix, not(any(target_os = "macos", target_os = "ios", target_os = "android"))))]
|
||||||
fn get_path() -> &'static Path {
|
fn get_path() -> &'static Path {
|
||||||
Path::new("libvulkan.so.1")
|
Path::new("libvulkan.so.1")
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,11 @@ fn get_path() -> &'static Path {
|
||||||
Path::new("libvulkan.so")
|
Path::new("libvulkan.so")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
||||||
|
fn get_path() -> &'static Path {
|
||||||
|
Path::new("libMoltenVK.dylib")
|
||||||
|
}
|
||||||
|
|
||||||
lazy_static!{
|
lazy_static!{
|
||||||
static ref VK_LIB: Result<DynamicLibrary, String> = DynamicLibrary::open(Some(get_path()));
|
static ref VK_LIB: Result<DynamicLibrary, String> = DynamicLibrary::open(Some(get_path()));
|
||||||
}
|
}
|
||||||
|
|
53
ash/src/extensions/ios_surface.rs
Normal file
53
ash/src/extensions/ios_surface.rs
Normal file
|
@ -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<E: EntryV1_0, I: InstanceV1_0>(
|
||||||
|
entry: &E,
|
||||||
|
instance: &I,
|
||||||
|
) -> Result<IOSSurface, Vec<&'static str>> {
|
||||||
|
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<vk::SurfaceKHR> {
|
||||||
|
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),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
53
ash/src/extensions/macos_surface.rs
Normal file
53
ash/src/extensions/macos_surface.rs
Normal file
|
@ -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<E: EntryV1_0, I: InstanceV1_0>(
|
||||||
|
entry: &E,
|
||||||
|
instance: &I,
|
||||||
|
) -> Result<MacOSSurface, Vec<&'static str>> {
|
||||||
|
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<vk::SurfaceKHR> {
|
||||||
|
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),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,6 +8,8 @@ pub use self::mir_surface::MirSurface;
|
||||||
pub use self::xcb_surface::XcbSurface;
|
pub use self::xcb_surface::XcbSurface;
|
||||||
pub use self::wayland_surface::WaylandSurface;
|
pub use self::wayland_surface::WaylandSurface;
|
||||||
pub use self::android_surface::AndroidSurface;
|
pub use self::android_surface::AndroidSurface;
|
||||||
|
pub use self::macos_surface::MacOSSurface;
|
||||||
|
pub use self::ios_surface::IOSSurface;
|
||||||
|
|
||||||
mod swapchain;
|
mod swapchain;
|
||||||
mod display_swapchain;
|
mod display_swapchain;
|
||||||
|
@ -19,3 +21,5 @@ mod mir_surface;
|
||||||
mod android_surface;
|
mod android_surface;
|
||||||
mod wayland_surface;
|
mod wayland_surface;
|
||||||
mod xcb_surface;
|
mod xcb_surface;
|
||||||
|
mod macos_surface;
|
||||||
|
mod ios_surface;
|
||||||
|
|
|
@ -270,6 +270,8 @@ pub mod types {
|
||||||
vk_bitflags_wrapped!(SwapchainCreateFlagsKHR, 0b0, Flags);
|
vk_bitflags_wrapped!(SwapchainCreateFlagsKHR, 0b0, Flags);
|
||||||
vk_bitflags_wrapped!(DisplayModeCreateFlagsKHR, 0b0, Flags);
|
vk_bitflags_wrapped!(DisplayModeCreateFlagsKHR, 0b0, Flags);
|
||||||
vk_bitflags_wrapped!(DisplaySurfaceCreateFlagsKHR, 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_MAX_PHYSICAL_DEVICE_NAME_SIZE: size_t = 256;
|
||||||
pub const VK_UUID_SIZE: size_t = 16;
|
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_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_SPEC_VERSION: uint32_t = 3;
|
||||||
pub const VK_EXT_DEBUG_REPORT_EXTENSION_NAME: &'static str = "VK_EXT_debug_report";
|
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)]
|
#[derive(Debug, Clone)]
|
||||||
#[repr(C)]
|
#[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
|
/// Temporary Hard-Coded union hack; will be automatically generated when actual unions become stable
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
@ -2741,6 +2764,8 @@ pub mod types {
|
||||||
DisplayModeCreateInfoKhr = 1000002000,
|
DisplayModeCreateInfoKhr = 1000002000,
|
||||||
DisplaySurfaceCreateInfoKhr = 1000002001,
|
DisplaySurfaceCreateInfoKhr = 1000002001,
|
||||||
DebugReportCallbackCreateInfoExt = 1000011000,
|
DebugReportCallbackCreateInfoExt = 1000011000,
|
||||||
|
IOSSurfaceCreateInfoMvk = 1000122000,
|
||||||
|
MacOSSurfaceCreateInfoMvk = 1000123000,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
@ -5104,4 +5129,24 @@ pub mod cmds {
|
||||||
p_surface: *mut SurfaceKHR,
|
p_surface: *mut SurfaceKHR,
|
||||||
) -> Result;
|
) -> 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue