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 <valentine.burley@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28307>
This commit is contained in:
Valentine Burley 2024-03-15 16:18:28 +00:00 committed by Marge Bot
parent 9e4c7dee3b
commit 4408aff896
1 changed files with 34 additions and 0 deletions

View File

@ -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;