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