mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-07 00:38:48 +02:00
venus: adopt vk_android_init_deferred_image
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41145>
This commit is contained in:
parent
d476c96bad
commit
61bd3fcd84
4 changed files with 18 additions and 115 deletions
|
|
@ -15,7 +15,6 @@
|
|||
|
||||
#include "util/os_file.h"
|
||||
#include "util/u_gralloc/u_gralloc.h"
|
||||
#include "vk_android.h"
|
||||
|
||||
#include "vn_buffer.h"
|
||||
#include "vn_device.h"
|
||||
|
|
@ -204,11 +203,7 @@ vn_android_get_image_builder(struct vn_device *dev,
|
|||
};
|
||||
out_builder->create.pNext = &out_builder->external;
|
||||
|
||||
/* fill VkImageFormatListCreateInfo if needed
|
||||
*
|
||||
* vn_image::deferred_info only stores VkImageFormatListCreateInfo with a
|
||||
* non-zero viewFormatCount, and that stored struct will be respected.
|
||||
*/
|
||||
/* fill VkImageFormatListCreateInfo if needed */
|
||||
if ((create_info->flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT) &&
|
||||
!vk_find_struct_const(create_info->pNext,
|
||||
IMAGE_FORMAT_LIST_CREATE_INFO)) {
|
||||
|
|
@ -388,7 +383,8 @@ vn_android_get_wsi_memory_from_bind_info(
|
|||
|
||||
struct vn_image *img = vn_image_from_handle(bind_info->image);
|
||||
VkResult result = vn_android_image_from_anb_internal(
|
||||
dev, &img->deferred_info->create, anb_info, &dev->base.vk.alloc, &img);
|
||||
dev, img->base.vk.android_deferred_create_info, anb_info,
|
||||
&dev->base.vk.alloc, &img);
|
||||
if (result != VK_SUCCESS)
|
||||
return NULL;
|
||||
|
||||
|
|
@ -423,8 +419,8 @@ vn_android_device_import_ahb(struct vn_device *dev,
|
|||
|
||||
/* If ahb is for an image, finish the deferred image creation first */
|
||||
struct vn_android_image_builder builder;
|
||||
result = vn_android_get_image_builder(dev, &img->deferred_info->create,
|
||||
handle, &builder);
|
||||
result = vn_android_get_image_builder(
|
||||
dev, img->base.vk.android_deferred_create_info, handle, &builder);
|
||||
if (result != VK_SUCCESS)
|
||||
return result;
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@
|
|||
#include <vulkan/vulkan.h>
|
||||
#include <vulkan/vulkan_android.h>
|
||||
|
||||
#include "vk_android.h"
|
||||
|
||||
#ifdef VK_USE_PLATFORM_ANDROID_KHR
|
||||
|
||||
VkResult
|
||||
|
|
|
|||
|
|
@ -350,7 +350,7 @@ vn_image_init_memory_requirements(struct vn_image *img,
|
|||
&img->requirements[0].memory);
|
||||
|
||||
/* AHB backed image requires dedicated allocation */
|
||||
if (img->deferred_info) {
|
||||
if (img->deferred) {
|
||||
img->requirements[0].dedicated.prefersDedicatedAllocation = VK_TRUE;
|
||||
img->requirements[0].dedicated.requiresDedicatedAllocation = VK_TRUE;
|
||||
}
|
||||
|
|
@ -373,93 +373,6 @@ vn_image_init_memory_requirements(struct vn_image *img,
|
|||
}
|
||||
}
|
||||
|
||||
static VkResult
|
||||
vn_image_deferred_info_init(struct vn_image *img,
|
||||
const VkImageCreateInfo *create_info,
|
||||
const VkAllocationCallbacks *alloc)
|
||||
{
|
||||
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: {
|
||||
/* 12.3. Images
|
||||
*
|
||||
* If viewFormatCount is zero, pViewFormats is ignored and the image
|
||||
* is created as if the VkImageFormatListCreateInfo structure were
|
||||
* not included in the pNext chain of VkImageCreateInfo.
|
||||
*/
|
||||
if (!((const VkImageFormatListCreateInfo *)src)->viewFormatCount)
|
||||
break;
|
||||
|
||||
memcpy(&info->list, src, sizeof(info->list));
|
||||
pnext = &info->list;
|
||||
|
||||
/* need a deep copy for view formats array */
|
||||
const size_t size = sizeof(VkFormat) * info->list.viewFormatCount;
|
||||
VkFormat *view_formats = vk_zalloc(
|
||||
alloc, size, VN_DEFAULT_ALIGN, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
|
||||
if (!view_formats) {
|
||||
vk_free(alloc, info);
|
||||
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
|
||||
memcpy(view_formats,
|
||||
((const VkImageFormatListCreateInfo *)src)->pViewFormats,
|
||||
size);
|
||||
info->list.pViewFormats = view_formats;
|
||||
break;
|
||||
}
|
||||
case VK_STRUCTURE_TYPE_IMAGE_STENCIL_USAGE_CREATE_INFO:
|
||||
memcpy(&info->stencil, src, sizeof(info->stencil));
|
||||
pnext = &info->stencil;
|
||||
break;
|
||||
case VK_STRUCTURE_TYPE_EXTERNAL_FORMAT_ANDROID: {
|
||||
const uint32_t external_format =
|
||||
(uint32_t)((const VkExternalFormatANDROID *)src)->externalFormat;
|
||||
if (external_format != 0)
|
||||
info->create.format = external_format;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (pnext) {
|
||||
dst->pNext = pnext;
|
||||
dst = pnext;
|
||||
}
|
||||
}
|
||||
dst->pNext = NULL;
|
||||
|
||||
img->deferred_info = info;
|
||||
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
static void
|
||||
vn_image_deferred_info_fini(struct vn_image *img,
|
||||
const VkAllocationCallbacks *alloc)
|
||||
{
|
||||
if (!img->deferred_info)
|
||||
return;
|
||||
|
||||
if (img->deferred_info->list.pViewFormats)
|
||||
vk_free(alloc, (void *)img->deferred_info->list.pViewFormats);
|
||||
|
||||
vk_free(alloc, img->deferred_info);
|
||||
}
|
||||
|
||||
static VkResult
|
||||
vn_image_init(struct vn_device *dev,
|
||||
const VkImageCreateInfo *create_info,
|
||||
|
|
@ -523,7 +436,7 @@ vn_image_init_deferred(struct vn_device *dev,
|
|||
struct vn_image *img)
|
||||
{
|
||||
VkResult result = vn_image_init(dev, create_info, img);
|
||||
img->deferred_info->initialized = result == VK_SUCCESS;
|
||||
img->deferred_initialized = result == VK_SUCCESS;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -540,12 +453,14 @@ vn_image_create_deferred(struct vn_device *dev,
|
|||
|
||||
vn_object_set_id(img, vn_get_next_obj_id(), VK_OBJECT_TYPE_IMAGE);
|
||||
|
||||
VkResult result = vn_image_deferred_info_init(img, create_info, alloc);
|
||||
VkResult result = vk_android_init_deferred_image(
|
||||
&dev->base.vk, &img->base.vk, create_info, alloc);
|
||||
if (result != VK_SUCCESS) {
|
||||
vk_image_destroy(&dev->base.vk, alloc, &img->base.vk);
|
||||
return result;
|
||||
}
|
||||
|
||||
img->deferred = true;
|
||||
*out_img = img;
|
||||
|
||||
return VK_SUCCESS;
|
||||
|
|
@ -722,11 +637,9 @@ vn_DestroyImage(VkDevice device,
|
|||
}
|
||||
|
||||
/* must not ask renderer to destroy uninitialized deferred image */
|
||||
if (!img->deferred_info || img->deferred_info->initialized)
|
||||
if (!img->deferred || img->deferred_initialized)
|
||||
vn_async_vkDestroyImage(dev->primary_ring, device, image, NULL);
|
||||
|
||||
vn_image_deferred_info_fini(img, alloc);
|
||||
|
||||
vk_image_destroy(&dev->base.vk, alloc, &img->base.vk);
|
||||
}
|
||||
|
||||
|
|
@ -852,7 +765,7 @@ vn_GetImageDrmFormatModifierPropertiesEXT(
|
|||
static VkImageAspectFlags
|
||||
vn_image_get_aspect(struct vn_image *img, VkImageAspectFlags aspect)
|
||||
{
|
||||
if (!img->deferred_info)
|
||||
if (!img->deferred)
|
||||
return aspect;
|
||||
|
||||
switch (aspect) {
|
||||
|
|
|
|||
|
|
@ -42,24 +42,16 @@ struct vn_image_reqs_cache {
|
|||
} debug;
|
||||
};
|
||||
|
||||
struct vn_image_create_deferred_info {
|
||||
VkImageCreateInfo create;
|
||||
VkImageFormatListCreateInfo list;
|
||||
VkImageStencilUsageCreateInfo stencil;
|
||||
|
||||
/* track whether vn_image_init_deferred succeeds */
|
||||
bool initialized;
|
||||
};
|
||||
|
||||
struct vn_image {
|
||||
struct vn_image_base base;
|
||||
|
||||
struct vn_image_memory_requirements requirements[4];
|
||||
|
||||
/* For VK_ANDROID_external_memory_android_hardware_buffer, real image
|
||||
* creation is deferred until bind image memory.
|
||||
/* track whether the image init has been deferred and whether the deferred
|
||||
* init has succeeded (renderer side image created)
|
||||
*/
|
||||
struct vn_image_create_deferred_info *deferred_info;
|
||||
bool deferred;
|
||||
bool deferred_initialized;
|
||||
|
||||
struct {
|
||||
bool is_prime_blit_src;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue