From 6e87b277bde71e30c98ab9dda7bd2f2017b77ed5 Mon Sep 17 00:00:00 2001 From: Filip Gawin Date: Sun, 2 Jul 2023 13:40:30 +0200 Subject: [PATCH] crocus: Avoid fast-clear with incompatible view Port of code from iris. Original author: Nanley Chery Helps with fast_color_clear@fcc-write-after-clear Cc: mesa-stable Reviewed-by: Lionel Landwerlin Part-of: --- .../drivers/crocus/ci/crocus-hsw-fails.txt | 2 -- src/gallium/drivers/crocus/crocus_clear.c | 4 +-- src/gallium/drivers/crocus/crocus_resolve.c | 32 +++++++++++++++++++ src/gallium/drivers/crocus/crocus_resource.h | 3 ++ 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/gallium/drivers/crocus/ci/crocus-hsw-fails.txt b/src/gallium/drivers/crocus/ci/crocus-hsw-fails.txt index b125c03f434..21803984be0 100644 --- a/src/gallium/drivers/crocus/ci/crocus-hsw-fails.txt +++ b/src/gallium/drivers/crocus/ci/crocus-hsw-fails.txt @@ -2,8 +2,6 @@ spec@!opengl 1.0@depth-clear-precision-check,Fail spec@!opengl 1.0@depth-clear-precision-check@depth16,Fail spec@!opengl 1.0@depth-clear-precision-check@depth32,Fail -fast_color_clear@fcc-write-after-clear,Fail - spec@!opengl 1.0@gl-1.0-swapbuffers-behavior,Fail # Compat mode failure diff --git a/src/gallium/drivers/crocus/crocus_clear.c b/src/gallium/drivers/crocus/crocus_clear.c index f5809e75187..6de70255aaa 100644 --- a/src/gallium/drivers/crocus/crocus_clear.c +++ b/src/gallium/drivers/crocus/crocus_clear.c @@ -101,8 +101,8 @@ can_fast_clear_color(struct crocus_context *ice, * during resolves because the resolve operations only know about the * resource and not the renderbuffer. */ - if (isl_format_srgb_to_linear(render_format) != - isl_format_srgb_to_linear(format)) { + if (!crocus_render_formats_color_compatible(render_format, res->surf.format, + color)) { return false; } diff --git a/src/gallium/drivers/crocus/crocus_resolve.c b/src/gallium/drivers/crocus/crocus_resolve.c index b32b8796707..30eae441bb7 100644 --- a/src/gallium/drivers/crocus/crocus_resolve.c +++ b/src/gallium/drivers/crocus/crocus_resolve.c @@ -981,6 +981,22 @@ crocus_resource_prepare_texture(struct crocus_context *ice, aux_usage, clear_supported); } +bool +crocus_render_formats_color_compatible(enum isl_format a, enum isl_format b, + union isl_color_value color) +{ + if (a == b) + return true; + + /* A difference in color space doesn't matter for 0/1 values. */ + if (isl_format_srgb_to_linear(a) == isl_format_srgb_to_linear(b) && + isl_color_value_is_zero_one(color, a)) { + return true; + } + + return false; +} + enum isl_aux_usage crocus_resource_render_aux_usage(struct crocus_context *ice, struct crocus_resource *res, @@ -999,6 +1015,22 @@ crocus_resource_render_aux_usage(struct crocus_context *ice, return res->aux.usage; case ISL_AUX_USAGE_CCS_D: + /* Disable CCS for some cases of texture-view rendering. On gfx12, HW + * may convert some subregions of shader output to fast-cleared blocks + * if CCS is enabled and the shader output matches the clear color. + * Existing fast-cleared blocks are correctly interpreted by the clear + * color and the resource format (see can_fast_clear_color). To avoid + * gaining new fast-cleared blocks that can't be interpreted by the + * resource format (and to avoid misinterpreting existing ones), shut + * off CCS when the interpretation of the clear color differs between + * the render_format and the resource format. + */ + if (!crocus_render_formats_color_compatible(render_format, + res->surf.format, + res->aux.clear_color)) { + return ISL_AUX_USAGE_NONE; + } + /* Otherwise, we try to fall back to CCS_D */ if (isl_format_supports_ccs_d(devinfo, render_format)) return ISL_AUX_USAGE_CCS_D; diff --git a/src/gallium/drivers/crocus/crocus_resource.h b/src/gallium/drivers/crocus/crocus_resource.h index 537f920a14d..61b42a8e17f 100644 --- a/src/gallium/drivers/crocus/crocus_resource.h +++ b/src/gallium/drivers/crocus/crocus_resource.h @@ -526,6 +526,9 @@ bool crocus_has_color_unresolved(const struct crocus_resource *res, unsigned start_level, unsigned num_levels, unsigned start_layer, unsigned num_layers); +bool crocus_render_formats_color_compatible(enum isl_format a, + enum isl_format b, + union isl_color_value color); enum isl_aux_usage crocus_resource_render_aux_usage(struct crocus_context *ice, struct crocus_resource *res, uint32_t level,