intel/isl: Add a helper for inverting swizzles
[mesa.git] / src / intel / isl / isl.h
index d81df31a372771c415ca6488d6b28d9db16f9aad..c1d73646ab4440e34301b4c9b1c6d470efd5c2fb 100644 (file)
@@ -618,7 +618,11 @@ enum isl_aux_usage {
  *       color by simply changing the clear color without modifying either
  *       surface.
  *
- *    2) Compressed w/ Clear:  In this state, neither the auxiliary surface
+ *    2) Partial Clear:  In this state, each block in the auxiliary surface
+ *       contains either the magic clear or pass-through value.  See Clear and
+ *       Pass-through for more details.
+ *
+ *    3) Compressed w/ Clear:  In this state, neither the auxiliary surface
  *       nor the primary surface has a complete representation of the data.
  *       Instead, both surfaces must be used together or else rendering
  *       corruption may occur.  Depending on the auxiliary compression format
@@ -627,19 +631,19 @@ enum isl_aux_usage {
  *       values.  Blocks may also be in the clear state (see Clear) and have
  *       their value taken from outside the surface.
  *
- *    3) Compressed w/o Clear:  This state is identical to the state above
+ *    4) Compressed w/o Clear:  This state is identical to the state above
  *       except that no blocks are in the clear state.  In this state, all of
  *       the data required to reconstruct the final sample values is contained
  *       in the auxiliary and primary surface and the clear value is not
  *       considered.
  *
- *    4) Resolved:  In this state, the primary surface contains 100% of the
+ *    5) Resolved:  In this state, the primary surface contains 100% of the
  *       data.  The auxiliary surface is also valid so the surface can be
  *       validly used with or without aux enabled.  The auxiliary surface may,
  *       however, contain non-trivial data and any update to the primary
  *       surface with aux disabled will cause the two to get out of sync.
  *
- *    5) Pass-through:  In this state, the primary surface contains 100% of the
+ *    6) Pass-through:  In this state, the primary surface contains 100% of the
  *       data and every block in the auxiliary surface contains a magic value
  *       which indicates that the auxiliary surface should be ignored and the
  *       only the primary surface should be considered.  Updating the primary
@@ -648,7 +652,7 @@ enum isl_aux_usage {
  *       cause the auxiliary buffer to contain non-trivial data and no longer
  *       be in the pass-through state.
  *
- *    5) Aux Invalid:  In this state, the primary surface contains 100% of the
+ *    7) Aux Invalid:  In this state, the primary surface contains 100% of the
  *       data and the auxiliary surface is completely bogus.  Any attempt to
  *       use the auxiliary surface is liable to result in rendering
  *       corruption.  The only thing that one can do to re-enable aux once
@@ -657,30 +661,8 @@ enum isl_aux_usage {
  *
  * Drawing with or without aux enabled may implicitly cause the surface to
  * transition between these states.  There are also four types of auxiliary
- * compression operations which cause an explicit transition:
- *
- *    1) Fast Clear:  This operation writes the magic "clear" value to the
- *       auxiliary surface.  This operation will safely transition any slice
- *       of a surface from any state to the clear state so long as the entire
- *       slice is fast cleared at once.
- *
- *    2) Full Resolve:  This operation combines the auxiliary surface data
- *       with the primary surface data and writes the result to the primary.
- *       For HiZ, the docs call this a depth resolve.  For CCS, the hardware
- *       full resolve operation does both a full resolve and an ambiguate so
- *       it actually takes you all the way to the pass-through state.
- *
- *    3) Partial Resolve:  This operation considers blocks which are in the
- *       "clear" state and writes the clear value directly into the primary or
- *       auxiliary surface.  Once this operation completes, the surface is
- *       still compressed but no longer references the clear color.  This
- *       operation is only available for CCS.
- *
- *    4) Ambiguate:  This operation throws away the current auxiliary data and
- *       replaces it with the magic pass-through value.  If an ambiguate
- *       operation is performed when the primary surface does not contain 100%
- *       of the data, data will be lost.  This operation is only implemented
- *       in hardware for depth where it is called a HiZ resolve.
+ * compression operations which cause an explicit transition which are
+ * described by the isl_aux_op enum below.
  *
  * Not all operations are valid or useful in all states.  The diagram below
  * contains a complete description of the states and all valid and useful
@@ -689,34 +671,46 @@ enum isl_aux_usage {
  *   Draw w/ Aux
  *   +----------+
  *   |          |
- *   |       +-------------+     Draw w/ Aux      +-------------+
- *   +------>| Compressed  |<---------------------|    Clear    |
- *           |  w/ Clear   |                      |             |
- *           +-------------+                      +-------------+
- *                  |   |                                |
- *          Partial |   |                                |
- *          Resolve |   |        Full Resolve            |
- *                  |   +----------------------------+   |  Full
- *                  |                                |   | Resolve
- *   Draw w/ aux    |                                |   |
- *   +----------+   |                                |   |
- *   |          |  \|/                              \|/ \|/
- *   |       +-------------+     Full Resolve     +-------------+
- *   +------>| Compressed  |--------------------->|  Resolved   |
- *           |  w/o Clear  |<---------------------|             |
- *           +-------------+     Draw w/ Aux      +-------------+
- *                 /|\                               |   |
- *                  |  Draw                          |   |  Draw
- *                  | w/ Aux                         |   | w/o Aux
- *                  |             Ambiguate          |   |
- *                  |   +----------------------------+   |
- *   Draw w/o Aux   |   |                                |   Draw w/o Aux
- *   +----------+   |   |                                |   +----------+
- *   |          |   |  \|/                              \|/  |          |
- *   |       +-------------+      Ambiguate       +-------------+       |
- *   +------>|    Pass-    |<---------------------|     Aux     |<------+
- *           |   through   |                      |   Invalid   |
- *           +-------------+                      +-------------+
+ *   |       +-------------+    Draw w/ Aux     +-------------+
+ *   +------>| Compressed  |<-------------------|    Clear    |
+ *           |  w/ Clear   |----->----+         |             |
+ *           +-------------+          |         +-------------+
+ *                  |  /|\            |            |   |
+ *                  |   |             |            |   |
+ *                  |   |             +------<-----+   |  Draw w/
+ *                  |   |             |                | Clear Only
+ *                  |   |      Full   |                |   +----------+
+ *          Partial |   |     Resolve |               \|/  |          |
+ *          Resolve |   |             |         +-------------+       |
+ *                  |   |             |         |   Partial   |<------+
+ *                  |   |             |         |    Clear    |<----------+
+ *                  |   |             |         +-------------+           |
+ *                  |   |             |                |                  |
+ *                  |   |             +------>---------+  Full            |
+ *                  |   |                              | Resolve          |
+ *   Draw w/ aux    |   |   Partial Fast Clear         |                  |
+ *   +----------+   |   +--------------------------+   |                  |
+ *   |          |  \|/                             |  \|/                 |
+ *   |       +-------------+    Full Resolve    +-------------+           |
+ *   +------>| Compressed  |------------------->|  Resolved   |           |
+ *           |  w/o Clear  |<-------------------|             |           |
+ *           +-------------+    Draw w/ Aux     +-------------+           |
+ *                 /|\                             |   |                  |
+ *                  |  Draw                        |   |  Draw            |
+ *                  | w/ Aux                       |   | w/o Aux          |
+ *                  |            Ambiguate         |   |                  |
+ *                  |   +--------------------------+   |                  |
+ *   Draw w/o Aux   |   |                              |   Draw w/o Aux   |
+ *   +----------+   |   |                              |   +----------+   |
+ *   |          |   |  \|/                            \|/  |          |   |
+ *   |       +-------------+     Ambiguate      +-------------+       |   |
+ *   +------>|    Pass-    |<-------------------|     Aux     |<------+   |
+ *   +------>|   through   |                    |   Invalid   |           |
+ *   |       +-------------+                    +-------------+           |
+ *   |          |   |                                                     |
+ *   +----------+   +-----------------------------------------------------+
+ *     Draw w/                       Partial Fast Clear
+ *    Clear Only
  *
  *
  * While the above general theory applies to all forms of auxiliary
@@ -742,7 +736,7 @@ enum isl_aux_usage {
  * CCS_D:   Single-sample fast-clears (also called CCS_D in ISL) are one of
  *          the simplest forms of compression since they don't do anything
  *          beyond clear color tracking.  They really only support three of
- *          the six states: Clear, Compressed w/ Clear, and Pass-through.  The
+ *          the six states: Clear, Partial Clear, and Pass-through.  The
  *          only CCS_D operation is "Resolve" which maps to a full resolve
  *          followed by an ambiguate.
  *
@@ -762,6 +756,7 @@ enum isl_aux_usage {
  */
 enum isl_aux_state {
    ISL_AUX_STATE_CLEAR = 0,
+   ISL_AUX_STATE_PARTIAL_CLEAR,
    ISL_AUX_STATE_COMPRESSED_CLEAR,
    ISL_AUX_STATE_COMPRESSED_NO_CLEAR,
    ISL_AUX_STATE_RESOLVED,
@@ -769,6 +764,53 @@ enum isl_aux_state {
    ISL_AUX_STATE_AUX_INVALID,
 };
 
+/**
+ * Enum which describes explicit aux transition operations.
+ */
+enum isl_aux_op {
+   ISL_AUX_OP_NONE,
+
+   /** Fast Clear
+    *
+    * This operation writes the magic "clear" value to the auxiliary surface.
+    * This operation will safely transition any slice of a surface from any
+    * state to the clear state so long as the entire slice is fast cleared at
+    * once.  A fast clear that only covers part of a slice of a surface is
+    * called a partial fast clear.
+    */
+   ISL_AUX_OP_FAST_CLEAR,
+
+   /** Full Resolve
+    *
+    * This operation combines the auxiliary surface data with the primary
+    * surface data and writes the result to the primary.  For HiZ, the docs
+    * call this a depth resolve.  For CCS, the hardware full resolve operation
+    * does both a full resolve and an ambiguate so it actually takes you all
+    * the way to the pass-through state.
+    */
+   ISL_AUX_OP_FULL_RESOLVE,
+
+   /** Partial Resolve
+    *
+    * This operation considers blocks which are in the "clear" state and
+    * writes the clear value directly into the primary or auxiliary surface.
+    * Once this operation completes, the surface is still compressed but no
+    * longer references the clear color.  This operation is only available
+    * for CCS_E.
+    */
+   ISL_AUX_OP_PARTIAL_RESOLVE,
+
+   /** Ambiguate
+    *
+    * This operation throws away the current auxiliary data and replaces it
+    * with the magic pass-through value.  If an ambiguate operation is
+    * performed when the primary surface does not contain 100% of the data,
+    * data will be lost.  This operation is only implemented in hardware for
+    * depth where it is called a HiZ resolve.
+    */
+   ISL_AUX_OP_AMBIGUATE,
+};
+
 /* TODO(chadv): Explain */
 enum isl_array_pitch_span {
    ISL_ARRAY_PITCH_SPAN_FULL,
@@ -919,6 +961,16 @@ struct isl_device {
       uint8_t align;
       uint8_t addr_offset;
       uint8_t aux_addr_offset;
+
+      /* Rounded up to the nearest dword to simplify GPU memcpy operations. */
+
+      /* size of the state buffer used to store the clear color + extra
+       * additional space used by the hardware */
+      uint8_t clear_color_state_size;
+      uint8_t clear_color_state_offset;
+      /* size of the clear color itself - used to copy it to/from a BO */
+      uint8_t clear_value_size;
+      uint8_t clear_value_offset;
    } ss;
 
    /**
@@ -972,15 +1024,18 @@ struct isl_format_layout {
    uint8_t bh; /**< Block height, in pixels */
    uint8_t bd; /**< Block depth, in pixels */
 
-   struct {
-      struct isl_channel_layout r; /**< Red channel */
-      struct isl_channel_layout g; /**< Green channel */
-      struct isl_channel_layout b; /**< Blue channel */
-      struct isl_channel_layout a; /**< Alpha channel */
-      struct isl_channel_layout l; /**< Luminance channel */
-      struct isl_channel_layout i; /**< Intensity channel */
-      struct isl_channel_layout p; /**< Palette channel */
-   } channels;
+   union {
+      struct {
+         struct isl_channel_layout r; /**< Red channel */
+         struct isl_channel_layout g; /**< Green channel */
+         struct isl_channel_layout b; /**< Blue channel */
+         struct isl_channel_layout a; /**< Alpha channel */
+         struct isl_channel_layout l; /**< Luminance channel */
+         struct isl_channel_layout i; /**< Intensity channel */
+         struct isl_channel_layout p; /**< Palette channel */
+      } channels;
+      struct isl_channel_layout channels_array[7];
+   };
 
    enum isl_colorspace colorspace;
    enum isl_txc txc;
@@ -1252,6 +1307,15 @@ struct isl_surf_fill_state_info {
     */
    union isl_color_value clear_color;
 
+   /**
+    * Send only the clear value address
+    *
+    * If set, we only pass the clear address to the GPU and it will fetch it
+    * from wherever it is.
+    */
+   bool use_clear_address;
+   uint64_t clear_address;
+
    /**
     * Surface write disables for gen4-5
     */
@@ -1361,6 +1425,8 @@ isl_format_get_layout(enum isl_format fmt)
    return &isl_format_layouts[fmt];
 }
 
+bool isl_format_is_valid(enum isl_format);
+
 static inline const char * ATTRIBUTE_CONST
 isl_format_get_name(enum isl_format fmt)
 {
@@ -1476,9 +1542,19 @@ isl_format_block_is_1x1x1(enum isl_format fmt)
    return fmtl->bw == 1 && fmtl->bh == 1 && fmtl->bd == 1;
 }
 
+static inline bool
+isl_format_is_srgb(enum isl_format fmt)
+{
+   return isl_format_layouts[fmt].colorspace == ISL_COLORSPACE_SRGB;
+}
+
+enum isl_format isl_format_srgb_to_linear(enum isl_format fmt);
+
 static inline bool
 isl_format_is_rgb(enum isl_format fmt)
 {
+   if (isl_format_is_yuv(fmt))
+      return false;
    return isl_format_layouts[fmt].channels.r.bits > 0 &&
           isl_format_layouts[fmt].channels.g.bits > 0 &&
           isl_format_layouts[fmt].channels.b.bits > 0 &&
@@ -1516,9 +1592,54 @@ isl_tiling_is_std_y(enum isl_tiling tiling)
 uint32_t
 isl_tiling_to_i915_tiling(enum isl_tiling tiling);
 
+enum isl_tiling 
+isl_tiling_from_i915_tiling(uint32_t tiling);
+
 const struct isl_drm_modifier_info * ATTRIBUTE_CONST
 isl_drm_modifier_get_info(uint64_t modifier);
 
+static inline bool
+isl_drm_modifier_has_aux(uint64_t modifier)
+{
+   return isl_drm_modifier_get_info(modifier)->aux_usage != ISL_AUX_USAGE_NONE;
+}
+
+/** Returns the default isl_aux_state for the given modifier.
+ *
+ * If we have a modifier which supports compression, then the auxiliary data
+ * could be in state other than ISL_AUX_STATE_AUX_INVALID.  In particular, it
+ * can be in any of the following:
+ *
+ *  - ISL_AUX_STATE_CLEAR
+ *  - ISL_AUX_STATE_PARTIAL_CLEAR
+ *  - ISL_AUX_STATE_COMPRESSED_CLEAR
+ *  - ISL_AUX_STATE_COMPRESSED_NO_CLEAR
+ *  - ISL_AUX_STATE_RESOLVED
+ *  - ISL_AUX_STATE_PASS_THROUGH
+ *
+ * If the modifier does not support fast-clears, then we are guaranteed
+ * that the surface is at least partially resolved and the first three not
+ * possible.  We return ISL_AUX_STATE_COMPRESSED_CLEAR if the modifier
+ * supports fast clears and ISL_AUX_STATE_COMPRESSED_NO_CLEAR if it does not
+ * because they are the least common denominator of the set of possible aux
+ * states and will yield a valid interpretation of the aux data.
+ *
+ * For modifiers with no aux support, ISL_AUX_STATE_AUX_INVALID is returned.
+ */
+static inline enum isl_aux_state
+isl_drm_modifier_get_default_aux_state(uint64_t modifier)
+{
+   const struct isl_drm_modifier_info *mod_info =
+      isl_drm_modifier_get_info(modifier);
+
+   if (!mod_info || mod_info->aux_usage == ISL_AUX_USAGE_NONE)
+      return ISL_AUX_STATE_AUX_INVALID;
+
+   assert(mod_info->aux_usage == ISL_AUX_USAGE_CCS_E);
+   return mod_info->supports_clear_color ? ISL_AUX_STATE_COMPRESSED_CLEAR :
+                                           ISL_AUX_STATE_COMPRESSED_NO_CLEAR;
+}
+
 struct isl_extent2d ATTRIBUTE_CONST
 isl_get_interleaved_msaa_px_size_sa(uint32_t samples);
 
@@ -1604,6 +1725,30 @@ isl_extent4d(uint32_t width, uint32_t height, uint32_t depth,
    return e;
 }
 
+bool isl_color_value_is_zero(union isl_color_value value,
+                             enum isl_format format);
+
+bool isl_color_value_is_zero_one(union isl_color_value value,
+                                 enum isl_format format);
+
+static inline bool
+isl_swizzle_is_identity(struct isl_swizzle swizzle)
+{
+   return swizzle.r == ISL_CHANNEL_SELECT_RED &&
+          swizzle.g == ISL_CHANNEL_SELECT_GREEN &&
+          swizzle.b == ISL_CHANNEL_SELECT_BLUE &&
+          swizzle.a == ISL_CHANNEL_SELECT_ALPHA;
+}
+
+bool
+isl_swizzle_supports_rendering(const struct gen_device_info *devinfo,
+                               struct isl_swizzle swizzle);
+
+struct isl_swizzle
+isl_swizzle_compose(struct isl_swizzle first, struct isl_swizzle second);
+struct isl_swizzle
+isl_swizzle_invert(struct isl_swizzle swizzle);
+
 #define isl_surf_init(dev, surf, ...) \
    isl_surf_init_s((dev), (surf), \
                    &(struct isl_surf_init_info) {  __VA_ARGS__ });
@@ -1649,6 +1794,10 @@ void
 isl_buffer_fill_state_s(const struct isl_device *dev, void *state,
                         const struct isl_buffer_fill_state_info *restrict info);
 
+void
+isl_null_fill_state(const struct isl_device *dev, void *state,
+                    struct isl_extent3d size);
+
 #define isl_emit_depth_stencil_hiz(dev, batch, ...) \
    isl_emit_depth_stencil_hiz_s((dev), (batch), \
                                 &(struct isl_depth_stencil_hiz_emit_info) {  __VA_ARGS__ })
@@ -1805,6 +1954,29 @@ isl_surf_get_image_offset_B_tile_sa(const struct isl_surf *surf,
                                     uint32_t *x_offset_sa,
                                     uint32_t *y_offset_sa);
 
+/**
+ * Create an isl_surf that represents a particular subimage in the surface.
+ *
+ * The newly created surface will have a single miplevel and array slice.  The
+ * surface lives at the returned byte and intratile offsets, in samples.
+ *
+ * It is safe to call this function with surf == image_surf.
+ *
+ * @invariant level < surface levels
+ * @invariant logical_array_layer < logical array length of surface
+ * @invariant logical_z_offset_px < logical depth of surface at level
+ */
+void
+isl_surf_get_image_surf(const struct isl_device *dev,
+                        const struct isl_surf *surf,
+                        uint32_t level,
+                        uint32_t logical_array_layer,
+                        uint32_t logical_z_offset_px,
+                        struct isl_surf *image_surf,
+                        uint32_t *offset_B,
+                        uint32_t *x_offset_sa,
+                        uint32_t *y_offset_sa);
+
 /**
  * @brief Calculate the intratile offsets to a surface.
  *