Signed-off-by: Józef Kucia jkucia@codeweavers.com --- dlls/wined3d/adapter_vk.c | 58 ++++++++++++++++++++++++++++++++++----- dlls/wined3d/wined3d_vk.h | 6 ++++ 2 files changed, 57 insertions(+), 7 deletions(-)
diff --git a/dlls/wined3d/adapter_vk.c b/dlls/wined3d/adapter_vk.c index e63e89361b0b..bb465b68135a 100644 --- a/dlls/wined3d/adapter_vk.c +++ b/dlls/wined3d/adapter_vk.c @@ -59,13 +59,37 @@ static const struct wined3d_adapter_ops wined3d_adapter_vk_ops = adapter_vk_check_format, };
-static BOOL wined3d_init_vulkan(struct wined3d_vk_info *vk_info) +#ifdef USE_WIN32_VULKAN +static BOOL wined3d_load_vulkan(struct wined3d_vk_info *vk_info) +{ + struct vulkan_ops *vk_ops = &vk_info->vk_ops; + + if (!(vk_info->vulkan_lib = LoadLibraryA("vulkan-1.dll"))) + { + WARN("Failed to load vulkan-1.dll.\n"); + return FALSE; + } + + vk_ops->vkGetInstanceProcAddr = (void *)GetProcAddress(vk_info->vulkan_lib, "vkGetInstanceProcAddr"); + if (!vk_ops->vkGetInstanceProcAddr) + { + FreeLibrary(vk_info->vulkan_lib); + return FALSE; + } + + return TRUE; +} + +static void wined3d_unload_vulkan(struct wined3d_vk_info *vk_info) +{ + FreeLibrary(vk_info->vulkan_lib); + vk_info->vulkan_lib = NULL; +} +#else +static BOOL wined3d_load_vulkan(struct wined3d_vk_info *vk_info) { struct vulkan_ops *vk_ops = &vk_info->vk_ops; const struct vulkan_funcs *vk_funcs; - VkInstanceCreateInfo instance_info; - VkInstance instance; - VkResult vr; HDC dc;
dc = GetDC(0); @@ -76,11 +100,26 @@ static BOOL wined3d_init_vulkan(struct wined3d_vk_info *vk_info) return FALSE;
vk_ops->vkGetInstanceProcAddr = (void *)vk_funcs->p_vkGetInstanceProcAddr; + return TRUE; +} + +static void wined3d_unload_vulkan(struct wined3d_vk_info *vk_info) {} +#endif + +static BOOL wined3d_init_vulkan(struct wined3d_vk_info *vk_info) +{ + struct vulkan_ops *vk_ops = &vk_info->vk_ops; + VkInstanceCreateInfo instance_info; + VkInstance instance; + VkResult vr; + + if (!wined3d_load_vulkan(vk_info)) + return FALSE;
if (!(vk_ops->vkCreateInstance = (void *)VK_CALL(vkGetInstanceProcAddr(NULL, "vkCreateInstance")))) { ERR("Could not get 'vkCreateInstance'.\n"); - return FALSE; + goto fail; }
memset(&instance_info, 0, sizeof(instance_info)); @@ -97,8 +136,9 @@ static BOOL wined3d_init_vulkan(struct wined3d_vk_info *vk_info) if (!(vk_ops->name = (void *)VK_CALL(vkGetInstanceProcAddr(instance, #name)))) \ { \ WARN("Could not get instance proc addr for '" #name "'.\n"); \ - vk_funcs->p_vkDestroyInstance(instance, NULL); \ - return FALSE; \ + if (vk_ops->vkDestroyInstance) \ + VK_CALL(vkDestroyInstance(instance, NULL)); \ + goto fail; \ } #define VK_INSTANCE_PFN LOAD_INSTANCE_PFN #define VK_DEVICE_PFN LOAD_INSTANCE_PFN @@ -110,6 +150,10 @@ static BOOL wined3d_init_vulkan(struct wined3d_vk_info *vk_info) vk_info->instance = instance;
return TRUE; + +fail: + wined3d_unload_vulkan(vk_info); + return FALSE; }
static BOOL wined3d_adapter_vk_init(struct wined3d_adapter_vk *adapter_vk, diff --git a/dlls/wined3d/wined3d_vk.h b/dlls/wined3d/wined3d_vk.h index ac59a2dcd1ab..784dd0c310c5 100644 --- a/dlls/wined3d/wined3d_vk.h +++ b/dlls/wined3d/wined3d_vk.h @@ -20,7 +20,9 @@ #define __WINE_WINED3D_VK_H
#define VK_NO_PROTOTYPES +#ifndef USE_WIN32_VULKAN #define WINE_VK_HOST +#endif #include "wine/vulkan.h"
#define VK_INSTANCE_FUNCS() \ @@ -179,6 +181,10 @@ struct wined3d_vk_info { VkInstance instance; struct vulkan_ops vk_ops; + +#ifdef USE_WIN32_VULKAN + HMODULE vulkan_lib; +#endif };
#define VK_CALL(f) (vk_info->vk_ops.f)