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>
This commit is contained in:

committed by
Marge Bot

parent
d75f797246
commit
b16cfe23ef
@@ -736,48 +736,10 @@ radv_create_ahb_memory(struct radv_device *device, struct radv_device_memory *me
|
|||||||
unsigned priority, const VkMemoryAllocateInfo *pAllocateInfo)
|
unsigned priority, const VkMemoryAllocateInfo *pAllocateInfo)
|
||||||
{
|
{
|
||||||
#if RADV_SUPPORT_ANDROID_HARDWARE_BUFFER
|
#if RADV_SUPPORT_ANDROID_HARDWARE_BUFFER
|
||||||
const VkMemoryDedicatedAllocateInfo *dedicated_info =
|
mem->android_hardware_buffer = vk_alloc_ahardware_buffer(pAllocateInfo);
|
||||||
vk_find_struct_const(pAllocateInfo->pNext, MEMORY_DEDICATED_ALLOCATE_INFO);
|
if (mem->android_hardware_buffer == NULL)
|
||||||
|
|
||||||
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) {
|
|
||||||
RADV_FROM_HANDLE(radv_image, image, dedicated_info->image);
|
|
||||||
w = image->info.width;
|
|
||||||
h = image->info.height;
|
|
||||||
layers = image->info.array_size;
|
|
||||||
format = radv_ahb_format_for_vk_format(image->vk.format);
|
|
||||||
usage = vk_image_usage_to_ahb_usage(image->vk.create_flags, image->vk.usage);
|
|
||||||
} else if (dedicated_info && dedicated_info->buffer) {
|
|
||||||
RADV_FROM_HANDLE(radv_buffer, buffer, dedicated_info->buffer);
|
|
||||||
w = buffer->vk.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 *android_hardware_buffer = NULL;
|
|
||||||
struct AHardwareBuffer_Desc desc = {
|
|
||||||
.width = w,
|
|
||||||
.height = h,
|
|
||||||
.layers = layers,
|
|
||||||
.format = format,
|
|
||||||
.usage = usage,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (AHardwareBuffer_allocate(&desc, &android_hardware_buffer) != 0)
|
|
||||||
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||||
|
|
||||||
mem->android_hardware_buffer = android_hardware_buffer;
|
|
||||||
|
|
||||||
const struct VkImportAndroidHardwareBufferInfoANDROID import_info = {
|
const struct VkImportAndroidHardwareBufferInfoANDROID import_info = {
|
||||||
.buffer = mem->android_hardware_buffer,
|
.buffer = mem->android_hardware_buffer,
|
||||||
};
|
};
|
||||||
|
@@ -385,48 +385,8 @@ anv_create_ahw_memory(VkDevice device_h,
|
|||||||
const VkMemoryAllocateInfo *pAllocateInfo)
|
const VkMemoryAllocateInfo *pAllocateInfo)
|
||||||
{
|
{
|
||||||
#if ANDROID_API_LEVEL >= 26
|
#if ANDROID_API_LEVEL >= 26
|
||||||
const VkMemoryDedicatedAllocateInfo *dedicated_info =
|
struct AHardwareBuffer *ahw = vk_alloc_ahardware_buffer(pAllocateInfo);
|
||||||
vk_find_struct_const(pAllocateInfo->pNext,
|
if (ahw == NULL)
|
||||||
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) {
|
|
||||||
ANV_FROM_HANDLE(anv_image, image, dedicated_info->image);
|
|
||||||
w = image->vk.extent.width;
|
|
||||||
h = image->vk.extent.height;
|
|
||||||
layers = image->vk.array_layers;
|
|
||||||
format = anv_ahw_format_for_vk_format(image->vk.format);
|
|
||||||
usage = vk_image_usage_to_ahb_usage(image->vk.create_flags,
|
|
||||||
image->vk.usage);
|
|
||||||
} else if (dedicated_info && dedicated_info->buffer) {
|
|
||||||
ANV_FROM_HANDLE(anv_buffer, buffer, dedicated_info->buffer);
|
|
||||||
w = buffer->vk.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 *ahw = NULL;
|
|
||||||
struct AHardwareBuffer_Desc desc = {
|
|
||||||
.width = w,
|
|
||||||
.height = h,
|
|
||||||
.layers = layers,
|
|
||||||
.format = format,
|
|
||||||
.usage = usage,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (AHardwareBuffer_allocate(&desc, &ahw) != 0)
|
|
||||||
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||||
|
|
||||||
const VkImportAndroidHardwareBufferInfoANDROID import_info = {
|
const VkImportAndroidHardwareBufferInfoANDROID import_info = {
|
||||||
|
@@ -384,48 +384,8 @@ anv_create_ahw_memory(VkDevice device_h,
|
|||||||
const VkMemoryAllocateInfo *pAllocateInfo)
|
const VkMemoryAllocateInfo *pAllocateInfo)
|
||||||
{
|
{
|
||||||
#if ANDROID_API_LEVEL >= 26
|
#if ANDROID_API_LEVEL >= 26
|
||||||
const VkMemoryDedicatedAllocateInfo *dedicated_info =
|
struct AHardwareBuffer *ahw = vk_alloc_ahardware_buffer(pAllocateInfo);
|
||||||
vk_find_struct_const(pAllocateInfo->pNext,
|
if (ahw == NULL)
|
||||||
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) {
|
|
||||||
ANV_FROM_HANDLE(anv_image, image, dedicated_info->image);
|
|
||||||
w = image->vk.extent.width;
|
|
||||||
h = image->vk.extent.height;
|
|
||||||
layers = image->vk.array_layers;
|
|
||||||
format = anv_ahw_format_for_vk_format(image->vk.format);
|
|
||||||
usage = vk_image_usage_to_ahb_usage(image->vk.create_flags,
|
|
||||||
image->vk.usage);
|
|
||||||
} else if (dedicated_info && dedicated_info->buffer) {
|
|
||||||
ANV_FROM_HANDLE(anv_buffer, buffer, dedicated_info->buffer);
|
|
||||||
w = buffer->vk.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 *ahw = NULL;
|
|
||||||
struct AHardwareBuffer_Desc desc = {
|
|
||||||
.width = w,
|
|
||||||
.height = h,
|
|
||||||
.layers = layers,
|
|
||||||
.format = format,
|
|
||||||
.usage = usage,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (AHardwareBuffer_allocate(&desc, &ahw) != 0)
|
|
||||||
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||||
|
|
||||||
const VkImportAndroidHardwareBufferInfoANDROID import_info = {
|
const VkImportAndroidHardwareBufferInfoANDROID import_info = {
|
||||||
|
@@ -23,13 +23,22 @@
|
|||||||
|
|
||||||
#include "vk_android.h"
|
#include "vk_android.h"
|
||||||
|
|
||||||
|
#include "vk_buffer.h"
|
||||||
#include "vk_common_entrypoints.h"
|
#include "vk_common_entrypoints.h"
|
||||||
#include "vk_device.h"
|
#include "vk_device.h"
|
||||||
|
#include "vk_image.h"
|
||||||
#include "vk_log.h"
|
#include "vk_log.h"
|
||||||
#include "vk_queue.h"
|
#include "vk_queue.h"
|
||||||
|
#include "vk_util.h"
|
||||||
|
|
||||||
#include "util/libsync.h"
|
#include "util/libsync.h"
|
||||||
|
|
||||||
|
#include <hardware/gralloc.h>
|
||||||
|
|
||||||
|
#if ANDROID_API_LEVEL >= 26
|
||||||
|
#include <hardware/gralloc1.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#if ANDROID_API_LEVEL >= 26
|
#if ANDROID_API_LEVEL >= 26
|
||||||
@@ -84,7 +93,61 @@ vk_image_usage_to_ahb_usage(const VkImageCreateFlags vk_create,
|
|||||||
if (ahb_usage == 0)
|
if (ahb_usage == 0)
|
||||||
ahb_usage = AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE;
|
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 */
|
#endif /* ANDROID_API_LEVEL >= 26 */
|
||||||
|
|
||||||
|
@@ -32,6 +32,9 @@ extern "C" {
|
|||||||
#if ANDROID_API_LEVEL >= 26
|
#if ANDROID_API_LEVEL >= 26
|
||||||
uint64_t vk_image_usage_to_ahb_usage(const VkImageCreateFlags vk_create,
|
uint64_t vk_image_usage_to_ahb_usage(const VkImageCreateFlags vk_create,
|
||||||
const VkImageUsageFlags vk_usage);
|
const VkImageUsageFlags vk_usage);
|
||||||
|
|
||||||
|
struct AHardwareBuffer *
|
||||||
|
vk_alloc_ahardware_buffer(const VkMemoryAllocateInfo *pAllocateInfo);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
Reference in New Issue
Block a user