From 494eb343486111a9c96c8e07439d94a96092ec9e Mon Sep 17 00:00:00 2001 From: ReversedGravity Date: Mon, 11 Apr 2022 12:57:45 -0700 Subject: [PATCH 1/7] Added TARGET_EXTENSIONS to ash-window. --- ash-window/src/lib.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/ash-window/src/lib.rs b/ash-window/src/lib.rs index d6cb0f301..60396c5f7 100644 --- a/ash-window/src/lib.rs +++ b/ash-window/src/lib.rs @@ -118,6 +118,40 @@ pub unsafe fn create_surface( } } +#[cfg(target_os = "windows")] +pub const TARGET_EXTENSIONS: [*const c_char; 2] = [ + khr::Surface::name().as_ptr(), + khr::Win32Surface::name().as_ptr(), +]; +#[cfg(any( + target_os = "linux", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd" +))] +pub const TARGET_EXTENSIONS: [*const c_char; 4] = [ + khr::Surface::name().as_ptr(), + khr::WaylandSurface::name().as_ptr(), + khr::XlibSurface::name().as_ptr(), + khr::XcbSurface::name().as_ptr(), +]; +#[cfg(any(target_os = "android"))] +pub const TARGET_EXTENSIONS: [*const c_char; 2] = [ + khr::Surface::name().as_ptr(), + khr::AndroidSurface::name().as_ptr(), +]; +#[cfg(any(target_os = "macos"))] +pub const TARGET_EXTENSIONS: [*const c_char; 2] = [ + khr::Surface::name().as_ptr(), + ext::MetalSurface::name().as_ptr(), +]; +#[cfg(any(target_os = "ios"))] +pub const TARGET_EXTENSIONS: [*const c_char; 2] = [ + khr::Surface::name().as_ptr(), + ext::MetalSurface::name().as_ptr(), +]; + /// Query the required instance extensions for creating a surface from a window handle. /// /// The returned extensions will include all extension dependencies. From 929adc5f537393da91b20fa5dca38589ac013229 Mon Sep 17 00:00:00 2001 From: ReversedGravity Date: Mon, 11 Apr 2022 13:22:43 -0700 Subject: [PATCH 2/7] Added documentation. --- ash-window/src/lib.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ash-window/src/lib.rs b/ash-window/src/lib.rs index 60396c5f7..a2cdc44f6 100644 --- a/ash-window/src/lib.rs +++ b/ash-window/src/lib.rs @@ -119,6 +119,7 @@ pub unsafe fn create_surface( } #[cfg(target_os = "windows")] +/// Extensions necessary for creating a surface on the target platform. pub const TARGET_EXTENSIONS: [*const c_char; 2] = [ khr::Surface::name().as_ptr(), khr::Win32Surface::name().as_ptr(), @@ -130,6 +131,7 @@ pub const TARGET_EXTENSIONS: [*const c_char; 2] = [ target_os = "netbsd", target_os = "openbsd" ))] +/// Extensions necessary for creating a surface on the target platform. pub const TARGET_EXTENSIONS: [*const c_char; 4] = [ khr::Surface::name().as_ptr(), khr::WaylandSurface::name().as_ptr(), @@ -137,16 +139,19 @@ pub const TARGET_EXTENSIONS: [*const c_char; 4] = [ khr::XcbSurface::name().as_ptr(), ]; #[cfg(any(target_os = "android"))] +/// Extensions necessary for creating a surface on the target platform. pub const TARGET_EXTENSIONS: [*const c_char; 2] = [ khr::Surface::name().as_ptr(), khr::AndroidSurface::name().as_ptr(), ]; #[cfg(any(target_os = "macos"))] +/// Extensions necessary for creating a surface on the target platform. pub const TARGET_EXTENSIONS: [*const c_char; 2] = [ khr::Surface::name().as_ptr(), ext::MetalSurface::name().as_ptr(), ]; #[cfg(any(target_os = "ios"))] +/// Extensions necessary for creating a surface on the target platform. pub const TARGET_EXTENSIONS: [*const c_char; 2] = [ khr::Surface::name().as_ptr(), ext::MetalSurface::name().as_ptr(), From 31782b1ae5dd4cf2e80f5d5ef1efdab14badad68 Mon Sep 17 00:00:00 2001 From: ReversedGravity Date: Mon, 11 Apr 2022 13:50:39 -0700 Subject: [PATCH 3/7] Chhanged from arrays to slices. --- ash-window/src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ash-window/src/lib.rs b/ash-window/src/lib.rs index a2cdc44f6..957aa67de 100644 --- a/ash-window/src/lib.rs +++ b/ash-window/src/lib.rs @@ -120,7 +120,7 @@ pub unsafe fn create_surface( #[cfg(target_os = "windows")] /// Extensions necessary for creating a surface on the target platform. -pub const TARGET_EXTENSIONS: [*const c_char; 2] = [ +pub const TARGET_EXTENSIONS: &'static [*const c_char] = &[ khr::Surface::name().as_ptr(), khr::Win32Surface::name().as_ptr(), ]; @@ -132,7 +132,7 @@ pub const TARGET_EXTENSIONS: [*const c_char; 2] = [ target_os = "openbsd" ))] /// Extensions necessary for creating a surface on the target platform. -pub const TARGET_EXTENSIONS: [*const c_char; 4] = [ +pub const TARGET_EXTENSIONS: &'static [*const c_char] = &[ khr::Surface::name().as_ptr(), khr::WaylandSurface::name().as_ptr(), khr::XlibSurface::name().as_ptr(), @@ -140,19 +140,19 @@ pub const TARGET_EXTENSIONS: [*const c_char; 4] = [ ]; #[cfg(any(target_os = "android"))] /// Extensions necessary for creating a surface on the target platform. -pub const TARGET_EXTENSIONS: [*const c_char; 2] = [ +pub const TARGET_EXTENSIONS: &'static [*const c_char] = &[ khr::Surface::name().as_ptr(), khr::AndroidSurface::name().as_ptr(), ]; #[cfg(any(target_os = "macos"))] /// Extensions necessary for creating a surface on the target platform. -pub const TARGET_EXTENSIONS: [*const c_char; 2] = [ +pub const TARGET_EXTENSIONS: &'static [*const c_char] = &[ khr::Surface::name().as_ptr(), ext::MetalSurface::name().as_ptr(), ]; #[cfg(any(target_os = "ios"))] /// Extensions necessary for creating a surface on the target platform. -pub const TARGET_EXTENSIONS: [*const c_char; 2] = [ +pub const TARGET_EXTENSIONS: &'static [*const c_char] = &[ khr::Surface::name().as_ptr(), ext::MetalSurface::name().as_ptr(), ]; From cfb320fd97f7012c4c8cd20c2eb15c8c53f96cca Mon Sep 17 00:00:00 2001 From: ReversedGravity Date: Mon, 11 Apr 2022 14:00:50 -0700 Subject: [PATCH 4/7] Updated documentation. --- ash-window/src/lib.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/ash-window/src/lib.rs b/ash-window/src/lib.rs index 957aa67de..14067bbe6 100644 --- a/ash-window/src/lib.rs +++ b/ash-window/src/lib.rs @@ -118,12 +118,15 @@ pub unsafe fn create_surface( } } -#[cfg(target_os = "windows")] /// Extensions necessary for creating a surface on the target platform. +/// (Note that on Unix, this is not equal to the return value of [`enumerate_required_extensions`]) +#[cfg(target_os = "windows")] pub const TARGET_EXTENSIONS: &'static [*const c_char] = &[ khr::Surface::name().as_ptr(), khr::Win32Surface::name().as_ptr(), ]; +/// Extensions necessary for creating a surface on the target platform. +/// (Note that on Unix, this is not equal to the return value of [`enumerate_required_extensions`]) #[cfg(any( target_os = "linux", target_os = "dragonfly", @@ -131,27 +134,29 @@ pub const TARGET_EXTENSIONS: &'static [*const c_char] = &[ target_os = "netbsd", target_os = "openbsd" ))] -/// Extensions necessary for creating a surface on the target platform. pub const TARGET_EXTENSIONS: &'static [*const c_char] = &[ khr::Surface::name().as_ptr(), khr::WaylandSurface::name().as_ptr(), khr::XlibSurface::name().as_ptr(), khr::XcbSurface::name().as_ptr(), ]; -#[cfg(any(target_os = "android"))] /// Extensions necessary for creating a surface on the target platform. +/// (Note that on Unix, this is not equal to the return value of [`enumerate_required_extensions`]) +#[cfg(any(target_os = "android"))] pub const TARGET_EXTENSIONS: &'static [*const c_char] = &[ khr::Surface::name().as_ptr(), khr::AndroidSurface::name().as_ptr(), ]; -#[cfg(any(target_os = "macos"))] /// Extensions necessary for creating a surface on the target platform. +/// (Note that on Unix, this is not equal to the return value of [`enumerate_required_extensions`]) +#[cfg(any(target_os = "macos"))] pub const TARGET_EXTENSIONS: &'static [*const c_char] = &[ khr::Surface::name().as_ptr(), ext::MetalSurface::name().as_ptr(), ]; -#[cfg(any(target_os = "ios"))] /// Extensions necessary for creating a surface on the target platform. +/// (Note that on Unix, this is not equal to the return value of [`enumerate_required_extensions`]) +#[cfg(any(target_os = "ios"))] pub const TARGET_EXTENSIONS: &'static [*const c_char] = &[ khr::Surface::name().as_ptr(), ext::MetalSurface::name().as_ptr(), From 9cca727797e5f4a6a88592ba7d1315919aaeea31 Mon Sep 17 00:00:00 2001 From: ReversedGravity Date: Tue, 12 Apr 2022 11:49:26 -0700 Subject: [PATCH 5/7] Removed duplicate code and publicized the per-platform extensions. --- ash-window/src/lib.rs | 100 +++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 60 deletions(-) diff --git a/ash-window/src/lib.rs b/ash-window/src/lib.rs index 14067bbe6..18950d7d2 100644 --- a/ash-window/src/lib.rs +++ b/ash-window/src/lib.rs @@ -2,7 +2,7 @@ use std::os::raw::c_char; -use ash::{extensions::khr, prelude::*, vk, Entry, Instance}; +use ash::{extensions::ext, extensions::khr, prelude::*, vk, Entry, Instance}; use raw_window_handle::{HasRawWindowHandle, RawWindowHandle}; #[cfg(any(target_os = "macos", target_os = "ios"))] @@ -118,49 +118,53 @@ pub unsafe fn create_surface( } } -/// Extensions necessary for creating a surface on the target platform. -/// (Note that on Unix, this is not equal to the return value of [`enumerate_required_extensions`]) -#[cfg(target_os = "windows")] -pub const TARGET_EXTENSIONS: &'static [*const c_char] = &[ +/// Extensions necessary for creating a surface on windows. +pub const WINDOWS_SURFACE_EXTENSIONS: &'static [*const c_char] = &[ khr::Surface::name().as_ptr(), khr::Win32Surface::name().as_ptr(), ]; -/// Extensions necessary for creating a surface on the target platform. -/// (Note that on Unix, this is not equal to the return value of [`enumerate_required_extensions`]) -#[cfg(any( - target_os = "linux", - target_os = "dragonfly", - target_os = "freebsd", - target_os = "netbsd", - target_os = "openbsd" -))] -pub const TARGET_EXTENSIONS: &'static [*const c_char] = &[ +/// Extensions necessary for creating a surface on unix. +/// Note that this is not equal to the return value of [`enumerate_required_extensions`] on Unix due to the multiple window types. +pub const UNIX_SURFACE_EXTENSIONS: &'static [*const c_char] = &[ khr::Surface::name().as_ptr(), khr::WaylandSurface::name().as_ptr(), khr::XlibSurface::name().as_ptr(), khr::XcbSurface::name().as_ptr(), ]; -/// Extensions necessary for creating a surface on the target platform. -/// (Note that on Unix, this is not equal to the return value of [`enumerate_required_extensions`]) -#[cfg(any(target_os = "android"))] -pub const TARGET_EXTENSIONS: &'static [*const c_char] = &[ +/// Extensions necessary for creating a surface on android. +pub const ANDROID_SURFACE_EXTENSIONS: &'static [*const c_char] = &[ khr::Surface::name().as_ptr(), khr::AndroidSurface::name().as_ptr(), ]; -/// Extensions necessary for creating a surface on the target platform. -/// (Note that on Unix, this is not equal to the return value of [`enumerate_required_extensions`]) -#[cfg(any(target_os = "macos"))] -pub const TARGET_EXTENSIONS: &'static [*const c_char] = &[ +/// Extensions necessary for creating a surface on macos. +pub const MACOS_SURFACE_EXTENSIONS: &'static [*const c_char] = &[ khr::Surface::name().as_ptr(), ext::MetalSurface::name().as_ptr(), ]; -/// Extensions necessary for creating a surface on the target platform. +/// Extensions necessary for creating a surface on ios. +pub const IOS_SURFACE_EXTENSIONS: &'static [*const c_char] = MACOS_SURFACE_EXTENSIONS; + +/// Extensions necessary for creating a surface on the current target platform. /// (Note that on Unix, this is not equal to the return value of [`enumerate_required_extensions`]) -#[cfg(any(target_os = "ios"))] -pub const TARGET_EXTENSIONS: &'static [*const c_char] = &[ - khr::Surface::name().as_ptr(), - ext::MetalSurface::name().as_ptr(), -]; +pub const TARGET_EXTENSIONS: &'static [*const c_char] = { + #[cfg(target_os = "windows")] + let out = WINDOWS_SURFACE_EXTENSIONS; + #[cfg(any( + target_os = "linux", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd" + ))] + let out = UNIX_SURFACE_EXTENSIONS; + #[cfg(target_os = "android")] + let out = ANDROID_SURFACE_EXTENSIONS; + #[cfg(target_os = "macos")] + let out = MACOS_SURFACE_EXTENSIONS; + #[cfg(target_os = "ios")] + let out = IOS_SURFACE_EXTENSIONS; + out +}; /// Query the required instance extensions for creating a surface from a window handle. /// @@ -170,13 +174,7 @@ pub fn enumerate_required_extensions( ) -> VkResult<&'static [*const c_char]> { let extensions = match window_handle.raw_window_handle() { #[cfg(target_os = "windows")] - RawWindowHandle::Windows(_) => { - const WINDOWS_EXTS: [*const c_char; 2] = [ - khr::Surface::name().as_ptr(), - khr::Win32Surface::name().as_ptr(), - ]; - &WINDOWS_EXTS - } + RawWindowHandle::Windows(_) => &WINDOWS_SURFACE_EXTENSIONS, #[cfg(any( target_os = "linux", @@ -223,32 +221,14 @@ pub fn enumerate_required_extensions( &XCB_EXTS } - #[cfg(any(target_os = "android"))] - RawWindowHandle::Android(_) => { - const ANDROID_EXTS: [*const c_char; 2] = [ - khr::Surface::name().as_ptr(), - khr::AndroidSurface::name().as_ptr(), - ]; - &ANDROID_EXTS - } + #[cfg(target_os = "android")] + RawWindowHandle::Android(_) => &ANDROID_SURFACE_EXTENSIONS, - #[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(target_os = "macos")] + RawWindowHandle::MacOS(_) => &METAL_SURFACE_EXTENSIONS, - #[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 - } + #[cfg(target_os = "ios")] + RawWindowHandle::IOS(_) => &IOS_SURFACE_EXTENSIONS, _ => return Err(vk::Result::ERROR_EXTENSION_NOT_PRESENT), }; From 4fdeb037dd22e3961898deb36c48ae8f6a2a628f Mon Sep 17 00:00:00 2001 From: ReversedGravity Date: Tue, 12 Apr 2022 12:19:09 -0700 Subject: [PATCH 6/7] Removed unnecessary &s. --- ash-window/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ash-window/src/lib.rs b/ash-window/src/lib.rs index 18950d7d2..4bef8a65f 100644 --- a/ash-window/src/lib.rs +++ b/ash-window/src/lib.rs @@ -174,7 +174,7 @@ pub fn enumerate_required_extensions( ) -> VkResult<&'static [*const c_char]> { let extensions = match window_handle.raw_window_handle() { #[cfg(target_os = "windows")] - RawWindowHandle::Windows(_) => &WINDOWS_SURFACE_EXTENSIONS, + RawWindowHandle::Windows(_) => WINDOWS_SURFACE_EXTENSIONS, #[cfg(any( target_os = "linux", @@ -222,13 +222,13 @@ pub fn enumerate_required_extensions( } #[cfg(target_os = "android")] - RawWindowHandle::Android(_) => &ANDROID_SURFACE_EXTENSIONS, + RawWindowHandle::Android(_) => ANDROID_SURFACE_EXTENSIONS, #[cfg(target_os = "macos")] - RawWindowHandle::MacOS(_) => &METAL_SURFACE_EXTENSIONS, + RawWindowHandle::MacOS(_) => METAL_SURFACE_EXTENSIONS, #[cfg(target_os = "ios")] - RawWindowHandle::IOS(_) => &IOS_SURFACE_EXTENSIONS, + RawWindowHandle::IOS(_) => IOS_SURFACE_EXTENSIONS, _ => return Err(vk::Result::ERROR_EXTENSION_NOT_PRESENT), }; From 4359a0621adfb031ca18d1a1f7dd63633b0c791b Mon Sep 17 00:00:00 2001 From: ReversedGravity Date: Tue, 12 Apr 2022 12:22:03 -0700 Subject: [PATCH 7/7] Made extensions private. --- ash-window/src/lib.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/ash-window/src/lib.rs b/ash-window/src/lib.rs index 4bef8a65f..a43933dfb 100644 --- a/ash-window/src/lib.rs +++ b/ash-window/src/lib.rs @@ -119,30 +119,35 @@ pub unsafe fn create_surface( } /// Extensions necessary for creating a surface on windows. -pub const WINDOWS_SURFACE_EXTENSIONS: &'static [*const c_char] = &[ +#[allow(dead_code)] +const WINDOWS_SURFACE_EXTENSIONS: &'static [*const c_char] = &[ khr::Surface::name().as_ptr(), khr::Win32Surface::name().as_ptr(), ]; /// Extensions necessary for creating a surface on unix. /// Note that this is not equal to the return value of [`enumerate_required_extensions`] on Unix due to the multiple window types. -pub const UNIX_SURFACE_EXTENSIONS: &'static [*const c_char] = &[ +#[allow(dead_code)] +const UNIX_SURFACE_EXTENSIONS: &'static [*const c_char] = &[ khr::Surface::name().as_ptr(), khr::WaylandSurface::name().as_ptr(), khr::XlibSurface::name().as_ptr(), khr::XcbSurface::name().as_ptr(), ]; /// Extensions necessary for creating a surface on android. -pub const ANDROID_SURFACE_EXTENSIONS: &'static [*const c_char] = &[ +#[allow(dead_code)] +const ANDROID_SURFACE_EXTENSIONS: &'static [*const c_char] = &[ khr::Surface::name().as_ptr(), khr::AndroidSurface::name().as_ptr(), ]; /// Extensions necessary for creating a surface on macos. -pub const MACOS_SURFACE_EXTENSIONS: &'static [*const c_char] = &[ +#[allow(dead_code)] +const MACOS_SURFACE_EXTENSIONS: &'static [*const c_char] = &[ khr::Surface::name().as_ptr(), ext::MetalSurface::name().as_ptr(), ]; /// Extensions necessary for creating a surface on ios. -pub const IOS_SURFACE_EXTENSIONS: &'static [*const c_char] = MACOS_SURFACE_EXTENSIONS; +#[allow(dead_code)] +const IOS_SURFACE_EXTENSIONS: &'static [*const c_char] = MACOS_SURFACE_EXTENSIONS; /// Extensions necessary for creating a surface on the current target platform. /// (Note that on Unix, this is not equal to the return value of [`enumerate_required_extensions`])