[Mesa-dev] [RFC v2 03/23] intel/isl: Add ISL <-> DRM modifier conversion

Louis-Francis Ratté-Boulianne lfrb at collabora.com
Thu Aug 31 04:23:58 UTC 2017


From: Chad Versace <chadversary at chromium.org>

It converts a DRM format modifier to and from enum isl_tiling and
aux_usage. That's all.
---
 src/intel/Makefile.isl.am |  1 +
 src/intel/isl/isl.c       | 59 +++++++++++++++++++++++++++++++++++++++++++++++
 src/intel/isl/isl.h       | 16 +++++++++++++
 3 files changed, 76 insertions(+)

diff --git a/src/intel/Makefile.isl.am b/src/intel/Makefile.isl.am
index 31273af36c..cea69ed0f1 100644
--- a/src/intel/Makefile.isl.am
+++ b/src/intel/Makefile.isl.am
@@ -34,6 +34,7 @@ noinst_LTLIBRARIES += $(ISL_GEN_LIBS) isl/libisl.la
 
 isl_libisl_la_LIBADD = $(ISL_GEN_LIBS)
 isl_libisl_la_SOURCES = $(ISL_FILES) $(ISL_GENERATED_FILES)
+isl_libisl_la_CFLAGS = $(AM_CFLAGS) $(LIBDRM_CFLAGS)
 
 isl_libisl_gen4_la_SOURCES = $(ISL_GEN4_FILES)
 isl_libisl_gen4_la_CFLAGS = $(AM_CFLAGS) -DGEN_VERSIONx10=40
diff --git a/src/intel/isl/isl.c b/src/intel/isl/isl.c
index 59f512fc05..fd8fcf5e93 100644
--- a/src/intel/isl/isl.c
+++ b/src/intel/isl/isl.c
@@ -26,6 +26,7 @@
 #include <stdio.h>
 
 #include "genxml/genX_bits.h"
+#include <drm_fourcc.h>
 
 #include "isl.h"
 #include "isl_gen4.h"
@@ -35,6 +36,10 @@
 #include "isl_gen9.h"
 #include "isl_priv.h"
 
+#ifndef DRM_FORMAT_MOD_LINEAR
+#define DRM_FORMAT_MOD_LINEAR 0 /* Linux 4.10 */
+#endif
+
 void PRINTFLIKE(3, 4) UNUSED
 __isl_finishme(const char *file, int line, const char *fmt, ...)
 {
@@ -48,6 +53,60 @@ __isl_finishme(const char *file, int line, const char *fmt, ...)
    fprintf(stderr, "%s:%d: FINISHME: %s\n", file, line, buf);
 }
 
+bool
+isl_tiling_from_drm_format_mod(uint64_t mod, enum isl_tiling *tiling,
+                               enum isl_aux_usage *aux_usage)
+{
+   switch (mod) {
+   case DRM_FORMAT_MOD_LINEAR:
+      *tiling = ISL_TILING_LINEAR;
+      *aux_usage = ISL_AUX_USAGE_NONE;
+      return true;
+   case I915_FORMAT_MOD_X_TILED:
+      *tiling = ISL_TILING_X;
+      *aux_usage = ISL_AUX_USAGE_NONE;
+      return true;
+   case I915_FORMAT_MOD_Y_TILED:
+      *tiling = ISL_TILING_Y0;
+      *aux_usage = ISL_AUX_USAGE_NONE;
+      return true;
+   case I915_FORMAT_MOD_Yf_TILED:
+      *tiling = ISL_TILING_Yf;
+      *aux_usage = ISL_AUX_USAGE_NONE;
+      return true;
+   }
+
+   return false;
+}
+
+uint64_t
+isl_tiling_to_drm_format_mod(enum isl_tiling tiling,
+                             enum isl_aux_usage aux_usage)
+{
+   /* XXX: Need to disambiguate aux surface usage; we can validly have a CCS
+    *      aux surface attached (e.g. Y_CCS modifier), but always resolve it
+    *      before usage such that sampling with no aux plane (e.g. plain Y mod)
+    *      is valid. Punt for now, and revisit when we expose aux surfaces to
+    *      external consumers. */
+
+   switch (tiling) {
+   case ISL_TILING_LINEAR:
+      return DRM_FORMAT_MOD_LINEAR;
+   case ISL_TILING_X:
+      return I915_FORMAT_MOD_X_TILED;
+   case ISL_TILING_Y0:
+      return I915_FORMAT_MOD_Y_TILED;
+   case ISL_TILING_Yf:
+      return I915_FORMAT_MOD_Yf_TILED;
+   case ISL_TILING_W:
+   case ISL_TILING_HIZ:
+   case ISL_TILING_CCS:
+      unreachable("non-color-buffer mode in isl_tiling_to_drm_format_mod");
+   }
+
+   unreachable("unknown tiling in isl_tiling_to_drm_format_mod");
+}
+
 void
 isl_device_init(struct isl_device *dev,
                 const struct gen_device_info *info,
diff --git a/src/intel/isl/isl.h b/src/intel/isl/isl.h
index ca4556ffcf..09b3850ca4 100644
--- a/src/intel/isl/isl.h
+++ b/src/intel/isl/isl.h
@@ -1531,6 +1531,22 @@ bool
 isl_has_matching_typed_storage_image_format(const struct gen_device_info *devinfo,
                                             enum isl_format fmt);
 
+/**
+ * Map a DRM format modifier to tiling and aux usage. If the modifier is not
+ * known to ISL, return false. The output parameters are only written on
+ * success.
+ */
+bool isl_tiling_from_drm_format_mod(uint64_t mod,
+                                    enum isl_tiling *tiling,
+                                    enum isl_aux_usage *aux_usage);
+
+/**
+ * Map tiling and aux usage to a DRM format modifier to tiling and aux usage.
+ * The parameters provided must map to a valid modifier.
+ */
+uint64_t isl_tiling_to_drm_format_mod(enum isl_tiling tiling,
+                                      enum isl_aux_usage aux_usage);
+
 static inline bool
 isl_tiling_is_any_y(enum isl_tiling tiling)
 {
-- 
2.13.0



More information about the mesa-dev mailing list