Skip to content

Commit

Permalink
[vulkan] Try loading winevulkan.dll before vulkan-1.dll
Browse files Browse the repository at this point in the history
Should bypass issues with third-party overlays trying to hook Vulkan.
  • Loading branch information
doitsujin committed Jan 18, 2023
1 parent c6668ff commit 4d0d455
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
44 changes: 34 additions & 10 deletions src/vulkan/vulkan_loader.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,48 @@
#include <tuple>

#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<HMODULE, PFN_vkGetInstanceProcAddr> loadVulkanLibrary() {
static const std::array<const char*, 2> 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<uintptr_t>(proc)));
return std::make_pair(library, reinterpret_cast<PFN_vkGetInstanceProcAddr>(proc));
}

Logger::err("Vulkan: vkGetInstanceProcAddr not found");
return { };
}

LibraryLoader::LibraryLoader()
: m_library(loadVulkanLibrary())
, m_getInstanceProcAddr(reinterpret_cast<PFN_vkGetInstanceProcAddr>(
GetProcAddress(m_library, "vkGetInstanceProcAddr"))) {
LibraryLoader::LibraryLoader() {
std::tie(m_library, m_getInstanceProcAddr) = loadVulkanLibrary();
}

LibraryLoader::~LibraryLoader() {
Expand Down
4 changes: 2 additions & 2 deletions src/vulkan/vulkan_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};


Expand Down

0 comments on commit 4d0d455

Please sign in to comment.