From c8d8961f3325c8d47931e4a71a6e092217ce97fc Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Wed, 14 Jun 2023 02:53:31 -0700 Subject: [PATCH] anv: avoid requiring ordered memory planes for explicit import The spec does not have such requirement, but anv requires it for validating the offset. However, for DRM_FORMAT_YVU420, chroma channels can be swapped upon import to match B/R channel order of VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM. This fixes some sw codec path in Instagram when interop with gpu. v2: fix image memory requirement for re-ordered explicit import Signed-off-by: Yiwei Zhang Reviewed-by: Emma Anholt (v1) Reviewed-by: Matt Tuner Part-of: --- src/intel/vulkan/anv_image.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c index 1ad9914d444..4d3657d46bb 100644 --- a/src/intel/vulkan/anv_image.c +++ b/src/intel/vulkan/anv_image.c @@ -144,20 +144,13 @@ image_binding_grow(const struct anv_device *device, "VkImageDrmFormatModifierExplicitCreateInfoEXT::" "pPlaneLayouts[]::offset is misaligned"); } - - /* We require that surfaces be added in memory-order. This simplifies the - * layout validation required by - * VkImageDrmFormatModifierExplicitCreateInfoEXT, - */ - if (unlikely(offset < container->size)) { - return vk_errorf(device, - VK_ERROR_INVALID_DRM_FORMAT_MODIFIER_PLANE_LAYOUT_EXT, - "VkImageDrmFormatModifierExplicitCreateInfoEXT::" - "pPlaneLayouts[]::offset is too small"); - } } - if (__builtin_add_overflow(offset, size, &container->size)) { + /* Surfaces can be added out of memory-order. Track the end of each memory + * plane to update the binding size properly. + */ + uint64_t memory_range_end; + if (__builtin_add_overflow(offset, size, &memory_range_end)) { if (has_implicit_offset) { assert(!"overflow"); return vk_errorf(device, VK_ERROR_UNKNOWN, @@ -170,6 +163,7 @@ image_binding_grow(const struct anv_device *device, } } + container->size = MAX2(container->size, memory_range_end); container->alignment = MAX2(container->alignment, alignment); *out_range = (struct anv_image_memory_range) {