Commit bd0d8826 authored by Alexandros Frantzis's avatar Alexandros Frantzis Committed by Alexandre Julliard

winewayland.drv: Implement vkCreateInstance.

Create a Vulkan instance, ensuring we use the proper (Wayland) SurfaceKHR extension when forwarding the request to the native Vulkan platform.
parent a9ed32b0
......@@ -25,6 +25,7 @@
#include "config.h"
#include <dlfcn.h>
#include <stdlib.h>
#include "waylanddrv.h"
#include "wine/debug.h"
......@@ -39,10 +40,82 @@ WINE_DEFAULT_DEBUG_CHANNEL(vulkan);
#ifdef SONAME_LIBVULKAN
static VkResult (*pvkCreateInstance)(const VkInstanceCreateInfo *, const VkAllocationCallbacks *, VkInstance *);
static VkResult (*pvkEnumerateInstanceExtensionProperties)(const char *, uint32_t *, VkExtensionProperties *);
static void *vulkan_handle;
/* Helper function for converting between win32 and Wayland compatible VkInstanceCreateInfo.
* Caller is responsible for allocation and cleanup of 'dst'. */
static VkResult wine_vk_instance_convert_create_info(const VkInstanceCreateInfo *src,
VkInstanceCreateInfo *dst)
{
unsigned int i;
const char **enabled_extensions = NULL;
dst->sType = src->sType;
dst->flags = src->flags;
dst->pApplicationInfo = src->pApplicationInfo;
dst->pNext = src->pNext;
dst->enabledLayerCount = 0;
dst->ppEnabledLayerNames = NULL;
dst->enabledExtensionCount = 0;
dst->ppEnabledExtensionNames = NULL;
if (src->enabledExtensionCount > 0)
{
enabled_extensions = calloc(src->enabledExtensionCount,
sizeof(*src->ppEnabledExtensionNames));
if (!enabled_extensions)
{
ERR("Failed to allocate memory for enabled extensions\n");
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
for (i = 0; i < src->enabledExtensionCount; i++)
{
/* Substitute extension with Wayland ones else copy. Long-term, when we
* support more extensions, we should store these in a list. */
if (!strcmp(src->ppEnabledExtensionNames[i], "VK_KHR_win32_surface"))
enabled_extensions[i] = "VK_KHR_wayland_surface";
else
enabled_extensions[i] = src->ppEnabledExtensionNames[i];
}
dst->ppEnabledExtensionNames = enabled_extensions;
dst->enabledExtensionCount = src->enabledExtensionCount;
}
return VK_SUCCESS;
}
static VkResult wayland_vkCreateInstance(const VkInstanceCreateInfo *create_info,
const VkAllocationCallbacks *allocator,
VkInstance *instance)
{
VkInstanceCreateInfo create_info_host;
VkResult res;
TRACE("create_info %p, allocator %p, instance %p\n", create_info, allocator, instance);
if (allocator)
FIXME("Support for allocation callbacks not implemented yet\n");
/* Perform a second pass on converting VkInstanceCreateInfo. Winevulkan
* performed a first pass in which it handles everything except for WSI
* functionality such as VK_KHR_win32_surface. Handle this now. */
res = wine_vk_instance_convert_create_info(create_info, &create_info_host);
if (res != VK_SUCCESS)
{
ERR("Failed to convert instance create info, res=%d\n", res);
return res;
}
res = pvkCreateInstance(&create_info_host, NULL /* allocator */, instance);
free((void *)create_info_host.ppEnabledExtensionNames);
return res;
}
static VkResult wayland_vkEnumerateInstanceExtensionProperties(const char *layer_name,
uint32_t *count,
VkExtensionProperties* properties)
......@@ -94,6 +167,7 @@ static void wine_vk_init(void)
}
#define LOAD_FUNCPTR(f) if (!(p##f = dlsym(vulkan_handle, #f))) goto fail
LOAD_FUNCPTR(vkCreateInstance);
LOAD_FUNCPTR(vkEnumerateInstanceExtensionProperties);
#undef LOAD_FUNCPTR
......@@ -106,6 +180,7 @@ fail:
static const struct vulkan_funcs vulkan_funcs =
{
.p_vkCreateInstance = wayland_vkCreateInstance,
.p_vkEnumerateInstanceExtensionProperties = wayland_vkEnumerateInstanceExtensionProperties,
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment