Skip to content

Commit

Permalink
Update raw-window-metal to v1.0
Browse files Browse the repository at this point in the history
Also improve support for tvOS.
  • Loading branch information
madsmtm committed Sep 8, 2024
1 parent c1f5ac7 commit eefa0d2
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 29 deletions.
6 changes: 3 additions & 3 deletions ash-examples/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ impl ExampleBase {
.to_vec();
extension_names.push(debug_utils::NAME.as_ptr());

#[cfg(any(target_os = "macos", target_os = "ios"))]
#[cfg(target_vendor = "apple")]
{
extension_names.push(ash::khr::portability_enumeration::NAME.as_ptr());
// Enabling this extension is a requirement when using `VK_KHR_portability_subset`
Expand All @@ -242,7 +242,7 @@ impl ExampleBase {
.engine_version(0)
.api_version(vk::make_api_version(0, 1, 0, 0));

let create_flags = if cfg!(any(target_os = "macos", target_os = "ios")) {
let create_flags = if cfg!(target_vendor = "apple") {
vk::InstanceCreateFlags::ENUMERATE_PORTABILITY_KHR
} else {
vk::InstanceCreateFlags::default()
Expand Down Expand Up @@ -315,7 +315,7 @@ impl ExampleBase {
let queue_family_index = queue_family_index as u32;
let device_extension_names_raw = [
swapchain::NAME.as_ptr(),
#[cfg(any(target_os = "macos", target_os = "ios"))]
#[cfg(target_vendor = "apple")]
ash::khr::portability_subset::NAME.as_ptr(),
];
let features = vk::PhysicalDeviceFeatures {
Expand Down
4 changes: 2 additions & 2 deletions ash-window/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ rust-version = "1.69.0"
ash = { path = "../ash", version = "0.38", default-features = false, features = ["std"] }
raw-window-handle = "0.6"

[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
raw-window-metal = "0.4"
[target.'cfg(target_vendor = "apple")'.dependencies]
raw-window-metal = "1.0"

[dev-dependencies]
winit = { version = "0.29", features = ["rwh_06"] }
Expand Down
2 changes: 1 addition & 1 deletion ash-window/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ ash = "0.37"

- [x] Windows (`VK_KHR_win32_surface`)
- [x] Unix (`VK_KHR_xlib_surface`/`VK_KHR_xcb_surface`/`VK_KHR_wayland_surface`)
- [x] MacOS/IOS (`VK_EXT_metal_surface`)
- [x] macOS/iOS/tvOS (`VK_EXT_metal_surface`)
- [x] Android (`VK_KHR_android_surface`)

## License
Expand Down
24 changes: 8 additions & 16 deletions ash-window/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,28 +95,20 @@ pub unsafe fn create_surface(
surface_fn.create_android_surface(&surface_desc, allocation_callbacks)
}

#[cfg(target_os = "macos")]
(RawDisplayHandle::AppKit(_), RawWindowHandle::AppKit(window)) => {
use raw_window_metal::{appkit, Layer};
#[cfg(target_vendor = "apple")]
(RawDisplayHandle::AppKit(_), RawWindowHandle::AppKit(handle)) => {
let layer = raw_window_metal::Layer::from_ns_view(handle.ns_view);

let layer = match appkit::metal_layer_from_handle(window) {
Layer::Existing(layer) | Layer::Allocated(layer) => layer.cast(),
};

let surface_desc = vk::MetalSurfaceCreateInfoEXT::default().layer(&*layer);
let surface_desc = vk::MetalSurfaceCreateInfoEXT::default().layer(layer.as_ptr());
let surface_fn = metal_surface::Instance::new(entry, instance);
surface_fn.create_metal_surface(&surface_desc, allocation_callbacks)
}

#[cfg(target_os = "ios")]
(RawDisplayHandle::UiKit(_), RawWindowHandle::UiKit(window)) => {
use raw_window_metal::{uikit, Layer};

let layer = match uikit::metal_layer_from_handle(window) {
Layer::Existing(layer) | Layer::Allocated(layer) => layer.cast(),
};
#[cfg(target_vendor = "apple")]
(RawDisplayHandle::UiKit(_), RawWindowHandle::UiKit(handle)) => {
let layer = raw_window_metal::Layer::from_ui_view(handle.ui_view);

let surface_desc = vk::MetalSurfaceCreateInfoEXT::default().layer(&*layer);
let surface_desc = vk::MetalSurfaceCreateInfoEXT::default().layer(layer.as_ptr());
let surface_fn = metal_surface::Instance::new(entry, instance);
surface_fn.create_metal_surface(&surface_desc, allocation_callbacks)
}
Expand Down
9 changes: 2 additions & 7 deletions ash/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,14 @@ impl Entry {

#[cfg(all(
unix,
not(any(
target_os = "macos",
target_os = "ios",
target_os = "android",
target_os = "fuchsia"
))
not(any(target_vendor = "apple", target_os = "android", target_os = "fuchsia"))
))]
const LIB_PATH: &str = "libvulkan.so.1";

#[cfg(any(target_os = "android", target_os = "fuchsia"))]
const LIB_PATH: &str = "libvulkan.so";

#[cfg(any(target_os = "macos", target_os = "ios"))]
#[cfg(target_vendor = "apple")]
const LIB_PATH: &str = "libvulkan.dylib";

Self::load_from(LIB_PATH)
Expand Down

0 comments on commit eefa0d2

Please sign in to comment.