From 4408aff896a87fca231e3856f4ac154a1bfc35ac Mon Sep 17 00:00:00 2001 From: Valentine Burley Date: Fri, 15 Mar 2024 16:18:28 +0000 Subject: [PATCH] tu: Fix missing implementation of creating images from swapchains These pNext structs are part of VK_KHR_swapchain which is core Vulkan 1.1 but they were missing. Based on ANV, RADV and NVK. Signed-off-by: Valentine Burley Part-of: --- src/freedreno/vulkan/tu_image.cc | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/freedreno/vulkan/tu_image.cc b/src/freedreno/vulkan/tu_image.cc index ca74d2ceccff5..48b2af249fb8d 100644 --- a/src/freedreno/vulkan/tu_image.cc +++ b/src/freedreno/vulkan/tu_image.cc @@ -22,6 +22,7 @@ #include "tu_device.h" #include "tu_formats.h" #include "tu_rmv.h" +#include "tu_wsi.h" uint32_t tu6_plane_count(VkFormat format) @@ -680,6 +681,22 @@ tu_CreateImage(VkDevice _device, const VkSubresourceLayout *plane_layouts = NULL; TU_FROM_HANDLE(tu_device, device, _device); + +#ifdef TU_USE_WSI_PLATFORM + /* Ignore swapchain creation info on Android. Since we don't have an + * implementation in Mesa, we're guaranteed to access an Android object + * incorrectly. + */ + const VkImageSwapchainCreateInfoKHR *swapchain_info = + vk_find_struct_const(pCreateInfo->pNext, IMAGE_SWAPCHAIN_CREATE_INFO_KHR); + if (swapchain_info && swapchain_info->swapchain != VK_NULL_HANDLE) { + return wsi_common_create_swapchain_image(device->physical_device->vk.wsi_device, + pCreateInfo, + swapchain_info->swapchain, + pImage); + } +#endif + struct tu_image *image = (struct tu_image *) vk_object_zalloc(&device->vk, alloc, sizeof(*image), VK_OBJECT_TYPE_IMAGE); @@ -785,6 +802,23 @@ tu_BindImageMemory2(VkDevice _device, TU_FROM_HANDLE(tu_image, image, pBindInfos[i].image); TU_FROM_HANDLE(tu_device_memory, mem, pBindInfos[i].memory); + /* Ignore this struct on Android, we cannot access swapchain structures there. */ +#ifdef TU_USE_WSI_PLATFORM + const VkBindImageMemorySwapchainInfoKHR *swapchain_info = + vk_find_struct_const(pBindInfos[i].pNext, BIND_IMAGE_MEMORY_SWAPCHAIN_INFO_KHR); + + if (swapchain_info && swapchain_info->swapchain != VK_NULL_HANDLE) { + VkImage _wsi_image = wsi_common_get_image(swapchain_info->swapchain, + swapchain_info->imageIndex); + TU_FROM_HANDLE(tu_image, wsi_img, _wsi_image); + + image->bo = wsi_img->bo; + image->map = NULL; + image->iova = wsi_img->iova; + continue; + } +#endif + if (mem) { image->bo = mem->bo; image->iova = mem->bo->iova + pBindInfos[i].memoryOffset;