mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-04-13 05:43:18 -07:00
libs/vkd3d: Load libvulkan dynamically.
Signed-off-by: Józef Kucia <jkucia@codeweavers.com> Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
committed by
Alexandre Julliard
parent
fcc6846559
commit
10b04414e8
@@ -18,6 +18,8 @@
|
||||
|
||||
#include "vkd3d_private.h"
|
||||
|
||||
#include <dlfcn.h>
|
||||
|
||||
struct vkd3d_optional_extension_info
|
||||
{
|
||||
const char *extension_name;
|
||||
@@ -176,16 +178,34 @@ static bool vkd3d_init_vk_global_procs(struct vkd3d_instance *instance,
|
||||
{
|
||||
struct vkd3d_vulkan_procs_info *procs = &instance->vk_global_procs;
|
||||
|
||||
instance->libvulkan = NULL;
|
||||
|
||||
if (vulkan_procs_info)
|
||||
{
|
||||
*procs = *vulkan_procs_info;
|
||||
return true;
|
||||
}
|
||||
|
||||
procs->vkCreateInstance = vkCreateInstance;
|
||||
procs->vkDestroyInstance = vkDestroyInstance;
|
||||
procs->vkGetInstanceProcAddr = vkGetInstanceProcAddr;
|
||||
procs->vkEnumerateInstanceExtensionProperties = vkEnumerateInstanceExtensionProperties;
|
||||
if (!(instance->libvulkan = dlopen("libvulkan.so.1", RTLD_NOW)))
|
||||
{
|
||||
ERR("Failed to load libvulkan.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
#define LOAD_PROC(name) \
|
||||
if (!(procs->name = dlsym(instance->libvulkan, #name))) \
|
||||
{ \
|
||||
ERR("Could not get proc addr for '" #name "'.\n"); \
|
||||
dlclose(instance->libvulkan); \
|
||||
instance->libvulkan = NULL; \
|
||||
return false; \
|
||||
}
|
||||
LOAD_PROC(vkCreateInstance)
|
||||
LOAD_PROC(vkDestroyInstance)
|
||||
LOAD_PROC(vkGetInstanceProcAddr)
|
||||
LOAD_PROC(vkEnumerateInstanceExtensionProperties)
|
||||
#undef LOAD_PROC
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -248,6 +268,8 @@ static HRESULT vkd3d_instance_init(struct vkd3d_instance *instance,
|
||||
if ((vr = vk_global_procs->vkCreateInstance(&instance_info, NULL, &vk_instance)))
|
||||
{
|
||||
ERR("Failed to create Vulkan instance, vr %d.\n", vr);
|
||||
if (instance->libvulkan)
|
||||
dlclose(instance->libvulkan);
|
||||
return hresult_from_vk_result(vr);
|
||||
}
|
||||
|
||||
@@ -255,6 +277,8 @@ static HRESULT vkd3d_instance_init(struct vkd3d_instance *instance,
|
||||
{
|
||||
ERR("Failed to load instance procs, hr %#x.\n", hr);
|
||||
vk_global_procs->vkDestroyInstance(vk_instance, NULL);
|
||||
if (instance->libvulkan)
|
||||
dlclose(instance->libvulkan);
|
||||
return hr;
|
||||
}
|
||||
|
||||
@@ -310,6 +334,8 @@ ULONG vkd3d_instance_decref(struct vkd3d_instance *instance)
|
||||
{
|
||||
const struct vkd3d_vk_instance_procs *vk_procs = &instance->vk_procs;
|
||||
VK_CALL(vkDestroyInstance(instance->vk_instance, NULL));
|
||||
if (instance->libvulkan)
|
||||
dlclose(instance->libvulkan);
|
||||
vkd3d_free(instance);
|
||||
}
|
||||
|
||||
|
@@ -88,6 +88,7 @@ struct vkd3d_instance
|
||||
|
||||
struct vkd3d_vulkan_info vk_info;
|
||||
struct vkd3d_vulkan_procs_info vk_global_procs;
|
||||
void *libvulkan;
|
||||
|
||||
LONG refcount;
|
||||
};
|
||||
@@ -752,13 +753,4 @@ HRESULT vkd3d_load_vk_instance_procs(struct vkd3d_vk_instance_procs *procs,
|
||||
HRESULT vkd3d_load_vk_device_procs(struct vkd3d_vk_device_procs *procs,
|
||||
const struct vkd3d_vk_instance_procs *parent_procs, VkDevice device) DECLSPEC_HIDDEN;
|
||||
|
||||
/* We link directly to the loader library and use the following exported functions. */
|
||||
VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance,
|
||||
const char *name);
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo *create_info,
|
||||
const VkAllocationCallbacks *allocator, VkInstance *instance);
|
||||
VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *layer_name,
|
||||
uint32_t *property_count, VkExtensionProperties *properties);
|
||||
VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks *allocator);
|
||||
|
||||
#endif /* __VKD3D_PRIVATE_H */
|
||||
|
Reference in New Issue
Block a user