mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-07 07:08:04 +02:00
venus: refactor vn_android_image_from_anb
Drop redundant codes. Add sufficient error logs on the wsi image creation path. Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29864>
This commit is contained in:
parent
4db32ac7ef
commit
f2c1931010
2 changed files with 42 additions and 65 deletions
|
|
@ -507,23 +507,8 @@ vn_android_image_from_anb(struct vn_device *dev,
|
||||||
* VK_EXT_image_drm_format_modifier support in the host driver. The struct
|
* VK_EXT_image_drm_format_modifier support in the host driver. The struct
|
||||||
* needs host storage info which can be queried from cros gralloc.
|
* needs host storage info which can be queried from cros gralloc.
|
||||||
*/
|
*/
|
||||||
VkResult result = VK_SUCCESS;
|
|
||||||
VkDevice device = vn_device_to_handle(dev);
|
|
||||||
VkDeviceMemory memory = VK_NULL_HANDLE;
|
|
||||||
VkImage image = VK_NULL_HANDLE;
|
|
||||||
struct vn_image *img = NULL;
|
struct vn_image *img = NULL;
|
||||||
uint64_t alloc_size = 0;
|
VkResult result;
|
||||||
uint32_t mem_type_bits = 0;
|
|
||||||
int dma_buf_fd = -1;
|
|
||||||
int dup_fd = -1;
|
|
||||||
VkImageCreateInfo local_create_info;
|
|
||||||
struct vn_android_image_builder builder;
|
|
||||||
|
|
||||||
dma_buf_fd = vn_android_gralloc_get_dma_buf_fd(anb_info->handle);
|
|
||||||
if (dma_buf_fd < 0) {
|
|
||||||
result = VK_ERROR_INVALID_EXTERNAL_HANDLE;
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(!(create_info->flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT));
|
assert(!(create_info->flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT));
|
||||||
assert(!vk_find_struct_const(create_info->pNext,
|
assert(!vk_find_struct_const(create_info->pNext,
|
||||||
|
|
@ -531,64 +516,56 @@ vn_android_image_from_anb(struct vn_device *dev,
|
||||||
assert(!vk_find_struct_const(create_info->pNext,
|
assert(!vk_find_struct_const(create_info->pNext,
|
||||||
IMAGE_STENCIL_USAGE_CREATE_INFO));
|
IMAGE_STENCIL_USAGE_CREATE_INFO));
|
||||||
|
|
||||||
/* strip VkNativeBufferANDROID and VkSwapchainImageCreateInfoANDROID */
|
struct vn_android_image_builder builder;
|
||||||
local_create_info = *create_info;
|
result = vn_android_get_image_builder(dev, create_info, anb_info->handle,
|
||||||
local_create_info.pNext = NULL;
|
&builder);
|
||||||
result = vn_android_get_image_builder(dev, &local_create_info,
|
|
||||||
anb_info->handle, &builder);
|
|
||||||
if (result != VK_SUCCESS)
|
if (result != VK_SUCCESS)
|
||||||
goto fail;
|
return result;
|
||||||
|
|
||||||
/* encoder will strip the Android specific pNext structs */
|
/* encoder will strip the Android specific pNext structs */
|
||||||
result = vn_image_create(dev, &builder.create, alloc, &img);
|
result = vn_image_create(dev, &builder.create, alloc, &img);
|
||||||
if (result != VK_SUCCESS) {
|
if (result != VK_SUCCESS) {
|
||||||
if (VN_DEBUG(WSI))
|
vn_log(dev->instance, "anb: vn_image_create failed");
|
||||||
vn_log(dev->instance, "vn_image_create failed");
|
return result;
|
||||||
goto fail;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
image = vn_image_to_handle(img);
|
img->wsi.is_wsi = true;
|
||||||
|
img->wsi.tiling_override = builder.create.tiling;
|
||||||
|
img->wsi.drm_format_modifier = builder.modifier.drmFormatModifier;
|
||||||
|
|
||||||
const VkMemoryRequirements *mem_req =
|
int dma_buf_fd = vn_android_gralloc_get_dma_buf_fd(anb_info->handle);
|
||||||
&img->requirements[0].memory.memoryRequirements;
|
if (dma_buf_fd < 0) {
|
||||||
if (!mem_req->memoryTypeBits) {
|
|
||||||
if (VN_DEBUG(WSI))
|
|
||||||
vn_log(dev->instance, "mem_req->memoryTypeBits cannot be zero");
|
|
||||||
result = VK_ERROR_INVALID_EXTERNAL_HANDLE;
|
result = VK_ERROR_INVALID_EXTERNAL_HANDLE;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t alloc_size = 0;
|
||||||
|
uint32_t mem_type_bits = 0;
|
||||||
result = vn_get_memory_dma_buf_properties(dev, dma_buf_fd, &alloc_size,
|
result = vn_get_memory_dma_buf_properties(dev, dma_buf_fd, &alloc_size,
|
||||||
&mem_type_bits);
|
&mem_type_bits);
|
||||||
if (result != VK_SUCCESS)
|
if (result != VK_SUCCESS)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
if (VN_DEBUG(WSI)) {
|
const VkMemoryRequirements *mem_req =
|
||||||
vn_log(dev->instance,
|
&img->requirements[0].memory.memoryRequirements;
|
||||||
"size = img(%" PRIu64 ") fd(%" PRIu64 "), "
|
|
||||||
"memoryTypeBits = img(0x%X) & fd(0x%X)",
|
|
||||||
mem_req->size, alloc_size, mem_req->memoryTypeBits,
|
|
||||||
mem_type_bits);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (alloc_size < mem_req->size) {
|
if (alloc_size < mem_req->size) {
|
||||||
if (VN_DEBUG(WSI)) {
|
vn_log(dev->instance,
|
||||||
vn_log(dev->instance,
|
"anb: alloc_size(%" PRIu64 ") mem_req->size(%" PRIu64 ")",
|
||||||
"alloc_size(%" PRIu64 ") mem_req->size(%" PRIu64 ")",
|
alloc_size, mem_req->size);
|
||||||
alloc_size, mem_req->size);
|
|
||||||
}
|
|
||||||
result = VK_ERROR_INVALID_EXTERNAL_HANDLE;
|
result = VK_ERROR_INVALID_EXTERNAL_HANDLE;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
mem_type_bits &= mem_req->memoryTypeBits;
|
mem_type_bits &= mem_req->memoryTypeBits;
|
||||||
if (!mem_type_bits) {
|
if (!mem_type_bits) {
|
||||||
|
vn_log(dev->instance, "anb: no compatible mem type");
|
||||||
result = VK_ERROR_INVALID_EXTERNAL_HANDLE;
|
result = VK_ERROR_INVALID_EXTERNAL_HANDLE;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
dup_fd = os_dupfd_cloexec(dma_buf_fd);
|
int dup_fd = os_dupfd_cloexec(dma_buf_fd);
|
||||||
if (dup_fd < 0) {
|
if (dup_fd < 0) {
|
||||||
|
vn_log(dev->instance, "anb: os_dupfd_cloexec failed(%d)", errno);
|
||||||
result = (errno == EMFILE) ? VK_ERROR_TOO_MANY_OBJECTS
|
result = (errno == EMFILE) ? VK_ERROR_TOO_MANY_OBJECTS
|
||||||
: VK_ERROR_OUT_OF_HOST_MEMORY;
|
: VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
@ -596,7 +573,6 @@ vn_android_image_from_anb(struct vn_device *dev,
|
||||||
|
|
||||||
const VkImportMemoryFdInfoKHR import_fd_info = {
|
const VkImportMemoryFdInfoKHR import_fd_info = {
|
||||||
.sType = VK_STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO_KHR,
|
.sType = VK_STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO_KHR,
|
||||||
.pNext = NULL,
|
|
||||||
.handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT,
|
.handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT,
|
||||||
.fd = dup_fd,
|
.fd = dup_fd,
|
||||||
};
|
};
|
||||||
|
|
@ -606,40 +582,37 @@ vn_android_image_from_anb(struct vn_device *dev,
|
||||||
.allocationSize = mem_req->size,
|
.allocationSize = mem_req->size,
|
||||||
.memoryTypeIndex = ffs(mem_type_bits) - 1,
|
.memoryTypeIndex = ffs(mem_type_bits) - 1,
|
||||||
};
|
};
|
||||||
result = vn_AllocateMemory(device, &memory_info, alloc, &memory);
|
VkDeviceMemory mem_handle;
|
||||||
|
result = vn_AllocateMemory(vn_device_to_handle(dev), &memory_info, alloc,
|
||||||
|
&mem_handle);
|
||||||
if (result != VK_SUCCESS) {
|
if (result != VK_SUCCESS) {
|
||||||
|
vn_log(dev->instance, "anb: mem import failed");
|
||||||
/* only need to close the dup_fd on import failure */
|
/* only need to close the dup_fd on import failure */
|
||||||
close(dup_fd);
|
close(dup_fd);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Android WSI image owns the memory */
|
||||||
|
img->wsi.memory = vn_device_memory_from_handle(mem_handle);
|
||||||
|
img->wsi.memory_owned = true;
|
||||||
|
|
||||||
const VkBindImageMemoryInfo bind_info = {
|
const VkBindImageMemoryInfo bind_info = {
|
||||||
.sType = VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_INFO,
|
.sType = VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_INFO,
|
||||||
.pNext = NULL,
|
.image = vn_image_to_handle(img),
|
||||||
.image = image,
|
.memory = vn_device_memory_to_handle(img->wsi.memory),
|
||||||
.memory = memory,
|
|
||||||
.memoryOffset = 0,
|
|
||||||
};
|
};
|
||||||
result = vn_BindImageMemory2(device, 1, &bind_info);
|
result = vn_BindImageMemory2(vn_device_to_handle(dev), 1, &bind_info);
|
||||||
if (result != VK_SUCCESS)
|
if (result != VK_SUCCESS)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
img->wsi.is_wsi = true;
|
|
||||||
img->wsi.tiling_override = builder.create.tiling;
|
|
||||||
img->wsi.drm_format_modifier = builder.modifier.drmFormatModifier;
|
|
||||||
/* Android WSI image owns the memory */
|
|
||||||
img->wsi.memory = vn_device_memory_from_handle(memory);
|
|
||||||
img->wsi.memory_owned = true;
|
|
||||||
*out_img = img;
|
*out_img = img;
|
||||||
|
|
||||||
return VK_SUCCESS;
|
return VK_SUCCESS;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
if (image != VK_NULL_HANDLE)
|
/* this handles mem free for owned import */
|
||||||
vn_DestroyImage(device, image, alloc);
|
vn_DestroyImage(vn_device_to_handle(dev), vn_image_to_handle(img), alloc);
|
||||||
if (memory != VK_NULL_HANDLE)
|
return result;
|
||||||
vn_FreeMemory(device, memory, alloc);
|
|
||||||
return vn_error(dev->instance, result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static VkResult
|
static VkResult
|
||||||
|
|
|
||||||
|
|
@ -589,8 +589,10 @@ vn_get_memory_dma_buf_properties(struct vn_device *dev,
|
||||||
struct vn_renderer_bo *bo;
|
struct vn_renderer_bo *bo;
|
||||||
VkResult result = vn_renderer_bo_create_from_dma_buf(
|
VkResult result = vn_renderer_bo_create_from_dma_buf(
|
||||||
dev->renderer, 0 /* size */, fd, 0 /* flags */, &bo);
|
dev->renderer, 0 /* size */, fd, 0 /* flags */, &bo);
|
||||||
if (result != VK_SUCCESS)
|
if (result != VK_SUCCESS) {
|
||||||
|
vn_log(dev->instance, "bo_create_from_dma_buf failed");
|
||||||
return result;
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
vn_ring_roundtrip(dev->primary_ring);
|
vn_ring_roundtrip(dev->primary_ring);
|
||||||
|
|
||||||
|
|
@ -605,8 +607,10 @@ vn_get_memory_dma_buf_properties(struct vn_device *dev,
|
||||||
result = vn_call_vkGetMemoryResourcePropertiesMESA(
|
result = vn_call_vkGetMemoryResourcePropertiesMESA(
|
||||||
dev->primary_ring, device, bo->res_id, &props);
|
dev->primary_ring, device, bo->res_id, &props);
|
||||||
vn_renderer_bo_unref(dev->renderer, bo);
|
vn_renderer_bo_unref(dev->renderer, bo);
|
||||||
if (result != VK_SUCCESS)
|
if (result != VK_SUCCESS) {
|
||||||
|
vn_log(dev->instance, "vkGetMemoryResourcePropertiesMESA failed");
|
||||||
return result;
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
*out_alloc_size = alloc_size_props.allocationSize;
|
*out_alloc_size = alloc_size_props.allocationSize;
|
||||||
*out_mem_type_bits = props.memoryTypeBits;
|
*out_mem_type_bits = props.memoryTypeBits;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue