anv/android: refactor out u_gralloc tiling query
Refactor out shared code for the u_gralloc tiling query so it can also be used by ahw and later anb resolves. Signed-off-by: Juston Li <justonli@google.com> Reviewed-by: Tapani Pälli <tapani.palli@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29850>
This commit is contained in:
@@ -317,6 +317,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,
|
||||
@@ -353,21 +377,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);
|
||||
|
||||
@@ -36,6 +36,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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -1985,7 +1985,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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user