From 35f02d8f36114484c6d56370a446eff89380d16a Mon Sep 17 00:00:00 2001 From: Nanley Chery Date: Fri, 6 Sep 2024 09:55:27 -0400 Subject: [PATCH] anv: Inline can_fast_clear_with_non_zero_color Reviewed-by: Lionel Landwerlin Part-of: --- src/intel/vulkan/anv_image.c | 35 ++++++++++++++++++++++-------- src/intel/vulkan/anv_private.h | 16 -------------- src/intel/vulkan/genX_cmd_buffer.c | 2 +- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c index 9465231cc35..f3c412641d7 100644 --- a/src/intel/vulkan/anv_image.c +++ b/src/intel/vulkan/anv_image.c @@ -1928,14 +1928,6 @@ anv_image_init(struct anv_device *device, struct anv_image *image, if (r != VK_SUCCESS) goto fail; - /* Once we have all the bindings, determine whether we can do non 0 fast - * clears for each plane. - */ - for (uint32_t p = 0; p < image->n_planes; p++) { - image->planes[p].can_non_zero_fast_clear = - can_fast_clear_with_non_zero_color(device->info, image, p, fmt_list); - } - if (anv_image_is_sparse(image)) { r = anv_image_init_sparse_bindings(image, create_info); if (r != VK_SUCCESS) @@ -3411,6 +3403,10 @@ anv_layout_to_fast_clear_type(const struct intel_device_info * const devinfo, const VkImageUsageFlags layout_usage = vk_image_layout_to_usage_flags(layout, aspect) & image->vk.usage; + 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; + switch (aux_state) { case ISL_AUX_STATE_CLEAR: unreachable("We never use this state"); @@ -3418,7 +3414,28 @@ anv_layout_to_fast_clear_type(const struct intel_device_info * const devinfo, case ISL_AUX_STATE_PARTIAL_CLEAR: case ISL_AUX_STATE_COMPRESSED_CLEAR: - if (!image->planes[plane].can_non_zero_fast_clear) + /* 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) && + !(isl_mod_info && isl_mod_info->supports_clear_color)) { + return ANV_FAST_CLEAR_DEFAULT_VALUE; + } + + /* On TGL (< C0), if a block of fragment shader outputs match the + * surface's clear color, the HW may convert them to fast-clears (see + * HSD 1607794140). This can lead to rendering corruptions if not + * handled properly. We restrict the clear color to zero to avoid issues + * that can occur with: + * - Texture view rendering (including blorp_copy calls) + * - Images with multiple levels or array layers + */ + if (image->planes[plane].aux_usage == ISL_AUX_USAGE_FCV_CCS_E) return ANV_FAST_CLEAR_DEFAULT_VALUE; /* On gfx9, we only load clear colors for attachments and for BLORP diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index c7f676ea551..fce45261fe4 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -5497,22 +5497,6 @@ struct anv_image { /** Location of the fast clear state. */ struct anv_image_memory_range fast_clear_memory_range; - /** - * Whether this image can be fast cleared with non-zero clear colors. - * This can happen with mutable images when formats of different bit - * sizes per components are used. - * - * On Gfx9+, because the clear colors are stored as a 4 components 32bit - * values, we can clear in R16G16_UNORM (store 2 16bit values in the - * components 0 & 1 of the clear color) and then draw in R32_UINT which - * would interpret the clear color as a single component value, using - * only the first 16bit component of the previous written clear color. - * - * On Gfx7/7.5/8, only CC_ZERO/CC_ONE clear colors are supported, this - * boolean will prevent the usage of CC_ONE. - */ - bool can_non_zero_fast_clear; - struct { /** Whether the image has CCS data mapped through AUX-TT. */ bool mapped; diff --git a/src/intel/vulkan/genX_cmd_buffer.c b/src/intel/vulkan/genX_cmd_buffer.c index cdbbf63a81c..6ef6ae52fd0 100644 --- a/src/intel/vulkan/genX_cmd_buffer.c +++ b/src/intel/vulkan/genX_cmd_buffer.c @@ -1242,7 +1242,7 @@ transition_color_buffer(struct anv_cmd_buffer *cmd_buffer, if (must_init_fast_clear_state) { if (image->planes[plane].aux_usage == ISL_AUX_USAGE_FCV_CCS_E) { - assert(!image->planes[plane].can_non_zero_fast_clear); + /* Ensure the raw and converted clear colors are in sync. */ const uint32_t zero_pixel[4] = {}; set_image_clear_color(cmd_buffer, image, aspect, zero_pixel); }