From 3b0f0b0ab963c25a0ec231a5d7db176210c50da7 Mon Sep 17 00:00:00 2001 From: Roman Stratiienko Date: Sun, 24 Sep 2023 00:54:25 +0300 Subject: [PATCH] vulkan/android: Add android buffer classification to vk_image Helps clients distinguish between non-android, Android native, and Android hardware buffers. Change-Id: Idc7838ead211048140128c1729241280e8ff9e59 Signed-off-by: Roman Stratiienko Tested-by: tarsin Acked-by: David Heidelberg Reviewed-by: Rob Clark Part-of: --- src/vulkan/runtime/vk_image.c | 12 +++++++++++ src/vulkan/runtime/vk_image.h | 38 +++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/src/vulkan/runtime/vk_image.c b/src/vulkan/runtime/vk_image.c index cada2dd6761..6efdeb3c083 100644 --- a/src/vulkan/runtime/vk_image.c +++ b/src/vulkan/runtime/vk_image.c @@ -101,6 +101,18 @@ vk_image_init(struct vk_device *device, #endif #if DETECT_OS_ANDROID + if (image->external_handle_types & + VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID) + image->android_buffer_type = ANDROID_BUFFER_HARDWARE; + + const VkNativeBufferANDROID *native_buffer = + vk_find_struct_const(pCreateInfo->pNext, NATIVE_BUFFER_ANDROID); + + if (native_buffer != NULL) { + assert(image->android_buffer_type == ANDROID_BUFFER_NONE); + image->android_buffer_type = ANDROID_BUFFER_NATIVE; + } + const VkExternalFormatANDROID *ext_format = vk_find_struct_const(pCreateInfo->pNext, EXTERNAL_FORMAT_ANDROID); if (ext_format && ext_format->externalFormat != 0) { diff --git a/src/vulkan/runtime/vk_image.h b/src/vulkan/runtime/vk_image.h index d69009a4abb..77ef8298d06 100644 --- a/src/vulkan/runtime/vk_image.h +++ b/src/vulkan/runtime/vk_image.h @@ -28,6 +28,14 @@ #include "util/detect_os.h" #include "util/u_math.h" +#if DETECT_OS_ANDROID +enum android_buffer_type { + ANDROID_BUFFER_NONE = 0, + ANDROID_BUFFER_NATIVE, + ANDROID_BUFFER_HARDWARE, +}; +#endif + #ifdef __cplusplus extern "C" { #endif @@ -81,6 +89,8 @@ struct vk_image { #endif #if DETECT_OS_ANDROID + enum android_buffer_type android_buffer_type; + /* AHARDWAREBUFFER_FORMAT for this image or 0 * * A default is provided by the Vulkan runtime code based on the VkFormat @@ -375,6 +385,34 @@ VkImageLayout vk_att_ref_stencil_layout(const VkAttachmentReference2 *att_ref, VkImageLayout vk_att_desc_stencil_layout(const VkAttachmentDescription2 *att_desc, bool final); +#if DETECT_OS_ANDROID +static inline bool +vk_image_is_android_native_buffer(struct vk_image *image) +{ + return image->android_buffer_type == ANDROID_BUFFER_NATIVE; +} +#else +static inline bool +vk_image_is_android_native_buffer(struct vk_image *image) +{ + return false; +} +#endif /* DETECT_OS_ANDROID */ + +#if DETECT_OS_ANDROID && ANDROID_API_LEVEL >= 26 +static inline bool +vk_image_is_android_hardware_buffer(struct vk_image *image) +{ + return image->android_buffer_type == ANDROID_BUFFER_HARDWARE; +} +#else +static inline bool +vk_image_is_android_hardware_buffer(struct vk_image *image) +{ + return false; +} +#endif + #ifdef __cplusplus } #endif