1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-13 16:08:50 +01:00
dxvk/src/vulkan/vulkan_loader.cpp
Joshua Ashton 482a7e433b [vulkan] Make LibraryLoader dynamically load vulkan-1
This makes LibraryLoader actually load the library and moves ownership
of GetInstanceProcAddr into it, which means we pass through the
loaders into their parents to grab stuff.
2022-08-27 19:32:03 +02:00

66 lines
1.8 KiB
C++

#include "vulkan_loader.h"
#include "../util/util_win32_compat.h"
namespace dxvk::vk {
LibraryLoader::LibraryLoader()
: m_library(LoadLibraryA("vulkan-1"))
, m_getInstanceProcAddr(reinterpret_cast<PFN_vkGetInstanceProcAddr>(
GetProcAddress(m_library, "vkGetInstanceProcAddr"))) {
}
LibraryLoader::~LibraryLoader() {
FreeLibrary(m_library);
}
PFN_vkVoidFunction LibraryLoader::sym(VkInstance instance, const char* name) const {
return m_getInstanceProcAddr(instance, name);
}
PFN_vkVoidFunction LibraryLoader::sym(const char* name) const {
return sym(nullptr, name);
}
InstanceLoader::InstanceLoader(const Rc<LibraryLoader>& library, bool owned, VkInstance instance)
: m_library(library), m_instance(instance), m_owned(owned) { }
PFN_vkVoidFunction InstanceLoader::sym(const char* name) const {
return m_library->sym(m_instance, name);
}
DeviceLoader::DeviceLoader(const Rc<InstanceLoader>& library, bool owned, VkDevice device)
: m_library(library)
, m_getDeviceProcAddr(reinterpret_cast<PFN_vkGetDeviceProcAddr>(
m_library->sym("vkGetDeviceProcAddr"))),
m_device(device), m_owned(owned) { }
PFN_vkVoidFunction DeviceLoader::sym(const char* name) const {
return m_getDeviceProcAddr(m_device, name);
}
LibraryFn::LibraryFn() { }
LibraryFn::~LibraryFn() { }
InstanceFn::InstanceFn(const Rc<LibraryLoader>& library, bool owned, VkInstance instance)
: InstanceLoader(library, owned, instance) { }
InstanceFn::~InstanceFn() {
if (m_owned)
this->vkDestroyInstance(m_instance, nullptr);
}
DeviceFn::DeviceFn(const Rc<InstanceLoader>& library, bool owned, VkDevice device)
: DeviceLoader(library, owned, device) { }
DeviceFn::~DeviceFn() {
if (m_owned)
this->vkDestroyDevice(m_device, nullptr);
}
}