Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ash-window: Upgrade to raw-window-handle 0.4.2 #505

Merged
merged 1 commit into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions ash-window/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ rust-version = "1.59.0"

[dependencies]
ash = { path = "../ash", version = "0.37", default-features = false }
raw-window-handle = "0.3.4"
raw-window-handle = "0.4.2"

[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
raw-window-metal = "0.1"
raw-window-metal = "0.2"

[dev-dependencies]
winit = "0.26"
Expand Down
6 changes: 6 additions & 0 deletions ash-window/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

## [Unreleased] - ReleaseDate

### Changed

- Bumped `raw-window-handle` to `0.4.2` (#505)

## [0.10.0] - 2022-03-23

### Changed

- Bumped `ash` version to [`0.37`](https://github.com/MaikKlein/ash/releases/tag/0.37.0) (#600)
- Make `enumerate_required_extensions()` return `&[*const c_char]` instead of `Vec<&CStr>` to match `ash::vk::InstanceCreateInfo` (#590)

Expand Down
97 changes: 21 additions & 76 deletions ash-window/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

use std::os::raw::c_char;

use ash::{extensions::khr, prelude::*, vk, Entry, Instance};
use ash::{
extensions::{ext, khr},
prelude::*,
vk, Entry, Instance,
};
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};

#[cfg(any(target_os = "macos", target_os = "ios"))]
use ash::extensions::ext; // portability extensions

/// Create a surface from a raw surface handle.
///
/// `instance` must have created with platform specific surface extensions enabled.
Expand All @@ -24,22 +25,14 @@ pub unsafe fn create_surface(
allocation_callbacks: Option<&vk::AllocationCallbacks>,
) -> VkResult<vk::SurfaceKHR> {
match window_handle.raw_window_handle() {
#[cfg(target_os = "windows")]
RawWindowHandle::Windows(handle) => {
RawWindowHandle::Win32(handle) => {
let surface_desc = vk::Win32SurfaceCreateInfoKHR::default()
.hinstance(handle.hinstance)
.hwnd(handle.hwnd);
let surface_fn = khr::Win32Surface::new(entry, instance);
surface_fn.create_win32_surface(&surface_desc, allocation_callbacks)
}

#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
))]
RawWindowHandle::Wayland(handle) => {
let surface_desc = vk::WaylandSurfaceCreateInfoKHR::default()
.display(handle.display)
Expand All @@ -48,13 +41,6 @@ pub unsafe fn create_surface(
surface_fn.create_wayland_surface(&surface_desc, allocation_callbacks)
}

#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
))]
RawWindowHandle::Xlib(handle) => {
let surface_desc = vk::XlibSurfaceCreateInfoKHR::default()
.dpy(handle.display as *mut _)
Expand All @@ -63,13 +49,6 @@ pub unsafe fn create_surface(
surface_fn.create_xlib_surface(&surface_desc, allocation_callbacks)
}

#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
))]
RawWindowHandle::Xcb(handle) => {
let surface_desc = vk::XcbSurfaceCreateInfoKHR::default()
.connection(handle.connection)
Expand All @@ -78,19 +57,18 @@ pub unsafe fn create_surface(
surface_fn.create_xcb_surface(&surface_desc, allocation_callbacks)
}

#[cfg(any(target_os = "android"))]
RawWindowHandle::Android(handle) => {
RawWindowHandle::AndroidNdk(handle) => {
let surface_desc =
vk::AndroidSurfaceCreateInfoKHR::default().window(handle.a_native_window);
let surface_fn = khr::AndroidSurface::new(entry, instance);
surface_fn.create_android_surface(&surface_desc, allocation_callbacks)
}

#[cfg(any(target_os = "macos"))]
RawWindowHandle::MacOS(handle) => {
use raw_window_metal::{macos, Layer};
#[cfg(target_os = "macos")]
RawWindowHandle::AppKit(handle) => {
use raw_window_metal::{appkit, Layer};

let layer = match macos::metal_layer_from_handle(handle) {
let layer = match appkit::metal_layer_from_handle(handle) {
Layer::Existing(layer) | Layer::Allocated(layer) => layer as *mut _,
Layer::None => return Err(vk::Result::ERROR_INITIALIZATION_FAILED),
};
Expand All @@ -100,11 +78,11 @@ pub unsafe fn create_surface(
surface_fn.create_metal_surface(&surface_desc, allocation_callbacks)
}

#[cfg(any(target_os = "ios"))]
RawWindowHandle::IOS(handle) => {
use raw_window_metal::{ios, Layer};
#[cfg(target_os = "ios")]
RawWindowHandle::UiKit(handle) => {
use raw_window_metal::{uikit, Layer};

let layer = match ios::metal_layer_from_handle(handle) {
let layer = match uikit::metal_layer_from_handle(handle) {
Layer::Existing(layer) | Layer::Allocated(layer) => layer as *mut _,
Layer::None => return Err(vk::Result::ERROR_INITIALIZATION_FAILED),
};
Expand All @@ -114,7 +92,7 @@ pub unsafe fn create_surface(
surface_fn.create_metal_surface(&surface_desc, allocation_callbacks)
}

_ => Err(vk::Result::ERROR_EXTENSION_NOT_PRESENT), // not supported
_ => Err(vk::Result::ERROR_EXTENSION_NOT_PRESENT),
}
}

Expand All @@ -125,22 +103,14 @@ pub fn enumerate_required_extensions(
window_handle: &dyn HasRawWindowHandle,
) -> VkResult<&'static [*const c_char]> {
let extensions = match window_handle.raw_window_handle() {
#[cfg(target_os = "windows")]
RawWindowHandle::Windows(_) => {
RawWindowHandle::Win32(_) => {
const WINDOWS_EXTS: [*const c_char; 2] = [
khr::Surface::name().as_ptr(),
khr::Win32Surface::name().as_ptr(),
];
&WINDOWS_EXTS
}

#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
))]
RawWindowHandle::Wayland(_) => {
const WAYLAND_EXTS: [*const c_char; 2] = [
khr::Surface::name().as_ptr(),
Expand All @@ -149,13 +119,6 @@ pub fn enumerate_required_extensions(
&WAYLAND_EXTS
}

#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
))]
RawWindowHandle::Xlib(_) => {
const XLIB_EXTS: [*const c_char; 2] = [
khr::Surface::name().as_ptr(),
Expand All @@ -164,13 +127,6 @@ pub fn enumerate_required_extensions(
&XLIB_EXTS
}

#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
))]
RawWindowHandle::Xcb(_) => {
const XCB_EXTS: [*const c_char; 2] = [
khr::Surface::name().as_ptr(),
Expand All @@ -179,31 +135,20 @@ pub fn enumerate_required_extensions(
&XCB_EXTS
}

#[cfg(any(target_os = "android"))]
RawWindowHandle::Android(_) => {
RawWindowHandle::AndroidNdk(_) => {
const ANDROID_EXTS: [*const c_char; 2] = [
khr::Surface::name().as_ptr(),
khr::AndroidSurface::name().as_ptr(),
];
&ANDROID_EXTS
}

#[cfg(any(target_os = "macos"))]
RawWindowHandle::MacOS(_) => {
const MACOS_EXTS: [*const c_char; 2] = [
khr::Surface::name().as_ptr(),
ext::MetalSurface::name().as_ptr(),
];
&MACOS_EXTS
}

#[cfg(any(target_os = "ios"))]
RawWindowHandle::IOS(_) => {
const IOS_EXTS: [*const c_char; 2] = [
RawWindowHandle::AppKit(_) | RawWindowHandle::UiKit(_) => {
const METAL_EXTS: [*const c_char; 2] = [
khr::Surface::name().as_ptr(),
ext::MetalSurface::name().as_ptr(),
];
&IOS_EXTS
&METAL_EXTS
}

_ => return Err(vk::Result::ERROR_EXTENSION_NOT_PRESENT),
Expand Down