VSG + static Vulkan or MoltenVK #1557
Replies: 2 comments 9 replies
-
Vulkan implementations are typically specific to the graphics hardware, so if it were hypothetically to statically link with it on one machine, you'd end up with an application that wouldn't work on a different machine with the same operating system but a different GPU. The point of APIs like Vulkan or OpenGL before it is that you don't need to have a hardware-specific interface to the hardware, and instead have something that you know will be present at runtime that will handle the hardware-specific parts for you. You can only achieve that with a dynamic/shared library which is loaded and linked at runtime. MoltenVK is an odd duck here as it's not hardware-specific, and really is just another library. It translates Vulkan calls to Metal calls which also aren't hardware-specific and get handled by the Metal runtime provided by MacOS that handles the hardware-specific parts. In principle, this means that you can statically link with MoltenVK. However, this can still have some downsides as you can't use layers like the validation layers and API dump layer if there's no way for their functions to be used at runtime. If you've already got an app that works perfectly, that might not be a problem, but until you're certain of that, you can more-or-less get the best of both worlds by providing MoltenVK as a |
Beta Was this translation helpful? Give feedback.
-
Not really sure what the issue is here, but on my Mac I just did
and everything builds and works fine for me |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
This is a bit of a complex subject, and the title implies that we may be discussing two separate issues depending on how people think they should be solved - but they aren't entirely mutually exclusive of each-other.
The first, and likely overarching subject - is static linkage of Vulkan itself. The reasons a user may want to do this vary and could be vast, but from self-contained libraries, executables, or modified Vulkan build are all on the table.
From my (paltry) knowledge of Vulkan and graphics programming - it's not uncommon practice to have a large function pointer resolution step before calling any Vulkan/graphics API. For example, with vkCreateInstance, one might do this:
Which allows intermediary libraries to inject custom versions of these functions, to provide... well whatever they provide. I'm really not an expert here, I just know it's common practice. Perhaps someone here knows more about why it's done. I think it's something to do pluggable symbol resolution to enable other implementations of vkCreateInstance to be used based on drivers.
I do know however, that it does allow resolving the required function pointers to symbols that can be defined wherever the user needs them to be defined (for example, statically built-in to a library, or provided by another library).
Now I also brought up MoltenVK - because it's required to do something as above to use a statically linked MoltenVK. This is because if the user is statically linking in MoltenVK, they need to swap out the call to
vkCreateInstance
to the MoltenVK version. Again - only if statically linking. From what I can tell, this is the best way to avoid going through the Vulkan Loader which will just dynamically link to the system MoltenVK.This becomes especially important if the user wants to use a more recent version of MoltenVK that isn't shipped on macOS by default (Apple usually lags behind here by quite a bit - my system ships with a MoltenVK that supports up to version 1.2.269 of Vulkan, but more recent MoltenVK from source or release already supports up to 1.4).
... let me know if I'm making any sense here, anyone with more knowledge on these issues please feel free to chime in and call me out on my ramblings.
While statically linking in a custom Vulkan is likely an edge case that might be rarely used in-practice, I think discussing static linkage caveats like this might be good to have anyway. Might help someone in the future.
Beta Was this translation helpful? Give feedback.
All reactions