iris: Avoid fast-clear with incompatible view
authorNanley Chery <nanley.g.chery@intel.com>
Tue, 5 May 2020 22:33:29 +0000 (15:33 -0700)
committerMarge Bot <eric+marge@anholt.net>
Fri, 19 Jun 2020 21:03:31 +0000 (21:03 +0000)
For rendering operations, avoid adding or using fast-cleared blocks if
the render format is incompatible with the clear color interpretation.
Note that the clear color is currently interpreted through the
resource's surface format.

Makes iris pass subtests of the fcc-write-after-clear piglit test:

* UNORM -> SNORM, partial block on gen8+.
* linear -> sRGB, partial block on gen9+.
* UNORM -> SNORM, full block on gen12.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4972>

src/gallium/drivers/iris/iris_clear.c
src/gallium/drivers/iris/iris_resolve.c
src/gallium/drivers/iris/iris_resource.h

index 32c8cd97772a307d2cd65548aaea1ac1bcfb90c8..a1e2218674a8170d1f62c93e41ce7c0d3444236e 100644 (file)
@@ -92,8 +92,8 @@ can_fast_clear_color(struct iris_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(res->surf.format)) {
+   if (!iris_render_formats_color_compatible(render_format, res->surf.format,
+                                             color)) {
       return false;
    }
 
index 0d647630f5d91b8c96bf947785b028466ca23c05..937dee11553c6d9a4d1f26f82342a50b9bc0ed30 100644 (file)
@@ -986,6 +986,25 @@ iris_resource_prepare_texture(struct iris_context *ice,
                                 aux_usage, clear_supported);
 }
 
+/* Whether or not rendering a color value with either format results in the
+ * same pixel. This can return false negatives.
+ */
+bool
+iris_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
 iris_resource_render_aux_usage(struct iris_context *ice,
                                struct iris_resource *res,
@@ -1015,6 +1034,22 @@ iris_resource_render_aux_usage(struct iris_context *ice,
           !isl_color_value_is_zero_one(res->aux.clear_color, render_format))
          return ISL_AUX_USAGE_NONE;
 
+      /* Disable CCS for some cases of texture-view rendering. On gen12, 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 (!iris_render_formats_color_compatible(render_format,
+                                                res->surf.format,
+                                                res->aux.clear_color)) {
+         return ISL_AUX_USAGE_NONE;
+      }
+
       if (res->aux.usage == ISL_AUX_USAGE_CCS_E &&
           format_ccs_e_compat_with_resource(devinfo, res, render_format))
          return ISL_AUX_USAGE_CCS_E;
index 955b8269a70cd0c2cbe19cd30b06c552276fb935..3323b132daee34f4dab978538b80937c81af4b09 100644 (file)
@@ -494,6 +494,9 @@ bool iris_has_color_unresolved(const struct iris_resource *res,
                                unsigned start_level, unsigned num_levels,
                                unsigned start_layer, unsigned num_layers);
 
+bool iris_render_formats_color_compatible(enum isl_format a,
+                                          enum isl_format b,
+                                          union isl_color_value color);
 enum isl_aux_usage iris_resource_render_aux_usage(struct iris_context *ice,
                                                   struct iris_resource *res,
                                                   enum isl_format render_fmt,