mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-07 02:48:06 +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/os_file.h"
|
||||||
#include "util/u_gralloc/u_gralloc.h"
|
#include "util/u_gralloc/u_gralloc.h"
|
||||||
#include "vk_android.h"
|
|
||||||
|
|
||||||
#include "vn_buffer.h"
|
#include "vn_buffer.h"
|
||||||
#include "vn_device.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;
|
out_builder->create.pNext = &out_builder->external;
|
||||||
|
|
||||||
/* fill VkImageFormatListCreateInfo if needed
|
/* fill VkImageFormatListCreateInfo if needed */
|
||||||
*
|
|
||||||
* vn_image::deferred_info only stores VkImageFormatListCreateInfo with a
|
|
||||||
* non-zero viewFormatCount, and that stored struct will be respected.
|
|
||||||
*/
|
|
||||||
if ((create_info->flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT) &&
|
if ((create_info->flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT) &&
|
||||||
!vk_find_struct_const(create_info->pNext,
|
!vk_find_struct_const(create_info->pNext,
|
||||||
IMAGE_FORMAT_LIST_CREATE_INFO)) {
|
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);
|
struct vn_image *img = vn_image_from_handle(bind_info->image);
|
||||||
VkResult result = vn_android_image_from_anb_internal(
|
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)
|
if (result != VK_SUCCESS)
|
||||||
return NULL;
|
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 */
|
/* If ahb is for an image, finish the deferred image creation first */
|
||||||
struct vn_android_image_builder builder;
|
struct vn_android_image_builder builder;
|
||||||
result = vn_android_get_image_builder(dev, &img->deferred_info->create,
|
result = vn_android_get_image_builder(
|
||||||
handle, &builder);
|
dev, img->base.vk.android_deferred_create_info, handle, &builder);
|
||||||
if (result != VK_SUCCESS)
|
if (result != VK_SUCCESS)
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@
|
||||||
#include <vulkan/vulkan.h>
|
#include <vulkan/vulkan.h>
|
||||||
#include <vulkan/vulkan_android.h>
|
#include <vulkan/vulkan_android.h>
|
||||||
|
|
||||||
|
#include "vk_android.h"
|
||||||
|
|
||||||
#ifdef VK_USE_PLATFORM_ANDROID_KHR
|
#ifdef VK_USE_PLATFORM_ANDROID_KHR
|
||||||
|
|
||||||
VkResult
|
VkResult
|
||||||
|
|
|
||||||
|
|
@ -350,7 +350,7 @@ vn_image_init_memory_requirements(struct vn_image *img,
|
||||||
&img->requirements[0].memory);
|
&img->requirements[0].memory);
|
||||||
|
|
||||||
/* AHB backed image requires dedicated allocation */
|
/* AHB backed image requires dedicated allocation */
|
||||||
if (img->deferred_info) {
|
if (img->deferred) {
|
||||||
img->requirements[0].dedicated.prefersDedicatedAllocation = VK_TRUE;
|
img->requirements[0].dedicated.prefersDedicatedAllocation = VK_TRUE;
|
||||||
img->requirements[0].dedicated.requiresDedicatedAllocation = 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
|
static VkResult
|
||||||
vn_image_init(struct vn_device *dev,
|
vn_image_init(struct vn_device *dev,
|
||||||
const VkImageCreateInfo *create_info,
|
const VkImageCreateInfo *create_info,
|
||||||
|
|
@ -523,7 +436,7 @@ vn_image_init_deferred(struct vn_device *dev,
|
||||||
struct vn_image *img)
|
struct vn_image *img)
|
||||||
{
|
{
|
||||||
VkResult result = vn_image_init(dev, create_info, 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;
|
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);
|
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) {
|
if (result != VK_SUCCESS) {
|
||||||
vk_image_destroy(&dev->base.vk, alloc, &img->base.vk);
|
vk_image_destroy(&dev->base.vk, alloc, &img->base.vk);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
img->deferred = true;
|
||||||
*out_img = img;
|
*out_img = img;
|
||||||
|
|
||||||
return VK_SUCCESS;
|
return VK_SUCCESS;
|
||||||
|
|
@ -722,11 +637,9 @@ vn_DestroyImage(VkDevice device,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* must not ask renderer to destroy uninitialized deferred image */
|
/* 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_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);
|
vk_image_destroy(&dev->base.vk, alloc, &img->base.vk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -852,7 +765,7 @@ vn_GetImageDrmFormatModifierPropertiesEXT(
|
||||||
static VkImageAspectFlags
|
static VkImageAspectFlags
|
||||||
vn_image_get_aspect(struct vn_image *img, VkImageAspectFlags aspect)
|
vn_image_get_aspect(struct vn_image *img, VkImageAspectFlags aspect)
|
||||||
{
|
{
|
||||||
if (!img->deferred_info)
|
if (!img->deferred)
|
||||||
return aspect;
|
return aspect;
|
||||||
|
|
||||||
switch (aspect) {
|
switch (aspect) {
|
||||||
|
|
|
||||||
|
|
@ -42,24 +42,16 @@ struct vn_image_reqs_cache {
|
||||||
} debug;
|
} 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 {
|
||||||
struct vn_image_base base;
|
struct vn_image_base base;
|
||||||
|
|
||||||
struct vn_image_memory_requirements requirements[4];
|
struct vn_image_memory_requirements requirements[4];
|
||||||
|
|
||||||
/* For VK_ANDROID_external_memory_android_hardware_buffer, real image
|
/* track whether the image init has been deferred and whether the deferred
|
||||||
* creation is deferred until bind image memory.
|
* init has succeeded (renderer side image created)
|
||||||
*/
|
*/
|
||||||
struct vn_image_create_deferred_info *deferred_info;
|
bool deferred;
|
||||||
|
bool deferred_initialized;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
bool is_prime_blit_src;
|
bool is_prime_blit_src;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue