diff --git a/ash-window/Cargo.toml b/ash-window/Cargo.toml index 1a69aae..982b250 100644 --- a/ash-window/Cargo.toml +++ b/ash-window/Cargo.toml @@ -16,14 +16,16 @@ rust-version = "1.64.0" [dependencies] ash = { path = "../ash", version = "0.37", default-features = false } -raw-window-handle = "0.5" +raw-window-handle = "0.6" [target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies] -raw-window-metal = "0.3" +raw-window-metal = "0.4" [dev-dependencies] winit = "0.27.1" -ash = { path = "../ash", version = "0.37", default-features = false, features = ["linked"] } +ash = { path = "../ash", version = "0.37", default-features = false, features = [ + "linked", +] } [[example]] name = "winit" diff --git a/ash-window/src/lib.rs b/ash-window/src/lib.rs index e82a2c7..ff7196b 100644 --- a/ash-window/src/lib.rs +++ b/ash-window/src/lib.rs @@ -1,6 +1,6 @@ #![warn(trivial_casts, trivial_numeric_casts)] -use std::os::raw::c_char; +use std::{ffi::c_void, os::raw::c_char}; use ash::{ extensions::{ext, khr}, @@ -42,23 +42,29 @@ pub unsafe fn create_surface( match (display_handle, window_handle) { (RawDisplayHandle::Windows(_), RawWindowHandle::Win32(window)) => { let surface_desc = vk::Win32SurfaceCreateInfoKHR::builder() - .hinstance(window.hinstance) - .hwnd(window.hwnd); + .hinstance(window.hinstance.ok_or(vk::Result::ERROR_UNKNOWN)?.get() as *mut c_void) + .hwnd(window.hwnd.get() as *mut c_void); let surface_fn = khr::Win32Surface::new(entry, instance); surface_fn.create_win32_surface(&surface_desc, allocation_callbacks) } (RawDisplayHandle::Wayland(display), RawWindowHandle::Wayland(window)) => { let surface_desc = vk::WaylandSurfaceCreateInfoKHR::builder() - .display(display.display) - .surface(window.surface); + .display(display.display.as_ptr()) + .surface(window.surface.as_ptr()); let surface_fn = khr::WaylandSurface::new(entry, instance); surface_fn.create_wayland_surface(&surface_desc, allocation_callbacks) } (RawDisplayHandle::Xlib(display), RawWindowHandle::Xlib(window)) => { let surface_desc = vk::XlibSurfaceCreateInfoKHR::builder() - .dpy(display.display.cast()) + .dpy( + display + .display + .ok_or(vk::Result::ERROR_UNKNOWN)? + .as_ptr() + .cast(), + ) .window(window.window); let surface_fn = khr::XlibSurface::new(entry, instance); surface_fn.create_xlib_surface(&surface_desc, allocation_callbacks) @@ -66,15 +72,20 @@ pub unsafe fn create_surface( (RawDisplayHandle::Xcb(display), RawWindowHandle::Xcb(window)) => { let surface_desc = vk::XcbSurfaceCreateInfoKHR::builder() - .connection(display.connection) - .window(window.window); + .connection( + display + .connection + .ok_or(vk::Result::ERROR_UNKNOWN)? + .as_ptr(), + ) + .window(window.window.get()); let surface_fn = khr::XcbSurface::new(entry, instance); surface_fn.create_xcb_surface(&surface_desc, allocation_callbacks) } (RawDisplayHandle::Android(_), RawWindowHandle::AndroidNdk(window)) => { let surface_desc = - vk::AndroidSurfaceCreateInfoKHR::builder().window(window.a_native_window); + vk::AndroidSurfaceCreateInfoKHR::builder().window(window.a_native_window.as_ptr()); let surface_fn = khr::AndroidSurface::new(entry, instance); surface_fn.create_android_surface(&surface_desc, allocation_callbacks) } @@ -85,7 +96,7 @@ pub unsafe fn create_surface( let layer = match appkit::metal_layer_from_handle(window) { Layer::Existing(layer) | Layer::Allocated(layer) => layer.cast(), - Layer::None => return Err(vk::Result::ERROR_INITIALIZATION_FAILED), + // Layer::None => return Err(vk::Result::ERROR_INITIALIZATION_FAILED), }; let surface_desc = vk::MetalSurfaceCreateInfoEXT::builder().layer(&*layer);