anv: And a new function to consolidate import paths

The new added function will be invoked on several paths
of importing Android native and hardware buffers.

Signed-off-by: Jianxun Zhang <jianxun.zhang@intel.com>
Reviewed-by: Ryan Neph <ryanneph@google.com>
Reviewed-by: Nanley Chery <nanley.g.chery@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36825>
This commit is contained in:
Jianxun Zhang 2025-09-16 14:39:40 -07:00
parent 4b63535d3c
commit fa8f98138a
3 changed files with 49 additions and 0 deletions

View file

@ -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.
*/

View file

@ -33,12 +33,18 @@
#include <vulkan/vulkan_android.h>
#include <vulkan/vk_android_native_buffer.h>
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,

View file

@ -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;
}