From 46d835f82308cd5230c8ec1c8cfe8ae2491028fa 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: (cherry picked from commit cef48af271b8bdb360f2a31e876ecdc05a820753) --- .pick_status.json | 2 +- src/freedreno/vulkan/tu_image.cc | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index e1e8000d129..13cb282b5ed 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -9704,7 +9704,7 @@ "description": "tu: bind aliased wsi image at memory offset zero", "nominated": true, "nomination_type": 2, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "f887116c499e658604aef933f142ba00233950ae", "notes": null diff --git a/src/freedreno/vulkan/tu_image.cc b/src/freedreno/vulkan/tu_image.cc index 1af7157920a..fc23167b51a 100644 --- a/src/freedreno/vulkan/tu_image.cc +++ b/src/freedreno/vulkan/tu_image.cc @@ -912,6 +912,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 @@ -925,6 +926,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 } @@ -956,8 +961,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)) { @@ -970,7 +975,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; }