ash-window: Upgrade to raw-window-handle 0.4.2 (#505)
The match arms are not guarded by `cfg` anymore, allowing us to compile-test these simple arms on every system whenever our Ash extension helpers and types are not guarded by `cfg` attributes either. This applies to every platform except Mac/IOS where the symbols and external raw-window-metal crate are themselves guarded by cfg's.
This commit is contained in:
parent
f4acfbe2cb
commit
da49568977
|
@ -16,10 +16,10 @@ rust-version = "1.59.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ash = { path = "../ash", version = "0.37", default-features = false }
|
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]
|
[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
|
||||||
raw-window-metal = "0.1"
|
raw-window-metal = "0.2"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
winit = "0.26"
|
winit = "0.26"
|
||||||
|
|
|
@ -2,8 +2,14 @@
|
||||||
|
|
||||||
## [Unreleased] - ReleaseDate
|
## [Unreleased] - ReleaseDate
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Bumped `raw-window-handle` to `0.4.2` (#505)
|
||||||
|
|
||||||
## [0.10.0] - 2022-03-23
|
## [0.10.0] - 2022-03-23
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
- Bumped `ash` version to [`0.37`](https://github.com/MaikKlein/ash/releases/tag/0.37.0) (#600)
|
- 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)
|
- Make `enumerate_required_extensions()` return `&[*const c_char]` instead of `Vec<&CStr>` to match `ash::vk::InstanceCreateInfo` (#590)
|
||||||
|
|
||||||
|
|
|
@ -2,12 +2,13 @@
|
||||||
|
|
||||||
use std::os::raw::c_char;
|
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};
|
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.
|
/// Create a surface from a raw surface handle.
|
||||||
///
|
///
|
||||||
/// `instance` must have created with platform specific surface extensions enabled.
|
/// `instance` must have created with platform specific surface extensions enabled.
|
||||||
|
@ -24,8 +25,7 @@ pub unsafe fn create_surface(
|
||||||
allocation_callbacks: Option<&vk::AllocationCallbacks>,
|
allocation_callbacks: Option<&vk::AllocationCallbacks>,
|
||||||
) -> VkResult<vk::SurfaceKHR> {
|
) -> VkResult<vk::SurfaceKHR> {
|
||||||
match window_handle.raw_window_handle() {
|
match window_handle.raw_window_handle() {
|
||||||
#[cfg(target_os = "windows")]
|
RawWindowHandle::Win32(handle) => {
|
||||||
RawWindowHandle::Windows(handle) => {
|
|
||||||
let surface_desc = vk::Win32SurfaceCreateInfoKHR::default()
|
let surface_desc = vk::Win32SurfaceCreateInfoKHR::default()
|
||||||
.hinstance(handle.hinstance)
|
.hinstance(handle.hinstance)
|
||||||
.hwnd(handle.hwnd);
|
.hwnd(handle.hwnd);
|
||||||
|
@ -33,13 +33,6 @@ pub unsafe fn create_surface(
|
||||||
surface_fn.create_win32_surface(&surface_desc, allocation_callbacks)
|
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) => {
|
RawWindowHandle::Wayland(handle) => {
|
||||||
let surface_desc = vk::WaylandSurfaceCreateInfoKHR::default()
|
let surface_desc = vk::WaylandSurfaceCreateInfoKHR::default()
|
||||||
.display(handle.display)
|
.display(handle.display)
|
||||||
|
@ -48,13 +41,6 @@ pub unsafe fn create_surface(
|
||||||
surface_fn.create_wayland_surface(&surface_desc, allocation_callbacks)
|
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) => {
|
RawWindowHandle::Xlib(handle) => {
|
||||||
let surface_desc = vk::XlibSurfaceCreateInfoKHR::default()
|
let surface_desc = vk::XlibSurfaceCreateInfoKHR::default()
|
||||||
.dpy(handle.display as *mut _)
|
.dpy(handle.display as *mut _)
|
||||||
|
@ -63,13 +49,6 @@ pub unsafe fn create_surface(
|
||||||
surface_fn.create_xlib_surface(&surface_desc, allocation_callbacks)
|
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) => {
|
RawWindowHandle::Xcb(handle) => {
|
||||||
let surface_desc = vk::XcbSurfaceCreateInfoKHR::default()
|
let surface_desc = vk::XcbSurfaceCreateInfoKHR::default()
|
||||||
.connection(handle.connection)
|
.connection(handle.connection)
|
||||||
|
@ -78,19 +57,18 @@ pub unsafe fn create_surface(
|
||||||
surface_fn.create_xcb_surface(&surface_desc, allocation_callbacks)
|
surface_fn.create_xcb_surface(&surface_desc, allocation_callbacks)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_os = "android"))]
|
RawWindowHandle::AndroidNdk(handle) => {
|
||||||
RawWindowHandle::Android(handle) => {
|
|
||||||
let surface_desc =
|
let surface_desc =
|
||||||
vk::AndroidSurfaceCreateInfoKHR::default().window(handle.a_native_window);
|
vk::AndroidSurfaceCreateInfoKHR::default().window(handle.a_native_window);
|
||||||
let surface_fn = khr::AndroidSurface::new(entry, instance);
|
let surface_fn = khr::AndroidSurface::new(entry, instance);
|
||||||
surface_fn.create_android_surface(&surface_desc, allocation_callbacks)
|
surface_fn.create_android_surface(&surface_desc, allocation_callbacks)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_os = "macos"))]
|
#[cfg(target_os = "macos")]
|
||||||
RawWindowHandle::MacOS(handle) => {
|
RawWindowHandle::AppKit(handle) => {
|
||||||
use raw_window_metal::{macos, Layer};
|
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::Existing(layer) | Layer::Allocated(layer) => layer as *mut _,
|
||||||
Layer::None => return Err(vk::Result::ERROR_INITIALIZATION_FAILED),
|
Layer::None => return Err(vk::Result::ERROR_INITIALIZATION_FAILED),
|
||||||
};
|
};
|
||||||
|
@ -100,11 +78,11 @@ pub unsafe fn create_surface(
|
||||||
surface_fn.create_metal_surface(&surface_desc, allocation_callbacks)
|
surface_fn.create_metal_surface(&surface_desc, allocation_callbacks)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_os = "ios"))]
|
#[cfg(target_os = "ios")]
|
||||||
RawWindowHandle::IOS(handle) => {
|
RawWindowHandle::UiKit(handle) => {
|
||||||
use raw_window_metal::{ios, Layer};
|
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::Existing(layer) | Layer::Allocated(layer) => layer as *mut _,
|
||||||
Layer::None => return Err(vk::Result::ERROR_INITIALIZATION_FAILED),
|
Layer::None => return Err(vk::Result::ERROR_INITIALIZATION_FAILED),
|
||||||
};
|
};
|
||||||
|
@ -114,7 +92,7 @@ pub unsafe fn create_surface(
|
||||||
surface_fn.create_metal_surface(&surface_desc, allocation_callbacks)
|
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),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,8 +103,7 @@ pub fn enumerate_required_extensions(
|
||||||
window_handle: &dyn HasRawWindowHandle,
|
window_handle: &dyn HasRawWindowHandle,
|
||||||
) -> VkResult<&'static [*const c_char]> {
|
) -> VkResult<&'static [*const c_char]> {
|
||||||
let extensions = match window_handle.raw_window_handle() {
|
let extensions = match window_handle.raw_window_handle() {
|
||||||
#[cfg(target_os = "windows")]
|
RawWindowHandle::Win32(_) => {
|
||||||
RawWindowHandle::Windows(_) => {
|
|
||||||
const WINDOWS_EXTS: [*const c_char; 2] = [
|
const WINDOWS_EXTS: [*const c_char; 2] = [
|
||||||
khr::Surface::name().as_ptr(),
|
khr::Surface::name().as_ptr(),
|
||||||
khr::Win32Surface::name().as_ptr(),
|
khr::Win32Surface::name().as_ptr(),
|
||||||
|
@ -134,13 +111,6 @@ pub fn enumerate_required_extensions(
|
||||||
&WINDOWS_EXTS
|
&WINDOWS_EXTS
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(
|
|
||||||
target_os = "linux",
|
|
||||||
target_os = "dragonfly",
|
|
||||||
target_os = "freebsd",
|
|
||||||
target_os = "netbsd",
|
|
||||||
target_os = "openbsd"
|
|
||||||
))]
|
|
||||||
RawWindowHandle::Wayland(_) => {
|
RawWindowHandle::Wayland(_) => {
|
||||||
const WAYLAND_EXTS: [*const c_char; 2] = [
|
const WAYLAND_EXTS: [*const c_char; 2] = [
|
||||||
khr::Surface::name().as_ptr(),
|
khr::Surface::name().as_ptr(),
|
||||||
|
@ -149,13 +119,6 @@ pub fn enumerate_required_extensions(
|
||||||
&WAYLAND_EXTS
|
&WAYLAND_EXTS
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(
|
|
||||||
target_os = "linux",
|
|
||||||
target_os = "dragonfly",
|
|
||||||
target_os = "freebsd",
|
|
||||||
target_os = "netbsd",
|
|
||||||
target_os = "openbsd"
|
|
||||||
))]
|
|
||||||
RawWindowHandle::Xlib(_) => {
|
RawWindowHandle::Xlib(_) => {
|
||||||
const XLIB_EXTS: [*const c_char; 2] = [
|
const XLIB_EXTS: [*const c_char; 2] = [
|
||||||
khr::Surface::name().as_ptr(),
|
khr::Surface::name().as_ptr(),
|
||||||
|
@ -164,13 +127,6 @@ pub fn enumerate_required_extensions(
|
||||||
&XLIB_EXTS
|
&XLIB_EXTS
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(
|
|
||||||
target_os = "linux",
|
|
||||||
target_os = "dragonfly",
|
|
||||||
target_os = "freebsd",
|
|
||||||
target_os = "netbsd",
|
|
||||||
target_os = "openbsd"
|
|
||||||
))]
|
|
||||||
RawWindowHandle::Xcb(_) => {
|
RawWindowHandle::Xcb(_) => {
|
||||||
const XCB_EXTS: [*const c_char; 2] = [
|
const XCB_EXTS: [*const c_char; 2] = [
|
||||||
khr::Surface::name().as_ptr(),
|
khr::Surface::name().as_ptr(),
|
||||||
|
@ -179,8 +135,7 @@ pub fn enumerate_required_extensions(
|
||||||
&XCB_EXTS
|
&XCB_EXTS
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_os = "android"))]
|
RawWindowHandle::AndroidNdk(_) => {
|
||||||
RawWindowHandle::Android(_) => {
|
|
||||||
const ANDROID_EXTS: [*const c_char; 2] = [
|
const ANDROID_EXTS: [*const c_char; 2] = [
|
||||||
khr::Surface::name().as_ptr(),
|
khr::Surface::name().as_ptr(),
|
||||||
khr::AndroidSurface::name().as_ptr(),
|
khr::AndroidSurface::name().as_ptr(),
|
||||||
|
@ -188,22 +143,12 @@ pub fn enumerate_required_extensions(
|
||||||
&ANDROID_EXTS
|
&ANDROID_EXTS
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_os = "macos"))]
|
RawWindowHandle::AppKit(_) | RawWindowHandle::UiKit(_) => {
|
||||||
RawWindowHandle::MacOS(_) => {
|
const METAL_EXTS: [*const c_char; 2] = [
|
||||||
const MACOS_EXTS: [*const c_char; 2] = [
|
|
||||||
khr::Surface::name().as_ptr(),
|
khr::Surface::name().as_ptr(),
|
||||||
ext::MetalSurface::name().as_ptr(),
|
ext::MetalSurface::name().as_ptr(),
|
||||||
];
|
];
|
||||||
&MACOS_EXTS
|
&METAL_EXTS
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(any(target_os = "ios"))]
|
|
||||||
RawWindowHandle::IOS(_) => {
|
|
||||||
const IOS_EXTS: [*const c_char; 2] = [
|
|
||||||
khr::Surface::name().as_ptr(),
|
|
||||||
ext::MetalSurface::name().as_ptr(),
|
|
||||||
];
|
|
||||||
&IOS_EXTS
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => return Err(vk::Result::ERROR_EXTENSION_NOT_PRESENT),
|
_ => return Err(vk::Result::ERROR_EXTENSION_NOT_PRESENT),
|
||||||
|
|
Loading…
Reference in a new issue