From b5b8ea828ade1491a3c2a3d6c9b273a158876058 Mon Sep 17 00:00:00 2001 From: Rua Date: Wed, 15 Nov 2023 18:07:20 +0100 Subject: [PATCH] Use concrete types from Ash for foreign handles (#2406) * Use concrete types from Ash for foreign handles * Fixes * Update vulkano/src/swapchain/mod.rs Co-authored-by: marc0246 <40955683+marc0246@users.noreply.github.com> * Foxes * Get CI to build vulkano-win * Weirdness * Faxes * F*xes * Re-disable vulkano-win --------- Co-authored-by: marc0246 <40955683+marc0246@users.noreply.github.com> --- Cargo.toml | 12 +- vulkano-win/src/raw_window_handle.rs | 20 +-- vulkano-win/src/winit.rs | 16 +- vulkano/src/device/physical.rs | 70 ++++---- vulkano/src/swapchain/mod.rs | 9 +- vulkano/src/swapchain/surface.rs | 236 +++++++++++++-------------- 6 files changed, 181 insertions(+), 182 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4302fe5e..91080ec2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,11 @@ [workspace] members = [ - "examples/*", - "vulkano", - "vulkano-macros", - "vulkano-shaders", - "vulkano-util", - # "vulkano-win", + "examples/*", + "vulkano", + "vulkano-macros", + "vulkano-shaders", + "vulkano-util", + # "vulkano-win", ] resolver = "2" diff --git a/vulkano-win/src/raw_window_handle.rs b/vulkano-win/src/raw_window_handle.rs index 7412ad5e..15d346da 100644 --- a/vulkano-win/src/raw_window_handle.rs +++ b/vulkano-win/src/raw_window_handle.rs @@ -23,8 +23,8 @@ pub fn create_surface_from_handle( #[cfg(target_os = "ios")] { // Ensure the layer is CAMetalLayer - let layer = get_metal_layer_ios(_h.ui_view); - Surface::from_ios(instance, layer, Some(window)) + let metal_layer = get_metal_layer_ios(_h.ui_view); + Surface::from_ios(instance, metal_layer.render_layer.0 as _, Some(window)) } #[cfg(not(target_os = "ios"))] { @@ -35,8 +35,8 @@ pub fn create_surface_from_handle( #[cfg(target_os = "macos")] { // Ensure the layer is CAMetalLayer - let layer = get_metal_layer_macos(_h.ns_view); - Surface::from_mac_os(instance, layer as *const (), Some(window)) + let metal_layer = get_metal_layer_macos(_h.ns_view); + Surface::from_mac_os(instance, metal_layer as _, Some(window)) } #[cfg(not(target_os = "macos"))] { @@ -65,7 +65,7 @@ pub fn create_surface_from_handle( RawDisplayHandle::Xlib(d) => d, _ => panic!("Invalid RawDisplayHandle"), }; - Surface::from_xlib(instance, d.display, h.window, Some(window)) + Surface::from_xlib(instance, d.display as _, h.window, Some(window)) } RawWindowHandle::Web(_) => unimplemented!(), _ => unimplemented!(), @@ -92,8 +92,8 @@ pub unsafe fn create_surface_from_handle_ref( #[cfg(target_os = "ios")] { // Ensure the layer is CAMetalLayer - let layer = get_metal_layer_ios(_h.ui_view); - Surface::from_ios(instance, layer, None) + let metal_layer = get_metal_layer_ios(_h.ui_view); + Surface::from_ios(instance, metal_layer.render_layer.0 as _, None) } #[cfg(not(target_os = "ios"))] { @@ -104,8 +104,8 @@ pub unsafe fn create_surface_from_handle_ref( #[cfg(target_os = "macos")] { // Ensure the layer is CAMetalLayer - let layer = get_metal_layer_macos(_h.ns_view); - Surface::from_mac_os(instance, layer as *const (), None) + let metal_layer = get_metal_layer_macos(_h.ns_view); + Surface::from_mac_os(instance, metal_layer as _, None) } #[cfg(not(target_os = "macos"))] { @@ -132,7 +132,7 @@ pub unsafe fn create_surface_from_handle_ref( RawDisplayHandle::Xlib(d) => d, _ => panic!("Invalid RawDisplayHandle"), }; - Surface::from_xlib(instance, d.display, h.window, None) + Surface::from_xlib(instance, d.display as _, h.window, None) } RawWindowHandle::Web(_) => unimplemented!(), _ => unimplemented!(), diff --git a/vulkano-win/src/winit.rs b/vulkano-win/src/winit.rs index ef8e180a..da3754bd 100644 --- a/vulkano-win/src/winit.rs +++ b/vulkano-win/src/winit.rs @@ -141,7 +141,7 @@ unsafe fn winit_to_surface( if instance.enabled_extensions().khr_xlib_surface { Surface::from_xlib( instance, - window.xlib_display().unwrap(), + window.xlib_display().unwrap() as _, window.xlib_window().unwrap() as _, Some(window), ) @@ -196,8 +196,8 @@ unsafe fn winit_to_surface( window: Arc, ) -> Result, Validated> { use winit::platform::macos::WindowExtMacOS; - let layer = get_metal_layer_macos(window.ns_view()); - Surface::from_mac_os(instance, layer as *const (), Some(window)) + let metal_layer = get_metal_layer_macos(window.ns_view()); + Surface::from_mac_os(instance, metal_layer as _, Some(window)) } #[cfg(target_os = "ios")] @@ -227,8 +227,8 @@ unsafe fn winit_to_surface( window: Arc, ) -> Result, Validated> { use winit::platform::ios::WindowExtIOS; - let layer = get_metal_layer_ios(window.ui_view()); - Surface::from_ios(instance, layer, Some(window)) + let metal_layer = get_metal_layer_ios(window.ui_view()); + Surface::from_ios(instance, metal_layer.render_layer.0 as _, Some(window)) } #[cfg(target_os = "windows")] @@ -240,8 +240,8 @@ unsafe fn winit_to_surface( Surface::from_win32( instance, - window.hinstance() as *const (), - window.hwnd() as *const (), + window.hinstance() as _, + window.hwnd() as _, Some(window), ) } @@ -255,5 +255,5 @@ use winit::{monitor::MonitorHandle, platform::windows::MonitorHandleExtWindows}; /// Creates a `Win32Monitor` from a Winit monitor handle. #[inline] pub fn create_win32_monitor_from_winit(monitor_handle: &MonitorHandle) -> Win32Monitor { - unsafe { Win32Monitor::new(monitor_handle.hmonitor() as *const ()) } + unsafe { Win32Monitor::new(monitor_handle.hmonitor() as _) } } diff --git a/vulkano/src/device/physical.rs b/vulkano/src/device/physical.rs index 984cf0d1..a3db13e6 100644 --- a/vulkano/src/device/physical.rs +++ b/vulkano/src/device/physical.rs @@ -425,20 +425,20 @@ impl PhysicalDevice { /// /// - `dfb` must be a valid DirectFB `IDirectFB` handle. #[inline] - pub unsafe fn directfb_presentation_support( + pub unsafe fn directfb_presentation_support( &self, queue_family_index: u32, - dfb: *const D, + dfb: *mut ash::vk::IDirectFB, ) -> Result> { self.validate_directfb_presentation_support(queue_family_index, dfb)?; Ok(self.directfb_presentation_support_unchecked(queue_family_index, dfb)) } - fn validate_directfb_presentation_support( + fn validate_directfb_presentation_support( &self, queue_family_index: u32, - _dfb: *const D, + _dfb: *mut ash::vk::IDirectFB, ) -> Result<(), Box> { if !self.instance.enabled_extensions().ext_directfb_surface { return Err(Box::new(ValidationError { @@ -469,17 +469,17 @@ impl PhysicalDevice { #[cfg_attr(not(feature = "document_unchecked"), doc(hidden))] #[inline] - pub unsafe fn directfb_presentation_support_unchecked( + pub unsafe fn directfb_presentation_support_unchecked( &self, queue_family_index: u32, - dfb: *const D, + dfb: *mut ash::vk::IDirectFB, ) -> bool { let fns = self.instance.fns(); (fns.ext_directfb_surface .get_physical_device_direct_fb_presentation_support_ext)( self.handle, queue_family_index, - dfb as *mut _, + dfb, ) != 0 } @@ -1678,20 +1678,20 @@ impl PhysicalDevice { /// # Safety /// /// - `window` must be a valid QNX Screen `_screen_window` handle. - pub unsafe fn qnx_screen_presentation_support( + pub unsafe fn qnx_screen_presentation_support( &self, queue_family_index: u32, - window: *const W, + window: *mut ash::vk::_screen_window, ) -> Result> { self.validate_qnx_screen_presentation_support(queue_family_index, window)?; Ok(self.qnx_screen_presentation_support_unchecked(queue_family_index, window)) } - fn validate_qnx_screen_presentation_support( + fn validate_qnx_screen_presentation_support( &self, queue_family_index: u32, - _window: *const W, + _window: *mut ash::vk::_screen_window, ) -> Result<(), Box> { if !self.instance.enabled_extensions().qnx_screen_surface { return Err(Box::new(ValidationError { @@ -1721,17 +1721,17 @@ impl PhysicalDevice { } #[cfg_attr(not(feature = "document_unchecked"), doc(hidden))] - pub unsafe fn qnx_screen_presentation_support_unchecked( + pub unsafe fn qnx_screen_presentation_support_unchecked( &self, queue_family_index: u32, - window: *const W, + window: *mut ash::vk::_screen_window, ) -> bool { let fns = self.instance.fns(); (fns.qnx_screen_surface .get_physical_device_screen_presentation_support_qnx)( self.handle, queue_family_index, - window as *mut _, + window, ) != 0 } @@ -3016,20 +3016,20 @@ impl PhysicalDevice { /// # Safety /// /// - `display` must be a valid Wayland `wl_display` handle. - pub unsafe fn wayland_presentation_support( + pub unsafe fn wayland_presentation_support( &self, queue_family_index: u32, - display: *const D, + display: *mut ash::vk::wl_display, ) -> Result> { self.validate_wayland_presentation_support(queue_family_index, display)?; Ok(self.wayland_presentation_support_unchecked(queue_family_index, display)) } - fn validate_wayland_presentation_support( + fn validate_wayland_presentation_support( &self, queue_family_index: u32, - _display: *const D, + _display: *mut ash::vk::wl_display, ) -> Result<(), Box> { if !self.instance.enabled_extensions().khr_wayland_surface { return Err(Box::new(ValidationError { @@ -3059,17 +3059,17 @@ impl PhysicalDevice { } #[cfg_attr(not(feature = "document_unchecked"), doc(hidden))] - pub unsafe fn wayland_presentation_support_unchecked( + pub unsafe fn wayland_presentation_support_unchecked( &self, queue_family_index: u32, - display: *const D, + display: *mut ash::vk::wl_display, ) -> bool { let fns = self.instance.fns(); (fns.khr_wayland_surface .get_physical_device_wayland_presentation_support_khr)( self.handle, queue_family_index, - display as *mut _, + display, ) != 0 } @@ -3129,10 +3129,10 @@ impl PhysicalDevice { /// # Safety /// /// - `connection` must be a valid X11 `xcb_connection_t` handle. - pub unsafe fn xcb_presentation_support( + pub unsafe fn xcb_presentation_support( &self, queue_family_index: u32, - connection: *const C, + connection: *mut ash::vk::xcb_connection_t, visual_id: ash::vk::xcb_visualid_t, ) -> Result> { self.validate_xcb_presentation_support(queue_family_index, connection, visual_id)?; @@ -3140,10 +3140,10 @@ impl PhysicalDevice { Ok(self.xcb_presentation_support_unchecked(queue_family_index, connection, visual_id)) } - fn validate_xcb_presentation_support( + fn validate_xcb_presentation_support( &self, queue_family_index: u32, - _connection: *const C, + _connection: *mut ash::vk::xcb_connection_t, _visual_id: ash::vk::xcb_visualid_t, ) -> Result<(), Box> { if !self.instance.enabled_extensions().khr_xcb_surface { @@ -3174,10 +3174,10 @@ impl PhysicalDevice { } #[cfg_attr(not(feature = "document_unchecked"), doc(hidden))] - pub unsafe fn xcb_presentation_support_unchecked( + pub unsafe fn xcb_presentation_support_unchecked( &self, queue_family_index: u32, - connection: *const C, + connection: *mut ash::vk::xcb_connection_t, visual_id: ash::vk::VisualID, ) -> bool { let fns = self.instance.fns(); @@ -3185,7 +3185,7 @@ impl PhysicalDevice { .get_physical_device_xcb_presentation_support_khr)( self.handle, queue_family_index, - connection as *mut _, + connection, visual_id, ) != 0 } @@ -3196,10 +3196,10 @@ impl PhysicalDevice { /// # Safety /// /// - `display` must be a valid Xlib `Display` handle. - pub unsafe fn xlib_presentation_support( + pub unsafe fn xlib_presentation_support( &self, queue_family_index: u32, - display: *const D, + display: *mut ash::vk::Display, visual_id: ash::vk::VisualID, ) -> Result> { self.validate_xlib_presentation_support(queue_family_index, display, visual_id)?; @@ -3207,10 +3207,10 @@ impl PhysicalDevice { Ok(self.xlib_presentation_support_unchecked(queue_family_index, display, visual_id)) } - fn validate_xlib_presentation_support( + fn validate_xlib_presentation_support( &self, queue_family_index: u32, - _display: *const D, + _display: *mut ash::vk::Display, _visual_id: ash::vk::VisualID, ) -> Result<(), Box> { if !self.instance.enabled_extensions().khr_xlib_surface { @@ -3241,10 +3241,10 @@ impl PhysicalDevice { } #[cfg_attr(not(feature = "document_unchecked"), doc(hidden))] - pub unsafe fn xlib_presentation_support_unchecked( + pub unsafe fn xlib_presentation_support_unchecked( &self, queue_family_index: u32, - display: *const D, + display: *mut ash::vk::Display, visual_id: ash::vk::VisualID, ) -> bool { let fns = self.instance.fns(); @@ -3252,7 +3252,7 @@ impl PhysicalDevice { .get_physical_device_xlib_presentation_support_khr)( self.handle, queue_family_index, - display as *mut _, + display, visual_id, ) != 0 } diff --git a/vulkano/src/swapchain/mod.rs b/vulkano/src/swapchain/mod.rs index e5ca04ac..df070821 100644 --- a/vulkano/src/swapchain/mod.rs +++ b/vulkano/src/swapchain/mod.rs @@ -80,10 +80,11 @@ //! # fn build_window() -> Arc { Arc::new(Window(ptr::null())) } //! let window = build_window(); // Third-party function, not provided by vulkano //! let _surface = unsafe { -//! let hinstance: *const () = ptr::null(); // Windows-specific object +//! let hinstance: *mut std::ffi::c_void = ptr::null_mut(); // Windows-specific object //! Surface::from_win32( //! instance.clone(), -//! hinstance, window.hwnd(), +//! hinstance, +//! window.hwnd() as ash::vk::HWND, //! Some(window), //! ).unwrap() //! }; @@ -2459,8 +2460,8 @@ impl Win32Monitor { /// # Safety /// /// - `hmonitor` must be a valid handle as returned by the Win32 API. - pub unsafe fn new(hmonitor: *const T) -> Self { - Self(hmonitor as _) + pub unsafe fn new(hmonitor: ash::vk::HMONITOR) -> Self { + Self(hmonitor) } } diff --git a/vulkano/src/swapchain/surface.rs b/vulkano/src/swapchain/surface.rs index 357b9322..7ed404dd 100644 --- a/vulkano/src/swapchain/surface.rs +++ b/vulkano/src/swapchain/surface.rs @@ -19,6 +19,7 @@ use smallvec::SmallVec; use std::{ any::Any, error::Error, + ffi::c_void, fmt::{Debug, Display, Error as FmtError, Formatter}, mem::MaybeUninit, num::NonZeroU64, @@ -104,48 +105,52 @@ impl Surface { match (window_handle.as_raw(), display_handle.as_raw()) { (RawWindowHandle::AndroidNdk(window), RawDisplayHandle::Android(_display)) => { - Self::from_android(instance, window.a_native_window.as_ptr(), None) + Self::from_android( + instance, + window.a_native_window.as_ptr() as *mut ash::vk::ANativeWindow, + None, + ) } #[cfg(target_os = "macos")] (RawWindowHandle::AppKit(window), RawDisplayHandle::AppKit(_display)) => { // Ensure the layer is `CAMetalLayer`. - let layer = get_metal_layer_macos(window.ns_view.as_ptr()); + let metal_layer = get_metal_layer_macos(window.ns_view.as_ptr() as *mut c_void); - Self::from_mac_os(instance, layer as *const (), None) + Self::from_mac_os(instance, metal_layer as *const c_void, None) } #[cfg(target_os = "ios")] (RawWindowHandle::UiKit(window), RawDisplayHandle::UiKit(_display)) => { // Ensure the layer is `CAMetalLayer`. - let layer = get_metal_layer_ios(window.ui_view.as_ptr()); + let metal_layer = get_metal_layer_ios(window.ui_view.as_ptr() as *mut c_void); - Self::from_ios(instance, layer, None) + Self::from_ios(instance, metal_layer.render_layer.0 as *const c_void, None) } (RawWindowHandle::Wayland(window), RawDisplayHandle::Wayland(display)) => { Self::from_wayland( instance, - display.display.as_ptr(), - window.surface.as_ptr(), + display.display.as_ptr() as *mut ash::vk::wl_display, + window.surface.as_ptr() as *mut ash::vk::wl_surface, None, ) } (RawWindowHandle::Win32(window), RawDisplayHandle::Windows(_display)) => { Self::from_win32( instance, - window.hinstance.unwrap().get() as *const (), - window.hwnd.get() as *const (), + window.hinstance.unwrap().get() as ash::vk::HINSTANCE, + window.hwnd.get() as ash::vk::HWND, None, ) } (RawWindowHandle::Xcb(window), RawDisplayHandle::Xcb(display)) => Self::from_xcb( instance, - display.connection.unwrap().as_ptr(), - window.window.get(), + display.connection.unwrap().as_ptr() as *mut ash::vk::xcb_connection_t, + window.window.get() as ash::vk::xcb_window_t, None, ), (RawWindowHandle::Xlib(window), RawDisplayHandle::Xlib(display)) => Self::from_xlib( instance, - display.display.unwrap().as_ptr(), - window.window, + display.display.unwrap().as_ptr() as *mut ash::vk::Display, + window.window as ash::vk::Window, None, ), _ => unimplemented!( @@ -431,9 +436,9 @@ impl Surface { /// - `window` must be a valid Android `ANativeWindow` handle. /// - The object referred to by `window` must outlive the created `Surface`. /// The `object` parameter can be used to ensure this. - pub unsafe fn from_android( + pub unsafe fn from_android( instance: Arc, - window: *const W, + window: *mut ash::vk::ANativeWindow, object: Option>, ) -> Result, Validated> { Self::validate_from_android(&instance, window)?; @@ -441,9 +446,9 @@ impl Surface { Ok(Self::from_android_unchecked(instance, window, object)?) } - fn validate_from_android( + fn validate_from_android( instance: &Instance, - _window: *const W, + _window: *mut ash::vk::ANativeWindow, ) -> Result<(), Box> { if !instance.enabled_extensions().khr_android_surface { return Err(Box::new(ValidationError { @@ -461,14 +466,14 @@ impl Surface { } #[cfg_attr(not(feature = "document_unchecked"), doc(hidden))] - pub unsafe fn from_android_unchecked( + pub unsafe fn from_android_unchecked( instance: Arc, - window: *const W, + window: *mut ash::vk::ANativeWindow, object: Option>, ) -> Result, VulkanError> { let create_info = ash::vk::AndroidSurfaceCreateInfoKHR { flags: ash::vk::AndroidSurfaceCreateFlagsKHR::empty(), - window: window as *mut _, + window, ..Default::default() }; @@ -502,10 +507,10 @@ impl Surface { /// - `surface` must be a valid DirectFB `IDirectFBSurface` handle. /// - The object referred to by `dfb` and `surface` must outlive the created `Surface`. /// The `object` parameter can be used to ensure this. - pub unsafe fn from_directfb( + pub unsafe fn from_directfb( instance: Arc, - dfb: *const D, - surface: *const S, + dfb: *mut ash::vk::IDirectFB, + surface: *mut ash::vk::IDirectFBSurface, object: Option>, ) -> Result, Validated> { Self::validate_from_directfb(&instance, dfb, surface)?; @@ -515,10 +520,10 @@ impl Surface { )?) } - fn validate_from_directfb( + fn validate_from_directfb( instance: &Instance, - _dfb: *const D, - _surface: *const S, + _dfb: *mut ash::vk::IDirectFB, + _surface: *mut ash::vk::IDirectFBSurface, ) -> Result<(), Box> { if !instance.enabled_extensions().ext_directfb_surface { return Err(Box::new(ValidationError { @@ -539,16 +544,16 @@ impl Surface { } #[cfg_attr(not(feature = "document_unchecked"), doc(hidden))] - pub unsafe fn from_directfb_unchecked( + pub unsafe fn from_directfb_unchecked( instance: Arc, - dfb: *const D, - surface: *const S, + dfb: *mut ash::vk::IDirectFB, + surface: *mut ash::vk::IDirectFBSurface, object: Option>, ) -> Result, VulkanError> { let create_info = ash::vk::DirectFBSurfaceCreateInfoEXT { flags: ash::vk::DirectFBSurfaceCreateFlagsEXT::empty(), - dfb: dfb as *mut _, - surface: surface as *mut _, + dfb, + surface, ..Default::default() }; @@ -732,21 +737,19 @@ impl Surface { /// - The object referred to by `metal_layer` must outlive the created `Surface`. /// The `object` parameter can be used to ensure this. /// - The `UIView` must be backed by a `CALayer` instance of type `CAMetalLayer`. - #[cfg(target_os = "ios")] pub unsafe fn from_ios( instance: Arc, - metal_layer: IOSMetalLayer, + view: *const c_void, object: Option>, ) -> Result, Validated> { - Self::validate_from_ios(&instance, &metal_layer)?; + Self::validate_from_ios(&instance, view)?; - Ok(Self::from_ios_unchecked(instance, metal_layer, object)?) + Ok(Self::from_ios_unchecked(instance, view, object)?) } - #[cfg(target_os = "ios")] fn validate_from_ios( instance: &Instance, - _metal_layer: &IOSMetalLayer, + _view: *const c_void, ) -> Result<(), Box> { if !instance.enabled_extensions().mvk_ios_surface { return Err(Box::new(ValidationError { @@ -766,16 +769,15 @@ impl Surface { Ok(()) } - #[cfg(target_os = "ios")] #[cfg_attr(not(feature = "document_unchecked"), doc(hidden))] pub unsafe fn from_ios_unchecked( instance: Arc, - metal_layer: IOSMetalLayer, + view: *const c_void, object: Option>, ) -> Result, VulkanError> { let create_info = ash::vk::IOSSurfaceCreateInfoMVK { flags: ash::vk::IOSSurfaceCreateFlagsMVK::empty(), - p_view: metal_layer.render_layer.0 as *const _, + p_view: view, ..Default::default() }; @@ -809,10 +811,9 @@ impl Surface { /// - The object referred to by `view` must outlive the created `Surface`. /// The `object` parameter can be used to ensure this. /// - The `NSView` must be backed by a `CALayer` instance of type `CAMetalLayer`. - #[cfg(target_os = "macos")] - pub unsafe fn from_mac_os( + pub unsafe fn from_mac_os( instance: Arc, - view: *const V, + view: *const c_void, object: Option>, ) -> Result, Validated> { Self::validate_from_mac_os(&instance, view)?; @@ -820,10 +821,9 @@ impl Surface { Ok(Self::from_mac_os_unchecked(instance, view, object)?) } - #[cfg(target_os = "macos")] - fn validate_from_mac_os( + fn validate_from_mac_os( instance: &Instance, - _view: *const V, + _view: *const c_void, ) -> Result<(), Box> { if !instance.enabled_extensions().mvk_macos_surface { return Err(Box::new(ValidationError { @@ -843,16 +843,15 @@ impl Surface { Ok(()) } - #[cfg(target_os = "macos")] #[cfg_attr(not(feature = "document_unchecked"), doc(hidden))] - pub unsafe fn from_mac_os_unchecked( + pub unsafe fn from_mac_os_unchecked( instance: Arc, - view: *const V, + view: *const c_void, object: Option>, ) -> Result, VulkanError> { let create_info = ash::vk::MacOSSurfaceCreateInfoMVK { flags: ash::vk::MacOSSurfaceCreateFlagsMVK::empty(), - p_view: view as *const _, + p_view: view, ..Default::default() }; @@ -885,9 +884,9 @@ impl Surface { /// - `layer` must be a valid Metal `CAMetalLayer` handle. /// - The object referred to by `layer` must outlive the created `Surface`. /// The `object` parameter can be used to ensure this. - pub unsafe fn from_metal( + pub unsafe fn from_metal( instance: Arc, - layer: *const L, + layer: *const ash::vk::CAMetalLayer, object: Option>, ) -> Result, Validated> { Self::validate_from_metal(&instance, layer)?; @@ -895,9 +894,9 @@ impl Surface { Ok(Self::from_metal_unchecked(instance, layer, object)?) } - fn validate_from_metal( + fn validate_from_metal( instance: &Instance, - _layer: *const L, + _layer: *const ash::vk::CAMetalLayer, ) -> Result<(), Box> { if !instance.enabled_extensions().ext_metal_surface { return Err(Box::new(ValidationError { @@ -912,14 +911,14 @@ impl Surface { } #[cfg_attr(not(feature = "document_unchecked"), doc(hidden))] - pub unsafe fn from_metal_unchecked( + pub unsafe fn from_metal_unchecked( instance: Arc, - layer: *const L, + layer: *const ash::vk::CAMetalLayer, object: Option>, ) -> Result, VulkanError> { let create_info = ash::vk::MetalSurfaceCreateInfoEXT { flags: ash::vk::MetalSurfaceCreateFlagsEXT::empty(), - p_layer: layer as *const _, + p_layer: layer, ..Default::default() }; @@ -953,10 +952,10 @@ impl Surface { /// - `window` must be a valid QNX Screen `_screen_window` handle. /// - The object referred to by `window` must outlive the created `Surface`. /// The `object` parameter can be used to ensure this. - pub unsafe fn from_qnx_screen( + pub unsafe fn from_qnx_screen( instance: Arc, - context: *const C, - window: *const W, + context: *mut ash::vk::_screen_context, + window: *mut ash::vk::_screen_window, object: Option>, ) -> Result, Validated> { Self::validate_from_qnx_screen(&instance, context, window)?; @@ -966,10 +965,10 @@ impl Surface { )?) } - fn validate_from_qnx_screen( + fn validate_from_qnx_screen( instance: &Instance, - _context: *const C, - _window: *const W, + _context: *mut ash::vk::_screen_context, + _window: *mut ash::vk::_screen_window, ) -> Result<(), Box> { if !instance.enabled_extensions().qnx_screen_surface { return Err(Box::new(ValidationError { @@ -990,16 +989,16 @@ impl Surface { } #[cfg_attr(not(feature = "document_unchecked"), doc(hidden))] - pub unsafe fn from_qnx_screen_unchecked( + pub unsafe fn from_qnx_screen_unchecked( instance: Arc, - context: *const C, - window: *const W, + context: *mut ash::vk::_screen_context, + window: *mut ash::vk::_screen_window, object: Option>, ) -> Result, VulkanError> { let create_info = ash::vk::ScreenSurfaceCreateInfoQNX { flags: ash::vk::ScreenSurfaceCreateFlagsQNX::empty(), - context: context as *mut _, - window: window as *mut _, + context, + window, ..Default::default() }; @@ -1032,9 +1031,9 @@ impl Surface { /// - `window` must be a valid `nn::vi::NativeWindowHandle` handle. /// - The object referred to by `window` must outlive the created `Surface`. /// The `object` parameter can be used to ensure this. - pub unsafe fn from_vi( + pub unsafe fn from_vi( instance: Arc, - window: *const W, + window: *mut c_void, object: Option>, ) -> Result, Validated> { Self::validate_from_vi(&instance, window)?; @@ -1042,9 +1041,9 @@ impl Surface { Ok(Self::from_vi_unchecked(instance, window, object)?) } - fn validate_from_vi( + fn validate_from_vi( instance: &Instance, - _window: *const W, + _window: *mut c_void, ) -> Result<(), Box> { if !instance.enabled_extensions().nn_vi_surface { return Err(Box::new(ValidationError { @@ -1062,14 +1061,14 @@ impl Surface { } #[cfg_attr(not(feature = "document_unchecked"), doc(hidden))] - pub unsafe fn from_vi_unchecked( + pub unsafe fn from_vi_unchecked( instance: Arc, - window: *const W, + window: *mut c_void, object: Option>, ) -> Result, VulkanError> { let create_info = ash::vk::ViSurfaceCreateInfoNN { flags: ash::vk::ViSurfaceCreateFlagsNN::empty(), - window: window as *mut _, + window, ..Default::default() }; @@ -1105,10 +1104,10 @@ impl Surface { /// - `surface` must be a valid Wayland `wl_surface` handle. /// - The objects referred to by `display` and `surface` must outlive the created `Surface`. /// The `object` parameter can be used to ensure this. - pub unsafe fn from_wayland( + pub unsafe fn from_wayland( instance: Arc, - display: *const D, - surface: *const S, + display: *mut ash::vk::wl_display, + surface: *mut ash::vk::wl_surface, object: Option>, ) -> Result, Validated> { Self::validate_from_wayland(&instance, display, surface)?; @@ -1118,10 +1117,10 @@ impl Surface { )?) } - fn validate_from_wayland( + fn validate_from_wayland( instance: &Instance, - _display: *const D, - _surface: *const S, + _display: *mut ash::vk::wl_display, + _surface: *mut ash::vk::wl_surface, ) -> Result<(), Box> { if !instance.enabled_extensions().khr_wayland_surface { return Err(Box::new(ValidationError { @@ -1142,16 +1141,16 @@ impl Surface { } #[cfg_attr(not(feature = "document_unchecked"), doc(hidden))] - pub unsafe fn from_wayland_unchecked( + pub unsafe fn from_wayland_unchecked( instance: Arc, - display: *const D, - surface: *const S, + display: *mut ash::vk::wl_display, + surface: *mut ash::vk::wl_surface, object: Option>, ) -> Result, VulkanError> { let create_info = ash::vk::WaylandSurfaceCreateInfoKHR { flags: ash::vk::WaylandSurfaceCreateFlagsKHR::empty(), - display: display as *mut _, - surface: surface as *mut _, + display, + surface, ..Default::default() }; @@ -1187,10 +1186,10 @@ impl Surface { /// - `hwnd` must be a valid Win32 `HWND` handle. /// - The objects referred to by `hwnd` and `hinstance` must outlive the created `Surface`. /// The `object` parameter can be used to ensure this. - pub unsafe fn from_win32( + pub unsafe fn from_win32( instance: Arc, - hinstance: *const I, - hwnd: *const W, + hinstance: ash::vk::HINSTANCE, + hwnd: ash::vk::HWND, object: Option>, ) -> Result, Validated> { Self::validate_from_win32(&instance, hinstance, hwnd)?; @@ -1200,10 +1199,10 @@ impl Surface { )?) } - fn validate_from_win32( + fn validate_from_win32( instance: &Instance, - _hinstance: *const I, - _hwnd: *const W, + _hinstance: ash::vk::HINSTANCE, + _hwnd: ash::vk::HWND, ) -> Result<(), Box> { if !instance.enabled_extensions().khr_win32_surface { return Err(Box::new(ValidationError { @@ -1224,16 +1223,16 @@ impl Surface { } #[cfg_attr(not(feature = "document_unchecked"), doc(hidden))] - pub unsafe fn from_win32_unchecked( + pub unsafe fn from_win32_unchecked( instance: Arc, - hinstance: *const I, - hwnd: *const W, + hinstance: ash::vk::HINSTANCE, + hwnd: ash::vk::HWND, object: Option>, ) -> Result, VulkanError> { let create_info = ash::vk::Win32SurfaceCreateInfoKHR { flags: ash::vk::Win32SurfaceCreateFlagsKHR::empty(), - hinstance: hinstance as *mut _, - hwnd: hwnd as *mut _, + hinstance, + hwnd, ..Default::default() }; @@ -1269,9 +1268,9 @@ impl Surface { /// - `window` must be a valid X11 `xcb_window_t` handle. /// - The objects referred to by `connection` and `window` must outlive the created `Surface`. /// The `object` parameter can be used to ensure this. - pub unsafe fn from_xcb( + pub unsafe fn from_xcb( instance: Arc, - connection: *const C, + connection: *mut ash::vk::xcb_connection_t, window: ash::vk::xcb_window_t, object: Option>, ) -> Result, Validated> { @@ -1282,9 +1281,9 @@ impl Surface { )?) } - fn validate_from_xcb( + fn validate_from_xcb( instance: &Instance, - _connection: *const C, + _connection: *mut ash::vk::xcb_connection_t, _window: ash::vk::xcb_window_t, ) -> Result<(), Box> { if !instance.enabled_extensions().khr_xcb_surface { @@ -1306,15 +1305,15 @@ impl Surface { } #[cfg_attr(not(feature = "document_unchecked"), doc(hidden))] - pub unsafe fn from_xcb_unchecked( + pub unsafe fn from_xcb_unchecked( instance: Arc, - connection: *const C, + connection: *mut ash::vk::xcb_connection_t, window: ash::vk::xcb_window_t, object: Option>, ) -> Result, VulkanError> { let create_info = ash::vk::XcbSurfaceCreateInfoKHR { flags: ash::vk::XcbSurfaceCreateFlagsKHR::empty(), - connection: connection as *mut _, + connection, window, ..Default::default() }; @@ -1351,9 +1350,9 @@ impl Surface { /// - `window` must be a valid Xlib `Window` handle. /// - The objects referred to by `display` and `window` must outlive the created `Surface`. /// The `object` parameter can be used to ensure this. - pub unsafe fn from_xlib( + pub unsafe fn from_xlib( instance: Arc, - display: *const D, + display: *mut ash::vk::Display, window: ash::vk::Window, object: Option>, ) -> Result, Validated> { @@ -1364,9 +1363,9 @@ impl Surface { )?) } - fn validate_from_xlib( + fn validate_from_xlib( instance: &Instance, - _display: *const D, + _display: *mut ash::vk::Display, _window: ash::vk::Window, ) -> Result<(), Box> { if !instance.enabled_extensions().khr_xlib_surface { @@ -1388,15 +1387,15 @@ impl Surface { } #[cfg_attr(not(feature = "document_unchecked"), doc(hidden))] - pub unsafe fn from_xlib_unchecked( + pub unsafe fn from_xlib_unchecked( instance: Arc, - display: *const D, + display: *mut ash::vk::Display, window: ash::vk::Window, object: Option>, ) -> Result, VulkanError> { let create_info = ash::vk::XlibSurfaceCreateInfoKHR { flags: ash::vk::XlibSurfaceCreateFlagsKHR::empty(), - dpy: display as *mut _, + dpy: display, window, ..Default::default() }; @@ -1515,7 +1514,7 @@ impl_id_counter!(Surface); /// Get sublayer from iOS main view (ui_view). The sublayer is created as `CAMetalLayer`. #[cfg(target_os = "ios")] -unsafe fn get_metal_layer_ios(ui_view: *mut std::ffi::c_void) -> IOSMetalLayer { +unsafe fn get_metal_layer_ios(ui_view: *mut c_void) -> IOSMetalLayer { use core_graphics_types::{base::CGFloat, geometry::CGRect}; let view: *mut Object = ui_view.cast(); @@ -1533,7 +1532,7 @@ unsafe fn get_metal_layer_ios(ui_view: *mut std::ffi::c_void) -> IOSMetalLayer { /// Get (and set) `CAMetalLayer` to `ns_view`. This is necessary to be able to render on Mac. #[cfg(target_os = "macos")] -unsafe fn get_metal_layer_macos(ns_view: *mut std::ffi::c_void) -> *mut Object { +unsafe fn get_metal_layer_macos(ns_view: *mut c_void) -> *mut Object { use core_graphics_types::base::CGFloat; use objc::runtime::YES; use objc::runtime::{BOOL, NO}; @@ -2392,7 +2391,7 @@ mod tests { #[test] fn khr_win32_surface_ext_missing() { let instance = instance!(); - match unsafe { Surface::from_win32(instance, ptr::null::(), ptr::null::(), None) } { + match unsafe { Surface::from_win32(instance, ptr::null_mut(), ptr::null_mut(), None) } { Err(Validated::ValidationError(err)) if matches!( *err, @@ -2410,7 +2409,7 @@ mod tests { #[test] fn khr_xcb_surface_ext_missing() { let instance = instance!(); - match unsafe { Surface::from_xcb(instance, ptr::null::(), 0, None) } { + match unsafe { Surface::from_xcb(instance, ptr::null_mut(), 0, None) } { Err(Validated::ValidationError(err)) if matches!( *err, @@ -2428,7 +2427,7 @@ mod tests { #[test] fn khr_xlib_surface_ext_missing() { let instance = instance!(); - match unsafe { Surface::from_xlib(instance, ptr::null::(), 0, None) } { + match unsafe { Surface::from_xlib(instance, ptr::null_mut(), 0, None) } { Err(Validated::ValidationError(err)) if matches!( *err, @@ -2446,8 +2445,7 @@ mod tests { #[test] fn khr_wayland_surface_ext_missing() { let instance = instance!(); - match unsafe { Surface::from_wayland(instance, ptr::null::(), ptr::null::(), None) } - { + match unsafe { Surface::from_wayland(instance, ptr::null_mut(), ptr::null_mut(), None) } { Err(Validated::ValidationError(err)) if matches!( *err, @@ -2465,7 +2463,7 @@ mod tests { #[test] fn khr_android_surface_ext_missing() { let instance = instance!(); - match unsafe { Surface::from_android(instance, ptr::null::(), None) } { + match unsafe { Surface::from_android(instance, ptr::null_mut(), None) } { Err(Validated::ValidationError(err)) if matches!( *err,