intel/compiler/test: use TEST_DEBUG env var consistently
[mesa.git] / src / intel / isl / isl_gen7.c
index 7064e852e654d71b0889da24f3692e2043007fa6..fa2456679684c4f9bd7d3ce3b9bf4086c0c64cfb 100644 (file)
 #include "isl_gen7.h"
 #include "isl_priv.h"
 
-bool
-gen7_choose_msaa_layout(const struct isl_device *dev,
-                        const struct isl_surf_init_info *info,
-                        enum isl_tiling tiling,
-                        enum isl_msaa_layout *msaa_layout)
+static bool
+gen7_format_needs_valign2(const struct isl_device *dev,
+                          enum isl_format format)
 {
-   const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
+   assert(ISL_DEV_GEN(dev) == 7);
+
+   /* From the Ivybridge PRM (2012-05-31), Volume 4, Part 1, Section 2.12.1,
+    * RENDER_SURFACE_STATE Surface Vertical Alignment:
+    *
+    *    - Value of 1 [VALIGN_4] is not supported for format YCRCB_NORMAL
+    *      (0x182), YCRCB_SWAPUVY (0x183), YCRCB_SWAPUV (0x18f), YCRCB_SWAPY
+    *      (0x190)
+    *
+    *    - VALIGN_4 is not supported for surface format R32G32B32_FLOAT.
+    *
+    * The R32G32B32_FLOAT restriction is dropped on Haswell.
+    */
+   return isl_format_is_yuv(format) ||
+          (format == ISL_FORMAT_R32G32B32_FLOAT && !ISL_DEV_IS_HASWELL(dev));
+}
 
+bool
+isl_gen7_choose_msaa_layout(const struct isl_device *dev,
+                            const struct isl_surf_init_info *info,
+                            enum isl_tiling tiling,
+                            enum isl_msaa_layout *msaa_layout)
+{
    bool require_array = false;
    bool require_interleaved = false;
 
@@ -43,19 +62,7 @@ gen7_choose_msaa_layout(const struct isl_device *dev,
       return true;
    }
 
-   /* From the Ivybridge PRM, Volume 4 Part 1 p63, SURFACE_STATE, Surface
-    * Format:
-    *
-    *    If Number of Multisamples is set to a value other than
-    *    MULTISAMPLECOUNT_1, this field cannot be set to the following
-    *    formats: any format with greater than 64 bits per element, any
-    *    compressed texture format (BC*), and any YCRCB* format.
-    */
-   if (fmtl->bs > 8)
-      return false;
-   if (isl_format_is_compressed(info->format))
-      return false;
-   if (isl_format_is_yuv(info->format))
+   if (!isl_format_supports_multisampling(dev->info, info->format))
       return false;
 
    /* From the Ivybridge PRM, Volume 4 Part 1 p73, SURFACE_STATE, Number of
@@ -90,8 +97,13 @@ gen7_choose_msaa_layout(const struct isl_device *dev,
     * Note that the above SINT restrictions apply only to *MSRTs* (that is,
     * *multisampled* render targets). The restrictions seem to permit an MCS
     * if the render target is singlesampled.
+    *
+    * Moreover, empirically it looks that hardware can render multisampled
+    * surfaces with RGBA8I, RGBA16I and RGBA32I.
     */
-   if (isl_format_has_sint_channel(info->format))
+
+   /* Multisampling requires vertical alignment of four. */
+   if (info->samples > 1 && gen7_format_needs_valign2(dev, info->format))
       return false;
 
    /* More obvious restrictions */
@@ -111,7 +123,8 @@ gen7_choose_msaa_layout(const struct isl_device *dev,
     * In the table above, MSFMT_MSS refers to ISL_MSAA_LAYOUT_ARRAY, and
     * MSFMT_DEPTH_STENCIL refers to ISL_MSAA_LAYOUT_INTERLEAVED.
     */
-   if (isl_surf_usage_is_depth_or_stencil(info->usage))
+   if (isl_surf_usage_is_depth_or_stencil(info->usage) ||
+       (info->usage & ISL_SURF_USAGE_HIZ_BIT))
       require_interleaved = true;
 
    /* From the Ivybridge PRM, Volume 4 Part 1 p72, SURFACE_STATE, Multisampled
@@ -121,7 +134,7 @@ gen7_choose_msaa_layout(const struct isl_device *dev,
     *    is >= 8192 (meaning the actual surface width is >= 8193 pixels), this
     *    field must be set to MSFMT_MSS.
     */
-   if (info->samples == 8 && info->width == 8192)
+   if (info->samples == 8 && info->width > 8192)
       require_array = true;
 
    /* From the Ivybridge PRM, Volume 4 Part 1 p72, SURFACE_STATE, Multisampled
@@ -164,27 +177,6 @@ gen7_choose_msaa_layout(const struct isl_device *dev,
    return true;
 }
 
-static bool
-gen7_format_needs_valign2(const struct isl_device *dev,
-                          enum isl_format format)
-{
-   /* This workaround applies only to gen7 */
-   if (ISL_DEV_GEN(dev) > 7)
-      return false;
-
-   /* From the Ivybridge PRM (2012-05-31), Volume 4, Part 1, Section 2.12.1,
-    * RENDER_SURFACE_STATE Surface Vertical Alignment:
-    *
-    *    - Value of 1 [VALIGN_4] is not supported for format YCRCB_NORMAL
-    *      (0x182), YCRCB_SWAPUVY (0x183), YCRCB_SWAPUV (0x18f), YCRCB_SWAPY
-    *      (0x190)
-    *
-    *    - VALIGN_4 is not supported for surface format R32G32B32_FLOAT.
-    */
-   return isl_format_is_yuv(format) ||
-          format == ISL_FORMAT_R32G32B32_FLOAT;
-}
-
 /**
  * @brief Filter out tiling flags that are incompatible with the surface.
  *
@@ -197,9 +189,9 @@ gen7_format_needs_valign2(const struct isl_device *dev,
  * flags except ISL_TILING_X_BIT and ISL_TILING_LINEAR_BIT.
  */
 void
-gen7_filter_tiling(const struct isl_device *dev,
-                   const struct isl_surf_init_info *restrict info,
-                   isl_tiling_flags_t *flags)
+isl_gen6_filter_tiling(const struct isl_device *dev,
+                       const struct isl_surf_init_info *restrict info,
+                       isl_tiling_flags_t *flags)
 {
    /* IVB+ requires separate stencil */
    assert(ISL_DEV_USE_SEPARATE_STENCIL(dev));
@@ -221,15 +213,28 @@ gen7_filter_tiling(const struct isl_device *dev,
       *flags &= ISL_TILING_ANY_Y_MASK;
    }
 
-   /* Separate stencil requires W tiling, and W tiling requires separate
-    * stencil.
-    */
    if (isl_surf_usage_is_stencil(info->usage)) {
-      *flags &= ISL_TILING_W_BIT;
+      if (ISL_DEV_GEN(dev) >= 12) {
+         /* Stencil requires Y. */
+         *flags &= ISL_TILING_ANY_Y_MASK;
+      } else {
+         /* Stencil requires W. */
+         *flags &= ISL_TILING_W_BIT;
+      }
    } else {
       *flags &= ~ISL_TILING_W_BIT;
    }
 
+   /* From the SKL+ PRMs, RENDER_SURFACE_STATE:TileMode,
+    *    If Surface Format is ASTC*, this field must be TILEMODE_YMAJOR.
+    */
+   if (isl_format_get_layout(info->format)->txc == ISL_TXC_ASTC)
+      *flags &= ISL_TILING_Y0_BIT;
+
+   /* MCS buffers are always Y-tiled */
+   if (isl_format_get_layout(info->format)->txc == ISL_TXC_MCS)
+      *flags &= ISL_TILING_Y0_BIT;
+
    if (info->usage & (ISL_SURF_USAGE_DISPLAY_ROTATE_90_BIT |
                       ISL_SURF_USAGE_DISPLAY_ROTATE_180_BIT |
                       ISL_SURF_USAGE_DISPLAY_ROTATE_270_BIT)) {
@@ -246,9 +251,19 @@ gen7_filter_tiling(const struct isl_device *dev,
    }
 
    if (info->usage & ISL_SURF_USAGE_DISPLAY_BIT) {
-      /* Before Skylake, the display engine does not accept Y */
-      /* FINISHME[SKL]: Y tiling for display surfaces */
-      *flags &= (ISL_TILING_LINEAR_BIT | ISL_TILING_X_BIT);
+      if (ISL_DEV_GEN(dev) >= 12) {
+         *flags &= (ISL_TILING_LINEAR_BIT | ISL_TILING_X_BIT |
+                    ISL_TILING_Y0_BIT);
+      } else if (ISL_DEV_GEN(dev) >= 9) {
+         /* Note we let Yf even though it was cleared above. This is just for
+          * completeness.
+          */
+         *flags &= (ISL_TILING_LINEAR_BIT | ISL_TILING_X_BIT |
+                    ISL_TILING_Y0_BIT | ISL_TILING_Yf_BIT);
+      } else {
+         /* Before Skylake, the display engine does not accept Y */
+         *flags &= (ISL_TILING_LINEAR_BIT | ISL_TILING_X_BIT);
+      }
    }
 
    if (info->samples > 1) {
@@ -258,9 +273,13 @@ gen7_filter_tiling(const struct isl_device *dev,
        *   For multisample render targets, this field must be 1 (true). MSRTs
        *   can only be tiled.
        *
-       * Multisample surfaces never require X tiling, and Y tiling generally
-       * performs better than X. So choose Y. (Unless it's stencil, then it
-       * must be W).
+       * From the Broadwell PRM >> Volume2d: Command Structures >>
+       * RENDER_SURFACE_STATE Tile Mode:
+       *
+       *   If Number of Multisamples is not MULTISAMPLECOUNT_1, this field
+       *   must be YMAJOR.
+       *
+       * As usual, though, stencil is special and requires W-tiling.
        */
       *flags &= (ISL_TILING_ANY_Y_MASK | ISL_TILING_W_BIT);
    }
@@ -278,118 +297,131 @@ gen7_filter_tiling(const struct isl_device *dev,
        */
       *flags &= ~ISL_TILING_Y0_BIT;
    }
-}
 
-/**
- * Choose horizontal subimage alignment, in units of surface elements.
- */
-static uint32_t
-gen7_choose_halign_el(const struct isl_device *dev,
-                      const struct isl_surf_init_info *restrict info)
-{
-   if (isl_format_is_compressed(info->format))
-      return 1;
-
-   /* From the Ivybridge PRM (2012-05-31), Volume 4, Part 1, Section 2.12.1,
-    * RENDER_SURFACE_STATE Surface Hoizontal Alignment:
+   /* From the Sandybridge PRM, Volume 1, Part 2, page 32:
+    *
+    *    "NOTE: 128BPE Format Color Buffer ( render target ) MUST be either
+    *     TileX or Linear."
     *
-    *    - This field is intended to be set to HALIGN_8 only if the surface
-    *      was rendered as a depth buffer with Z16 format or a stencil buffer,
-    *      since these surfaces support only alignment of 8. Use of HALIGN_8
-    *      for other surfaces is supported, but uses more memory.
+    * This is necessary all the way back to 965, but is permitted on Gen7+.
     */
-   if (isl_surf_info_is_z16(info) ||
-       isl_surf_usage_is_stencil(info->usage))
-      return 8;
+   if (ISL_DEV_GEN(dev) < 7 && isl_format_get_layout(info->format)->bpb >= 128)
+      *flags &= ~ISL_TILING_Y0_BIT;
 
-   return 4;
+   /* From the BDW and SKL PRMs, Volume 2d,
+    * RENDER_SURFACE_STATE::Width - Programming Notes:
+    *
+    *   A known issue exists if a primitive is rendered to the first 2 rows and
+    *   last 2 columns of a 16K width surface. If any geometry is drawn inside
+    *   this square it will be copied to column X=2 and X=3 (arrangement on Y
+    *   position will stay the same). If any geometry exceeds the boundaries of
+    *   this 2x2 region it will be drawn normally. The issue also only occurs
+    *   if the surface has TileMode != Linear.
+    *
+    * [Internal documentation notes that this issue isn't present on SKL GT4.]
+    * To prevent this rendering corruption, only allow linear tiling for
+    * surfaces with widths greater than 16K-2 pixels.
+    *
+    * TODO: Is this an issue for multisampled surfaces as well?
+    */
+   if (info->width > 16382 && info->samples == 1 &&
+       info->usage & ISL_SURF_USAGE_RENDER_TARGET_BIT &&
+       (ISL_DEV_GEN(dev) == 8 ||
+        (dev->info->is_skylake && dev->info->gt != 4))) {
+          *flags &= ISL_TILING_LINEAR_BIT;
+   }
 }
 
-/**
- * Choose vertical subimage alignment, in units of surface elements.
- */
-static uint32_t
-gen7_choose_valign_el(const struct isl_device *dev,
-                      const struct isl_surf_init_info *restrict info,
-                      enum isl_tiling tiling)
+void
+isl_gen7_choose_image_alignment_el(const struct isl_device *dev,
+                                   const struct isl_surf_init_info *restrict info,
+                                   enum isl_tiling tiling,
+                                   enum isl_dim_layout dim_layout,
+                                   enum isl_msaa_layout msaa_layout,
+                                   struct isl_extent3d *image_align_el)
 {
-   bool require_valign2 = false;
-   bool require_valign4 = false;
+   assert(ISL_DEV_GEN(dev) == 7);
+
+   /* Handled by isl_choose_image_alignment_el */
+   assert(info->format != ISL_FORMAT_HIZ);
+
+   /* IVB+ does not support combined depthstencil. */
+   assert(!isl_surf_usage_is_depth_and_stencil(info->usage));
+
+   /* From the Ivy Bridge PRM, Vol. 2, Part 2, Section 6.18.4.4,
+    * "Alignment unit size", the alignment parameters are summarized in the
+    * following table:
+    *
+    *     Surface Defined By | Surface Format  | Align Width | Align Height
+    *    --------------------+-----------------+-------------+--------------
+    *       DEPTH_BUFFER     |   D16_UNORM     |      8      |      4
+    *                        |     other       |      4      |      4
+    *    --------------------+-----------------+-------------+--------------
+    *       STENCIL_BUFFER   |      N/A        |      8      |      8
+    *    --------------------+-----------------+-------------+--------------
+    *       SURFACE_STATE    | BC*, ETC*, EAC* |      4      |      4
+    *                        |      FXT1       |      8      |      4
+    *                        |   all others    |   HALIGN    |   VALIGN
+    *    -------------------------------------------------------------------
+    */
+   if (isl_surf_usage_is_depth(info->usage)) {
+      *image_align_el = info->format == ISL_FORMAT_R16_UNORM ?
+                        isl_extent3d(8, 4, 1) : isl_extent3d(4, 4, 1);
+      return;
+   } else if (isl_surf_usage_is_stencil(info->usage)) {
+      *image_align_el = isl_extent3d(8, 8, 1);
+      return;
+   } else if (isl_format_is_compressed(info->format)) {
+      /* Compressed formats all have alignment equal to block size. */
+      *image_align_el = isl_extent3d(1, 1, 1);
+      return;
+   }
 
-   if (isl_format_is_compressed(info->format))
-      return 1;
+   /* Everything after this point is in the "set by Surface Horizontal or
+    * Vertical Alignment" case.  Now it's just a matter of applying
+    * restrictions.
+    */
 
-   if (gen7_format_needs_valign2(dev, info->format))
-      require_valign2 = true;
+   /* There are no restrictions on halign beyond what's given in the table
+    * above.  We set it to the minimum value of 4 because that uses the least
+    * memory.
+    */
+   const uint32_t halign = 4;
+
+   bool require_valign4 = false;
 
    /* From the Ivybridge PRM, Volume 4, Part 1, Section 2.12.1:
     * RENDER_SURFACE_STATE Surface Vertical Alignment:
     *
-    *    - This field is intended to be set to VALIGN_4 if the surface was
-    *      rendered as a depth buffer, for a multisampled (4x) render target,
-    *      or for a multisampled (8x) render target, since these surfaces
-    *      support only alignment of 4.  Use of VALIGN_4 for other surfaces is
-    *      supported, but uses more memory.  This field must be set to
-    *      VALIGN_4 for all tiled Y Render Target surfaces.
+    *    * This field is intended to be set to VALIGN_4 if the surface was
+    *      rendered as a depth buffer,
+    *
+    *    * for a multisampled (4x) render target, or for a multisampled (8x)
+    *      render target, since these surfaces support only alignment of 4.
+    *
+    *    * This field must be set to VALIGN_4 for all tiled Y Render Target
+    *      surfaces
     *
+    *    * Value of 1 is not supported for format YCRCB_NORMAL (0x182),
+    *      YCRCB_SWAPUVY (0x183), YCRCB_SWAPUV (0x18f), YCRCB_SWAPY (0x190)
+    *
+    *    * If Number of Multisamples is not MULTISAMPLECOUNT_1, this field
+    *      must be set to VALIGN_4."
+    *
+    * The first restriction is already handled by the table above and the
+    * second restriction is redundant with the fifth.
     */
-   if (isl_surf_usage_is_depth(info->usage) ||
-       info->samples > 1 ||
-       tiling == ISL_TILING_Y0) {
+   if (info->samples > 1)
       require_valign4 = true;
-   }
 
-   if (isl_surf_usage_is_stencil(info->usage)) {
-      /* The Ivybridge PRM states that the stencil buffer's vertical alignment
-       * is 8 [Ivybridge PRM, Volume 1, Part 1, Section 6.18.4.4 Alignment
-       * Unit Size]. However, valign=8 is outside the set of valid values of
-       * RENDER_SURFACE_STATE.SurfaceVerticalAlignment, which is VALIGN_2
-       * (0x0) and VALIGN_4 (0x1).
-       *
-       * The PRM is generally confused about the width, height, and alignment
-       * of the stencil buffer; and this confusion appears elsewhere. For
-       * example, the following PRM text effectively converts the stencil
-       * buffer's 8-pixel alignment to a 4-pixel alignment [Ivybridge PRM,
-       * Volume 1, Part 1, Section
-       * 6.18.4.2 Base Address and LOD Calculation]:
-       *
-       *    For separate stencil buffer, the width must be mutiplied by 2 and
-       *    height divided by 2 as follows:
-       *
-       *       w_L = 2*i*ceil(W_L/i)
-       *       h_L = 1/2*j*ceil(H_L/j)
-       *
-       * The root of the confusion is that, in W tiling, each pair of rows is
-       * interleaved into one.
-       *
-       * FINISHME(chadv): Decide to set valign=4 or valign=8 after isl's API
-       * is more polished.
-       */
+   if (tiling == ISL_TILING_Y0 &&
+       (info->usage & ISL_SURF_USAGE_RENDER_TARGET_BIT))
       require_valign4 = true;
-   }
-
-   assert(!require_valign2 || !require_valign4);
 
-   if (require_valign4)
-      return 4;
+   assert(!(require_valign4 && gen7_format_needs_valign2(dev, info->format)));
 
-   /* Prefer VALIGN_2 because it conserves memory. */
-   return 2;
-}
-
-void
-gen7_choose_image_alignment_el(const struct isl_device *dev,
-                               const struct isl_surf_init_info *restrict info,
-                               enum isl_tiling tiling,
-                               enum isl_msaa_layout msaa_layout,
-                               struct isl_extent3d *image_align_el)
-{
-   /* IVB+ does not support combined depthstencil. */
-   assert(!isl_surf_usage_is_depth_and_stencil(info->usage));
+   /* We default to VALIGN_2 because it uses the least memory. */
+   const uint32_t valign = require_valign4 ? 4 : 2;
 
-   *image_align_el = (struct isl_extent3d) {
-      .w = gen7_choose_halign_el(dev, info),
-      .h = gen7_choose_valign_el(dev, info, tiling),
-      .d = 1,
-   };
+   *image_align_el = isl_extent3d(halign, valign, 1);
 }