-
Notifications
You must be signed in to change notification settings - Fork 192
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
Support linking Vulkan directly #457
Conversation
1e8bc44
to
33c291b
Compare
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.
Nice, I've been intending to propose the same after 0.33
is out assuming we can get permission to absorb detection and static linking of MoltenVK
through the same mechanism, effectively making ash-molten
obsolete.
I'm still conflicted on the linked
name, but guess it makes sense if we were to support both dynamic and static linking at some point in time.
Please be aware that the current implementation (indirect linking) is recommended in order to achieve optimal performance as per the Vulkan Loader documentation. |
@Friz64 You probably intended to link https://github.com/KhronosGroup/Vulkan-Loader/blob/master/loader/LoaderAndLayerInterface.md#indirectly-linking-to-the-loader as https://github.com/KhronosGroup/Vulkan-Loader/blob/master/loader/LoaderAndLayerInterface.md#best-application-performance-setup is specific to linking Vulkan functions after having acquired The section you linked seems to recommend using |
Yes, i intended to link that one instead. The documentation is somewhat confusing in this regard, but i understand now. |
None of this code is sensitive to whether the linked library is static or dynamic; it's just a matter of what's in your search path. |
It feels like there should be something to distinguish it from runtime linking/loading, perhaps renaming |
|
e17fff4
to
b8c4783
Compare
I've added a commit which folds all the various entry types into a single monomorphic |
7b8cb71
to
b1b5e69
Compare
Findings from CI: libvulkan.so.1 (which is what ends up in the binary's RUNPATH) is installed by default, but libvulkan.so (which is the symlink the linker finds at compiletime) comes from libvulkan-dev, which is not. |
The |
What exactly about the current iteration poses a problem for you? You've always been able to access the function pointer table directly via e.g. |
True, but it feels a bit weird to construct an |
How exactly do you not intend to use it? |
While I would technically agree, this isn't the first time I have seen it being called a
Should be fine, it's extremely unlikely for the features to be used together. In the rare event that someone wishes to use multiple Vulkan libraries at the same time (building whatever arbitration and circumventing the ICD) they better use runtime loading to keep the libraries separated.
Fortunately we're already using
@Ralith It appears @Rua is referring to this shorthand: Which allows all structs in But that has always been the case. Not sure if it should change towards |
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.
This is looking really good so far. Should we let the CI run on it? I'm curious what others think on it, @MaikKlein? It's quite an impactful change, but I'd love to roll this out soon.
InstanceError::LoadError was never constructed.
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.
Awesome, I don't have any concerns here.
If anyone has any ideas what, if any, special measures are needed for good behavior on macOS, let me know!
Not sure myself. I am also not sure how this will integrate with ash-molten.
I'd like to keep ash-molten as a separate crate because it is quite opinionated and builds or downloads moltenvk itself.
I think we can keep ash-molten as is and it can internally do Entry::from_static_fn
. I think we can use no-default-features there as well and let ash-molten statically link with vulkan.
Yeah, that. Good to see it run now.
Nothing that this PR changes, afaik. They must not be using
Derp. Yes, that is totally sensible. We're already using
Exactly. That's better than making them incompatible and breaking
With both features enabled by default I don't think it matters too much anymore. |
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.
Ready to get in. Not sure if we should bite the bullet and accept StaticFn
instead of Entry
in all the extension constructors though, this PR is already touching all those lines anyway.
This PR disables dynamic loading by default, since it's a niche case and brings in an extra dependency. I think the docs still do a reasonably good job of making things clear thanks to
I'd prefer to leave that for future work, since it's logically independent and you can easily construct an |
Then we'll wait for @MaikKlein to give the final sign-off on this, and get it in! Let's immediately cut a new minor release as well with perhaps some other PRs? |
Simplifies the interface and allows a bunch of code to become monomorphic.
@MaikKlein ping? |
Sorry for the delay, looks good 🥳 and I'd like to get this in. Two high level comments:
|
According to #457 (comment) this needs
According to https://github.com/MaikKlein/ash/pull/457/files#r689123563 the .so is preferred over the .a. I marked #462 as linked to this PR since the asker only seems to have a
There's the optional |
Yeah that is what I meant. It will break all the CIs without a vulkan environment and they have to add |
Yes, the build environment will need to have a libvulkan for the target available. IMO it's a reasonable default. For one thing, the linker error you get for a missing foreign library is highly recognizable and easy to google, with the same solution across all programming languages, whereas a build error due to not having default features would be more idiosyncratic. Leaving the default unchanged wouldn't be a disaster, but there's something to be said for defaulting to the lighter-weight, more robust, and more conventional configuration.
As @MarijnS95 says, it'll use whatever's available in the search path. If the target environment only has a static library, then that's what'll be used. I expect this will be sufficient in practice; especially when cross-compiling, the user has considerable control over the available libraries. |
I'll resurrect this thread now that ash 0.34 is out and we're starting to see the first linker errors across our crates. I think this may have been a mistake. Rust users aren't used to fixing (or seeing) linker errors, and I honestly think this is a bad precedent to set from a usability point of view. |
FWIW, there is overwhelming precedent for this behavior for FFI crates (e.g. cpal, openssl, openexr, gtk, ...). While I'm sure ash 0.34 will be some peoples' first encounter with link-time dependencies, most ash users should find this familiar and easily diagnosed. |
I agree with @Jasper-Bekkers. This imposes a burden that is 100% avoidable. This is not the same as a sys crate where we are building the |
Along with this, it's quite unclear what the need for this change was to begin with, dropping a small and extremely common dependency is not really a gain. Neither in build times (only if you look at them in isolation, not when you look at them in the context of a much larger app) nor in runtime performance. At best it's a dubious default to have, at worst it actively harms usability for this crate. I would suggest doing a fox release that reverts this behavior honestly. |
This is the preferred pattern in most environments when an application cannot function without Vulkan, as it saves the libloading dependency, eliminates an error case, and makes the Vulkan dependency visible to the OS.
Ideally I'd like to move towards this being the default, but that might be more disruptive than is justified.
Draft until I've tested this properly on Windows. The build script might need to explicitly add
VULKAN_SDK/lib
to the linker search path.