Skip to content

Commit

Permalink
ash-window: Upgrade to raw-window-handle 0.6.0
Browse files Browse the repository at this point in the history
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]: rust-windowing/raw-window-metal#8
  • Loading branch information
MarijnS95 committed Oct 14, 2023
1 parent d0d5ea1 commit 2ac7248
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 18 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ members = [
"generator",
"generator-rewrite",
]

[patch.crates-io]
raw-window-metal = { git = "https://github.com/MarijnS95/raw-window-metal", rev = "517317cb27bacd82dd60b166bd5c1e12c90ba06d" }
4 changes: 2 additions & 2 deletions ash-window/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down
1 change: 1 addition & 0 deletions ash-window/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 6 additions & 4 deletions ash-window/examples/winit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn Error>> {
let event_loop = EventLoop::new();
let event_loop = EventLoop::new()?;

unsafe {
let entry = ash::Entry::linked();
Expand Down
33 changes: 23 additions & 10 deletions ash-window/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,39 +42,54 @@ 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)
}

(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)
}
Expand All @@ -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);
Expand All @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 2ac7248

Please sign in to comment.