-
Notifications
You must be signed in to change notification settings - Fork 229
Add platform-specific extension list for creating a surface to ash_window #611
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
base: master
Are you sure you want to change the base?
Changes from all commits
494eb34
929adc5
31782b1
cfb320f
9cca727
4fdeb03
4359a06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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,6 +118,59 @@ pub unsafe fn create_surface( | |||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| /// Extensions necessary for creating a surface on windows. | ||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
| #[allow(dead_code)] | ||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If not making them public it seems cleaner to just repeat the |
||||||||||||||||||||
| 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. | ||||||||||||||||||||
|
Comment on lines
+127
to
+128
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about elaborating this to return all possible extensions on Unix, and explaining how
Suggested change
Also add this to (If you intend these to be separate paragraphs, add an empty |
||||||||||||||||||||
| #[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. | ||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
| #[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. | ||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
At least I think this is the right capitalization? |
||||||||||||||||||||
| #[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. | ||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
| #[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`]) | ||||||||||||||||||||
|
Comment on lines
+152
to
+153
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same "create a separate paragraph for this":
Suggested change
Same comment applies here though: elaborate how it differs . After all, with the removal of |
||||||||||||||||||||
| pub const TARGET_EXTENSIONS: &'static [*const c_char] = { | ||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since
Suggested change
|
||||||||||||||||||||
| #[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 | ||||||||||||||||||||
| }; | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
entropylost marked this conversation as resolved.
|
||||||||||||||||||||
| /// Query the required instance extensions for creating a surface from a window handle. | ||||||||||||||||||||
| /// | ||||||||||||||||||||
| /// The returned extensions will include all extension dependencies. | ||||||||||||||||||||
|
|
@@ -126,13 +179,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", | ||||||||||||||||||||
|
|
@@ -179,32 +226,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), | ||||||||||||||||||||
| }; | ||||||||||||||||||||
|
|
||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then remove:
You can't import the same thing in scope twice.
(But I rather see
cfg()on the per-platformconsts then)