From 1c3798ed86d9f2b18a37ea36b9694d6bad835fef Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Sat, 12 Jul 2025 20:58:28 -0700 Subject: [PATCH] hasvk: avoid leaking private binding for aliased wsi image This time for hasvk and is the same with https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35893 Aliased wsi image has to share the same private binding with the original wsi image for memory consistency. If the private binding exists, it needs to be released before being overridden. Cc: mesa-stable Reviewed-by: Lionel Landwerlin Part-of: (cherry picked from commit c647c422dbddf59e65a26fda2ff13113e48cd35a) --- .pick_status.json | 2 +- src/intel/vulkan_hasvk/anv_image.c | 26 +++++++++++++++----------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 7d6fc934b40..202aa6d75d4 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -2234,7 +2234,7 @@ "description": "hasvk: avoid leaking private binding for aliased wsi image", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null, "notes": null diff --git a/src/intel/vulkan_hasvk/anv_image.c b/src/intel/vulkan_hasvk/anv_image.c index 844948099e7..a6dd4ef3b27 100644 --- a/src/intel/vulkan_hasvk/anv_image.c +++ b/src/intel/vulkan_hasvk/anv_image.c @@ -1162,14 +1162,6 @@ alloc_private_binding(struct anv_device *device, if (binding->memory_range.size == 0) return VK_SUCCESS; - const VkImageSwapchainCreateInfoKHR *swapchain_info = - vk_find_struct_const(create_info->pNext, IMAGE_SWAPCHAIN_CREATE_INFO_KHR); - - if (swapchain_info && swapchain_info->swapchain != VK_NULL_HANDLE) { - /* The image will be bound to swapchain memory. */ - return VK_SUCCESS; - } - return anv_device_alloc_bo(device, "image-binding-private", binding->memory_range.size, 0, 0, &binding->address.bo); @@ -1670,6 +1662,19 @@ VkResult anv_BindImageMemory2( assert(image->vk.aspects == swapchain_image->vk.aspects); assert(mem == NULL); + /* Remove the internally allocated private binding since we're going + * to replace everything with BOs from the WSI image, we don't want + * to leak the current BO. + */ + struct anv_bo *private_bo = + image->bindings[ANV_IMAGE_MEMORY_BINDING_PRIVATE].address.bo; + if (private_bo) { + assert(image->bindings[ANV_IMAGE_MEMORY_BINDING_PRIVATE].memory_range.size); + + anv_device_release_bo(device, private_bo); + image->bindings[ANV_IMAGE_MEMORY_BINDING_PRIVATE].address.bo = NULL; + } + for (int j = 0; j < ARRAY_SIZE(image->bindings); ++j) { assert(memory_ranges_equal(image->bindings[j].memory_range, swapchain_image->bindings[j].memory_range)); @@ -1679,8 +1684,7 @@ VkResult anv_BindImageMemory2( /* We must bump the private binding's bo's refcount because, unlike the other * bindings, its lifetime is not application-managed. */ - struct anv_bo *private_bo = - image->bindings[ANV_IMAGE_MEMORY_BINDING_PRIVATE].address.bo; + private_bo = image->bindings[ANV_IMAGE_MEMORY_BINDING_PRIVATE].address.bo; if (private_bo) anv_bo_ref(private_bo); @@ -2675,4 +2679,4 @@ void anv_GetRenderingAreaGranularityKHR( .width = 1, .height = 1, }; -} \ No newline at end of file +}