Skip to content

Commit

Permalink
anv/android: refactor out u_gralloc tiling query
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Tapani Pälli <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29850>
  • Loading branch information
juston-li authored and Marge Bot committed Aug 5, 2024
1 parent 0e27df4 commit bcb17ac
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 11 deletions.
37 changes: 27 additions & 10 deletions src/intel/vulkan/anv_android.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions src/intel/vulkan/anv_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions src/intel/vulkan/anv_android_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 8 additions & 1 deletion src/intel/vulkan/anv_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit bcb17ac

Please sign in to comment.