wine/dlls/winex11.drv/vulkan.c

134 lines
4.4 KiB
C

/* X11DRV Vulkan implementation
*
* Copyright 2017 Roderick Colenbrander
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
/* NOTE: If making changes here, consider whether they should be reflected in
* the other drivers. */
#if 0
#pragma makedep unix
#endif
#include "config.h"
#include <stdarg.h>
#include <stdio.h>
#include <dlfcn.h>
#include "ntstatus.h"
#define WIN32_NO_STATUS
#include "windef.h"
#include "winbase.h"
#include "wine/debug.h"
#include "x11drv.h"
#include "xcomposite.h"
#include "wine/vulkan.h"
#include "wine/vulkan_driver.h"
WINE_DEFAULT_DEBUG_CHANNEL(vulkan);
#ifdef SONAME_LIBVULKAN
#define VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR 1000004000
typedef struct VkXlibSurfaceCreateInfoKHR
{
VkStructureType sType;
const void *pNext;
VkXlibSurfaceCreateFlagsKHR flags;
Display *dpy;
Window window;
} VkXlibSurfaceCreateInfoKHR;
static VkResult (*pvkCreateXlibSurfaceKHR)(VkInstance, const VkXlibSurfaceCreateInfoKHR *, const VkAllocationCallbacks *, VkSurfaceKHR *);
static VkBool32 (*pvkGetPhysicalDeviceXlibPresentationSupportKHR)(VkPhysicalDevice, uint32_t, Display *, VisualID);
static const struct vulkan_driver_funcs x11drv_vulkan_driver_funcs;
static VkResult X11DRV_vulkan_surface_create( HWND hwnd, const struct vulkan_instance *instance, VkSurfaceKHR *handle,
struct client_surface **client )
{
VkXlibSurfaceCreateInfoKHR info =
{
.sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR,
.dpy = gdi_display,
};
TRACE( "%p %p %p %p\n", hwnd, instance, handle, client );
if (!(info.window = x11drv_client_surface_create( hwnd, &default_visual, default_colormap, client ))) return VK_ERROR_OUT_OF_HOST_MEMORY;
if (pvkCreateXlibSurfaceKHR( instance->host.instance, &info, NULL /* allocator */, handle ))
{
ERR("Failed to create Xlib surface\n");
client_surface_release( *client );
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
TRACE( "Created surface 0x%s, client %s\n", wine_dbgstr_longlong( *handle ), debugstr_client_surface( *client ) );
return VK_SUCCESS;
}
static VkBool32 X11DRV_vkGetPhysicalDeviceWin32PresentationSupportKHR(VkPhysicalDevice phys_dev,
uint32_t index)
{
TRACE("%p %u\n", phys_dev, index);
return pvkGetPhysicalDeviceXlibPresentationSupportKHR(phys_dev, index, gdi_display,
default_visual.visual->visualid);
}
static const char *X11DRV_get_host_surface_extension(void)
{
return "VK_KHR_xlib_surface";
}
static const struct vulkan_driver_funcs x11drv_vulkan_driver_funcs =
{
.p_vulkan_surface_create = X11DRV_vulkan_surface_create,
.p_vkGetPhysicalDeviceWin32PresentationSupportKHR = X11DRV_vkGetPhysicalDeviceWin32PresentationSupportKHR,
.p_get_host_surface_extension = X11DRV_get_host_surface_extension,
};
UINT X11DRV_VulkanInit( UINT version, void *vulkan_handle, const struct vulkan_driver_funcs **driver_funcs )
{
if (version != WINE_VULKAN_DRIVER_VERSION)
{
ERR( "version mismatch, win32u wants %u but driver has %u\n", version, WINE_VULKAN_DRIVER_VERSION );
return STATUS_INVALID_PARAMETER;
}
#define LOAD_FUNCPTR( f ) if (!(p##f = dlsym( vulkan_handle, #f ))) return STATUS_PROCEDURE_NOT_FOUND;
LOAD_FUNCPTR( vkCreateXlibSurfaceKHR );
LOAD_FUNCPTR( vkGetPhysicalDeviceXlibPresentationSupportKHR );
#undef LOAD_FUNCPTR
*driver_funcs = &x11drv_vulkan_driver_funcs;
return STATUS_SUCCESS;
}
#else /* No vulkan */
UINT X11DRV_VulkanInit( UINT version, void *vulkan_handle, const struct vulkan_driver_funcs **driver_funcs )
{
ERR( "Wine was built without Vulkan support.\n" );
return STATUS_NOT_IMPLEMENTED;
}
#endif /* SONAME_LIBVULKAN */