winevulkan: Wrap VkSurfaceKHR in winevulkan.

Signed-off-by: Georg Lehmann <dadschoorse@gmail.com>
Signed-off-by: Liam Middlebrook <lmiddlebrook@nvidia.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Georg Lehmann 2021-01-22 18:31:56 +01:00 committed by Alexandre Julliard
parent d22bafa763
commit d9c9b5ea61
8 changed files with 126 additions and 20 deletions

View file

@ -99,7 +99,7 @@ static void *macdrv_get_vk_instance_proc_addr(VkInstance instance, const char *n
static inline struct wine_vk_surface *surface_from_handle(VkSurfaceKHR handle)
{
return (struct wine_vk_surface *)(uintptr_t)handle;
return vulkan_driver_get_surface_data(handle);
}
static void *vulkan_handle;
@ -320,7 +320,7 @@ static VkResult macdrv_vkCreateWin32SurfaceKHR(VkInstance instance,
goto err;
}
*surface = (uintptr_t)mac_surface;
vulkan_driver_init_surface(*surface, mac_surface->surface, mac_surface);
release_win_data(data);

View file

@ -131,7 +131,7 @@ CORE_EXTENSIONS = [
# Functions part of our winevulkan graphics driver interface.
# DRIVER_VERSION should be bumped on any change to driver interface
# in FUNCTION_OVERRIDES
DRIVER_VERSION = 8
DRIVER_VERSION = 9
# Table of functions for which we have a special implementation.
# These are regular device / instance functions for which we need
@ -174,7 +174,7 @@ FUNCTION_OVERRIDES = {
"vkQueueSubmit" : {"dispatch": True, "driver" : False, "thunk" : False},
# VK_KHR_surface
"vkDestroySurfaceKHR" : {"dispatch" : True, "driver" : True, "thunk" : True},
"vkDestroySurfaceKHR" : {"dispatch" : True, "driver" : True, "thunk" : False},
"vkGetPhysicalDeviceSurfaceSupportKHR" : {"dispatch" : True, "driver" : True, "thunk" : True},
"vkGetPhysicalDeviceSurfaceCapabilitiesKHR" : {"dispatch" : True, "driver" : True, "thunk" : False, "private_thunk" : True},
"vkGetPhysicalDeviceSurfaceFormatsKHR" : {"dispatch" : True, "driver" : True, "thunk" : True},
@ -185,7 +185,7 @@ FUNCTION_OVERRIDES = {
"vkGetPhysicalDeviceSurfaceFormats2KHR" : {"dispatch" : True, "driver" : True, "thunk" : True},
# VK_KHR_win32_surface
"vkCreateWin32SurfaceKHR" : {"dispatch" : True, "driver" : True, "thunk" : True},
"vkCreateWin32SurfaceKHR" : {"dispatch" : True, "driver" : True, "thunk" : False},
"vkGetPhysicalDeviceWin32PresentationSupportKHR" : {"dispatch" : True, "driver" : True, "thunk" : True},
# VK_KHR_swapchain
@ -2584,6 +2584,32 @@ class VkGenerator(object):
f.write(" name -= 2;\n\n")
f.write(" return get_vulkan_driver_device_proc_addr(vulkan_funcs, name);\n}\n\n")
f.write("struct wine_surface_base\n")
f.write("{\n")
f.write(" VkSurfaceKHR surface; /* native surface */\n")
f.write(" void *driver_data;\n")
f.write("};\n\n")
f.write("static inline void vulkan_driver_init_surface(\n")
f.write(" VkSurfaceKHR surface, VkSurfaceKHR native_surface, void *data)\n")
f.write("{\n")
f.write(" struct wine_surface_base *object = (void *)(uintptr_t)surface;\n")
f.write(" object->surface = native_surface;\n")
f.write(" object->driver_data = data;\n")
f.write("};\n\n")
f.write("static inline VkSurfaceKHR vulkan_driver_get_native_surface(VkSurfaceKHR surface)\n")
f.write("{\n")
f.write(" struct wine_surface_base *object = (void *)(uintptr_t)surface;\n")
f.write(" return object->surface;\n")
f.write("};\n\n")
f.write("static inline void *vulkan_driver_get_surface_data(VkSurfaceKHR surface)\n")
f.write("{\n")
f.write(" struct wine_surface_base *object = (void *)(uintptr_t)surface;\n")
f.write(" return object->driver_data;\n")
f.write("};\n\n")
f.write("#endif /* __WINE_VULKAN_DRIVER_H */\n")
def generate_vulkan_spec(self, f):

View file

@ -1770,6 +1770,53 @@ void WINAPI wine_vkGetPrivateDataEXT(VkDevice device, VkObjectType object_type,
device->funcs.p_vkGetPrivateDataEXT(device->device, object_type, object_handle, private_data_slot, data);
}
VkResult WINAPI wine_vkCreateWin32SurfaceKHR(VkInstance instance,
const VkWin32SurfaceCreateInfoKHR *createInfo, const VkAllocationCallbacks *allocator, VkSurfaceKHR *surface)
{
struct wine_surface *object;
VkResult res;
TRACE("%p, %p, %p, %p\n", instance, createInfo, allocator, surface);
if (allocator)
FIXME("Support for allocation callbacks not implemented yet\n");
object = heap_alloc_zero(sizeof(*object));
if (!object)
return VK_ERROR_OUT_OF_HOST_MEMORY;
*surface = wine_surface_to_handle(object);
res = instance->funcs.p_vkCreateWin32SurfaceKHR(instance->instance, createInfo, NULL, surface);
if (res != VK_SUCCESS)
{
heap_free(object);
*surface = VK_NULL_HANDLE;
return res;
}
WINE_VK_ADD_NON_DISPATCHABLE_MAPPING(instance, object, object->base.surface);
return VK_SUCCESS;
}
void WINAPI wine_vkDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface, const VkAllocationCallbacks *allocator)
{
struct wine_surface *object = wine_surface_from_handle(surface);
TRACE("%p, 0x%s, %p\n", instance, wine_dbgstr_longlong(surface), allocator);
if (!object)
return;
instance->funcs.p_vkDestroySurfaceKHR(instance->instance, surface, NULL);
WINE_VK_REMOVE_HANDLE_MAPPING(instance, object);
heap_free(object);
}
static inline void adjust_max_image_count(VkPhysicalDevice phys_dev, VkSurfaceCapabilitiesKHR* capabilities)
{
/* Many Windows games, for example Strange Brigade, No Man's Sky, Path of Exile

View file

@ -213,6 +213,23 @@ static inline VkDebugReportCallbackEXT wine_debug_report_callback_to_handle(
return (VkDebugReportCallbackEXT)(uintptr_t)debug_messenger;
}
struct wine_surface
{
struct wine_surface_base base;
struct wine_vk_mapping mapping;
};
static inline struct wine_surface *wine_surface_from_handle(VkSurfaceKHR handle)
{
return (struct wine_surface *)(uintptr_t)handle;
}
static inline VkSurfaceKHR wine_surface_to_handle(struct wine_surface *surface)
{
return (VkSurfaceKHR)(uintptr_t)surface;
}
void *wine_vk_get_device_proc_addr(const char *name) DECLSPEC_HIDDEN;
void *wine_vk_get_instance_proc_addr(const char *name) DECLSPEC_HIDDEN;

View file

@ -5196,12 +5196,6 @@ static VkResult WINAPI wine_vkCreateValidationCacheEXT(VkDevice device, const Vk
return device->funcs.p_vkCreateValidationCacheEXT(device->device, pCreateInfo, NULL, pValidationCache);
}
VkResult WINAPI wine_vkCreateWin32SurfaceKHR(VkInstance instance, const VkWin32SurfaceCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface)
{
TRACE("%p, %p, %p, %p\n", instance, pCreateInfo, pAllocator, pSurface);
return instance->funcs.p_vkCreateWin32SurfaceKHR(instance->instance, pCreateInfo, NULL, pSurface);
}
VkResult thunk_vkDebugMarkerSetObjectNameEXT(VkDevice device, const VkDebugMarkerObjectNameInfoEXT *pNameInfo)
{
#if defined(USE_STRUCT_CONVERSION)
@ -5392,12 +5386,6 @@ void WINAPI wine_vkDestroyShaderModule(VkDevice device, VkShaderModule shaderMod
device->funcs.p_vkDestroyShaderModule(device->device, shaderModule, NULL);
}
void WINAPI wine_vkDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface, const VkAllocationCallbacks *pAllocator)
{
TRACE("%p, 0x%s, %p\n", instance, wine_dbgstr_longlong(surface), pAllocator);
instance->funcs.p_vkDestroySurfaceKHR(instance->instance, surface, NULL);
}
void WINAPI wine_vkDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapchain, const VkAllocationCallbacks *pAllocator)
{
TRACE("%p, 0x%s, %p\n", device, wine_dbgstr_longlong(swapchain), pAllocator);

View file

@ -21,6 +21,7 @@ VkResult WINAPI wine_vkCreateCommandPool(VkDevice device, const VkCommandPoolCre
VkResult WINAPI wine_vkCreateDebugReportCallbackEXT(VkInstance instance, const VkDebugReportCallbackCreateInfoEXT *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkDebugReportCallbackEXT *pCallback) DECLSPEC_HIDDEN;
VkResult WINAPI wine_vkCreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkDebugUtilsMessengerEXT *pMessenger) DECLSPEC_HIDDEN;
VkResult WINAPI wine_vkCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkDevice *pDevice);
VkResult WINAPI wine_vkCreateWin32SurfaceKHR(VkInstance instance, const VkWin32SurfaceCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface);
VkResult WINAPI wine_vkDebugMarkerSetObjectNameEXT(VkDevice device, const VkDebugMarkerObjectNameInfoEXT *pNameInfo) DECLSPEC_HIDDEN;
VkResult WINAPI wine_vkDebugMarkerSetObjectTagEXT(VkDevice device, const VkDebugMarkerObjectTagInfoEXT *pTagInfo) DECLSPEC_HIDDEN;
void WINAPI wine_vkDebugReportMessageEXT(VkInstance instance, VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objectType, uint64_t object, size_t location, int32_t messageCode, const char *pLayerPrefix, const char *pMessage) DECLSPEC_HIDDEN;
@ -29,6 +30,7 @@ void WINAPI wine_vkDestroyDebugReportCallbackEXT(VkInstance instance, VkDebugRep
void WINAPI wine_vkDestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT messenger, const VkAllocationCallbacks *pAllocator) DECLSPEC_HIDDEN;
void WINAPI wine_vkDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator);
void WINAPI wine_vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator);
void WINAPI wine_vkDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface, const VkAllocationCallbacks *pAllocator);
VkResult WINAPI wine_vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char *pLayerName, uint32_t *pPropertyCount, VkExtensionProperties *pProperties);
VkResult WINAPI wine_vkEnumeratePhysicalDeviceGroups(VkInstance instance, uint32_t *pPhysicalDeviceGroupCount, VkPhysicalDeviceGroupProperties *pPhysicalDeviceGroupProperties);
VkResult WINAPI wine_vkEnumeratePhysicalDeviceGroupsKHR(VkInstance instance, uint32_t *pPhysicalDeviceGroupCount, VkPhysicalDeviceGroupProperties *pPhysicalDeviceGroupProperties) DECLSPEC_HIDDEN;

View file

@ -99,7 +99,7 @@ static void *X11DRV_get_vk_instance_proc_addr(VkInstance instance, const char *n
static inline struct wine_vk_surface *surface_from_handle(VkSurfaceKHR handle)
{
return (struct wine_vk_surface *)(uintptr_t)handle;
return vulkan_driver_get_surface_data(handle);
}
static void *vulkan_handle;
@ -324,7 +324,7 @@ static VkResult X11DRV_vkCreateWin32SurfaceKHR(VkInstance instance,
XSaveContext(gdi_display, (XID)create_info->hwnd, vulkan_hwnd_context, (char *)wine_vk_surface_grab(x11_surface));
LeaveCriticalSection(&context_section);
*surface = (uintptr_t)x11_surface;
vulkan_driver_init_surface(*surface, x11_surface->surface, x11_surface);
TRACE("Created surface=0x%s\n", wine_dbgstr_longlong(*surface));
return VK_SUCCESS;

View file

@ -13,7 +13,7 @@
#define __WINE_VULKAN_DRIVER_H
/* Wine internal vulkan driver version, needs to be bumped upon vulkan_funcs changes. */
#define WINE_VULKAN_DRIVER_VERSION 8
#define WINE_VULKAN_DRIVER_VERSION 9
struct vulkan_funcs
{
@ -112,4 +112,30 @@ static inline void *get_vulkan_driver_instance_proc_addr(
return get_vulkan_driver_device_proc_addr(vulkan_funcs, name);
}
struct wine_surface_base
{
VkSurfaceKHR surface; /* native surface */
void *driver_data;
};
static inline void vulkan_driver_init_surface(
VkSurfaceKHR surface, VkSurfaceKHR native_surface, void *data)
{
struct wine_surface_base *object = (void *)(uintptr_t)surface;
object->surface = native_surface;
object->driver_data = data;
};
static inline VkSurfaceKHR vulkan_driver_get_native_surface(VkSurfaceKHR surface)
{
struct wine_surface_base *object = (void *)(uintptr_t)surface;
return object->surface;
};
static inline void *vulkan_driver_get_surface_data(VkSurfaceKHR surface)
{
struct wine_surface_base *object = (void *)(uintptr_t)surface;
return object->driver_data;
};
#endif /* __WINE_VULKAN_DRIVER_H */