From cef48af271b8bdb360f2a31e876ecdc05a820753 Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Sat, 30 Aug 2025 07:28:35 +0000 Subject: [PATCH] tu: bind aliased wsi image at memory offset zero The vulkan spec says that we should ignore memoryOffset when VkBindImageMemorySwapchainInfoKHR is present. wsi common assumes that we bind the wsi image at offset 0, so set the offset to 0. This change aligns with common wsi, and also obeys dedicated alloc requirement. Fixes: f887116c499 ("turnip: adopt wsi_common_get_memory") Reviewed-by: Connor Abbott Part-of: --- src/freedreno/vulkan/tu_image.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/freedreno/vulkan/tu_image.cc b/src/freedreno/vulkan/tu_image.cc index 871fd600bef..0c4a7e07ff8 100644 --- a/src/freedreno/vulkan/tu_image.cc +++ b/src/freedreno/vulkan/tu_image.cc @@ -953,6 +953,7 @@ tu_BindImageMemory2(VkDevice _device, for (uint32_t i = 0; i < bindInfoCount; ++i) { VK_FROM_HANDLE(tu_image, image, pBindInfos[i].image); VK_FROM_HANDLE(tu_device_memory, mem, pBindInfos[i].memory); + uint64_t offset = pBindInfos[i].memoryOffset; if (!mem) { #if DETECT_OS_ANDROID @@ -966,6 +967,10 @@ tu_BindImageMemory2(VkDevice _device, swapchain_info->swapchain != VK_NULL_HANDLE); mem = tu_device_memory_from_handle(wsi_common_get_memory( swapchain_info->swapchain, swapchain_info->imageIndex)); + /* memoryOffset is ignored when VkBindImageMemorySwapchainInfoKHR is + * present, so we follow common wsi to set the offset to 0 here. + */ + offset = 0; #endif } @@ -997,8 +1002,8 @@ tu_BindImageMemory2(VkDevice _device, } } image->bo = mem->bo; - image->bo_offset = pBindInfos[i].memoryOffset; - image->iova = mem->bo->iova + pBindInfos[i].memoryOffset; + image->bo_offset = offset; + image->iova = mem->bo->iova + offset; if (image->vk.usage & (VK_IMAGE_USAGE_FRAGMENT_DENSITY_MAP_BIT_EXT | VK_IMAGE_USAGE_HOST_TRANSFER_BIT_EXT)) { @@ -1011,7 +1016,7 @@ tu_BindImageMemory2(VkDevice _device, } } - image->map = (char *) mem->bo->map + pBindInfos[i].memoryOffset; + image->map = (char *) mem->bo->map + offset; } else { image->map = NULL; }