From 22ac3d74e0c3ef3792cf0463b5276815e5b8e9ea Mon Sep 17 00:00:00 2001 From: Chad Versace Date: Mon, 14 Dec 2020 18:08:37 -0800 Subject: [PATCH] anv/image: Clean up anv_GetImageMemoryRequirements2 If the image is disjoint, there is no reason to calculate image-global memory requirements. Instead, only per-plane memory requirements are needed. Also, delete a large duplicate comment. Reviewed-by: Jason Ekstrand Part-of: --- src/intel/vulkan/anv_image.c | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c index b88c2e3..7811bed 100644 --- a/src/intel/vulkan/anv_image.c +++ b/src/intel/vulkan/anv_image.c @@ -1098,6 +1098,8 @@ void anv_GetImageMemoryRequirements2( ANV_FROM_HANDLE(anv_device, device, _device); ANV_FROM_HANDLE(anv_image, image, pInfo->image); + const VkImagePlaneMemoryRequirementsInfo *plane_reqs = NULL; + /* The Vulkan spec (git aaed022) says: * * memoryTypeBits is a bitfield and contains one bit set for every @@ -1109,36 +1111,20 @@ void anv_GetImageMemoryRequirements2( */ uint32_t memory_types = (1ull << device->physical->memory.type_count) - 1; - pMemoryRequirements->memoryRequirements.size = image->size; - pMemoryRequirements->memoryRequirements.alignment = image->alignment; - pMemoryRequirements->memoryRequirements.memoryTypeBits = memory_types; - vk_foreach_struct_const(ext, pInfo->pNext) { switch (ext->sType) { case VK_STRUCTURE_TYPE_IMAGE_PLANE_MEMORY_REQUIREMENTS_INFO: { - const VkImagePlaneMemoryRequirementsInfo *plane_reqs = - (const VkImagePlaneMemoryRequirementsInfo *) ext; + assert(image->disjoint); + plane_reqs = (const VkImagePlaneMemoryRequirementsInfo *) ext; uint32_t plane = anv_image_aspect_to_plane(image->aspects, plane_reqs->planeAspect); assert(image->planes[plane].offset == 0); - /* The Vulkan spec (git aaed022) says: - * - * memoryTypeBits is a bitfield and contains one bit set for every - * supported memory type for the resource. The bit `1<memoryRequirements.memoryTypeBits = - (1ull << device->physical->memory.type_count) - 1; - pMemoryRequirements->memoryRequirements.size = image->planes[plane].size; pMemoryRequirements->memoryRequirements.alignment = image->planes[plane].alignment; + pMemoryRequirements->memoryRequirements.memoryTypeBits = memory_types; break; } @@ -1172,6 +1158,24 @@ void anv_GetImageMemoryRequirements2( break; } } + + /* If the image is disjoint, then we must return the memory requirements for + * the single plane specified in VkImagePlaneMemoryRequirementsInfo. If + * non-disjoint, then exactly one set of memory requirements exists for the + * whole image. + * + * This is enforced by the Valid Usage for VkImageMemoryRequirementsInfo2, + * which requires that the app provide VkImagePlaneMemoryRequirementsInfo if + * and only if the image is disjoint (that is, multi-planar format and + * VK_IMAGE_CREATE_DISJOINT_BIT). + */ + assert(image->disjoint == (plane_reqs != NULL)); + + if (!image->disjoint) { + pMemoryRequirements->memoryRequirements.size = image->size; + pMemoryRequirements->memoryRequirements.alignment = image->alignment; + pMemoryRequirements->memoryRequirements.memoryTypeBits = memory_types; + } } void anv_GetImageSparseMemoryRequirements( -- 2.7.4