Add platform-specific extension list for creating a surface to ash_window #611
Add platform-specific extension list for creating a surface to ash_window #611entropylost wants to merge 7 commits into
Conversation
There was a problem hiding this comment.
Would you mind including the current platform name in the doc comment, so that users know it can vary across compilation targets? Would be bad if they start relying on the type containing ie. an array of size 2 and trivially fail compiling on Linux(es) [EDIT: Yes, better fix that with a static slice as suggested above]. At the same time I don't think we should be using cfgs to hide other options depending on the compile target, we're not doing that for platform-specific extensions either. As such, I'd rather see something like the following:
- Make all of these arrays available, under the appropriate platform name.
TARGET_EXTENSIONS_WINDOWS,TARGET_EXTENSIONS_UNIX/LINUX,TARGET_EXTENSIONS_ANDROID, etc. Cover it in a doc comment too; - Create a separate
TARGET_EXTENSIONS_CURRENT_PLATFORMthat sources from the right platform throughcfg, documenting that it will obviously vary across targets on compile-time; - Reuse these slices in
fn enumerate_required_extensions()because copying them is wasteful and confusing; - Nit: It seems common to write doc comments above attributes (
#[cfg]), not below.
|
@MarijnS95 Points 1, 2, and 4 seem nice, but actually enumerate_required_extensions doesn't give the same return value as TARGET_EXTENSIONS for linux (because of the 3 different windowing managers). |
|
I'm not sure I agree with point 1. What's the use case for individual constants as part of the public API? If there is no specific compelling case, we shouldn't make the API wider than necessary; the current draft is solving a concrete use case as it stands. "TARGET" also already conveys "the compile target," so that naming is odd. |
|
Forgive the copy-paste typo,
That's an exception to one out of the five supported platforms here, not the rule. That should still allow the remaining 4 platforms to only have their array/slice of required extensions defined once? |
|
@MarijnS95 Alright, I fixed all of your points. It should be good now. |
This sounds good to me on its own, but they don't have to be part of the public API for that. |
True, but there are some potential cases them be in the public api might be helpful, I don't really care though. |
|
I think we should prefer not to complicate our public API except when it is specifically known to solve a real problem someone's having. |
|
Alright. |
MarijnS95
left a comment
There was a problem hiding this comment.
Looks like the doc comments still need some work, and this probably fails to compile on mac/ios now.
| } | ||
| } | ||
|
|
||
| /// Extensions necessary for creating a surface on windows. |
There was a problem hiding this comment.
| /// Extensions necessary for creating a surface on windows. | |
| /// Extensions necessary for creating a surface on Windows. |
| /// 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. |
There was a problem hiding this comment.
| /// 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. | |
| /// 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. |
There was a problem hiding this comment.
How about elaborating this to return all possible extensions on Unix, and explaining how enumerate_required_extensions() differs in that situation?
| /// 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. | |
| /// _All_ possible extensions for creating a surface on Unix. | |
| /// | |
| /// Defer to [`enumerate_required_extensions()`] for a subset of this list applicable to the display server protocol specific to the given [`HasRawWindowHandle`]. |
Also add this to TARGET_SURFACE_EXTENSIONS since UNIX_SURFACE_EXTENSIONS is not public 😞
(If you intend these to be separate paragraphs, add an empty /// in between. Otherwise the two sentences get concatenated into one paragraph.)
| khr::XlibSurface::name().as_ptr(), | ||
| khr::XcbSurface::name().as_ptr(), | ||
| ]; | ||
| /// Extensions necessary for creating a surface on android. |
There was a problem hiding this comment.
| /// Extensions necessary for creating a surface on android. | |
| /// Extensions necessary for creating a surface on Android. |
| khr::Surface::name().as_ptr(), | ||
| khr::AndroidSurface::name().as_ptr(), | ||
| ]; | ||
| /// Extensions necessary for creating a surface on macos. |
There was a problem hiding this comment.
| /// Extensions necessary for creating a surface on macos. | |
| /// Extensions necessary for creating a surface on macOS. |
At least I think this is the right capitalization?
| khr::Surface::name().as_ptr(), | ||
| ext::MetalSurface::name().as_ptr(), | ||
| ]; | ||
| /// Extensions necessary for creating a surface on ios. |
There was a problem hiding this comment.
| /// Extensions necessary for creating a surface on ios. | |
| /// Extensions necessary for creating a surface on iOS. |
| } | ||
|
|
||
| /// Extensions necessary for creating a surface on windows. | ||
| #[allow(dead_code)] |
There was a problem hiding this comment.
If not making them public it seems cleaner to just repeat the cfg()?
|
|
||
| /// 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`]) | ||
| pub const TARGET_EXTENSIONS: &'static [*const c_char] = { |
There was a problem hiding this comment.
Since TARGET here refers to the current target_os, are we perhaps missing _SURFACE_ in between? So:
| pub const TARGET_EXTENSIONS: &'static [*const c_char] = { | |
| pub const TARGET_SURFACE_EXTENSIONS: &'static [*const c_char] = { |
| /// 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`]) |
There was a problem hiding this comment.
The same "create a separate paragraph for this":
| /// 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`]) | |
| /// Extensions necessary for creating a surface on the current target platform. | |
| /// | |
| /// On Unix, contains _all_ possible extensions for creating a surface. Defer to [`enumerate_required_extensions()`] for a subset of this list applicable to the display server protocol specific to the given [`HasRawWindowHandle`]. |
Same comment applies here though: elaborate how it differs . After all, with the removal of pub readers won't see what doc comment is written on UNIX_SURFACE_EXTENSIONS 👎
| use std::os::raw::c_char; | ||
|
|
||
| use ash::{extensions::khr, prelude::*, vk, Entry, Instance}; | ||
| use ash::{extensions::ext, extensions::khr, prelude::*, vk, Entry, Instance}; |
There was a problem hiding this comment.
Then remove:
#[cfg(any(target_os = "macos", target_os = "ios"))]
use ash::extensions::ext; // portability extensionsYou can't import the same thing in scope twice.
(But I rather see cfg() on the per-platform consts then)
Note though that this is the separate, smaller I had some use-case in mind but I guess I'll have to PR the In any case, the |
|
@iMplode-nZ do you still intend to push this forward after a year? Otherwise I'll redo this with all of my requested changes applied. |
|
Sorry, I forgot about it; I'd appreciate if you did it according to your designs though. |
|
@iMplode-nZ no worries, it happens. I'll see what I can do, and ping @Ralith on some of my review comments to make sure my view/opinion makes sense before making any massive changes, but would like to keep your PR for context and authorship as base. |
This pull request adds a constant
TARGET_EXTENSIONSto ash_window, which allows people to create theInstancebefore the window by using it instead ofenumerate_required_extensions. (see #595)