diff --git a/src/intel/vulkan/anv_android.c b/src/intel/vulkan/anv_android.c index 418e844c471..f4f00c159f7 100644 --- a/src/intel/vulkan/anv_android.c +++ b/src/intel/vulkan/anv_android.c @@ -537,16 +537,12 @@ anv_image_from_gralloc(VkDevice device_h, if (result != VK_SUCCESS) goto fail_create; - VkImageMemoryRequirementsInfo2 mem_reqs_info = { - .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2, - .image = image_h, - }; - VkMemoryRequirements2 mem_reqs = { .sType = VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2, }; - anv_GetImageMemoryRequirements2(device_h, &mem_reqs_info, &mem_reqs); + anv_image_get_memory_requirements(device, image, image->vk.aspects, + &mem_reqs); VkDeviceSize aligned_image_size = align_u64(mem_reqs.memoryRequirements.size, diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c index 46ce702cec3..12a99d24088 100644 --- a/src/intel/vulkan/anv_image.c +++ b/src/intel/vulkan/anv_image.c @@ -1564,16 +1564,12 @@ resolve_ahw_image(struct anv_device *device, #endif } -void anv_GetImageMemoryRequirements2( - VkDevice _device, - const VkImageMemoryRequirementsInfo2* pInfo, - VkMemoryRequirements2* pMemoryRequirements) +void +anv_image_get_memory_requirements(struct anv_device *device, + struct anv_image *image, + VkImageAspectFlags aspects, + VkMemoryRequirements2 *pMemoryRequirements) { - 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 @@ -1585,28 +1581,6 @@ void anv_GetImageMemoryRequirements2( */ uint32_t memory_types = (1ull << device->physical->memory.type_count) - 1; - vk_foreach_struct_const(ext, pInfo->pNext) { - switch (ext->sType) { - case VK_STRUCTURE_TYPE_IMAGE_PLANE_MEMORY_REQUIREMENTS_INFO: { - assert(image->disjoint); - plane_reqs = (const VkImagePlaneMemoryRequirementsInfo *) ext; - const struct anv_image_binding *binding = - image_aspect_to_binding(image, plane_reqs->planeAspect); - - pMemoryRequirements->memoryRequirements = (VkMemoryRequirements) { - .size = binding->memory_range.size, - .alignment = binding->memory_range.alignment, - .memoryTypeBits = memory_types, - }; - break; - } - - default: - anv_debug_ignored_stype(ext->sType); - break; - } - } - vk_foreach_struct(ext, pMemoryRequirements->pNext) { switch (ext->sType) { case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS: { @@ -1642,18 +1616,51 @@ void anv_GetImageMemoryRequirements2( * 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) { - const struct anv_image_binding *binding = - &image->bindings[ANV_IMAGE_MEMORY_BINDING_MAIN]; - - pMemoryRequirements->memoryRequirements = (VkMemoryRequirements) { - .size = binding->memory_range.size, - .alignment = binding->memory_range.alignment, - .memoryTypeBits = memory_types, - }; + const struct anv_image_binding *binding; + if (image->disjoint) { + assert(util_bitcount(aspects) == 1); + assert(aspects & image->vk.aspects); + binding = image_aspect_to_binding(image, aspects); + } else { + assert(aspects == image->vk.aspects); + binding = &image->bindings[ANV_IMAGE_MEMORY_BINDING_MAIN]; } + + pMemoryRequirements->memoryRequirements = (VkMemoryRequirements) { + .size = binding->memory_range.size, + .alignment = binding->memory_range.alignment, + .memoryTypeBits = memory_types, + }; +} + +void anv_GetImageMemoryRequirements2( + VkDevice _device, + const VkImageMemoryRequirementsInfo2* pInfo, + VkMemoryRequirements2* pMemoryRequirements) +{ + ANV_FROM_HANDLE(anv_device, device, _device); + ANV_FROM_HANDLE(anv_image, image, pInfo->image); + + VkImageAspectFlags aspects = image->vk.aspects; + + vk_foreach_struct_const(ext, pInfo->pNext) { + switch (ext->sType) { + case VK_STRUCTURE_TYPE_IMAGE_PLANE_MEMORY_REQUIREMENTS_INFO: { + assert(image->disjoint); + const VkImagePlaneMemoryRequirementsInfo *plane_reqs = + (const VkImagePlaneMemoryRequirementsInfo *) ext; + aspects = plane_reqs->planeAspect; + break; + } + + default: + anv_debug_ignored_stype(ext->sType); + break; + } + } + + anv_image_get_memory_requirements(device, image, aspects, + pMemoryRequirements); } void anv_GetImageSparseMemoryRequirements( diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index 961c450911d..ccde5349ee0 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -4420,6 +4420,11 @@ VkResult anv_image_create(VkDevice _device, const VkAllocationCallbacks* alloc, VkImage *pImage); +void anv_image_get_memory_requirements(struct anv_device *device, + struct anv_image *image, + VkImageAspectFlags aspects, + VkMemoryRequirements2 *pMemoryRequirements); + enum isl_format anv_isl_format_for_descriptor_type(const struct anv_device *device, VkDescriptorType type);