From 49310dbe10615cfc5b516e0f292a9daba0ae4d9a Mon Sep 17 00:00:00 2001 From: renderexpert Date: Fri, 10 Jan 2025 19:57:23 +0000 Subject: [PATCH] Extend vulkan wrapper Signed-off-by: renderexpert --- 3party/vulkan_wrapper/CMakeLists.txt | 3 +++ 3party/vulkan_wrapper/vulkan_wrapper.cpp | 23 ++++++++++++++++++++++- 3party/vulkan_wrapper/vulkan_wrapper.h | 8 ++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/3party/vulkan_wrapper/CMakeLists.txt b/3party/vulkan_wrapper/CMakeLists.txt index fe73f1bb2e..6638f31373 100644 --- a/3party/vulkan_wrapper/CMakeLists.txt +++ b/3party/vulkan_wrapper/CMakeLists.txt @@ -17,6 +17,9 @@ endif() target_include_directories(${PROJECT_NAME} PUBLIC .) +if (PLATFORM_LINUX) + target_compile_definitions(${PROJECT_NAME} PRIVATE VK_USE_PLATFORM_XLIB_KHR) +endif() # dlopen target_link_libraries(${PROJECT_NAME} $<$:${CMAKE_DL_LIBS}>) diff --git a/3party/vulkan_wrapper/vulkan_wrapper.cpp b/3party/vulkan_wrapper/vulkan_wrapper.cpp index e025139038..4322a49d94 100755 --- a/3party/vulkan_wrapper/vulkan_wrapper.cpp +++ b/3party/vulkan_wrapper/vulkan_wrapper.cpp @@ -22,7 +22,20 @@ extern "C" { #include int InitVulkan(void) { - void* libvulkan = dlopen("libvulkan.so", RTLD_NOW | RTLD_LOCAL); +#if defined(__APPLE__) + void* libvulkan = dlopen("libvulkan.dylib", RTLD_NOW | RTLD_LOCAL); + if (!libvulkan) { + libvulkan = dlopen("libvulkan.1.dylib", RTLD_NOW | RTLD_LOCAL); + } + if (!libvulkan) { + libvulkan = dlopen("libMoltenVK.dylib", RTLD_NOW | RTLD_LOCAL); + } +#else + void* libvulkan = dlopen("libvulkan.so.1", RTLD_NOW | RTLD_LOCAL); + if (!libvulkan) { + libvulkan = dlopen("libvulkan.so", RTLD_NOW | RTLD_LOCAL); + } +#endif if (!libvulkan) return 0; // Vulkan supported, set function addresses @@ -545,6 +558,10 @@ int InitVulkan(void) { vkDestroyDebugReportCallbackEXT = reinterpret_cast(dlsym(libvulkan, "vkDestroyDebugReportCallbackEXT")); vkDebugReportMessageEXT = reinterpret_cast(dlsym(libvulkan, "vkDebugReportMessageEXT")); +#if defined(__APPLE__) + vkCreateMacOSSurfaceMVK = reinterpret_cast(dlsym(libvulkan, "vkCreateMacOSSurfaceMVK")); +#endif + return 1; } @@ -1137,6 +1154,10 @@ PFN_vkCmdDecodeVideoKHR vkCmdDecodeVideoKHR; PFN_vkCmdEncodeVideoKHR vkCmdEncodeVideoKHR; #endif +#if defined(__APPLE__) +PFN_vkCreateMacOSSurfaceMVK vkCreateMacOSSurfaceMVK; +#endif + #ifdef __cplusplus } #endif diff --git a/3party/vulkan_wrapper/vulkan_wrapper.h b/3party/vulkan_wrapper/vulkan_wrapper.h index 79f1105b44..e29b084071 100755 --- a/3party/vulkan_wrapper/vulkan_wrapper.h +++ b/3party/vulkan_wrapper/vulkan_wrapper.h @@ -25,6 +25,10 @@ extern "C" { #define VK_USE_PLATFORM_ANDROID_KHR 1 #include +#if defined(__APPLE__) +#include +#endif + /* Initialize the Vulkan function pointer variables declared in this header. * Returns 0 if vulkan is not available, non-zero if it is available. */ @@ -500,6 +504,10 @@ extern PFN_vkCreateDebugReportCallbackEXT vkCreateDebugReportCallbackEXT; extern PFN_vkDestroyDebugReportCallbackEXT vkDestroyDebugReportCallbackEXT; extern PFN_vkDebugReportMessageEXT vkDebugReportMessageEXT; +#if defined(__APPLE__) +extern PFN_vkCreateMacOSSurfaceMVK vkCreateMacOSSurfaceMVK; +#endif + #ifdef __cplusplus } #endif