diff --git a/src/intel/vulkan/anv_android.c b/src/intel/vulkan/anv_android.c index c0d501562b8..94d6b715e6a 100644 --- a/src/intel/vulkan/anv_android.c +++ b/src/intel/vulkan/anv_android.c @@ -316,6 +316,30 @@ anv_import_ahw_memory(VkDevice device_h, #endif } +VkResult +anv_android_get_tiling(struct anv_device *device, + struct u_gralloc_buffer_handle *gr_handle, + enum isl_tiling *tiling_out) +{ + assert(device->u_gralloc); + + struct u_gralloc_buffer_basic_info buf_info; + if (u_gralloc_get_buffer_basic_info(device->u_gralloc, gr_handle, &buf_info)) + return vk_errorf(device, VK_ERROR_INVALID_EXTERNAL_HANDLE, + "failed to get tiling from gralloc buffer info"); + + const struct isl_drm_modifier_info *mod_info = + isl_drm_modifier_get_info(buf_info.modifier); + if (!mod_info) { + return vk_errorf(device, VK_ERROR_INVALID_EXTERNAL_HANDLE, + "invalid drm modifier from VkNativeBufferANDROID " + "gralloc buffer info 0x%"PRIx64"", buf_info.modifier); + } + + *tiling_out = mod_info->tiling; + return VK_SUCCESS; +} + VkResult anv_image_init_from_gralloc(struct anv_device *device, struct anv_image *image, @@ -352,21 +376,14 @@ anv_image_init_from_gralloc(struct anv_device *device, enum isl_tiling tiling; if (device->u_gralloc) { - struct u_gralloc_buffer_basic_info buf_info; struct u_gralloc_buffer_handle gr_handle = { .handle = gralloc_info->handle, .hal_format = gralloc_info->format, .pixel_stride = gralloc_info->stride, }; - u_gralloc_get_buffer_basic_info(device->u_gralloc, &gr_handle, &buf_info); - const struct isl_drm_modifier_info *mod_info = - isl_drm_modifier_get_info(buf_info.modifier); - if (mod_info) { - tiling = mod_info->tiling; - } else { - return vk_errorf(device, VK_ERROR_INVALID_EXTERNAL_HANDLE, - "unknown modifier of BO from VkNativeBufferANDROID"); - } + result = anv_android_get_tiling(device, &gr_handle, &tiling); + if (result != VK_SUCCESS) + return result; } else { /* Fallback to get_tiling API. */ result = anv_device_get_bo_tiling(device, bo, &tiling); diff --git a/src/intel/vulkan/anv_android.h b/src/intel/vulkan/anv_android.h index e1f099e1f4f..6eeff850723 100644 --- a/src/intel/vulkan/anv_android.h +++ b/src/intel/vulkan/anv_android.h @@ -34,6 +34,13 @@ struct anv_device_memory; struct anv_device; struct anv_image; +struct u_gralloc_buffer_handle; +enum isl_tiling; + +VkResult +anv_android_get_tiling(struct anv_device *device, + struct u_gralloc_buffer_handle *gr_handle, + enum isl_tiling *tiling_out); VkResult anv_image_init_from_gralloc(struct anv_device *device, struct anv_image *image, diff --git a/src/intel/vulkan/anv_android_stubs.c b/src/intel/vulkan/anv_android_stubs.c index f1b2ef6b6f8..1c095e0aa82 100644 --- a/src/intel/vulkan/anv_android_stubs.c +++ b/src/intel/vulkan/anv_android_stubs.c @@ -23,6 +23,14 @@ #include "anv_android.h" +VkResult +anv_android_get_tiling(struct anv_device *device, + struct u_gralloc_buffer_handle *gr_handle, + enum isl_tiling *tiling_out) +{ + return VK_ERROR_EXTENSION_NOT_PRESENT; +} + VkResult anv_image_init_from_gralloc(struct anv_device *device, struct anv_image *image, diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c index 6ead10079b2..cbadc914626 100644 --- a/src/intel/vulkan/anv_image.c +++ b/src/intel/vulkan/anv_image.c @@ -1928,7 +1928,14 @@ resolve_ahw_image(struct anv_device *device, /* Check tiling. */ enum isl_tiling tiling; - result = anv_device_get_bo_tiling(device, mem->bo, &tiling); + const native_handle_t *handle = + AHardwareBuffer_getNativeHandle(mem->vk.ahardware_buffer); + struct u_gralloc_buffer_handle gr_handle = { + .handle = handle, + .hal_format = desc.format, + .pixel_stride = desc.stride, + }; + result = anv_android_get_tiling(device, &gr_handle, &tiling); assert(result == VK_SUCCESS); isl_tiling_flags_t isl_tiling_flags = (1u << tiling);