From: Rémi Bernon rbernon@codeweavers.com
--- dlls/winevulkan/make_vulkan | 2 ++ dlls/winevulkan/vulkan.c | 47 +++++++++++++++++++++++++++++++++ dlls/winevulkan/vulkan_thunks.c | 31 +++++----------------- dlls/winevulkan/vulkan_thunks.h | 2 ++ 4 files changed, 58 insertions(+), 24 deletions(-)
diff --git a/dlls/winevulkan/make_vulkan b/dlls/winevulkan/make_vulkan index 7990336706e..7500d31d56a 100755 --- a/dlls/winevulkan/make_vulkan +++ b/dlls/winevulkan/make_vulkan @@ -208,6 +208,8 @@ USER_DRIVER_FUNCS = {
# functions for which the unix thunk is manually implemented MANUAL_UNIX_THUNKS = { + "vkAcquireNextImage2KHR", + "vkAcquireNextImageKHR", "vkAllocateCommandBuffers", "vkAllocateMemory", "vkCreateBuffer", diff --git a/dlls/winevulkan/vulkan.c b/dlls/winevulkan/vulkan.c index 5f513b96480..972de3cedaf 100644 --- a/dlls/winevulkan/vulkan.c +++ b/dlls/winevulkan/vulkan.c @@ -1630,6 +1630,53 @@ static BOOL extents_equals(const VkExtent2D *extents, const RECT *rect) extents->height == rect->bottom - rect->top; }
+VkResult wine_vkAcquireNextImage2KHR(VkDevice device_handle, const VkAcquireNextImageInfoKHR *acquire_info, + uint32_t *image_index) +{ + struct wine_swapchain *swapchain = wine_swapchain_from_handle(acquire_info->swapchain); + struct wine_device *device = wine_device_from_handle(device_handle); + VkAcquireNextImageInfoKHR acquire_info_host = *acquire_info; + struct wine_surface *surface = swapchain->surface; + RECT client_rect; + VkResult res; + + acquire_info_host.swapchain = swapchain->host_swapchain; + res = device->funcs.p_vkAcquireNextImage2KHR(device->host_device, &acquire_info_host, image_index); + + if (res == VK_SUCCESS && NtUserGetClientRect(surface->hwnd, &client_rect) && + !extents_equals(&swapchain->extents, &client_rect)) + { + WARN("Swapchain size %dx%d does not match client rect %s, returning VK_SUBOPTIMAL_KHR\n", + swapchain->extents.width, swapchain->extents.height, wine_dbgstr_rect(&client_rect)); + return VK_SUBOPTIMAL_KHR; + } + + return res; +} + +VkResult wine_vkAcquireNextImageKHR(VkDevice device_handle, VkSwapchainKHR swapchain_handle, uint64_t timeout, + VkSemaphore semaphore, VkFence fence, uint32_t *image_index) +{ + struct wine_swapchain *swapchain = wine_swapchain_from_handle(swapchain_handle); + struct wine_device *device = wine_device_from_handle(device_handle); + struct wine_surface *surface = swapchain->surface; + RECT client_rect; + VkResult res; + + res = device->funcs.p_vkAcquireNextImageKHR(device->host_device, swapchain->host_swapchain, timeout, + semaphore, fence, image_index); + + if (res == VK_SUCCESS && NtUserGetClientRect(surface->hwnd, &client_rect) && + !extents_equals(&swapchain->extents, &client_rect)) + { + WARN("Swapchain size %dx%d does not match client rect %s, returning VK_SUBOPTIMAL_KHR\n", + swapchain->extents.width, swapchain->extents.height, wine_dbgstr_rect(&client_rect)); + return VK_SUBOPTIMAL_KHR; + } + + return res; +} + VkResult wine_vkCreateSwapchainKHR(VkDevice device_handle, const VkSwapchainCreateInfoKHR *create_info, const VkAllocationCallbacks *allocator, VkSwapchainKHR *swapchain_handle) { diff --git a/dlls/winevulkan/vulkan_thunks.c b/dlls/winevulkan/vulkan_thunks.c index 7ec0300e8cb..5c1d6b1685d 100644 --- a/dlls/winevulkan/vulkan_thunks.c +++ b/dlls/winevulkan/vulkan_thunks.c @@ -7112,28 +7112,13 @@ static uint64_t wine_vk_unwrap_handle(uint32_t type, uint64_t handle) } }
-#ifdef _WIN64 -static inline void convert_VkAcquireNextImageInfoKHR_win64_to_host(const VkAcquireNextImageInfoKHR *in, VkAcquireNextImageInfoKHR *out) -{ - if (!in) return; - - out->sType = in->sType; - out->pNext = in->pNext; - out->swapchain = wine_swapchain_from_handle(in->swapchain)->host_swapchain; - out->timeout = in->timeout; - out->semaphore = in->semaphore; - out->fence = in->fence; - out->deviceMask = in->deviceMask; -} -#endif /* _WIN64 */ - -static inline void convert_VkAcquireNextImageInfoKHR_win32_to_host(const VkAcquireNextImageInfoKHR32 *in, VkAcquireNextImageInfoKHR *out) +static inline void convert_VkAcquireNextImageInfoKHR_win32_to_unwrapped_host(const VkAcquireNextImageInfoKHR32 *in, VkAcquireNextImageInfoKHR *out) { if (!in) return;
out->sType = in->sType; out->pNext = NULL; - out->swapchain = wine_swapchain_from_handle(in->swapchain)->host_swapchain; + out->swapchain = in->swapchain; out->timeout = in->timeout; out->semaphore = in->semaphore; out->fence = in->fence; @@ -30193,12 +30178,10 @@ static inline void convert_VkSemaphoreWaitInfo_win32_to_host(const VkSemaphoreWa static NTSTATUS thunk64_vkAcquireNextImage2KHR(void *args) { struct vkAcquireNextImage2KHR_params *params = args; - VkAcquireNextImageInfoKHR pAcquireInfo_host;
TRACE("%p, %p, %p\n", params->device, params->pAcquireInfo, params->pImageIndex);
- convert_VkAcquireNextImageInfoKHR_win64_to_host(params->pAcquireInfo, &pAcquireInfo_host); - params->result = wine_device_from_handle(params->device)->funcs.p_vkAcquireNextImage2KHR(wine_device_from_handle(params->device)->host_device, &pAcquireInfo_host, params->pImageIndex); + params->result = wine_vkAcquireNextImage2KHR(params->device, params->pAcquireInfo, params->pImageIndex); return STATUS_SUCCESS; } #endif /* _WIN64 */ @@ -30216,8 +30199,8 @@ static NTSTATUS thunk32_vkAcquireNextImage2KHR(void *args)
TRACE("%#x, %#x, %#x\n", params->device, params->pAcquireInfo, params->pImageIndex);
- convert_VkAcquireNextImageInfoKHR_win32_to_host((const VkAcquireNextImageInfoKHR32 *)UlongToPtr(params->pAcquireInfo), &pAcquireInfo_host); - params->result = wine_device_from_handle((VkDevice)UlongToPtr(params->device))->funcs.p_vkAcquireNextImage2KHR(wine_device_from_handle((VkDevice)UlongToPtr(params->device))->host_device, &pAcquireInfo_host, (uint32_t *)UlongToPtr(params->pImageIndex)); + convert_VkAcquireNextImageInfoKHR_win32_to_unwrapped_host((const VkAcquireNextImageInfoKHR32 *)UlongToPtr(params->pAcquireInfo), &pAcquireInfo_host); + params->result = wine_vkAcquireNextImage2KHR((VkDevice)UlongToPtr(params->device), &pAcquireInfo_host, (uint32_t *)UlongToPtr(params->pImageIndex)); return STATUS_SUCCESS; }
@@ -30228,7 +30211,7 @@ static NTSTATUS thunk64_vkAcquireNextImageKHR(void *args)
TRACE("%p, 0x%s, 0x%s, 0x%s, 0x%s, %p\n", params->device, wine_dbgstr_longlong(params->swapchain), wine_dbgstr_longlong(params->timeout), wine_dbgstr_longlong(params->semaphore), wine_dbgstr_longlong(params->fence), params->pImageIndex);
- params->result = wine_device_from_handle(params->device)->funcs.p_vkAcquireNextImageKHR(wine_device_from_handle(params->device)->host_device, wine_swapchain_from_handle(params->swapchain)->host_swapchain, params->timeout, params->semaphore, params->fence, params->pImageIndex); + params->result = wine_vkAcquireNextImageKHR(params->device, params->swapchain, params->timeout, params->semaphore, params->fence, params->pImageIndex); return STATUS_SUCCESS; } #endif /* _WIN64 */ @@ -30248,7 +30231,7 @@ static NTSTATUS thunk32_vkAcquireNextImageKHR(void *args)
TRACE("%#x, 0x%s, 0x%s, 0x%s, 0x%s, %#x\n", params->device, wine_dbgstr_longlong(params->swapchain), wine_dbgstr_longlong(params->timeout), wine_dbgstr_longlong(params->semaphore), wine_dbgstr_longlong(params->fence), params->pImageIndex);
- params->result = wine_device_from_handle((VkDevice)UlongToPtr(params->device))->funcs.p_vkAcquireNextImageKHR(wine_device_from_handle((VkDevice)UlongToPtr(params->device))->host_device, wine_swapchain_from_handle(params->swapchain)->host_swapchain, params->timeout, params->semaphore, params->fence, (uint32_t *)UlongToPtr(params->pImageIndex)); + params->result = wine_vkAcquireNextImageKHR((VkDevice)UlongToPtr(params->device), params->swapchain, params->timeout, params->semaphore, params->fence, (uint32_t *)UlongToPtr(params->pImageIndex)); return STATUS_SUCCESS; }
diff --git a/dlls/winevulkan/vulkan_thunks.h b/dlls/winevulkan/vulkan_thunks.h index 699a21c580e..f27fae3f07c 100644 --- a/dlls/winevulkan/vulkan_thunks.h +++ b/dlls/winevulkan/vulkan_thunks.h @@ -15,6 +15,8 @@ #define WINE_VK_VERSION VK_API_VERSION_1_3
/* Functions for which we have custom implementations outside of the thunks. */ +VkResult wine_vkAcquireNextImage2KHR(VkDevice device, const VkAcquireNextImageInfoKHR *pAcquireInfo, uint32_t *pImageIndex); +VkResult wine_vkAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout, VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex); VkResult wine_vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo *pAllocateInfo, VkCommandBuffer *pCommandBuffers); VkResult wine_vkAllocateMemory(VkDevice device, const VkMemoryAllocateInfo *pAllocateInfo, const VkAllocationCallbacks *pAllocator, VkDeviceMemory *pMemory); VkResult wine_vkCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkBuffer *pBuffer);