From 8ba1b27f23684b4c26e33e60bfdcd47c998a79f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Bernon?= Date: Sat, 25 Nov 2023 15:15:44 +0100 Subject: [PATCH] winevulkan: Handle creation of surfaces with no HWND directly. --- dlls/winevulkan/vulkan.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/dlls/winevulkan/vulkan.c b/dlls/winevulkan/vulkan.c index 9123e65da4c..5d9d9e452b8 100644 --- a/dlls/winevulkan/vulkan.c +++ b/dlls/winevulkan/vulkan.c @@ -1503,18 +1503,31 @@ VkResult wine_vkCreateWin32SurfaceKHR(VkInstance handle, const VkWin32SurfaceCre const VkAllocationCallbacks *allocator, VkSurfaceKHR *surface) { struct wine_instance *instance = wine_instance_from_handle(handle); + VkWin32SurfaceCreateInfoKHR create_info_host = *create_info; struct wine_surface *object; + HWND dummy = NULL; VkResult res; if (allocator) FIXME("Support for allocation callbacks not implemented yet\n"); if (!(object = calloc(1, sizeof(*object)))) return VK_ERROR_OUT_OF_HOST_MEMORY; - object->hwnd = create_info->hwnd; - res = instance->funcs.p_vkCreateWin32SurfaceKHR(instance->host_instance, create_info, + /* Windows allows surfaces to be created with no HWND, they return VK_ERROR_SURFACE_LOST_KHR later */ + if (!(object->hwnd = create_info->hwnd)) + { + static const WCHAR staticW[] = {'s','t','a','t','i','c',0}; + UNICODE_STRING static_us = RTL_CONSTANT_STRING(staticW); + dummy = NtUserCreateWindowEx(0, &static_us, &static_us, &static_us, WS_POPUP, + 0, 0, 0, 0, NULL, NULL, NULL, NULL, 0, NULL, 0, FALSE); + WARN("Created dummy window %p for null surface window\n", dummy); + create_info_host.hwnd = object->hwnd = dummy; + } + + res = instance->funcs.p_vkCreateWin32SurfaceKHR(instance->host_instance, &create_info_host, NULL /* allocator */, &object->driver_surface); if (res != VK_SUCCESS) { + if (dummy) NtUserDestroyWindow(dummy); free(object); return res; } @@ -1522,6 +1535,9 @@ VkResult wine_vkCreateWin32SurfaceKHR(VkInstance handle, const VkWin32SurfaceCre object->host_surface = vk_funcs->p_wine_get_host_surface(object->driver_surface); WINE_VK_ADD_NON_DISPATCHABLE_MAPPING(instance, object, object->host_surface, object); + *surface = wine_surface_to_handle(object); + if (dummy) NtUserDestroyWindow(dummy); + *surface = wine_surface_to_handle(object); return VK_SUCCESS;