diff --git a/src/vulkan/vulkan_loader.cpp b/src/vulkan/vulkan_loader.cpp index b435b22a..e5981e94 100644 --- a/src/vulkan/vulkan_loader.cpp +++ b/src/vulkan/vulkan_loader.cpp @@ -1,24 +1,48 @@ +#include + #include "vulkan_loader.h" +#include "../util/log/log.h" + +#include "../util/util_string.h" #include "../util/util_win32_compat.h" namespace dxvk::vk { - static HMODULE loadVulkanLibrary() { + static std::pair loadVulkanLibrary() { + static const std::array dllNames = {{ #ifdef _WIN32 - return LoadLibraryA("vulkan-1.dll"); + "winevulkan.dll", + "vulkan-1.dll", #else - HMODULE library = LoadLibraryA("libvulkan.so"); - if (!library) - library = LoadLibraryA("libvulkan.so.1"); - return library; + "libvulkan.so", + "libvulkan.so.1", #endif + }}; + + for (auto dllName : dllNames) { + HMODULE library = LoadLibraryA(dllName); + + if (!library) + continue; + + auto proc = GetProcAddress(library, "vkGetInstanceProcAddr"); + + if (!proc) { + FreeLibrary(library); + continue; + } + + Logger::info(str::format("Vulkan: Found vkGetInstanceProcAddr in ", dllName, " @ 0x", std::hex, reinterpret_cast(proc))); + return std::make_pair(library, reinterpret_cast(proc)); + } + + Logger::err("Vulkan: vkGetInstanceProcAddr not found"); + return { }; } - LibraryLoader::LibraryLoader() - : m_library(loadVulkanLibrary()) - , m_getInstanceProcAddr(reinterpret_cast( - GetProcAddress(m_library, "vkGetInstanceProcAddr"))) { + LibraryLoader::LibraryLoader() { + std::tie(m_library, m_getInstanceProcAddr) = loadVulkanLibrary(); } LibraryLoader::~LibraryLoader() { diff --git a/src/vulkan/vulkan_loader.h b/src/vulkan/vulkan_loader.h index 71b2dab2..89944e09 100644 --- a/src/vulkan/vulkan_loader.h +++ b/src/vulkan/vulkan_loader.h @@ -26,8 +26,8 @@ namespace dxvk::vk { PFN_vkGetInstanceProcAddr getLoaderProc() const { return m_getInstanceProcAddr; } bool valid() const; protected: - const HMODULE m_library; - const PFN_vkGetInstanceProcAddr m_getInstanceProcAddr; + HMODULE m_library = nullptr; + PFN_vkGetInstanceProcAddr m_getInstanceProcAddr = nullptr; };