From 2ac7248a9d659ef1325be7a290db8d39d82b0e02 Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Wed, 11 Oct 2023 18:51:11 +0200 Subject: [PATCH] ash-window: Upgrade to raw-window-handle 0.6.0 This is the successor to #795. While it doesn't tackle things like backwards-compatibility nor use of the new lifetimed handles (if we _can_ even come up with a safe abstraction for them - it's very likely out of scope!), it includes the following improvements: - Upgrade `raw-window-metal` via [#8] (Mac/iOS wasn't tested in our CI); - Fix Windows platform types (in the `ash` crate) to be `isize` instead of `*const c_void`, matching the usptream definition; - Update example code (impossible until `winit` with `raw-window-handle 0.6` becomes available). [#8]: https://github.com/norse-rs/raw-window-metal/pull/8 --- Cargo.toml | 3 +++ ash-window/Cargo.toml | 4 ++-- ash-window/Changelog.md | 1 + ash-window/examples/winit.rs | 10 ++++++---- ash-window/src/lib.rs | 33 +++++++++++++++++++++++---------- examples/Cargo.toml | 3 +-- 6 files changed, 36 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a11a2c018..6c6b35ec6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,6 @@ members = [ "generator", "generator-rewrite", ] + +[patch.crates-io] +raw-window-metal = { git = "https://github.com/MarijnS95/raw-window-metal", rev = "517317cb27bacd82dd60b166bd5c1e12c90ba06d" } diff --git a/ash-window/Cargo.toml b/ash-window/Cargo.toml index 76ad7c154..86f8c2a70 100644 --- a/ash-window/Cargo.toml +++ b/ash-window/Cargo.toml @@ -16,13 +16,13 @@ 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" [dev-dependencies] -winit = "0.28.0" +winit = "0.29.1-beta" ash = { path = "../ash", version = "0.37", default-features = false, features = ["linked"] } [[example]] diff --git a/ash-window/Changelog.md b/ash-window/Changelog.md index ec2cbbf8f..bca103d99 100644 --- a/ash-window/Changelog.md +++ b/ash-window/Changelog.md @@ -3,6 +3,7 @@ ## [Unreleased] - ReleaseDate - Bumped MSRV from 1.59 to 1.64 for `winit 0.28` and `raw-window-handle 0.5.1`. (#709, #716) +- Bumped `raw-window-handle` to `0.6.0` (#799) ## [0.12.0] - 2022-09-23 diff --git a/ash-window/examples/winit.rs b/ash-window/examples/winit.rs index b730e94a8..78a453391 100644 --- a/ash-window/examples/winit.rs +++ b/ash-window/examples/winit.rs @@ -6,17 +6,19 @@ //! On instance extensions platform specific extensions need to be enabled. use ash::vk; -use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle}; use std::error::Error; use winit::{ dpi::PhysicalSize, - event::{Event, VirtualKeyCode, WindowEvent}, + event::{Event, WindowEvent}, event_loop::{ControlFlow, EventLoop}, - window::WindowBuilder, + window::{ + raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle}, + WindowBuilder, + }, }; fn main() -> Result<(), Box> { - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new()?; unsafe { let entry = ash::Entry::linked(); diff --git a/ash-window/src/lib.rs b/ash-window/src/lib.rs index a11991961..784915385 100644 --- a/ash-window/src/lib.rs +++ b/ash-window/src/lib.rs @@ -42,23 +42,33 @@ pub unsafe fn create_surface( match (display_handle, window_handle) { (RawDisplayHandle::Windows(_), RawWindowHandle::Win32(window)) => { let surface_desc = vk::Win32SurfaceCreateInfoKHR::default() - .hinstance(window.hinstance as isize) - .hwnd(window.hwnd as isize); + .hwnd(window.hwnd.get()) + .hinstance( + window + .hinstance + .ok_or(vk::Result::ERROR_INITIALIZATION_FAILED)? + .get(), + ); 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::default() - .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::default() - .dpy(display.display.cast()) + .dpy( + display + .display + .ok_or(vk::Result::ERROR_INITIALIZATION_FAILED)? + .as_ptr(), + ) .window(window.window); let surface_fn = khr::XlibSurface::new(entry, instance); surface_fn.create_xlib_surface(&surface_desc, allocation_callbacks) @@ -66,15 +76,20 @@ pub unsafe fn create_surface( (RawDisplayHandle::Xcb(display), RawWindowHandle::Xcb(window)) => { let surface_desc = vk::XcbSurfaceCreateInfoKHR::default() - .connection(display.connection) - .window(window.window); + .connection( + display + .connection + .ok_or(vk::Result::ERROR_INITIALIZATION_FAILED)? + .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::default().window(window.a_native_window); + vk::AndroidSurfaceCreateInfoKHR::default().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 +100,6 @@ 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), }; let surface_desc = vk::MetalSurfaceCreateInfoEXT::default().layer(&*layer); @@ -99,7 +113,6 @@ pub unsafe fn create_surface( let layer = match uikit::metal_layer_from_handle(window) { Layer::Existing(layer) | Layer::Allocated(layer) => layer.cast(), - Layer::None => return Err(vk::Result::ERROR_INITIALIZATION_FAILED), }; let surface_desc = vk::MetalSurfaceCreateInfoEXT::default().layer(&*layer); diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 22ddf61fe..1c3c36bfd 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -6,8 +6,7 @@ edition = "2021" [dependencies] image = "0.24" -raw-window-handle = "0.5" -winit = "0.28.0" +winit = "0.29.1-beta" # The examples require the validation layers, which means the SDK or # equivalent development packages should be present, so we can link # directly and benefit from the infallible `Entry` constructor.