From 673f1963a068fb7d5cd8af9bb209c7633950e8f8 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Thu, 31 May 2018 04:23:45 -0700 Subject: Vulkan: Support macOS via MoltenVK The path to the MoltenVK library can be specified by the LIBMOLTENVK_PATH environment variable, otherwise it assumes it is located in the application bundle's Contents/MacOS directory. --- Source/Core/VideoBackends/Vulkan/VulkanLoader.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'Source/Core/VideoBackends/Vulkan/VulkanLoader.cpp') diff --git a/Source/Core/VideoBackends/Vulkan/VulkanLoader.cpp b/Source/Core/VideoBackends/Vulkan/VulkanLoader.cpp index 0c9fae677b..96f955ce2c 100644 --- a/Source/Core/VideoBackends/Vulkan/VulkanLoader.cpp +++ b/Source/Core/VideoBackends/Vulkan/VulkanLoader.cpp @@ -4,8 +4,10 @@ #include #include +#include #include "Common/CommonFuncs.h" +#include "Common/FileUtil.h" #include "Common/Logging/Log.h" #include "Common/StringUtil.h" @@ -14,7 +16,8 @@ #if defined(VK_USE_PLATFORM_WIN32_KHR) #include #elif defined(VK_USE_PLATFORM_XLIB_KHR) || defined(VK_USE_PLATFORM_XCB_KHR) || \ - defined(VK_USE_PLATFORM_ANDROID_KHR) || defined(USE_HEADLESS) + defined(VK_USE_PLATFORM_ANDROID_KHR) || defined(VK_USE_PLATFORM_MACOS_MVK) || \ + defined(USE_HEADLESS) #include #endif @@ -98,7 +101,8 @@ void UnloadVulkanLibrary() } #elif defined(VK_USE_PLATFORM_XLIB_KHR) || defined(VK_USE_PLATFORM_XCB_KHR) || \ - defined(VK_USE_PLATFORM_ANDROID_KHR) || defined(USE_HEADLESS) + defined(VK_USE_PLATFORM_ANDROID_KHR) || defined(VK_USE_PLATFORM_MACOS_MVK) || \ + defined(USE_HEADLESS) static void* vulkan_module; static std::atomic_int vulkan_module_ref_count = {0}; @@ -112,15 +116,27 @@ bool LoadVulkanLibrary() return true; } +#if defined(__APPLE__) + // Check if a path to a specific Vulkan library has been specified. + char* libvulkan_env = getenv("LIBVULKAN_PATH"); + if (libvulkan_env) + vulkan_module = dlopen(libvulkan_env, RTLD_NOW); + if (!vulkan_module) + { + // Use the libvulkan.dylib from the application bundle. + std::string path = File::GetBundleDirectory() + "/Contents/Frameworks/libvulkan.dylib"; + vulkan_module = dlopen(path.c_str(), RTLD_NOW); + } +#else // Names of libraries to search. Desktop should use libvulkan.so.1 or libvulkan.so. static const char* search_lib_names[] = {"libvulkan.so.1", "libvulkan.so"}; - for (size_t i = 0; i < ArraySize(search_lib_names); i++) { vulkan_module = dlopen(search_lib_names[i], RTLD_NOW); if (vulkan_module) break; } +#endif if (!vulkan_module) { @@ -164,6 +180,7 @@ void UnloadVulkanLibrary() dlclose(vulkan_module); vulkan_module = nullptr; } + #else //#warning Unknown platform, not compiling loader. -- cgit v1.2.3