crocus: Avoid fast-clear with incompatible view
authorFilip Gawin <filip.gawin@collabora.com>
Sun, 2 Jul 2023 11:40:30 +0000 (13:40 +0200)
committerMarge Bot <emma+marge@anholt.net>
Thu, 13 Jul 2023 15:02:38 +0000 (15:02 +0000)
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 <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24135>

src/gallium/drivers/crocus/ci/crocus-hsw-fails.txt
src/gallium/drivers/crocus/crocus_clear.c
src/gallium/drivers/crocus/crocus_resolve.c
src/gallium/drivers/crocus/crocus_resource.h

index b125c03f434c8b05c9cf4b043ab422dcaca7082e..21803984be0262102ecacef4dbf64a047baaf0b2 100644 (file)
@@ -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
index f5809e751871f6dbefbcfe953f4676e6448b71dd..6de70255aaa5c454611745071944ca510608c871 100644 (file)
@@ -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;
    }
 
index b32b8796707f306cd8b64840cf7e7688ec0df4f9..30eae441bb75cc37c69c352fe25a96e1db156433 100644 (file)
@@ -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;
index 537f920a14d218d2f7d679bacd10e09a2305309e..61b42a8e17fa92debdc609571de4fe50748c5668 100644 (file)
@@ -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,