From aac51c3a0b07563bae0b75a3f9464474bad08df0 Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Sun, 6 Jul 2025 22:48:51 -0700 Subject: [PATCH] vulkan/android: improve memoryTypeBits reporting in AHB props query Instead of reporting all memory types being compatible, at least we can limit the types to those compatible for dma-buf import. Optionally, we can do even better here to actually create the image or buffer with the AHB to get more accurate memory type bits for memory import. However, it is optional since we can touch up in the common layer upon actual AHB import time. Reviewed-by: Antonio Ospite Part-of: --- src/vulkan/runtime/vk_android.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/vulkan/runtime/vk_android.c b/src/vulkan/runtime/vk_android.c index 5040d6dfea7..6ef5e8ea3e2 100644 --- a/src/vulkan/runtime/vk_android.c +++ b/src/vulkan/runtime/vk_android.c @@ -857,8 +857,6 @@ vk_common_GetAndroidHardwareBufferPropertiesANDROID( VkAndroidHardwareBufferPropertiesANDROID *pProperties) { VK_FROM_HANDLE(vk_device, device, device_h); - struct vk_physical_device *pdevice = device->physical; - VkResult result; VkAndroidHardwareBufferFormatPropertiesANDROID *format_prop = @@ -897,13 +895,16 @@ vk_common_GetAndroidHardwareBufferPropertiesANDROID( assert(handle && handle->numFds > 0); pProperties->allocationSize = lseek(handle->data[0], 0, SEEK_END); - VkPhysicalDeviceMemoryProperties mem_props; + VkMemoryFdPropertiesKHR fd_props = { + .sType = VK_STRUCTURE_TYPE_MEMORY_FD_PROPERTIES_KHR, + }; + result = device->dispatch_table.GetMemoryFdPropertiesKHR( + device_h, VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT, handle->data[0], + &fd_props); + if (result != VK_SUCCESS) + return result; - device->physical->dispatch_table.GetPhysicalDeviceMemoryProperties( - (VkPhysicalDevice)pdevice, &mem_props); - - /* All memory types. (Should we be smarter than this?) */ - pProperties->memoryTypeBits = (1u << mem_props.memoryTypeCount) - 1; + pProperties->memoryTypeBits = fd_props.memoryTypeBits; return VK_SUCCESS; }