This PR correctly raised concerns over here:
#14503
Right now Cocoa_Vulkan_LoadLibrary probes @executable_path/../Frameworks/libMoltenVK.dylib first and treats a successful dlopen as "the app bundles MoltenVK". That is not an existence check: dyld resolves every load request by leaf name against DYLD_LIBRARY_PATH before trying the path as written (this includes @executable_path/...).
The Vulkan SDK's setup-env.sh puts $VULKAN_SDK/lib (which contains libMoltenVK.dylib) on DYLD_LIBRARY_PATH meaning that the current mechanism circumvents the loader infrastructure for every bare binary on machines that want to use the regular Vulkan SDK infrastructure (because moltenvk is found via DYLD_LIBRARY_PATH, consequently always skipping the loader).
Long story short, I believe volk reverting this logic (see zeux/volk#268) is the (more) correct behavior.
A resolution logic along the following lines should be able to satisfy both:
- Check
@executable_path/../Frameworks/libMoltenVK.dylib first, so an app that ships MoltenVK still wins.
- Before calling
dlopen on it, check if the file is actually there relative to the executable, skip otherwise
- With that check the behavior is: bundle present → bundled MoltenVK; no bundle → libvulkan.1.dylib via the loader (I believe this is similar to SDL2)
Happy to discuss this further and open a PR with improved resolution logic if it helps.
This PR correctly raised concerns over here:
#14503
Right now
Cocoa_Vulkan_LoadLibraryprobes@executable_path/../Frameworks/libMoltenVK.dylibfirst and treats a successfuldlopenas "the app bundles MoltenVK". That is not an existence check:dyldresolves every load request by leaf name againstDYLD_LIBRARY_PATHbefore trying the path as written (this includes@executable_path/...).The Vulkan SDK's
setup-env.shputs$VULKAN_SDK/lib(which contains libMoltenVK.dylib) onDYLD_LIBRARY_PATHmeaning that the current mechanism circumvents the loader infrastructure for every bare binary on machines that want to use the regular Vulkan SDK infrastructure (because moltenvk is found viaDYLD_LIBRARY_PATH, consequently always skipping the loader).Long story short, I believe
volkreverting this logic (see zeux/volk#268) is the (more) correct behavior.A resolution logic along the following lines should be able to satisfy both:
@executable_path/../Frameworks/libMoltenVK.dylibfirst, so an app that ships MoltenVK still wins.dlopenon it, check if the file is actually there relative to the executable, skip otherwiseHappy to discuss this further and open a PR with improved resolution logic if it helps.