intel/isl: Add a formats_are_ccs_e_compatible helper
authorJason Ekstrand <jason.ekstrand@intel.com>
Wed, 1 Feb 2017 19:46:54 +0000 (11:46 -0800)
committerJason Ekstrand <jason.ekstrand@intel.com>
Thu, 2 Feb 2017 21:33:43 +0000 (13:33 -0800)
Reviewed-by: Samuel Iglesias Gonsálvez <siglesias@igalia.com>
Reviewed-by: Chad Versace <chadversary@chromium.org>
Reviewed-by: Anuj Phogat <anuj.phogat@gmail.com>
src/intel/blorp/blorp_blit.c
src/intel/isl/isl.h
src/intel/isl/isl_format.c

index 8a944fba624e60ebdf5eee68f07a7a39c051e85f..b89a112b8c403315706b961e209a360478787c56 100644 (file)
@@ -2395,11 +2395,17 @@ blorp_copy(struct blorp_batch *batch,
    }
 
    if (params.src.aux_usage == ISL_AUX_USAGE_CCS_E) {
+      assert(isl_formats_are_ccs_e_compatible(batch->blorp->isl_dev->info,
+                                              src_surf->surf->format,
+                                              params.src.view.format));
       params.src.clear_color =
          bitcast_color_value_to_uint(params.src.clear_color, src_fmtl);
    }
 
    if (params.dst.aux_usage == ISL_AUX_USAGE_CCS_E) {
+      assert(isl_formats_are_ccs_e_compatible(batch->blorp->isl_dev->info,
+                                              dst_surf->surf->format,
+                                              params.dst.view.format));
       params.dst.clear_color =
          bitcast_color_value_to_uint(params.dst.clear_color, dst_fmtl);
    }
index 47e4a1eb4ee432e276d054f8005de53d84198bfa..eff7218748e86b557c9ea287002ab14503d0be75 100644 (file)
@@ -1047,6 +1047,10 @@ bool isl_format_supports_ccs_e(const struct gen_device_info *devinfo,
 bool isl_format_supports_multisampling(const struct gen_device_info *devinfo,
                                        enum isl_format format);
 
+bool isl_formats_are_ccs_e_compatible(const struct gen_device_info *devinfo,
+                                      enum isl_format format1,
+                                      enum isl_format format2);
+
 bool isl_format_has_unorm_channel(enum isl_format fmt) ATTRIBUTE_CONST;
 bool isl_format_has_snorm_channel(enum isl_format fmt) ATTRIBUTE_CONST;
 bool isl_format_has_ufloat_channel(enum isl_format fmt) ATTRIBUTE_CONST;
index ed5a0636eb4fb7806dd9db81b5144ccc43e7431f..ef6c98d50b360a16a0c5b2545603eb4b6c3e85c3 100644 (file)
@@ -504,6 +504,37 @@ isl_format_supports_multisampling(const struct gen_device_info *devinfo,
    }
 }
 
+/**
+ * Returns true if the two formats are "CCS_E compatible" meaning that you can
+ * render in one format with CCS_E enabled and then texture using the other
+ * format without needing a resolve.
+ *
+ * Note: Even if the formats are compatible, special care must be taken if a
+ * clear color is involved because the encoding of the clear color is heavily
+ * format-dependent.
+ */
+bool
+isl_formats_are_ccs_e_compatible(const struct gen_device_info *devinfo,
+                                 enum isl_format format1,
+                                 enum isl_format format2)
+{
+   /* They must support CCS_E */
+   if (!isl_format_supports_ccs_e(devinfo, format1) ||
+       !isl_format_supports_ccs_e(devinfo, format2))
+      return false;
+
+   const struct isl_format_layout *fmtl1 = isl_format_get_layout(format1);
+   const struct isl_format_layout *fmtl2 = isl_format_get_layout(format2);
+
+   /* The compression used by CCS is not dependent on the actual data encoding
+    * of the format but only depends on the bit-layout of the channels.
+    */
+   return fmtl1->channels.r.bits == fmtl2->channels.r.bits &&
+          fmtl1->channels.g.bits == fmtl2->channels.g.bits &&
+          fmtl1->channels.b.bits == fmtl2->channels.b.bits &&
+          fmtl1->channels.a.bits == fmtl2->channels.a.bits;
+}
+
 static inline bool
 isl_format_has_channel_type(enum isl_format fmt, enum isl_base_type type)
 {