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

winewayland.drv: Detect and report vkQueuePresentKHR errors.

If the VkSwapchainKHR extent does not match the target window client area, report VK_ERROR_OUT_OF_DATE_KHR, to notify the app that it should recreate the swapchain. We also report VK_ERROR_OUT_OF_DATE_KHR if the HWND is no longer valid, to match win32 behavior (e.g., nvidia). The application will eventually get VK_ERROR_SURFACE_LOST_KHR during the swapchain recreation process.
parent 8a4e2546
......@@ -73,12 +73,23 @@ static VkResult (*pvkQueuePresentKHR)(VkQueue, const VkPresentInfoKHR *);
static void *vulkan_handle;
static const struct vulkan_funcs vulkan_funcs;
static pthread_mutex_t wine_vk_swapchain_mutex = PTHREAD_MUTEX_INITIALIZER;
static struct list wine_vk_swapchain_list = LIST_INIT(wine_vk_swapchain_list);
struct wine_vk_surface
{
struct wayland_client_surface *client;
VkSurfaceKHR native;
};
struct wine_vk_swapchain
{
struct list entry;
VkSwapchainKHR native;
HWND hwnd;
VkExtent2D extent;
};
static struct wine_vk_surface *wine_vk_surface_from_handle(VkSurfaceKHR handle)
{
return (struct wine_vk_surface *)(uintptr_t)handle;
......@@ -122,6 +133,25 @@ static BOOL wine_vk_surface_is_valid(struct wine_vk_surface *wine_vk_surface)
return FALSE;
}
static struct wine_vk_swapchain *wine_vk_swapchain_from_handle(VkSwapchainKHR handle)
{
struct wine_vk_swapchain *wine_vk_swapchain;
pthread_mutex_lock(&wine_vk_swapchain_mutex);
LIST_FOR_EACH_ENTRY(wine_vk_swapchain, &wine_vk_swapchain_list,
struct wine_vk_swapchain, entry)
{
if (wine_vk_swapchain->native == handle)
{
pthread_mutex_unlock(&wine_vk_swapchain_mutex);
return wine_vk_swapchain;
}
}
pthread_mutex_unlock(&wine_vk_swapchain_mutex);
return NULL;
}
/* 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,
......@@ -206,6 +236,58 @@ static VkResult wine_vk_surface_update_caps(struct wine_vk_surface *wine_vk_surf
return VK_SUCCESS;
}
static void vk_result_update_out_of_date(VkResult *res)
{
/* If the current result is less severe than out_of_date, which for
* now applies to all non-failure results, update it.
* TODO: Handle VK_ERROR_FULL_SCREEN_EXCLUSIVE_MODE_LOST_EXT when
* it is supported by winevulkan, since it's also considered
* less severe than out_of_date. */
if (*res >= 0) *res = VK_ERROR_OUT_OF_DATE_KHR;
}
static VkResult check_queue_present(const VkPresentInfoKHR *present_info,
VkResult present_res)
{
VkResult res = present_res;
uint32_t i;
for (i = 0; i < present_info->swapchainCount; ++i)
{
struct wine_vk_swapchain *wine_vk_swapchain =
wine_vk_swapchain_from_handle(present_info->pSwapchains[i]);
HWND hwnd = wine_vk_swapchain->hwnd;
struct wayland_surface *wayland_surface;
if ((wayland_surface = wayland_surface_lock_hwnd(hwnd)))
{
int client_width = wayland_surface->window.client_rect.right -
wayland_surface->window.client_rect.left;
int client_height = wayland_surface->window.client_rect.bottom -
wayland_surface->window.client_rect.top;
pthread_mutex_unlock(&wayland_surface->mutex);
if (client_width == wine_vk_swapchain->extent.width &&
client_height == wine_vk_swapchain->extent.height)
{
/* The window is still available and matches the swapchain size,
* so there is no new error to report. */
continue;
}
}
/* We use the out_of_date error even if the window is no longer
* available, to match win32 behavior (e.g., nvidia). The application
* will get surface_lost when it tries to recreate the swapchain. */
if (present_info->pResults)
vk_result_update_out_of_date(&present_info->pResults[i]);
vk_result_update_out_of_date(&res);
}
return res;
}
static VkResult wayland_vkCreateInstance(const VkInstanceCreateInfo *create_info,
const VkAllocationCallbacks *allocator,
VkInstance *instance)
......@@ -242,6 +324,7 @@ static VkResult wayland_vkCreateSwapchainKHR(VkDevice device,
VkResult res;
VkSwapchainCreateInfoKHR create_info_host;
struct wine_vk_surface *wine_vk_surface;
struct wine_vk_swapchain *wine_vk_swapchain;
TRACE("%p %p %p %p\n", device, create_info, allocator, swapchain);
......@@ -252,6 +335,13 @@ static VkResult wayland_vkCreateSwapchainKHR(VkDevice device,
if (!wine_vk_surface_is_valid(wine_vk_surface))
return VK_ERROR_SURFACE_LOST_KHR;
wine_vk_swapchain = calloc(1, sizeof(*wine_vk_swapchain));
if (!wine_vk_swapchain)
return VK_ERROR_OUT_OF_HOST_MEMORY;
wine_vk_swapchain->hwnd = wine_vk_surface_get_hwnd(wine_vk_surface);
wine_vk_swapchain->extent = create_info->imageExtent;
create_info_host = *create_info;
create_info_host.surface = wine_vk_surface->native;
......@@ -270,9 +360,16 @@ static VkResult wayland_vkCreateSwapchainKHR(VkDevice device,
if (res != VK_SUCCESS)
{
ERR("Failed to create vulkan wayland swapchain, res=%d\n", res);
free(wine_vk_swapchain);
return res;
}
wine_vk_swapchain->native = *swapchain;
pthread_mutex_lock(&wine_vk_swapchain_mutex);
list_add_head(&wine_vk_swapchain_list, &wine_vk_swapchain->entry);
pthread_mutex_unlock(&wine_vk_swapchain_mutex);
TRACE("Created swapchain=0x%s\n", wine_dbgstr_longlong(*swapchain));
return res;
}
......@@ -377,12 +474,22 @@ static void wayland_vkDestroySwapchainKHR(VkDevice device,
VkSwapchainKHR swapchain,
const VkAllocationCallbacks *allocator)
{
struct wine_vk_swapchain *wine_vk_swapchain;
TRACE("%p, 0x%s %p\n", device, wine_dbgstr_longlong(swapchain), allocator);
if (allocator)
FIXME("Support for allocation callbacks not implemented yet\n");
pvkDestroySwapchainKHR(device, swapchain, NULL /* allocator */);
if ((wine_vk_swapchain = wine_vk_swapchain_from_handle(swapchain)))
{
pthread_mutex_lock(&wine_vk_swapchain_mutex);
list_remove(&wine_vk_swapchain->entry);
pthread_mutex_unlock(&wine_vk_swapchain_mutex);
free(wine_vk_swapchain);
}
}
static VkResult wayland_vkEnumerateInstanceExtensionProperties(const char *layer_name,
......@@ -636,9 +743,13 @@ static VkResult wayland_vkGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR
static VkResult wayland_vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *present_info)
{
VkResult res;
TRACE("%p, %p\n", queue, present_info);
return pvkQueuePresentKHR(queue, present_info);
res = pvkQueuePresentKHR(queue, present_info);
return check_queue_present(present_info, res);
}
static VkSurfaceKHR wayland_wine_get_native_surface(VkSurfaceKHR surface)
......
......@@ -36,6 +36,7 @@
#include "winbase.h"
#include "ntgdi.h"
#include "wine/gdi_driver.h"
#include "wine/list.h"
#include "wine/rbtree.h"
#include "unixlib.h"
......
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