From e4fd12001ce2088530080b2562841af4670a3f97 Mon Sep 17 00:00:00 2001 From: Luflosi Date: Fri, 17 Jan 2020 14:12:05 +0100 Subject: [PATCH] Cocoa: Add fully dynamic loading of Vulkan loader From upstream: https://github.com/glfw/glfw/commit/7da87aaae7039cbdc132f8f563a2603c5e3c73a1. --- glfw/cocoa_init.m | 26 ++++++++++++++++++++++++++ glfw/cocoa_platform.h | 2 ++ glfw/vulkan.c | 2 ++ 3 files changed, 30 insertions(+) diff --git a/glfw/cocoa_init.m b/glfw/cocoa_init.m index bdad46aa8..5252614b7 100644 --- a/glfw/cocoa_init.m +++ b/glfw/cocoa_init.m @@ -529,6 +529,32 @@ static GLFWapplicationwillfinishlaunchingfun finish_launching_callback = NULL; @end +////////////////////////////////////////////////////////////////////////// +////// GLFW internal API ////// +////////////////////////////////////////////////////////////////////////// + +void* _glfwLoadLocalVulkanLoaderNS(void) +{ + CFBundleRef bundle = CFBundleGetMainBundle(); + if (!bundle) + return NULL; + + CFURLRef url = + CFBundleCopyAuxiliaryExecutableURL(bundle, CFSTR("libvulkan.1.dylib")); + if (!url) + return NULL; + + char path[PATH_MAX]; + void* handle = NULL; + + if (CFURLGetFileSystemRepresentation(url, true, (UInt8*) path, sizeof(path) - 1)) + handle = _glfw_dlopen(path); + + CFRelease(url); + return handle; +} + + ////////////////////////////////////////////////////////////////////////// ////// GLFW platform API ////// ////////////////////////////////////////////////////////////////////////// diff --git a/glfw/cocoa_platform.h b/glfw/cocoa_platform.h index 226950a3f..bcad82fce 100644 --- a/glfw/cocoa_platform.h +++ b/glfw/cocoa_platform.h @@ -239,6 +239,8 @@ void _glfwRestoreVideoModeNS(_GLFWmonitor* monitor); float _glfwTransformYNS(float y); +void* _glfwLoadLocalVulkanLoaderNS(void); + void _glfwClearDisplayLinks(void); void _glfwRestartDisplayLinks(void); void _glfwDispatchTickCallback(void); diff --git a/glfw/vulkan.c b/glfw/vulkan.c index 3f5ba0161..fe8485210 100644 --- a/glfw/vulkan.c +++ b/glfw/vulkan.c @@ -57,6 +57,8 @@ bool _glfwInitVulkan(int mode) _glfw.vk.handle = _glfw_dlopen("vulkan-1.dll"); #elif defined(_GLFW_COCOA) _glfw.vk.handle = _glfw_dlopen("libvulkan.1.dylib"); + if (!_glfw.vk.handle) + _glfw.vk.handle = _glfwLoadLocalVulkanLoaderNS(); #else _glfw.vk.handle = _glfw_dlopen("libvulkan.so.1"); #endif