anv/android: Fix size check for imported gralloc bo

1. Don't compare bo->size to image->size. An upcoming patch replaces
anv_image::size with complicated stuff. Instead, properly query the
required size with anv_GetImageMemoryRequirements.

2. Require the bo to fit the *aligned* image size.

Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8097>
This commit is contained in:
Chad Versace 2021-02-05 12:07:08 -08:00 committed by chadversary
parent 449df3808f
commit 3e6d3bca1d
1 changed files with 17 additions and 2 deletions

View File

@ -511,11 +511,26 @@ anv_image_from_gralloc(VkDevice device_h,
if (result != VK_SUCCESS)
goto fail_create;
if (bo->size < image->size) {
VkImageMemoryRequirementsInfo2 mem_reqs_info = {
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2,
.image = image_h,
};
VkMemoryRequirements2 mem_reqs = {
.sType = VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2,
};
anv_GetImageMemoryRequirements2(_device, &mem_reqs_info, &mem_reqs);
VkDeviceSize aligned_image_size =
align_u64(mem_reqs.memoryRequirements.size,
mem_reqs.memoryRequirements.alignment);
if (bo->size < aligned_image_size) {
result = vk_errorf(device, device, VK_ERROR_INVALID_EXTERNAL_HANDLE,
"dma-buf from VkNativeBufferANDROID is too small for "
"VkImage: %"PRIu64"B < %"PRIu64"B",
bo->size, image->size);
bo->size, aligned_image_size);
goto fail_size;
}