diff options
author | Faith Ekstrand <faith.ekstrand@collabora.com> | 2023-03-20 18:41:31 -0500 |
---|---|---|
committer | Marge Bot <emma+marge@anholt.net> | 2023-03-31 14:57:03 +0000 |
commit | b16cfe23ef1c2e2c5fdc07d95fa80b7859105fa5 (patch) | |
tree | 270be74c029acf68ba75b95f627ee9317b2b1ef3 /src/vulkan | |
parent | d75f797246c0eab0a51d41a8c829bd7d2d8cc2b3 (diff) | |
download | mesa-b16cfe23ef1c2e2c5fdc07d95fa80b7859105fa5.tar.gz mesa-b16cfe23ef1c2e2c5fdc07d95fa80b7859105fa5.tar.bz2 mesa-b16cfe23ef1c2e2c5fdc07d95fa80b7859105fa5.zip |
vulkan,anv,hasvk,radv: Unify Android hardware buffer creation
Reviewed-by: Lina Versace <lina@kiwitree.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22038>
Diffstat (limited to 'src/vulkan')
-rw-r--r-- | src/vulkan/runtime/vk_android.c | 65 | ||||
-rw-r--r-- | src/vulkan/runtime/vk_android.h | 3 |
2 files changed, 67 insertions, 1 deletions
diff --git a/src/vulkan/runtime/vk_android.c b/src/vulkan/runtime/vk_android.c index 862a9374ee7..eb54b1d1cbf 100644 --- a/src/vulkan/runtime/vk_android.c +++ b/src/vulkan/runtime/vk_android.c @@ -23,13 +23,22 @@ #include "vk_android.h" +#include "vk_buffer.h" #include "vk_common_entrypoints.h" #include "vk_device.h" +#include "vk_image.h" #include "vk_log.h" #include "vk_queue.h" +#include "vk_util.h" #include "util/libsync.h" +#include <hardware/gralloc.h> + +#if ANDROID_API_LEVEL >= 26 +#include <hardware/gralloc1.h> +#endif + #include <unistd.h> #if ANDROID_API_LEVEL >= 26 @@ -84,7 +93,61 @@ vk_image_usage_to_ahb_usage(const VkImageCreateFlags vk_create, if (ahb_usage == 0) ahb_usage = AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE; - return ahb_usage + return ahb_usage; +} + +struct AHardwareBuffer * +vk_alloc_ahardware_buffer(const VkMemoryAllocateInfo *pAllocateInfo) +{ + const VkMemoryDedicatedAllocateInfo *dedicated_info = + vk_find_struct_const(pAllocateInfo->pNext, + MEMORY_DEDICATED_ALLOCATE_INFO); + + uint32_t w = 0; + uint32_t h = 1; + uint32_t layers = 1; + uint32_t format = 0; + uint64_t usage = 0; + + /* If caller passed dedicated information. */ + if (dedicated_info && dedicated_info->image) { + VK_FROM_HANDLE(vk_image, image, dedicated_info->image); + w = image->extent.width; + h = image->extent.height; + layers = image->array_layers; + assert(image->ahardware_buffer_format != 0); + /* TODO: This feels a bit sketchy. We should probably be taking the + * external format into account somehow. + */ + format = image->ahardware_buffer_format; + usage = vk_image_usage_to_ahb_usage(image->create_flags, + image->usage); + } else if (dedicated_info && dedicated_info->buffer) { + VK_FROM_HANDLE(vk_buffer, buffer, dedicated_info->buffer); + w = buffer->size; + format = AHARDWAREBUFFER_FORMAT_BLOB; + usage = AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN | + AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN; + } else { + w = pAllocateInfo->allocationSize; + format = AHARDWAREBUFFER_FORMAT_BLOB; + usage = AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN | + AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN; + } + + struct AHardwareBuffer_Desc desc = { + .width = w, + .height = h, + .layers = layers, + .format = format, + .usage = usage, + }; + + struct AHardwareBuffer *ahb; + if (AHardwareBuffer_allocate(&desc, &ahb) != 0) + return NULL; + + return ahb; } #endif /* ANDROID_API_LEVEL >= 26 */ diff --git a/src/vulkan/runtime/vk_android.h b/src/vulkan/runtime/vk_android.h index 668b01febdf..25b346c4f88 100644 --- a/src/vulkan/runtime/vk_android.h +++ b/src/vulkan/runtime/vk_android.h @@ -32,6 +32,9 @@ extern "C" { #if ANDROID_API_LEVEL >= 26 uint64_t vk_image_usage_to_ahb_usage(const VkImageCreateFlags vk_create, const VkImageUsageFlags vk_usage); + +struct AHardwareBuffer * +vk_alloc_ahardware_buffer(const VkMemoryAllocateInfo *pAllocateInfo); #endif #ifdef __cplusplus |