From 209e402720757773557cb8377cbb37d6685a462c Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Thu, 17 Jul 2025 22:46:58 -0700 Subject: [PATCH] lavapipe: do not short-circuit AHB export alloc (non-import) Per spec VUID-VkMemoryAllocateInfo-pNext-01874: If the parameters do not define an import operation, and the pNext chain includes a VkExportMemoryAllocateInfo structure with VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID included in its handleTypes member, and the pNext chain includes a VkMemoryDedicatedAllocateInfo structure with image not equal to VK_NULL_HANDLE, then allocationSize must be 0 - before: total 116, skip 66, pass 36, fail 14 - after: total 116, skip 66, pass 50, fail 0 Fixes: cebb2bf2662 ("lavapipe: Add AHB extension") Reviewed-by: Lucas Fryzek Part-of: --- src/gallium/frontends/lavapipe/lvp_device.c | 24 ++++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/gallium/frontends/lavapipe/lvp_device.c b/src/gallium/frontends/lavapipe/lvp_device.c index ec42ba00e74..525255be6e5 100644 --- a/src/gallium/frontends/lavapipe/lvp_device.c +++ b/src/gallium/frontends/lavapipe/lvp_device.c @@ -1967,12 +1967,7 @@ VKAPI_ATTR VkResult VKAPI_CALL lvp_AllocateMemory( VkResult error = VK_ERROR_OUT_OF_DEVICE_MEMORY; assert(pAllocateInfo->sType == VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO); int priority = 0; - - if (pAllocateInfo->allocationSize == 0) { - /* Apparently, this is allowed */ - *pMem = VK_NULL_HANDLE; - return VK_SUCCESS; - } + bool is_ahb_export_alloc = false; vk_foreach_struct_const(ext, pAllocateInfo->pNext) { switch ((unsigned)ext->sType) { @@ -2007,6 +2002,20 @@ VKAPI_ATTR VkResult VKAPI_CALL lvp_AllocateMemory( } } +#if DETECT_OS_ANDROID + is_ahb_export_alloc = !ahb_import_info && export_info && + export_info->handleTypes & VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID; +#endif + + /* Can early return with size 0 if not AHB export alloc. See + * VUID-VkMemoryAllocateInfo-pNext-01874 for details. + */ + if (pAllocateInfo->allocationSize == 0 && !is_ahb_export_alloc) { + /* Apparently, this is allowed */ + *pMem = VK_NULL_HANDLE; + return VK_SUCCESS; + } + #ifdef PIPE_MEMORY_FD if (import_info != NULL && import_info->fd < 0) { return vk_error(device->instance, VK_ERROR_INVALID_EXTERNAL_HANDLE); @@ -2042,8 +2051,7 @@ VKAPI_ATTR VkResult VKAPI_CALL lvp_AllocateMemory( error = lvp_import_ahb_memory(device, mem, ahb_import_info); if (error != VK_SUCCESS) goto fail; - } else if(export_info && - (export_info->handleTypes & VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID)) { + } else if (is_ahb_export_alloc) { error = lvp_create_ahb_memory(device, mem, pAllocateInfo); if (error != VK_SUCCESS) goto fail;