anv: Add an anv_image_get_memory_requirements helper
This is similar to a patch from Lionel except works in terms of aspects rather than bindings. This makes it easy to use from the Android code. Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13199>
This commit is contained in:

committed by
Marge Bot

parent
76b1d04e72
commit
8c2a1ed3da
@@ -537,16 +537,12 @@ anv_image_from_gralloc(VkDevice device_h,
|
|||||||
if (result != VK_SUCCESS)
|
if (result != VK_SUCCESS)
|
||||||
goto fail_create;
|
goto fail_create;
|
||||||
|
|
||||||
VkImageMemoryRequirementsInfo2 mem_reqs_info = {
|
|
||||||
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2,
|
|
||||||
.image = image_h,
|
|
||||||
};
|
|
||||||
|
|
||||||
VkMemoryRequirements2 mem_reqs = {
|
VkMemoryRequirements2 mem_reqs = {
|
||||||
.sType = VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2,
|
.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 =
|
VkDeviceSize aligned_image_size =
|
||||||
align_u64(mem_reqs.memoryRequirements.size,
|
align_u64(mem_reqs.memoryRequirements.size,
|
||||||
|
@@ -1564,16 +1564,12 @@ resolve_ahw_image(struct anv_device *device,
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void anv_GetImageMemoryRequirements2(
|
void
|
||||||
VkDevice _device,
|
anv_image_get_memory_requirements(struct anv_device *device,
|
||||||
const VkImageMemoryRequirementsInfo2* pInfo,
|
struct anv_image *image,
|
||||||
VkMemoryRequirements2* pMemoryRequirements)
|
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:
|
/* The Vulkan spec (git aaed022) says:
|
||||||
*
|
*
|
||||||
* memoryTypeBits is a bitfield and contains one bit set for every
|
* 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;
|
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) {
|
vk_foreach_struct(ext, pMemoryRequirements->pNext) {
|
||||||
switch (ext->sType) {
|
switch (ext->sType) {
|
||||||
case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS: {
|
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
|
* and only if the image is disjoint (that is, multi-planar format and
|
||||||
* VK_IMAGE_CREATE_DISJOINT_BIT).
|
* VK_IMAGE_CREATE_DISJOINT_BIT).
|
||||||
*/
|
*/
|
||||||
assert(image->disjoint == (plane_reqs != NULL));
|
const struct anv_image_binding *binding;
|
||||||
|
if (image->disjoint) {
|
||||||
if (!image->disjoint) {
|
assert(util_bitcount(aspects) == 1);
|
||||||
const struct anv_image_binding *binding =
|
assert(aspects & image->vk.aspects);
|
||||||
&image->bindings[ANV_IMAGE_MEMORY_BINDING_MAIN];
|
binding = image_aspect_to_binding(image, aspects);
|
||||||
|
} else {
|
||||||
pMemoryRequirements->memoryRequirements = (VkMemoryRequirements) {
|
assert(aspects == image->vk.aspects);
|
||||||
.size = binding->memory_range.size,
|
binding = &image->bindings[ANV_IMAGE_MEMORY_BINDING_MAIN];
|
||||||
.alignment = binding->memory_range.alignment,
|
|
||||||
.memoryTypeBits = memory_types,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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(
|
void anv_GetImageSparseMemoryRequirements(
|
||||||
|
@@ -4420,6 +4420,11 @@ VkResult anv_image_create(VkDevice _device,
|
|||||||
const VkAllocationCallbacks* alloc,
|
const VkAllocationCallbacks* alloc,
|
||||||
VkImage *pImage);
|
VkImage *pImage);
|
||||||
|
|
||||||
|
void anv_image_get_memory_requirements(struct anv_device *device,
|
||||||
|
struct anv_image *image,
|
||||||
|
VkImageAspectFlags aspects,
|
||||||
|
VkMemoryRequirements2 *pMemoryRequirements);
|
||||||
|
|
||||||
enum isl_format
|
enum isl_format
|
||||||
anv_isl_format_for_descriptor_type(const struct anv_device *device,
|
anv_isl_format_for_descriptor_type(const struct anv_device *device,
|
||||||
VkDescriptorType type);
|
VkDescriptorType type);
|
||||||
|
Reference in New Issue
Block a user