From 8f9ed7e93237d91467a288a1aaea12346a2f46a4 Mon Sep 17 00:00:00 2001 From: Nanley Chery Date: Tue, 10 Sep 2024 14:16:21 -0400 Subject: [PATCH] anv: Prepare dmabufs for clear color arrays In later commits, we'll rely on the number of view formats used by an image to determine the size allocated for an array of clear colors in the aux-state tracking buffer. Having a single view format for dmabufs with clear color support allows anv to transparently handle this case. Restrict the number of view formats by explicitly setting the image format list to incomplete. Secondly, loosen the non-zero clear color restriction on clear color supporting dmabufs. Those images can support any clear color even with an incomplete list because we restrict problematic accesses for the clear color during the negotiation phase. Lastly, update add_all_surfaces_explicit_layout() to assert that the sizing of the imported clear color struct meets expectations. Reviewed-by: Lionel Landwerlin Part-of: --- src/intel/vulkan/anv_image.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c index 45b7e626029..8de2ac0bdb2 100644 --- a/src/intel/vulkan/anv_image.c +++ b/src/intel/vulkan/anv_image.c @@ -399,8 +399,17 @@ can_fast_clear_with_non_zero_color(const struct intel_device_info *devinfo, /* Generally, enabling non-zero fast-clears is dependent on knowing which * formats will be used with the surface. So, disable them if we lack this * knowledge. + * + * For dmabufs with clear color modifiers, we already restrict + * problematic accesses for the clear color during the negotiation + * phase. So, don't restrict clear color support in this case. */ - if (anv_image_view_formats_incomplete(image)) + const struct isl_drm_modifier_info *isl_mod_info = + image->vk.tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT ? + isl_drm_modifier_get_info(image->vk.drm_format_mod) : NULL; + + if (anv_image_view_formats_incomplete(image) && + !(isl_mod_info && isl_mod_info->supports_clear_color)) return false; enum isl_format img_format = image->planes[plane].primary_surface.isl.format; @@ -1419,6 +1428,10 @@ add_all_surfaces_explicit_layout( return result; assert(isl_aux_usage_has_ccs(image->planes[plane].aux_usage)); + if (aux_state_offset != ANV_OFFSET_IMPLICIT) { + assert(image->planes[plane].fast_clear_memory_range.size <= + device->isl_dev.ss.clear_color_state_size); + } } } @@ -1844,6 +1857,19 @@ anv_image_init(struct anv_device *device, struct anv_image *image, } } + if (isl_mod_info && isl_mod_info->supports_clear_color) { + if (image->num_view_formats > 1) { + /* We use the number of view formats to determine the number of + * CLEAR_COLOR structures to append to the image. For an imported + * dmabuf supporting clear colors, we're limited to a single such + * struct. So, mark the view format list as incomplete because doing + * so shrinks the list size to one. + */ + mark_image_view_formats_incomplete(image); + } + assert(image->num_view_formats == 1); + } + if (mod_explicit_info) { r = add_all_surfaces_explicit_layout(device, image, fmt_list, mod_explicit_info, isl_tiling_flags,