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 <r.stratiienko@gmail.com>
Tested-by: tarsin <yuanqingxiang233@163.com>
Acked-by: David Heidelberg <david.heidelberg@collabora.com>
Reviewed-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25360>
This commit is contained in:
Roman Stratiienko 2023-09-24 00:54:25 +03:00 committed by Marge Bot
parent c406d53858
commit 3b0f0b0ab9
2 changed files with 50 additions and 0 deletions

View file

@ -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) {

View file

@ -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