From 74f53a9293542b77b11eeca0cf2a44b32f1ce49f 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: --- src/gallium/frontends/lavapipe/lvp_device.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/gallium/frontends/lavapipe/lvp_device.c b/src/gallium/frontends/lavapipe/lvp_device.c index 4ad1853474f..5cc4c154f53 100644 --- a/src/gallium/frontends/lavapipe/lvp_device.c +++ b/src/gallium/frontends/lavapipe/lvp_device.c @@ -2342,6 +2342,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) { @@ -2355,6 +2356,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 } @@ -2366,7 +2368,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) @@ -2375,7 +2377,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)