diff --git a/libportability-gfx/src/impls.rs b/libportability-gfx/src/impls.rs index 3787a23..b6e22e0 100644 --- a/libportability-gfx/src/impls.rs +++ b/libportability-gfx/src/impls.rs @@ -277,7 +277,7 @@ pub extern "C" fn gfxGetPhysicalDeviceProperties( driverVersion: DRIVER_VERSION, vendorID: adapter_info.vendor as _, deviceID: adapter_info.device as _, - deviceType: VkPhysicalDeviceType::VK_PHYSICAL_DEVICE_TYPE_OTHER, // TODO + deviceType: VkPhysicalDeviceType::VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU, // TODO deviceName: device_name, pipelineCacheUUID: [0; 16usize], limits, @@ -354,6 +354,9 @@ pub extern "C" fn gfxGetInstanceProcAddr( vkGetPhysicalDeviceSurfacePresentModesKHR, PFN_vkGetPhysicalDeviceSurfacePresentModesKHR => gfxGetPhysicalDeviceSurfacePresentModesKHR, vkCreateWin32SurfaceKHR, PFN_vkCreateWin32SurfaceKHR => gfxCreateWin32SurfaceKHR, + vkCreateMacOSSurfaceMVK, PFN_vkCreateMacOSSurfaceMVK => gfxCreateMacOSSurfaceMVK, + + vkDestroySurfaceKHR, PFN_vkDestroySurfaceKHR => gfxDestroySurfaceKHR, } } @@ -624,7 +627,12 @@ lazy_static! { VkExtensionProperties { extensionName: [0; 256], // VK_KHR_WIN32_SURFACE_EXTENSION_NAME specVersion: VK_KHR_WIN32_SURFACE_SPEC_VERSION, - } + }, + #[cfg(target_os="macos")] + VkExtensionProperties { + extensionName: [0; 256], // VK_MVK_MACOS_SURFACE_EXTENSION_NAME + specVersion: VK_MVK_MACOS_SURFACE_SPEC_VERSION, + }, ]; extensions[0] @@ -638,6 +646,12 @@ lazy_static! { .copy_from_slice(unsafe { mem::transmute(VK_KHR_WIN32_SURFACE_EXTENSION_NAME as &[u8]) }); + #[cfg(target_os = "macos")] + extensions[1] + .extensionName[..VK_MVK_MACOS_SURFACE_EXTENSION_NAME.len()] + .copy_from_slice(unsafe { + mem::transmute(VK_MVK_MACOS_SURFACE_EXTENSION_NAME as &[u8]) + }); extensions.to_vec() }; @@ -3893,3 +3907,27 @@ pub extern "C" fn gfxQueuePresentKHR( VkResult::VK_SUCCESS } + +#[inline] +pub extern "C" fn gfxCreateMacOSSurfaceMVK( + instance: VkInstance, + pCreateInfo: *const VkMacOSSurfaceCreateInfoMVK, + pAllocator: *const VkAllocationCallbacks, + pSurface: *mut VkSurfaceKHR, +) -> VkResult { + assert!(pAllocator.is_null()); + let info = unsafe { &*pCreateInfo }; + #[cfg(target_os="macos")] + unsafe { + assert_eq!(info.flags, 0); + *pSurface = Handle::new( + instance.backend.create_surface_from_nsview(info.pView), + ); + VkResult::VK_SUCCESS + } + #[cfg(not(target_os = "macos"))] + { + let _ = (instance, info, pSurface); + unreachable!() + } +} diff --git a/libportability-gfx/src/lib.rs b/libportability-gfx/src/lib.rs index 782895f..0a799fb 100644 --- a/libportability-gfx/src/lib.rs +++ b/libportability-gfx/src/lib.rs @@ -288,8 +288,11 @@ pub const VK_KHR_SURFACE_SPEC_VERSION: ::std::os::raw::c_uint = 25; pub const VK_KHR_SURFACE_EXTENSION_NAME: &'static [u8; 15usize] = b"VK_KHR_surface\x00"; pub const VK_KHR_WIN32_SURFACE_SPEC_VERSION: ::std::os::raw::c_uint = 6; +pub const VK_MVK_MACOS_SURFACE_SPEC_VERSION: ::std::os::raw::c_uint = 2; pub const VK_KHR_WIN32_SURFACE_EXTENSION_NAME: &'static [u8; 21usize] = b"VK_KHR_win32_surface\x00"; +pub const VK_MVK_MACOS_SURFACE_EXTENSION_NAME: &'static [u8; 21usize] = + b"VK_MVK_macos_surface\x00"; pub const VK_KHR_swapchain: ::std::os::raw::c_uint = 1; pub const VK_KHR_SWAPCHAIN_SPEC_VERSION: ::std::os::raw::c_uint = 68; pub const VK_KHR_SWAPCHAIN_EXTENSION_NAME: &'static [u8; 17usize] = @@ -4866,6 +4869,18 @@ pub struct VkXcbSurfaceCreateInfoKHR { impl Clone for VkXcbSurfaceCreateInfoKHR { fn clone(&self) -> Self { *self } } +pub type VkMacOSSurfaceCreateFlagsMVK = VkFlags; +#[repr(C)] +#[derive(Debug, Copy)] +pub struct VkMacOSSurfaceCreateInfoMVK { + pub sType: VkStructureType, + pub pNext: *mut ::std::os::raw::c_void, + pub flags: VkMacOSSurfaceCreateFlagsMVK, + pub pView: *mut ::std::os::raw::c_void, +} +impl Clone for VkMacOSSurfaceCreateInfoMVK { + fn clone(&self) -> Self { *self } +} #[repr(C)] #[derive(Debug, Copy)] pub struct VkPhysicalDeviceFeatures2KHR { @@ -6919,3 +6934,10 @@ pub type PFN_vkCreateWin32SurfaceKHR = ::std::option::Option VkResult>; + +pub type PFN_vkCreateMacOSSurfaceMVK = ::std::option::Option VkResult>; diff --git a/libportability/src/lib.rs b/libportability/src/lib.rs index fb40d84..0074e8b 100644 --- a/libportability/src/lib.rs +++ b/libportability/src/lib.rs @@ -276,6 +276,16 @@ pub extern "C" fn vkCreateWin32SurfaceKHR( gfxCreateWin32SurfaceKHR(instance, pCreateInfos, pAllocator, pSurface) } +#[no_mangle] +pub extern "C" fn vkCreateMacOSSurfaceMVK( + instance: VkInstance, + pCreateInfos: *const VkMacOSSurfaceCreateInfoMVK, + pAllocator: *const VkAllocationCallbacks, + pSurface: *mut VkSurfaceKHR, +) -> VkResult { + gfxCreateMacOSSurfaceMVK(instance, pCreateInfos, pAllocator, pSurface) +} + #[no_mangle] pub extern "C" fn vkCreateXcbSurfaceKHR( instance: VkInstance,