summaryrefslogtreecommitdiffstats
path: root/src/intel/vulkan/anv_device.c
diff options
context:
space:
mode:
authorTapani Pälli <[email protected]>2018-11-08 10:20:35 +0200
committerTapani Pälli <[email protected]>2018-12-19 09:38:41 +0200
commitc79a528d2b58dfa6f3d856271cbf29697a5322a1 (patch)
tree2f685992a3e78e96671c7a55c71858f8f5c5189a /src/intel/vulkan/anv_device.c
parent5c65c60d6c9120b2704e8767f3381faef97c4052 (diff)
anv/android: support import/export of AHardwareBuffer objects
v2: add support for non-image buffers (AHARDWAREBUFFER_FORMAT_BLOB) v3: properly handle usage bits when creating from image v4: refactor, code cleanup (Jason) v5: rebase to b43f955037c changes, initialize bo flags as ANV_BO_EXTERNAL (Lionel) v6: add assert that anv_bo_cache_import succeeds, add comment about multi-bo support to clarify current implementation (Lionel) Signed-off-by: Tapani Pälli <[email protected]> Reviewed-by: Lionel Landwerlin <[email protected]>
Diffstat (limited to 'src/intel/vulkan/anv_device.c')
-rw-r--r--src/intel/vulkan/anv_device.c45
1 files changed, 43 insertions, 2 deletions
diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index fb824d3ca43..fa3a8a417b9 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -2268,6 +2268,7 @@ VkResult anv_AllocateMemory(
mem->type = &pdevice->memory.types[pAllocateInfo->memoryTypeIndex];
mem->map = NULL;
mem->map_size = 0;
+ mem->ahw = NULL;
uint64_t bo_flags = 0;
@@ -2290,6 +2291,43 @@ VkResult anv_AllocateMemory(
if (pdevice->use_softpin)
bo_flags |= EXEC_OBJECT_PINNED;
+ const VkExportMemoryAllocateInfo *export_info =
+ vk_find_struct_const(pAllocateInfo->pNext, EXPORT_MEMORY_ALLOCATE_INFO);
+
+ /* Check if we need to support Android HW buffer export. If so,
+ * create AHardwareBuffer and import memory from it.
+ */
+ bool android_export = false;
+ if (export_info && export_info->handleTypes &
+ VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID)
+ android_export = true;
+
+ /* Android memory import. */
+ const struct VkImportAndroidHardwareBufferInfoANDROID *ahw_import_info =
+ vk_find_struct_const(pAllocateInfo->pNext,
+ IMPORT_ANDROID_HARDWARE_BUFFER_INFO_ANDROID);
+
+ if (ahw_import_info) {
+ result = anv_import_ahw_memory(_device, mem, ahw_import_info);
+ if (result != VK_SUCCESS)
+ goto fail;
+
+ goto success;
+ } else if (android_export) {
+ result = anv_create_ahw_memory(_device, mem, pAllocateInfo);
+ if (result != VK_SUCCESS)
+ goto fail;
+
+ const struct VkImportAndroidHardwareBufferInfoANDROID import_info = {
+ .buffer = mem->ahw,
+ };
+ result = anv_import_ahw_memory(_device, mem, &import_info);
+ if (result != VK_SUCCESS)
+ goto fail;
+
+ goto success;
+ }
+
const VkImportMemoryFdInfoKHR *fd_info =
vk_find_struct_const(pAllocateInfo->pNext, IMPORT_MEMORY_FD_INFO_KHR);
@@ -2345,8 +2383,6 @@ VkResult anv_AllocateMemory(
/* Regular allocate (not importing memory). */
- const VkExportMemoryAllocateInfoKHR *export_info =
- vk_find_struct_const(pAllocateInfo->pNext, EXPORT_MEMORY_ALLOCATE_INFO_KHR);
if (export_info && export_info->handleTypes)
bo_flags |= ANV_BO_EXTERNAL;
@@ -2450,6 +2486,11 @@ void anv_FreeMemory(
anv_bo_cache_release(device, &device->bo_cache, mem->bo);
+#ifdef ANDROID
+ if (mem->ahw)
+ AHardwareBuffer_release(mem->ahw);
+#endif
+
vk_free2(&device->alloc, pAllocator, mem);
}