Skip to content

Commit

Permalink
Use concrete types from Ash for foreign handles (#2406)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
Rua and marc0246 authored Nov 15, 2023
1 parent 3749e17 commit b5b8ea8
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 182 deletions.
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
20 changes: 10 additions & 10 deletions vulkano-win/src/raw_window_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
{
Expand All @@ -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"))]
{
Expand Down Expand Up @@ -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!(),
Expand All @@ -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"))]
{
Expand All @@ -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"))]
{
Expand All @@ -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!(),
Expand Down
16 changes: 8 additions & 8 deletions vulkano-win/src/winit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
Expand Down Expand Up @@ -196,8 +196,8 @@ unsafe fn winit_to_surface(
window: Arc<Window>,
) -> Result<Arc<Surface>, Validated<VulkanError>> {
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")]
Expand Down Expand Up @@ -227,8 +227,8 @@ unsafe fn winit_to_surface(
window: Arc<Window>,
) -> Result<Arc<Surface>, Validated<VulkanError>> {
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")]
Expand All @@ -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),
)
}
Expand All @@ -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 _) }
}
70 changes: 35 additions & 35 deletions vulkano/src/device/physical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,20 +425,20 @@ impl PhysicalDevice {
///
/// - `dfb` must be a valid DirectFB `IDirectFB` handle.
#[inline]
pub unsafe fn directfb_presentation_support<D>(
pub unsafe fn directfb_presentation_support(
&self,
queue_family_index: u32,
dfb: *const D,
dfb: *mut ash::vk::IDirectFB,
) -> Result<bool, Box<ValidationError>> {
self.validate_directfb_presentation_support(queue_family_index, dfb)?;

Ok(self.directfb_presentation_support_unchecked(queue_family_index, dfb))
}

fn validate_directfb_presentation_support<D>(
fn validate_directfb_presentation_support(
&self,
queue_family_index: u32,
_dfb: *const D,
_dfb: *mut ash::vk::IDirectFB,
) -> Result<(), Box<ValidationError>> {
if !self.instance.enabled_extensions().ext_directfb_surface {
return Err(Box::new(ValidationError {
Expand Down Expand Up @@ -469,17 +469,17 @@ impl PhysicalDevice {

#[cfg_attr(not(feature = "document_unchecked"), doc(hidden))]
#[inline]
pub unsafe fn directfb_presentation_support_unchecked<D>(
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
}

Expand Down Expand Up @@ -1678,20 +1678,20 @@ impl PhysicalDevice {
/// # Safety
///
/// - `window` must be a valid QNX Screen `_screen_window` handle.
pub unsafe fn qnx_screen_presentation_support<W>(
pub unsafe fn qnx_screen_presentation_support(
&self,
queue_family_index: u32,
window: *const W,
window: *mut ash::vk::_screen_window,
) -> Result<bool, Box<ValidationError>> {
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<W>(
fn validate_qnx_screen_presentation_support(
&self,
queue_family_index: u32,
_window: *const W,
_window: *mut ash::vk::_screen_window,
) -> Result<(), Box<ValidationError>> {
if !self.instance.enabled_extensions().qnx_screen_surface {
return Err(Box::new(ValidationError {
Expand Down Expand Up @@ -1721,17 +1721,17 @@ impl PhysicalDevice {
}

#[cfg_attr(not(feature = "document_unchecked"), doc(hidden))]
pub unsafe fn qnx_screen_presentation_support_unchecked<W>(
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
}

Expand Down Expand Up @@ -3016,20 +3016,20 @@ impl PhysicalDevice {
/// # Safety
///
/// - `display` must be a valid Wayland `wl_display` handle.
pub unsafe fn wayland_presentation_support<D>(
pub unsafe fn wayland_presentation_support(
&self,
queue_family_index: u32,
display: *const D,
display: *mut ash::vk::wl_display,
) -> Result<bool, Box<ValidationError>> {
self.validate_wayland_presentation_support(queue_family_index, display)?;

Ok(self.wayland_presentation_support_unchecked(queue_family_index, display))
}

fn validate_wayland_presentation_support<D>(
fn validate_wayland_presentation_support(
&self,
queue_family_index: u32,
_display: *const D,
_display: *mut ash::vk::wl_display,
) -> Result<(), Box<ValidationError>> {
if !self.instance.enabled_extensions().khr_wayland_surface {
return Err(Box::new(ValidationError {
Expand Down Expand Up @@ -3059,17 +3059,17 @@ impl PhysicalDevice {
}

#[cfg_attr(not(feature = "document_unchecked"), doc(hidden))]
pub unsafe fn wayland_presentation_support_unchecked<D>(
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
}

Expand Down Expand Up @@ -3129,21 +3129,21 @@ impl PhysicalDevice {
/// # Safety
///
/// - `connection` must be a valid X11 `xcb_connection_t` handle.
pub unsafe fn xcb_presentation_support<C>(
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<bool, Box<ValidationError>> {
self.validate_xcb_presentation_support(queue_family_index, connection, visual_id)?;

Ok(self.xcb_presentation_support_unchecked(queue_family_index, connection, visual_id))
}

fn validate_xcb_presentation_support<C>(
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<ValidationError>> {
if !self.instance.enabled_extensions().khr_xcb_surface {
Expand Down Expand Up @@ -3174,18 +3174,18 @@ impl PhysicalDevice {
}

#[cfg_attr(not(feature = "document_unchecked"), doc(hidden))]
pub unsafe fn xcb_presentation_support_unchecked<C>(
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();
(fns.khr_xcb_surface
.get_physical_device_xcb_presentation_support_khr)(
self.handle,
queue_family_index,
connection as *mut _,
connection,
visual_id,
) != 0
}
Expand All @@ -3196,21 +3196,21 @@ impl PhysicalDevice {
/// # Safety
///
/// - `display` must be a valid Xlib `Display` handle.
pub unsafe fn xlib_presentation_support<D>(
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<bool, Box<ValidationError>> {
self.validate_xlib_presentation_support(queue_family_index, display, visual_id)?;

Ok(self.xlib_presentation_support_unchecked(queue_family_index, display, visual_id))
}

fn validate_xlib_presentation_support<D>(
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<ValidationError>> {
if !self.instance.enabled_extensions().khr_xlib_surface {
Expand Down Expand Up @@ -3241,18 +3241,18 @@ impl PhysicalDevice {
}

#[cfg_attr(not(feature = "document_unchecked"), doc(hidden))]
pub unsafe fn xlib_presentation_support_unchecked<D>(
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();
(fns.khr_xlib_surface
.get_physical_device_xlib_presentation_support_khr)(
self.handle,
queue_family_index,
display as *mut _,
display,
visual_id,
) != 0
}
Expand Down
9 changes: 5 additions & 4 deletions vulkano/src/swapchain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,11 @@
//! # fn build_window() -> Arc<Window> { 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()
//! };
Expand Down Expand Up @@ -2459,8 +2460,8 @@ impl Win32Monitor {
/// # Safety
///
/// - `hmonitor` must be a valid handle as returned by the Win32 API.
pub unsafe fn new<T>(hmonitor: *const T) -> Self {
Self(hmonitor as _)
pub unsafe fn new(hmonitor: ash::vk::HMONITOR) -> Self {
Self(hmonitor)
}
}

Expand Down
Loading

0 comments on commit b5b8ea8

Please sign in to comment.