venus: implement AHB allocation and import (part 1/2)
This patch refactors the struct look up logic for memory allocation, and it prepares the necessary info for ahb allocation and import. Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org> Reviewed-by: Chia-I Wu <olvaffe@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10960>
This commit is contained in:
parent
4958ce582c
commit
1743892f24
|
@ -972,3 +972,20 @@ vn_android_image_from_ahb(struct vn_device *dev,
|
|||
|
||||
return vn_image_create_deferred(dev, create_info, alloc, out_img);
|
||||
}
|
||||
|
||||
VkResult
|
||||
vn_android_device_import_ahb(struct vn_device *dev,
|
||||
struct vn_device_memory *mem,
|
||||
const VkMemoryAllocateInfo *alloc_info,
|
||||
struct AHardwareBuffer *ahb)
|
||||
{
|
||||
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
|
||||
VkResult
|
||||
vn_android_device_allocate_ahb(struct vn_device *dev,
|
||||
struct vn_device_memory *mem,
|
||||
const VkMemoryAllocateInfo *alloc_info)
|
||||
{
|
||||
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
|
|
|
@ -67,6 +67,17 @@ vn_android_image_from_ahb(struct vn_device *dev,
|
|||
const VkAllocationCallbacks *alloc,
|
||||
struct vn_image **out_img);
|
||||
|
||||
VkResult
|
||||
vn_android_device_import_ahb(struct vn_device *dev,
|
||||
struct vn_device_memory *mem,
|
||||
const VkMemoryAllocateInfo *alloc_info,
|
||||
struct AHardwareBuffer *ahb);
|
||||
|
||||
VkResult
|
||||
vn_android_device_allocate_ahb(struct vn_device *dev,
|
||||
struct vn_device_memory *mem,
|
||||
const VkMemoryAllocateInfo *alloc_info);
|
||||
|
||||
#else
|
||||
|
||||
static inline VkResult
|
||||
|
@ -123,6 +134,23 @@ vn_android_image_from_ahb(UNUSED struct vn_device *dev,
|
|||
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
|
||||
static inline VkResult
|
||||
vn_android_device_import_ahb(UNUSED struct vn_device *dev,
|
||||
UNUSED struct vn_device_memory *mem,
|
||||
UNUSED const VkMemoryAllocateInfo *alloc_info,
|
||||
UNUSED struct AHardwareBuffer *ahb)
|
||||
{
|
||||
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
|
||||
static inline VkResult
|
||||
vn_android_device_allocate_ahb(UNUSED struct vn_device *dev,
|
||||
UNUSED struct vn_device_memory *mem,
|
||||
UNUSED const VkMemoryAllocateInfo *alloc_info)
|
||||
{
|
||||
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
|
||||
#endif /* ANDROID */
|
||||
|
||||
#endif /* VN_ANDROID_H */
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "venus-protocol/vn_protocol_driver_device_memory.h"
|
||||
#include "venus-protocol/vn_protocol_driver_transport.h"
|
||||
|
||||
#include "vn_android.h"
|
||||
#include "vn_device.h"
|
||||
|
||||
/* device memory commands */
|
||||
|
@ -235,13 +236,33 @@ vn_AllocateMemory(VkDevice device,
|
|||
&dev->physical_device->memory_properties.memoryProperties;
|
||||
const VkMemoryType *mem_type =
|
||||
&mem_props->memoryTypes[pAllocateInfo->memoryTypeIndex];
|
||||
const VkImportMemoryFdInfoKHR *import_fd_info =
|
||||
vk_find_struct_const(pAllocateInfo->pNext, IMPORT_MEMORY_FD_INFO_KHR);
|
||||
const VkExportMemoryAllocateInfo *export_info =
|
||||
vk_find_struct_const(pAllocateInfo->pNext, EXPORT_MEMORY_ALLOCATE_INFO);
|
||||
if (export_info && !export_info->handleTypes)
|
||||
export_info = NULL;
|
||||
|
||||
const VkExportMemoryAllocateInfo *export_info = NULL;
|
||||
const VkImportAndroidHardwareBufferInfoANDROID *import_ahb_info = NULL;
|
||||
const VkImportMemoryFdInfoKHR *import_fd_info = NULL;
|
||||
|
||||
vk_foreach_struct_const(pnext, pAllocateInfo->pNext) {
|
||||
switch (pnext->sType) {
|
||||
case VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO:
|
||||
export_info = (void *)pnext;
|
||||
if (!export_info->handleTypes)
|
||||
export_info = NULL;
|
||||
break;
|
||||
case VK_STRUCTURE_TYPE_IMPORT_ANDROID_HARDWARE_BUFFER_INFO_ANDROID:
|
||||
import_ahb_info = (void *)pnext;
|
||||
break;
|
||||
case VK_STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO_KHR:
|
||||
import_fd_info = (void *)pnext;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const bool export_ahb =
|
||||
export_info &&
|
||||
(export_info->handleTypes &
|
||||
VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID);
|
||||
const bool need_bo =
|
||||
(mem_type->propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) ||
|
||||
export_info;
|
||||
|
@ -261,7 +282,14 @@ vn_AllocateMemory(VkDevice device,
|
|||
|
||||
VkDeviceMemory mem_handle = vn_device_memory_to_handle(mem);
|
||||
VkResult result;
|
||||
if (import_fd_info) {
|
||||
if (import_ahb_info) {
|
||||
result = vn_android_device_import_ahb(dev, mem, pAllocateInfo,
|
||||
import_ahb_info->buffer);
|
||||
assert(mem->base_bo);
|
||||
} else if (export_ahb) {
|
||||
result = vn_android_device_allocate_ahb(dev, mem, pAllocateInfo);
|
||||
assert(mem->base_bo);
|
||||
} else if (import_fd_info) {
|
||||
result = vn_device_memory_import_dmabuf(dev, mem, pAllocateInfo,
|
||||
import_fd_info->fd);
|
||||
assert(mem->base_bo);
|
||||
|
|
Loading…
Reference in New Issue