diff --git a/src/intel/vulkan/anv_android.c b/src/intel/vulkan/anv_android.c index 3dec9025219..8083af29ad6 100644 --- a/src/intel/vulkan/anv_android.c +++ b/src/intel/vulkan/anv_android.c @@ -23,6 +23,40 @@ #include "anv_private.h" +VkResult +anv_android_import_from_handle(struct anv_device *device, + const buffer_handle_t handle, + uint64_t modifier, + struct anv_bo **bo_out) +{ + /* NOTE - We support buffers with only one handle but do not error on + * multiple handle case. Reason is that we want to support YUV formats + * where we have many logical planes but they all point to the same + * buffer, like is the case with VK_FORMAT_G8_B8R8_2PLANE_420_UNORM. + * + * Do not close the gralloc handle's dma_buf. The lifetime of the dma_buf + * must exceed that of the gralloc handle, and we do not own the gralloc + * handle. + */ + int dma_buf = (handle && handle->numFds) ? handle->data[0] : -1; + if (dma_buf < 0) + return VK_ERROR_INVALID_EXTERNAL_HANDLE; + + enum anv_bo_alloc_flags alloc_flags = ANV_BO_ALLOC_EXTERNAL; + if (device->info->ver >= 20 && isl_drm_modifier_has_aux(modifier)) { + /* We always set scanout flag when importing buffers with Xe2 + * modifiers, same as the rest in anv and iris drivers. + */ + alloc_flags |= ANV_BO_ALLOC_COMPRESSED | ANV_BO_ALLOC_SCANOUT; + } + + return anv_device_import_bo(device, + dma_buf, + alloc_flags, + 0 /* client_address */, + bo_out); +} + /* * Called from anv_AllocateMemory when import AHardwareBuffer. */ diff --git a/src/intel/vulkan/anv_android.h b/src/intel/vulkan/anv_android.h index da177165415..0bd5a38fd89 100644 --- a/src/intel/vulkan/anv_android.h +++ b/src/intel/vulkan/anv_android.h @@ -33,12 +33,18 @@ #include #include +struct anv_bo; struct anv_device_memory; struct anv_device; struct anv_image; struct u_gralloc_buffer_handle; enum isl_tiling; +VkResult +anv_android_import_from_handle(struct anv_device *device, + const buffer_handle_t handle, + uint64_t modifier, + struct anv_bo **bo_out); VkResult anv_android_get_tiling(struct anv_device *device, struct u_gralloc_buffer_handle *gr_handle, diff --git a/src/intel/vulkan/anv_android_stubs.c b/src/intel/vulkan/anv_android_stubs.c index 7fcfe85fe2c..df7f9259b3e 100644 --- a/src/intel/vulkan/anv_android_stubs.c +++ b/src/intel/vulkan/anv_android_stubs.c @@ -46,3 +46,12 @@ anv_import_ahb_memory(VkDevice device_h, { return VK_ERROR_EXTENSION_NOT_PRESENT; } + +VkResult +anv_android_import_from_handle(struct anv_device *device, + const buffer_handle_t handle, + uint64_t modifier, + struct anv_bo **bo_out) +{ + return VK_ERROR_EXTENSION_NOT_PRESENT; +}