From b187952593d05d0e906240e0d2aa94ff2c401e34 Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Tue, 22 Jul 2025 14:49:55 -0700 Subject: [PATCH] lavapipe: ensure to use zero memoryOffset for wsi image alias binding Per spec of VkBindImageMemorySwapchainInfoKHR: > If swapchain is not NULL, the swapchain and imageIndex are used to determine the memory that the image is bound to, instead of memory and memoryOffset. Meanwhile, common wsi is doing dedicated allocation for swapchain image memory, so it's required to use zero memoryOffset by the spec. Then here we can safely set to zero memoryOffset before passing to the actual binding call. In practice, when the struct is initialized with proper sType and memory being VK_NULL_HANDLE, the memoryOffset is most likely left being zero initialized. Not a critical must fix but still a bug. Fixes: ace49d9e52a ("lavapipe: adopt wsi_common_get_memory") Reviewed-by: Lucas Fryzek Part-of: (cherry picked from commit 74f53a9293542b77b11eeca0cf2a44b32f1ce49f) --- .pick_status.json | 2 +- src/gallium/frontends/lavapipe/lvp_device.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 7d63c0a9fd9..9eb866955ca 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -2084,7 +2084,7 @@ "description": "lavapipe: ensure to use zero memoryOffset for wsi image alias binding", "nominated": true, "nomination_type": 2, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "ace49d9e52a6156f114ee00eec759d734bd84fc0", "notes": null diff --git a/src/gallium/frontends/lavapipe/lvp_device.c b/src/gallium/frontends/lavapipe/lvp_device.c index f16a996febf..04c5b9a29ea 100644 --- a/src/gallium/frontends/lavapipe/lvp_device.c +++ b/src/gallium/frontends/lavapipe/lvp_device.c @@ -2379,6 +2379,7 @@ VKAPI_ATTR VkResult VKAPI_CALL lvp_BindImageMemory2(VkDevice _device, const VkBindImageMemoryInfo *bind_info = &pBindInfos[i]; LVP_FROM_HANDLE(lvp_device_memory, mem, bind_info->memory); LVP_FROM_HANDLE(lvp_image, image, bind_info->image); + uint64_t mem_offset = bind_info->memoryOffset; VkBindMemoryStatusKHR *status = (void*)vk_find_struct_const(&pBindInfos[i], BIND_MEMORY_STATUS_KHR); if (!mem) { @@ -2392,6 +2393,7 @@ VKAPI_ATTR VkResult VKAPI_CALL lvp_BindImageMemory2(VkDevice _device, assert(swapchain_info && swapchain_info->swapchain != VK_NULL_HANDLE); mem = lvp_device_memory_from_handle(wsi_common_get_memory( swapchain_info->swapchain, swapchain_info->imageIndex)); + mem_offset = 0; #endif } @@ -2403,7 +2405,7 @@ VKAPI_ATTR VkResult VKAPI_CALL lvp_BindImageMemory2(VkDevice _device, vk_find_struct_const(pBindInfos[i].pNext, BIND_IMAGE_PLANE_MEMORY_INFO); uint8_t plane = lvp_image_aspects_to_plane(image, plane_info->planeAspect); result = lvp_image_plane_bind(device, &image->planes[plane], - mem, bind_info->memoryOffset, &offset_B); + mem, mem_offset, &offset_B); if (status) *status->pResult = result; if (result != VK_SUCCESS) @@ -2412,7 +2414,7 @@ VKAPI_ATTR VkResult VKAPI_CALL lvp_BindImageMemory2(VkDevice _device, VkResult fail = VK_SUCCESS; for (unsigned plane = 0; plane < image->plane_count; plane++) { result = lvp_image_plane_bind(device, &image->planes[plane], - mem, bind_info->memoryOffset + image->offset, &offset_B); + mem, mem_offset + image->offset, &offset_B); if (status) *status->pResult = res; if (result != VK_SUCCESS)