From ec70092d55c913a9a24f21d184511bf65fc2ae65 Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Wed, 9 Jun 2021 00:53:55 +0000 Subject: [PATCH] anv: support multi-planar format in add_all_surfaces_explicit_layout Add initial multi-planar format support on the images with modifiers: - With aux usage, - Format plane count must be 1. - Memory plane count must be 2. - Without aux usage, - Each format plane must map to a distinct memory plane. For the other cases, currently there is no way to properly map memory planes to format planes and aux planes due to the lack of defined ABI for external multi-planar images. This patch doesn't include some potentially supported cases like all format planes mapping to a single memory plane, additional refactoring is needed to workaround explicit base offset + ANV_OFFSET_IMPLICIT. Signed-off-by: Yiwei Zhang Reviewed-by: Chad Versace Part-of: --- src/intel/vulkan/anv_image.c | 98 ++++++++++++++++++++---------------- 1 file changed, 55 insertions(+), 43 deletions(-) diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c index 77c7cd1281a..a2ebab3f794 100644 --- a/src/intel/vulkan/anv_image.c +++ b/src/intel/vulkan/anv_image.c @@ -1087,8 +1087,8 @@ add_all_surfaces_explicit_layout( { const struct intel_device_info *devinfo = &device->info; const uint32_t mod_plane_count = drm_info->drmFormatModifierPlaneCount; - const struct isl_drm_modifier_info *isl_mod_info = - isl_drm_modifier_get_info(drm_info->drmFormatModifier); + const bool mod_has_aux = + isl_drm_modifier_has_aux(drm_info->drmFormatModifier); VkResult result; /* About valid usage in the Vulkan spec: @@ -1102,20 +1102,27 @@ add_all_surfaces_explicit_layout( * Most validation of plane layout occurs in add_surface(). */ - /* We support a restricted set of images with modifiers. */ - assert(image->aspects == VK_IMAGE_ASPECT_COLOR_BIT); - assert(image->n_planes == 1); - - if (isl_mod_info->aux_usage == ISL_AUX_USAGE_NONE) - assert(mod_plane_count == 1); + /* We support a restricted set of images with modifiers. + * + * With aux usage, + * - Format plane count must be 1. + * - Memory plane count must be 2. + * Without aux usage, + * - Each format plane must map to a distint memory plane. + * + * For the other cases, currently there is no way to properly map memory + * planes to format planes and aux planes due to the lack of defined ABI + * for external multi-planar images. + */ + if (image->n_planes == 1) + assert(image->aspects == VK_IMAGE_ASPECT_COLOR_BIT); else - assert(mod_plane_count == 2); + assert(!(image->aspects & ~VK_IMAGE_ASPECT_PLANES_BITS_ANV)); - const uint32_t plane = anv_image_aspect_to_plane(image->aspects, - VK_IMAGE_ASPECT_COLOR_BIT); - const struct anv_format_plane format_plane = - anv_get_format_plane(devinfo, image->vk_format, VK_IMAGE_ASPECT_COLOR_BIT, - image->tiling); + if (mod_has_aux) + assert(image->n_planes == 1 && mod_plane_count == 2); + else + assert(image->n_planes == mod_plane_count); /* Reject special values in the app-provided plane layouts. */ for (uint32_t i = 0; i < mod_plane_count; ++i) { @@ -1135,39 +1142,44 @@ add_all_surfaces_explicit_layout( } } - const VkSubresourceLayout *primary_layout = &drm_info->pPlaneLayouts[0]; - result = add_primary_surface(device, image, plane, - format_plane, - primary_layout->offset, - primary_layout->rowPitch, - isl_tiling_flags, - isl_extra_usage_flags); - if (result != VK_SUCCESS) - return result; + u_foreach_bit(b, image->aspects) { + const VkImageAspectFlagBits aspect = 1 << b; + const uint32_t plane = anv_image_aspect_to_plane(image->aspects, aspect); + const struct anv_format_plane format_plane = + anv_get_format_plane(devinfo, image->vk_format, aspect, image->tiling); + const VkSubresourceLayout *primary_layout = &drm_info->pPlaneLayouts[plane]; - if (isl_mod_info->aux_usage == ISL_AUX_USAGE_NONE) { - /* Even though the modifier does not support aux, try to create - * a driver-private aux to improve performance. - */ - result = add_aux_surface_if_supported(device, image, plane, - format_plane, - format_list_info, - ANV_OFFSET_IMPLICIT, 0, - isl_extra_usage_flags); + result = add_primary_surface(device, image, plane, + format_plane, + primary_layout->offset, + primary_layout->rowPitch, + isl_tiling_flags, + isl_extra_usage_flags); if (result != VK_SUCCESS) return result; - } else { - assert(mod_plane_count == 2); - const VkSubresourceLayout *aux_layout = &drm_info->pPlaneLayouts[1]; - result = add_aux_surface_if_supported(device, image, plane, - format_plane, - format_list_info, - aux_layout->offset, - aux_layout->rowPitch, - isl_extra_usage_flags); - if (result != VK_SUCCESS) - return result; + if (!mod_has_aux) { + /* Even though the modifier does not support aux, try to create + * a driver-private aux to improve performance. + */ + result = add_aux_surface_if_supported(device, image, plane, + format_plane, + format_list_info, + ANV_OFFSET_IMPLICIT, 0, + isl_extra_usage_flags); + if (result != VK_SUCCESS) + return result; + } else { + const VkSubresourceLayout *aux_layout = &drm_info->pPlaneLayouts[1]; + result = add_aux_surface_if_supported(device, image, plane, + format_plane, + format_list_info, + aux_layout->offset, + aux_layout->rowPitch, + isl_extra_usage_flags); + if (result != VK_SUCCESS) + return result; + } } return VK_SUCCESS;