From 05e8abbde06e324e77e035e0fdcd0e1f859840a0 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Tue, 30 Jan 2018 11:19:37 -0500 Subject: [PATCH] XCB support --- libportability-gfx/src/impls.rs | 32 +++++++++++++++++++++++++++----- libportability-gfx/src/lib.rs | 13 +++++++++++++ libportability/src/lib.rs | 10 ++++++++++ 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/libportability-gfx/src/impls.rs b/libportability-gfx/src/impls.rs index 5d77e9c..6f3041e 100644 --- a/libportability-gfx/src/impls.rs +++ b/libportability-gfx/src/impls.rs @@ -2856,17 +2856,18 @@ pub extern "C" fn gfxCmdSetDiscardRectangleEXT( #[inline] pub extern "C" fn gfxCreateWin32SurfaceKHR( instance: VkInstance, - pCreateInfos: *const VkWin32SurfaceCreateInfoKHR, + pCreateInfo: *const VkWin32SurfaceCreateInfoKHR, pAllocator: *const VkAllocationCallbacks, pSurface: *mut VkSurfaceKHR, ) -> VkResult { + let info = unsafe { &*pCreateInfo }; #[cfg(all(feature = "vulkan", target_os = "windows"))] { unsafe { - assert_eq!((*pCreateInfos).flags, 0); + assert_eq!(info.flags, 0); assert!(pAllocator.is_null()); *pSurface = Handle::new( - instance.create_surface_from_hwnd((*pCreateInfos).hinstance, (*pCreateInfos).hwnd), + instance.create_surface_from_hwnd(info.hinstance, info.hwnd), ); VkResult::VK_SUCCESS } @@ -2874,15 +2875,36 @@ pub extern "C" fn gfxCreateWin32SurfaceKHR( #[cfg(feature = "dx12")] { unsafe { - assert_eq!((*pCreateInfos).flags, 0); + assert_eq!(info.flags, 0); assert!(pAllocator.is_null()); - *pSurface = Handle::new(instance.create_surface_from_hwnd((*pCreateInfos).hwnd)); + *pSurface = Handle::new(instance.create_surface_from_hwnd(info.hwnd)); VkResult::VK_SUCCESS } } #[cfg(not(target_os = "windows"))] unreachable!() } +pub extern "C" fn gfxCreateXcbSurfaceKHR( + instance: VkInstance, + pCreateInfo: *const VkXcbSurfaceCreateInfoKHR, + pAllocator: *const VkAllocationCallbacks, + pSurface: *mut VkSurfaceKHR, +) -> VkResult { + let info = unsafe { &*pCreateInfo }; + #[cfg(feature = "vulkan")] + { + unsafe { + assert_eq!(info.flags, 0); + assert!(pAllocator.is_null()); + *pSurface = Handle::new( + instance.create_surface_from_xcb(info.connection as _, info.window), + ); + VkResult::VK_SUCCESS + } + } + #[cfg(not(feature = "vulkan"))] + unreachable!() +} #[inline] pub extern "C" fn gfxAcquireNextImageKHR( _device: VkDevice, diff --git a/libportability-gfx/src/lib.rs b/libportability-gfx/src/lib.rs index 94d751d..b90fecd 100644 --- a/libportability-gfx/src/lib.rs +++ b/libportability-gfx/src/lib.rs @@ -4753,6 +4753,19 @@ pub struct VkWin32SurfaceCreateInfoKHR { impl Clone for VkWin32SurfaceCreateInfoKHR { fn clone(&self) -> Self { *self } } +pub type VkXcbSurfaceCreateFlagsKHR = VkFlags; +#[repr(C)] +#[derive(Debug, Copy)] +pub struct VkXcbSurfaceCreateInfoKHR { + pub sType: VkStructureType, + pub pNext: *mut ::std::os::raw::c_void, + pub flags: VkXcbSurfaceCreateFlagsKHR, + pub connection: *mut ::std::os::raw::c_void, + pub window: u32, +} +impl Clone for VkXcbSurfaceCreateInfoKHR { + fn clone(&self) -> Self { *self } +} #[repr(C)] #[derive(Debug, Copy)] pub struct VkPhysicalDeviceFeatures2KHR { diff --git a/libportability/src/lib.rs b/libportability/src/lib.rs index 5ca76e5..fb40d84 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 vkCreateXcbSurfaceKHR( + instance: VkInstance, + pCreateInfos: *const VkXcbSurfaceCreateInfoKHR, + pAllocator: *const VkAllocationCallbacks, + pSurface: *mut VkSurfaceKHR, +) -> VkResult { + gfxCreateXcbSurfaceKHR(instance, pCreateInfos, pAllocator, pSurface) +} + #[no_mangle] pub extern "C" fn vkMapMemory( device: VkDevice,