mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-27 04:00:10 +01:00
venus: prepare image creation helpers for AHB
Store image create info for deferred creation of AHB image. Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org> Reviewed-by: Chia-I Wu <olvaffe@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10960>
This commit is contained in:
parent
53e35f716e
commit
19b7b09885
2 changed files with 130 additions and 9 deletions
|
|
@ -244,32 +244,129 @@ vn_image_init_memory_requirements(struct vn_image *img,
|
|||
}
|
||||
}
|
||||
|
||||
static VkResult
|
||||
vn_image_store_deferred_create_info(
|
||||
const VkImageCreateInfo *create_info,
|
||||
const VkAllocationCallbacks *alloc,
|
||||
struct vn_image_create_deferred_info **out_info)
|
||||
{
|
||||
struct vn_image_create_deferred_info *info = NULL;
|
||||
VkBaseOutStructure *dst = NULL;
|
||||
|
||||
info = vk_zalloc(alloc, sizeof(*info), VN_DEFAULT_ALIGN,
|
||||
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
|
||||
if (!info)
|
||||
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
|
||||
info->create = *create_info;
|
||||
dst = (void *)&info->create;
|
||||
|
||||
vk_foreach_struct_const(src, create_info->pNext) {
|
||||
void *pnext = NULL;
|
||||
switch (src->sType) {
|
||||
case VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO:
|
||||
memcpy(&info->list, src, sizeof(info->list));
|
||||
pnext = &info->list;
|
||||
break;
|
||||
case VK_STRUCTURE_TYPE_IMAGE_STENCIL_USAGE_CREATE_INFO:
|
||||
memcpy(&info->stencil, src, sizeof(info->stencil));
|
||||
pnext = &info->stencil;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (pnext) {
|
||||
dst->pNext = pnext;
|
||||
dst = pnext;
|
||||
}
|
||||
}
|
||||
dst->pNext = NULL;
|
||||
|
||||
*out_info = info;
|
||||
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
static VkResult
|
||||
vn_image_init(struct vn_device *dev,
|
||||
const VkImageCreateInfo *create_info,
|
||||
struct vn_image *img)
|
||||
{
|
||||
VkDevice device = vn_device_to_handle(dev);
|
||||
VkImage image = vn_image_to_handle(img);
|
||||
VkResult result = VK_SUCCESS;
|
||||
|
||||
/* TODO async */
|
||||
result =
|
||||
vn_call_vkCreateImage(dev->instance, device, create_info, NULL, &image);
|
||||
if (result != VK_SUCCESS)
|
||||
return result;
|
||||
|
||||
vn_image_init_memory_requirements(img, dev, create_info);
|
||||
|
||||
img->sharing_mode = create_info->sharingMode;
|
||||
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
VkResult
|
||||
vn_image_create(struct vn_device *dev,
|
||||
const VkImageCreateInfo *create_info,
|
||||
const VkAllocationCallbacks *alloc,
|
||||
struct vn_image **out_img)
|
||||
{
|
||||
struct vn_image *img = vk_zalloc(alloc, sizeof(*img), VN_DEFAULT_ALIGN,
|
||||
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
|
||||
struct vn_image *img = NULL;
|
||||
VkResult result = VK_SUCCESS;
|
||||
|
||||
img = vk_zalloc(alloc, sizeof(*img), VN_DEFAULT_ALIGN,
|
||||
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
|
||||
if (!img)
|
||||
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
|
||||
vn_object_base_init(&img->base, VK_OBJECT_TYPE_IMAGE, &dev->base);
|
||||
|
||||
VkDevice dev_handle = vn_device_to_handle(dev);
|
||||
VkImage img_handle = vn_image_to_handle(img);
|
||||
/* TODO async */
|
||||
VkResult result = vn_call_vkCreateImage(dev->instance, dev_handle,
|
||||
create_info, NULL, &img_handle);
|
||||
result = vn_image_init(dev, create_info, img);
|
||||
if (result != VK_SUCCESS) {
|
||||
vk_free(alloc, img);
|
||||
return result;
|
||||
}
|
||||
|
||||
vn_image_init_memory_requirements(img, dev, create_info);
|
||||
*out_img = img;
|
||||
|
||||
img->sharing_mode = create_info->sharingMode;
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
VkResult
|
||||
vn_image_init_deferred(struct vn_device *dev,
|
||||
const VkImageCreateInfo *create_info,
|
||||
struct vn_image *img)
|
||||
{
|
||||
return vn_image_init(dev, create_info, img);
|
||||
}
|
||||
|
||||
VkResult
|
||||
vn_image_create_deferred(struct vn_device *dev,
|
||||
const VkImageCreateInfo *create_info,
|
||||
const VkAllocationCallbacks *alloc,
|
||||
struct vn_image **out_img)
|
||||
{
|
||||
struct vn_image *img = NULL;
|
||||
VkResult result = VK_SUCCESS;
|
||||
|
||||
img = vk_zalloc(alloc, sizeof(*img), VN_DEFAULT_ALIGN,
|
||||
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
|
||||
if (!img)
|
||||
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
|
||||
vn_object_base_init(&img->base, VK_OBJECT_TYPE_IMAGE, &dev->base);
|
||||
|
||||
result = vn_image_store_deferred_create_info(create_info, alloc,
|
||||
&img->deferred_info);
|
||||
if (result != VK_SUCCESS) {
|
||||
vk_free(alloc, img);
|
||||
return result;
|
||||
}
|
||||
|
||||
*out_img = img;
|
||||
|
||||
|
|
@ -332,6 +429,9 @@ vn_DestroyImage(VkDevice device,
|
|||
|
||||
vn_async_vkDestroyImage(dev->instance, device, image, NULL);
|
||||
|
||||
if (img->deferred_info)
|
||||
vk_free(alloc, img->deferred_info);
|
||||
|
||||
vn_object_base_fini(&img->base);
|
||||
vk_free(alloc, img);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,12 @@ struct vn_image_ownership_cmds {
|
|||
VkCommandBuffer cmds[2];
|
||||
};
|
||||
|
||||
struct vn_image_create_deferred_info {
|
||||
VkImageCreateInfo create;
|
||||
VkImageFormatListCreateInfo list;
|
||||
VkImageStencilUsageCreateInfo stencil;
|
||||
};
|
||||
|
||||
struct vn_image {
|
||||
struct vn_object_base base;
|
||||
|
||||
|
|
@ -29,6 +35,10 @@ struct vn_image {
|
|||
VkMemoryDedicatedRequirements dedicated_requirements[4];
|
||||
/* For VK_ANDROID_native_buffer, the WSI image owns the memory, */
|
||||
VkDeviceMemory private_memory;
|
||||
/* For VK_ANDROID_external_memory_android_hardware_buffer, real image
|
||||
* creation is deferred until bind image memory.
|
||||
*/
|
||||
struct vn_image_create_deferred_info *deferred_info;
|
||||
/* For queue family ownership transfer of WSI images */
|
||||
VkSharingMode sharing_mode;
|
||||
struct vn_image_ownership_cmds *ownership_cmds;
|
||||
|
|
@ -69,6 +79,17 @@ vn_image_create(struct vn_device *dev,
|
|||
const VkAllocationCallbacks *alloc,
|
||||
struct vn_image **out_img);
|
||||
|
||||
VkResult
|
||||
vn_image_init_deferred(struct vn_device *dev,
|
||||
const VkImageCreateInfo *create_info,
|
||||
struct vn_image *img);
|
||||
|
||||
VkResult
|
||||
vn_image_create_deferred(struct vn_device *dev,
|
||||
const VkImageCreateInfo *create_info,
|
||||
const VkAllocationCallbacks *alloc,
|
||||
struct vn_image **out_img);
|
||||
|
||||
VkResult
|
||||
vn_image_android_wsi_init(struct vn_device *dev,
|
||||
struct vn_image *img,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue