From f419a0bc4efe4075e300fe7bfc9583f8d8890f6f Mon Sep 17 00:00:00 2001 From: Rebecca Mckeever Date: Sun, 9 Feb 2025 18:43:14 -0800 Subject: [PATCH] vk/image: Add vk_image_can_be_aliased_to_yuv_plane() helper vk_image_can_be_aliased_to_yuv_plane() checks whether an image has a format that is compatible with a plane of a multiplane image and can be aliased to it. Signed-off-by: Rebecca Mckeever Reviewed-by: Boris Brezillon Reviewed-by: Faith Ekstrand Part-of: --- src/vulkan/runtime/vk_image.c | 28 ++++++++++++++++++++++++++++ src/vulkan/runtime/vk_image.h | 2 ++ 2 files changed, 30 insertions(+) diff --git a/src/vulkan/runtime/vk_image.c b/src/vulkan/runtime/vk_image.c index ac229178fd3..459ba6a068c 100644 --- a/src/vulkan/runtime/vk_image.c +++ b/src/vulkan/runtime/vk_image.c @@ -379,6 +379,34 @@ vk_image_to_memory_copy_layout(const struct vk_image *image, return vk_image_buffer_copy_layout(image, &bic); } +bool +vk_image_can_be_aliased_to_yuv_plane(const struct vk_image *image) +{ + if (!(image->create_flags & VK_IMAGE_CREATE_ALIAS_BIT)) + return false; + + VkFormat format = image->format; + + /* Only the 8-bit, 16-bit, and 32-bit classes listed in + * https://registry.khronos.org/vulkan/specs/latest/html/vkspec.html#formats-compatibility-classes + * are compatible with yuv planes. We must exclude other classes with the + * same block size as these. + */ + if (vk_format_is_depth_or_stencil(format) || + vk_format_is_alpha(format) || + vk_format_get_blockwidth(format) != 1 || + vk_format_get_blockheight(format) != 1) + return false; + + unsigned block_size = vk_format_get_blocksize(format); + + /* The planes of all the multiplane formats have a block size of 1, 2, or 4. + * See: + * https://registry.khronos.org/vulkan/specs/latest/html/vkspec.html#formats-compatible-planes + */ + return block_size == 1 || block_size == 2 || block_size == 4; +} + static VkComponentSwizzle remap_swizzle(VkComponentSwizzle swizzle, VkComponentSwizzle component) { diff --git a/src/vulkan/runtime/vk_image.h b/src/vulkan/runtime/vk_image.h index 71dadab48fa..9c7dbdd8a7a 100644 --- a/src/vulkan/runtime/vk_image.h +++ b/src/vulkan/runtime/vk_image.h @@ -255,6 +255,8 @@ struct vk_image_buffer_layout vk_image_to_memory_copy_layout(const struct vk_image *image, const VkImageToMemoryCopyEXT* region); +bool vk_image_can_be_aliased_to_yuv_plane(const struct vk_image *image); + struct vk_image_view { struct vk_object_base base;