From 05764e2e77a27d08999d43dfa9490c14d5dddd63 Mon Sep 17 00:00:00 2001 From: Joshua Groves Date: Tue, 5 Jun 2018 20:54:02 -0600 Subject: [PATCH 1/2] Add `debug-version` target --- Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ab576ea..8fdc529 100644 --- a/Makefile +++ b/Makefile @@ -43,7 +43,7 @@ FULL_LIBRARY_PATH=$(CURDIR)/target/debug LIBRARY=target/debug/libportability.$(LIB_EXTENSION) LIBRARY_FAST=target/release/libportability.$(LIB_EXTENSION) -.PHONY: all rebuild debug release binding run cts cts-pick cts-debug clean cherry +.PHONY: all rebuild debug debug-version release binding run cts cts-pick cts-debug clean cherry all: $(TARGET) @@ -53,6 +53,9 @@ rebuild: debug: cargo build --manifest-path libportability/Cargo.toml --features "$(BACKEND) debug" +debug-version: + cargo rustc --manifest-path libportability/Cargo.toml --features "$(BACKEND) debug" -- -Clink-arg="-current_version 1.0.0" -Clink-arg="-compatibility_version 1.0.0" + release: $(LIBRARY_FAST) binding: $(BINDING) From cbcfdf58dd1804b992b6c46a5dcf6fba6f85c3bd Mon Sep 17 00:00:00 2001 From: Joshua Groves Date: Tue, 5 Jun 2018 20:54:11 -0600 Subject: [PATCH 2/2] Add macOS surface --- libportability-gfx/src/impls.rs | 42 +++++++++++++++++++++++++++++++-- libportability-gfx/src/lib.rs | 22 +++++++++++++++++ libportability/src/lib.rs | 10 ++++++++ 3 files changed, 72 insertions(+), 2 deletions(-) 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,