Skip to content

Add platform-specific extension list for creating a surface to ash_window #611

Open
entropylost wants to merge 7 commits into
ash-rs:masterfrom
entropylost:master
Open

Add platform-specific extension list for creating a surface to ash_window #611
entropylost wants to merge 7 commits into
ash-rs:masterfrom
entropylost:master

Conversation

@entropylost

Copy link
Copy Markdown

This pull request adds a constant TARGET_EXTENSIONS to ash_window, which allows people to create the Instance before the window by using it instead of enumerate_required_extensions. (see #595)

Comment thread ash-window/src/lib.rs

@MarijnS95 MarijnS95 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. 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;
  2. Create a separate TARGET_EXTENSIONS_CURRENT_PLATFORM that sources from the right platform through cfg, documenting that it will obviously vary across targets on compile-time;
  3. Reuse these slices in fn enumerate_required_extensions() because copying them is wasteful and confusing;
  4. Nit: It seems common to write doc comments above attributes (#[cfg]), not below.

@entropylost

Copy link
Copy Markdown
Author

@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).

@Ralith

Ralith commented Apr 11, 2022

Copy link
Copy Markdown
Collaborator

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.

@MarijnS95

Copy link
Copy Markdown
Collaborator

Forgive the copy-paste typo, s/TARGET/WSI or something more relevant. Its main use is reuse in fn enumerate_required_extensions(), instead of "depending" on the fact that both the match statement and the enablement of these consts share the same cfg.

but actually enumerate_required_extensions doesn't give the same return value as TARGET_EXTENSIONS for linux (because of the 3 different windowing managers).

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?

Comment thread ash-window/src/lib.rs Outdated
@entropylost

Copy link
Copy Markdown
Author

@MarijnS95 Alright, I fixed all of your points. It should be good now.

@Ralith

Ralith commented Apr 12, 2022

Copy link
Copy Markdown
Collaborator

Its main use is reuse in fn enumerate_required_extensions(), instead of "depending" on the fact that both the match statement and the enablement of these consts share the same cfg.

This sounds good to me on its own, but they don't have to be part of the public API for that.

Comment thread ash-window/src/lib.rs Outdated
@entropylost

Copy link
Copy Markdown
Author

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.

@Ralith

Ralith commented Apr 12, 2022

Copy link
Copy Markdown
Collaborator

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.

@entropylost

Copy link
Copy Markdown
Author

Alright.

@MarijnS95 MarijnS95 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the doc comments still need some work, and this probably fails to compile on mac/ios now.

Comment thread ash-window/src/lib.rs
}
}

/// Extensions necessary for creating a surface on windows.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Extensions necessary for creating a surface on windows.
/// Extensions necessary for creating a surface on Windows.

Comment thread ash-window/src/lib.rs
Comment on lines +127 to +128
/// 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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// 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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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 enumerate_required_extensions() differs in that situation?

Suggested change
/// 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.)

Comment thread ash-window/src/lib.rs
khr::XlibSurface::name().as_ptr(),
khr::XcbSurface::name().as_ptr(),
];
/// Extensions necessary for creating a surface on android.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Extensions necessary for creating a surface on android.
/// Extensions necessary for creating a surface on Android.

Comment thread ash-window/src/lib.rs
khr::Surface::name().as_ptr(),
khr::AndroidSurface::name().as_ptr(),
];
/// Extensions necessary for creating a surface on macos.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// 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?

Comment thread ash-window/src/lib.rs
khr::Surface::name().as_ptr(),
ext::MetalSurface::name().as_ptr(),
];
/// Extensions necessary for creating a surface on ios.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Extensions necessary for creating a surface on ios.
/// Extensions necessary for creating a surface on iOS.

Comment thread ash-window/src/lib.rs
}

/// Extensions necessary for creating a surface on windows.
#[allow(dead_code)]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not making them public it seems cleaner to just repeat the cfg()?

Comment thread ash-window/src/lib.rs

/// 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] = {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since TARGET here refers to the current target_os, are we perhaps missing _SURFACE_ in between? So:

Suggested change
pub const TARGET_EXTENSIONS: &'static [*const c_char] = {
pub const TARGET_SURFACE_EXTENSIONS: &'static [*const c_char] = {

Comment thread ash-window/src/lib.rs
Comment on lines +152 to +153
/// 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`])

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same "create a separate paragraph for this":

Suggested change
/// 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 👎

Comment thread ash-window/src/lib.rs
use std::os::raw::c_char;

use ash::{extensions::khr, prelude::*, vk, Entry, Instance};
use ash::{extensions::ext, extensions::khr, prelude::*, vk, Entry, Instance};

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then remove:

#[cfg(any(target_os = "macos", target_os = "ios"))]
use ash::extensions::ext; // portability extensions

You can't import the same thing in scope twice.

(But I rather see cfg() on the per-platform consts then)

@MarijnS95

Copy link
Copy Markdown
Collaborator

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.

Note though that this is the separate, smaller ash-window support crate; we're not clobbering the main ash crate here.

I had some use-case in mind but I guess I'll have to PR the publicization of these when I actually come up with something and actively need it.

In any case, the allow(dead_code) seems ugly to me, rather repeat the cfg() so that things are not defined when not used. And it's unfortunate that nice doc comments don't show up in the final documentation either, even though they're still relevant.

@MarijnS95

Copy link
Copy Markdown
Collaborator

@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.

@entropylost

Copy link
Copy Markdown
Author

Sorry, I forgot about it; I'd appreciate if you did it according to your designs though.

@entropylost entropylost closed this May 6, 2023
@MarijnS95

MarijnS95 commented May 6, 2023

Copy link
Copy Markdown
Collaborator

@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.

@MarijnS95 MarijnS95 reopened this May 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants