17ec681f3Smrg/*
27ec681f3Smrg * Copyright 2015 Intel Corporation
37ec681f3Smrg *
47ec681f3Smrg *  Permission is hereby granted, free of charge, to any person obtaining a
57ec681f3Smrg *  copy of this software and associated documentation files (the "Software"),
67ec681f3Smrg *  to deal in the Software without restriction, including without limitation
77ec681f3Smrg *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
87ec681f3Smrg *  and/or sell copies of the Software, and to permit persons to whom the
97ec681f3Smrg *  Software is furnished to do so, subject to the following conditions:
107ec681f3Smrg *
117ec681f3Smrg *  The above copyright notice and this permission notice (including the next
127ec681f3Smrg *  paragraph) shall be included in all copies or substantial portions of the
137ec681f3Smrg *  Software.
147ec681f3Smrg *
157ec681f3Smrg *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
167ec681f3Smrg *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
177ec681f3Smrg *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
187ec681f3Smrg *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
197ec681f3Smrg *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
207ec681f3Smrg *  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
217ec681f3Smrg *  IN THE SOFTWARE.
227ec681f3Smrg */
237ec681f3Smrg
247ec681f3Smrg#include "isl_gfx7.h"
257ec681f3Smrg#include "isl_priv.h"
267ec681f3Smrg
277ec681f3Smrgstatic bool
287ec681f3Smrggfx7_format_needs_valign2(const struct isl_device *dev,
297ec681f3Smrg                          enum isl_format format)
307ec681f3Smrg{
317ec681f3Smrg   assert(ISL_GFX_VER(dev) == 7);
327ec681f3Smrg
337ec681f3Smrg   /* From the Ivybridge PRM (2012-05-31), Volume 4, Part 1, Section 2.12.1,
347ec681f3Smrg    * RENDER_SURFACE_STATE Surface Vertical Alignment:
357ec681f3Smrg    *
367ec681f3Smrg    *    - Value of 1 [VALIGN_4] is not supported for format YCRCB_NORMAL
377ec681f3Smrg    *      (0x182), YCRCB_SWAPUVY (0x183), YCRCB_SWAPUV (0x18f), YCRCB_SWAPY
387ec681f3Smrg    *      (0x190)
397ec681f3Smrg    *
407ec681f3Smrg    *    - VALIGN_4 is not supported for surface format R32G32B32_FLOAT.
417ec681f3Smrg    *
427ec681f3Smrg    * The R32G32B32_FLOAT restriction is dropped on Haswell.
437ec681f3Smrg    */
447ec681f3Smrg   return isl_format_is_yuv(format) ||
457ec681f3Smrg          (format == ISL_FORMAT_R32G32B32_FLOAT && !ISL_DEV_IS_HASWELL(dev));
467ec681f3Smrg}
477ec681f3Smrg
487ec681f3Smrgbool
497ec681f3Smrgisl_gfx7_choose_msaa_layout(const struct isl_device *dev,
507ec681f3Smrg                            const struct isl_surf_init_info *info,
517ec681f3Smrg                            enum isl_tiling tiling,
527ec681f3Smrg                            enum isl_msaa_layout *msaa_layout)
537ec681f3Smrg{
547ec681f3Smrg   bool require_array = false;
557ec681f3Smrg   bool require_interleaved = false;
567ec681f3Smrg
577ec681f3Smrg   assert(ISL_GFX_VER(dev) == 7);
587ec681f3Smrg   assert(info->samples >= 1);
597ec681f3Smrg
607ec681f3Smrg   if (info->samples == 1) {
617ec681f3Smrg      *msaa_layout = ISL_MSAA_LAYOUT_NONE;
627ec681f3Smrg      return true;
637ec681f3Smrg   }
647ec681f3Smrg
657ec681f3Smrg   if (!isl_format_supports_multisampling(dev->info, info->format))
667ec681f3Smrg      return false;
677ec681f3Smrg
687ec681f3Smrg   /* From the Ivybridge PRM, Volume 4 Part 1 p73, SURFACE_STATE, Number of
697ec681f3Smrg    * Multisamples:
707ec681f3Smrg    *
717ec681f3Smrg    *    - If this field is any value other than MULTISAMPLECOUNT_1, the
727ec681f3Smrg    *      Surface Type must be SURFTYPE_2D.
737ec681f3Smrg    *
747ec681f3Smrg    *    - If this field is any value other than MULTISAMPLECOUNT_1, Surface
757ec681f3Smrg    *      Min LOD, Mip Count / LOD, and Resource Min LOD must be set to zero
767ec681f3Smrg    */
777ec681f3Smrg   if (info->dim != ISL_SURF_DIM_2D)
787ec681f3Smrg      return false;
797ec681f3Smrg   if (info->levels > 1)
807ec681f3Smrg      return false;
817ec681f3Smrg
827ec681f3Smrg   /* The Ivyrbridge PRM insists twice that signed integer formats cannot be
837ec681f3Smrg    * multisampled.
847ec681f3Smrg    *
857ec681f3Smrg    * From the Ivybridge PRM, Volume 4 Part 1 p73, SURFACE_STATE, Number of
867ec681f3Smrg    * Multisamples:
877ec681f3Smrg    *
887ec681f3Smrg    *    - This field must be set to MULTISAMPLECOUNT_1 for SINT MSRTs when
897ec681f3Smrg    *      all RT channels are not written.
907ec681f3Smrg    *
917ec681f3Smrg    * And errata from the Ivybridge PRM, Volume 4 Part 1 p77,
927ec681f3Smrg    * RENDER_SURFACE_STATE, MCS Enable:
937ec681f3Smrg    *
947ec681f3Smrg    *   This field must be set to 0 [MULTISAMPLECOUNT_1] for all SINT MSRTs
957ec681f3Smrg    *   when all RT channels are not written.
967ec681f3Smrg    *
977ec681f3Smrg    * Note that the above SINT restrictions apply only to *MSRTs* (that is,
987ec681f3Smrg    * *multisampled* render targets). The restrictions seem to permit an MCS
997ec681f3Smrg    * if the render target is singlesampled.
1007ec681f3Smrg    *
1017ec681f3Smrg    * Moreover, empirically it looks that hardware can render multisampled
1027ec681f3Smrg    * surfaces with RGBA8I, RGBA16I and RGBA32I.
1037ec681f3Smrg    */
1047ec681f3Smrg
1057ec681f3Smrg   /* Multisampling requires vertical alignment of four. */
1067ec681f3Smrg   if (info->samples > 1 && gfx7_format_needs_valign2(dev, info->format))
1077ec681f3Smrg      return false;
1087ec681f3Smrg
1097ec681f3Smrg   /* More obvious restrictions */
1107ec681f3Smrg   if (isl_surf_usage_is_display(info->usage))
1117ec681f3Smrg      return false;
1127ec681f3Smrg   if (tiling == ISL_TILING_LINEAR)
1137ec681f3Smrg      return false;
1147ec681f3Smrg
1157ec681f3Smrg   /* From the Ivybridge PRM, Volume 4 Part 1 p72, SURFACE_STATE, Multisampled
1167ec681f3Smrg    * Suface Storage Format:
1177ec681f3Smrg    *
1187ec681f3Smrg    *    +---------------------+----------------------------------------------------------------+
1197ec681f3Smrg    *    | MSFMT_MSS           | Multsampled surface was/is rendered as a render target         |
1207ec681f3Smrg    *    | MSFMT_DEPTH_STENCIL | Multisampled surface was rendered as a depth or stencil buffer |
1217ec681f3Smrg    *    +---------------------+----------------------------------------------------------------+
1227ec681f3Smrg    *
1237ec681f3Smrg    * In the table above, MSFMT_MSS refers to ISL_MSAA_LAYOUT_ARRAY, and
1247ec681f3Smrg    * MSFMT_DEPTH_STENCIL refers to ISL_MSAA_LAYOUT_INTERLEAVED.
1257ec681f3Smrg    */
1267ec681f3Smrg   if (isl_surf_usage_is_depth_or_stencil(info->usage) ||
1277ec681f3Smrg       (info->usage & ISL_SURF_USAGE_HIZ_BIT))
1287ec681f3Smrg      require_interleaved = true;
1297ec681f3Smrg
1307ec681f3Smrg   /* From the Ivybridge PRM, Volume 4 Part 1 p72, SURFACE_STATE, Multisampled
1317ec681f3Smrg    * Suface Storage Format:
1327ec681f3Smrg    *
1337ec681f3Smrg    *    If the surface’s Number of Multisamples is MULTISAMPLECOUNT_8, Width
1347ec681f3Smrg    *    is >= 8192 (meaning the actual surface width is >= 8193 pixels), this
1357ec681f3Smrg    *    field must be set to MSFMT_MSS.
1367ec681f3Smrg    */
1377ec681f3Smrg   if (info->samples == 8 && info->width > 8192)
1387ec681f3Smrg      require_array = true;
1397ec681f3Smrg
1407ec681f3Smrg   /* From the Ivybridge PRM, Volume 4 Part 1 p72, SURFACE_STATE, Multisampled
1417ec681f3Smrg    * Suface Storage Format:
1427ec681f3Smrg    *
1437ec681f3Smrg    *    If the surface’s Number of Multisamples is MULTISAMPLECOUNT_8,
1447ec681f3Smrg    *    ((Depth+1) * (Height+1)) is > 4,194,304, OR if the surface’s Number
1457ec681f3Smrg    *    of Multisamples is MULTISAMPLECOUNT_4, ((Depth+1) * (Height+1)) is
1467ec681f3Smrg    *    > 8,388,608, this field must be set to MSFMT_DEPTH_STENCIL.
1477ec681f3Smrg    */
1487ec681f3Smrg   if ((info->samples == 8 && info->height > 4194304u) ||
1497ec681f3Smrg       (info->samples == 4 && info->height > 8388608u))
1507ec681f3Smrg      require_interleaved = true;
1517ec681f3Smrg
1527ec681f3Smrg   /* From the Ivybridge PRM, Volume 4 Part 1 p72, SURFACE_STATE, Multisampled
1537ec681f3Smrg    * Suface Storage Format:
1547ec681f3Smrg    *
1557ec681f3Smrg    *    This field must be set to MSFMT_DEPTH_STENCIL if Surface Format is
1567ec681f3Smrg    *    one of the following: I24X8_UNORM, L24X8_UNORM, A24X8_UNORM, or
1577ec681f3Smrg    *    R24_UNORM_X8_TYPELESS.
1587ec681f3Smrg    */
1597ec681f3Smrg   if (info->format == ISL_FORMAT_I24X8_UNORM ||
1607ec681f3Smrg       info->format == ISL_FORMAT_L24X8_UNORM ||
1617ec681f3Smrg       info->format == ISL_FORMAT_A24X8_UNORM ||
1627ec681f3Smrg       info->format == ISL_FORMAT_R24_UNORM_X8_TYPELESS)
1637ec681f3Smrg      require_interleaved = true;
1647ec681f3Smrg
1657ec681f3Smrg   if (require_array && require_interleaved)
1667ec681f3Smrg      return false;
1677ec681f3Smrg
1687ec681f3Smrg   if (require_interleaved) {
1697ec681f3Smrg      *msaa_layout = ISL_MSAA_LAYOUT_INTERLEAVED;
1707ec681f3Smrg      return true;
1717ec681f3Smrg   }
1727ec681f3Smrg
1737ec681f3Smrg   /* Default to the array layout because it permits multisample
1747ec681f3Smrg    * compression.
1757ec681f3Smrg    */
1767ec681f3Smrg   *msaa_layout = ISL_MSAA_LAYOUT_ARRAY;
1777ec681f3Smrg   return true;
1787ec681f3Smrg}
1797ec681f3Smrg
1807ec681f3Smrg/**
1817ec681f3Smrg * @brief Filter out tiling flags that are incompatible with the surface.
1827ec681f3Smrg *
1837ec681f3Smrg * The resultant outgoing @a flags is a subset of the incoming @a flags. The
1847ec681f3Smrg * outgoing flags may be empty (0x0) if the incoming flags were too
1857ec681f3Smrg * restrictive.
1867ec681f3Smrg *
1877ec681f3Smrg * For example, if the surface will be used for a display
1887ec681f3Smrg * (ISL_SURF_USAGE_DISPLAY_BIT), then this function filters out all tiling
1897ec681f3Smrg * flags except ISL_TILING_X_BIT and ISL_TILING_LINEAR_BIT.
1907ec681f3Smrg */
1917ec681f3Smrgvoid
1927ec681f3Smrgisl_gfx6_filter_tiling(const struct isl_device *dev,
1937ec681f3Smrg                       const struct isl_surf_init_info *restrict info,
1947ec681f3Smrg                       isl_tiling_flags_t *flags)
1957ec681f3Smrg{
1967ec681f3Smrg   /* IVB+ requires separate stencil */
1977ec681f3Smrg   assert(ISL_DEV_USE_SEPARATE_STENCIL(dev));
1987ec681f3Smrg
1997ec681f3Smrg   /* Clear flags unsupported on this hardware */
2007ec681f3Smrg   assert(ISL_GFX_VERX10(dev) < 125);
2017ec681f3Smrg   if (ISL_GFX_VER(dev) >= 12) {
2027ec681f3Smrg      *flags &= ISL_TILING_LINEAR_BIT |
2037ec681f3Smrg                ISL_TILING_X_BIT |
2047ec681f3Smrg                ISL_TILING_ANY_Y_MASK;
2057ec681f3Smrg   } else if (ISL_GFX_VER(dev) >= 9) {
2067ec681f3Smrg      *flags &= ISL_TILING_LINEAR_BIT |
2077ec681f3Smrg                ISL_TILING_X_BIT |
2087ec681f3Smrg                ISL_TILING_W_BIT |
2097ec681f3Smrg                ISL_TILING_ANY_Y_MASK;
2107ec681f3Smrg   } else {
2117ec681f3Smrg      *flags &= ISL_TILING_LINEAR_BIT |
2127ec681f3Smrg                ISL_TILING_X_BIT |
2137ec681f3Smrg                ISL_TILING_W_BIT |
2147ec681f3Smrg                ISL_TILING_Y0_BIT;
2157ec681f3Smrg   }
2167ec681f3Smrg
2177ec681f3Smrg   /* And... clear the Yf and Ys bits anyway because Anvil doesn't support
2187ec681f3Smrg    * them yet.
2197ec681f3Smrg    */
2207ec681f3Smrg   *flags &= ~ISL_TILING_Yf_BIT; /* FINISHME[SKL]: Support Yf */
2217ec681f3Smrg   *flags &= ~ISL_TILING_Ys_BIT; /* FINISHME[SKL]: Support Ys */
2227ec681f3Smrg
2237ec681f3Smrg   if (isl_surf_usage_is_depth(info->usage)) {
2247ec681f3Smrg      /* Depth requires Y. */
2257ec681f3Smrg      *flags &= ISL_TILING_ANY_Y_MASK;
2267ec681f3Smrg   }
2277ec681f3Smrg
2287ec681f3Smrg   if (isl_surf_usage_is_stencil(info->usage)) {
2297ec681f3Smrg      if (ISL_GFX_VER(dev) >= 12) {
2307ec681f3Smrg         /* Stencil requires Y. */
2317ec681f3Smrg         *flags &= ISL_TILING_ANY_Y_MASK;
2327ec681f3Smrg      } else {
2337ec681f3Smrg         /* Stencil requires W. */
2347ec681f3Smrg         *flags &= ISL_TILING_W_BIT;
2357ec681f3Smrg      }
2367ec681f3Smrg   } else {
2377ec681f3Smrg      *flags &= ~ISL_TILING_W_BIT;
2387ec681f3Smrg   }
2397ec681f3Smrg
2407ec681f3Smrg   /* From the SKL+ PRMs, RENDER_SURFACE_STATE:TileMode,
2417ec681f3Smrg    *    If Surface Format is ASTC*, this field must be TILEMODE_YMAJOR.
2427ec681f3Smrg    */
2437ec681f3Smrg   if (isl_format_get_layout(info->format)->txc == ISL_TXC_ASTC)
2447ec681f3Smrg      *flags &= ISL_TILING_Y0_BIT;
2457ec681f3Smrg
2467ec681f3Smrg   /* MCS buffers are always Y-tiled */
2477ec681f3Smrg   if (isl_format_get_layout(info->format)->txc == ISL_TXC_MCS)
2487ec681f3Smrg      *flags &= ISL_TILING_Y0_BIT;
2497ec681f3Smrg
2507ec681f3Smrg   if (info->usage & ISL_SURF_USAGE_DISPLAY_BIT) {
2517ec681f3Smrg      if (ISL_GFX_VER(dev) >= 12) {
2527ec681f3Smrg         *flags &= (ISL_TILING_LINEAR_BIT | ISL_TILING_X_BIT |
2537ec681f3Smrg                    ISL_TILING_Y0_BIT);
2547ec681f3Smrg      } else if (ISL_GFX_VER(dev) >= 9) {
2557ec681f3Smrg         /* Note we let Yf even though it was cleared above. This is just for
2567ec681f3Smrg          * completeness.
2577ec681f3Smrg          */
2587ec681f3Smrg         *flags &= (ISL_TILING_LINEAR_BIT | ISL_TILING_X_BIT |
2597ec681f3Smrg                    ISL_TILING_Y0_BIT | ISL_TILING_Yf_BIT);
2607ec681f3Smrg      } else {
2617ec681f3Smrg         /* Before Skylake, the display engine does not accept Y */
2627ec681f3Smrg         *flags &= (ISL_TILING_LINEAR_BIT | ISL_TILING_X_BIT);
2637ec681f3Smrg      }
2647ec681f3Smrg   }
2657ec681f3Smrg
2667ec681f3Smrg   if (info->samples > 1) {
2677ec681f3Smrg      /* From the Sandybridge PRM, Volume 4 Part 1, SURFACE_STATE Tiled
2687ec681f3Smrg       * Surface:
2697ec681f3Smrg       *
2707ec681f3Smrg       *   For multisample render targets, this field must be 1 (true). MSRTs
2717ec681f3Smrg       *   can only be tiled.
2727ec681f3Smrg       *
2737ec681f3Smrg       * From the Broadwell PRM >> Volume2d: Command Structures >>
2747ec681f3Smrg       * RENDER_SURFACE_STATE Tile Mode:
2757ec681f3Smrg       *
2767ec681f3Smrg       *   If Number of Multisamples is not MULTISAMPLECOUNT_1, this field
2777ec681f3Smrg       *   must be YMAJOR.
2787ec681f3Smrg       *
2797ec681f3Smrg       * As usual, though, stencil is special and requires W-tiling.
2807ec681f3Smrg       */
2817ec681f3Smrg      *flags &= (ISL_TILING_ANY_Y_MASK | ISL_TILING_W_BIT);
2827ec681f3Smrg   }
2837ec681f3Smrg
2847ec681f3Smrg   /* workaround */
2857ec681f3Smrg   if (ISL_GFX_VER(dev) == 7 &&
2867ec681f3Smrg       gfx7_format_needs_valign2(dev, info->format) &&
2877ec681f3Smrg       (info->usage & ISL_SURF_USAGE_RENDER_TARGET_BIT) &&
2887ec681f3Smrg       info->samples == 1) {
2897ec681f3Smrg      /* Y tiling is illegal. From the Ivybridge PRM, Vol4 Part1 2.12.2.1,
2907ec681f3Smrg       * SURFACE_STATE Surface Vertical Alignment:
2917ec681f3Smrg       *
2927ec681f3Smrg       *     This field must be set to VALIGN_4 for all tiled Y Render Target
2937ec681f3Smrg       *     surfaces.
2947ec681f3Smrg       */
2957ec681f3Smrg      *flags &= ~ISL_TILING_Y0_BIT;
2967ec681f3Smrg   }
2977ec681f3Smrg
2987ec681f3Smrg   /* From the Sandybridge PRM, Volume 1, Part 2, page 32:
2997ec681f3Smrg    *
3007ec681f3Smrg    *    "NOTE: 128BPE Format Color Buffer ( render target ) MUST be either
3017ec681f3Smrg    *     TileX or Linear."
3027ec681f3Smrg    *
3037ec681f3Smrg    * This is necessary all the way back to 965, but is permitted on Gfx7+.
3047ec681f3Smrg    */
3057ec681f3Smrg   if (ISL_GFX_VER(dev) < 7 && isl_format_get_layout(info->format)->bpb >= 128)
3067ec681f3Smrg      *flags &= ~ISL_TILING_Y0_BIT;
3077ec681f3Smrg
3087ec681f3Smrg   /* From the BDW and SKL PRMs, Volume 2d,
3097ec681f3Smrg    * RENDER_SURFACE_STATE::Width - Programming Notes:
3107ec681f3Smrg    *
3117ec681f3Smrg    *   A known issue exists if a primitive is rendered to the first 2 rows and
3127ec681f3Smrg    *   last 2 columns of a 16K width surface. If any geometry is drawn inside
3137ec681f3Smrg    *   this square it will be copied to column X=2 and X=3 (arrangement on Y
3147ec681f3Smrg    *   position will stay the same). If any geometry exceeds the boundaries of
3157ec681f3Smrg    *   this 2x2 region it will be drawn normally. The issue also only occurs
3167ec681f3Smrg    *   if the surface has TileMode != Linear.
3177ec681f3Smrg    *
3187ec681f3Smrg    * [Internal documentation notes that this issue isn't present on SKL GT4.]
3197ec681f3Smrg    * To prevent this rendering corruption, only allow linear tiling for
3207ec681f3Smrg    * surfaces with widths greater than 16K-2 pixels.
3217ec681f3Smrg    *
3227ec681f3Smrg    * TODO: Is this an issue for multisampled surfaces as well?
3237ec681f3Smrg    */
3247ec681f3Smrg   if (info->width > 16382 && info->samples == 1 &&
3257ec681f3Smrg       info->usage & ISL_SURF_USAGE_RENDER_TARGET_BIT &&
3267ec681f3Smrg       (ISL_GFX_VER(dev) == 8 ||
3277ec681f3Smrg        (dev->info->is_skylake && dev->info->gt != 4))) {
3287ec681f3Smrg          *flags &= ISL_TILING_LINEAR_BIT;
3297ec681f3Smrg   }
3307ec681f3Smrg}
3317ec681f3Smrg
3327ec681f3Smrgvoid
3337ec681f3Smrgisl_gfx7_choose_image_alignment_el(const struct isl_device *dev,
3347ec681f3Smrg                                   const struct isl_surf_init_info *restrict info,
3357ec681f3Smrg                                   enum isl_tiling tiling,
3367ec681f3Smrg                                   enum isl_dim_layout dim_layout,
3377ec681f3Smrg                                   enum isl_msaa_layout msaa_layout,
3387ec681f3Smrg                                   struct isl_extent3d *image_align_el)
3397ec681f3Smrg{
3407ec681f3Smrg   assert(ISL_GFX_VER(dev) == 7);
3417ec681f3Smrg
3427ec681f3Smrg   /* Handled by isl_choose_image_alignment_el */
3437ec681f3Smrg   assert(info->format != ISL_FORMAT_HIZ);
3447ec681f3Smrg
3457ec681f3Smrg   /* IVB+ does not support combined depthstencil. */
3467ec681f3Smrg   assert(!isl_surf_usage_is_depth_and_stencil(info->usage));
3477ec681f3Smrg
3487ec681f3Smrg   /* From the Ivy Bridge PRM, Vol. 2, Part 2, Section 6.18.4.4,
3497ec681f3Smrg    * "Alignment unit size", the alignment parameters are summarized in the
3507ec681f3Smrg    * following table:
3517ec681f3Smrg    *
3527ec681f3Smrg    *     Surface Defined By | Surface Format  | Align Width | Align Height
3537ec681f3Smrg    *    --------------------+-----------------+-------------+--------------
3547ec681f3Smrg    *       DEPTH_BUFFER     |   D16_UNORM     |      8      |      4
3557ec681f3Smrg    *                        |     other       |      4      |      4
3567ec681f3Smrg    *    --------------------+-----------------+-------------+--------------
3577ec681f3Smrg    *       STENCIL_BUFFER   |      N/A        |      8      |      8
3587ec681f3Smrg    *    --------------------+-----------------+-------------+--------------
3597ec681f3Smrg    *       SURFACE_STATE    | BC*, ETC*, EAC* |      4      |      4
3607ec681f3Smrg    *                        |      FXT1       |      8      |      4
3617ec681f3Smrg    *                        |   all others    |   HALIGN    |   VALIGN
3627ec681f3Smrg    *    -------------------------------------------------------------------
3637ec681f3Smrg    */
3647ec681f3Smrg   if (isl_surf_usage_is_depth(info->usage)) {
3657ec681f3Smrg      *image_align_el = info->format == ISL_FORMAT_R16_UNORM ?
3667ec681f3Smrg                        isl_extent3d(8, 4, 1) : isl_extent3d(4, 4, 1);
3677ec681f3Smrg      return;
3687ec681f3Smrg   } else if (isl_surf_usage_is_stencil(info->usage)) {
3697ec681f3Smrg      *image_align_el = isl_extent3d(8, 8, 1);
3707ec681f3Smrg      return;
3717ec681f3Smrg   } else if (isl_format_is_compressed(info->format)) {
3727ec681f3Smrg      /* Compressed formats all have alignment equal to block size. */
3737ec681f3Smrg      *image_align_el = isl_extent3d(1, 1, 1);
3747ec681f3Smrg      return;
3757ec681f3Smrg   }
3767ec681f3Smrg
3777ec681f3Smrg   /* Everything after this point is in the "set by Surface Horizontal or
3787ec681f3Smrg    * Vertical Alignment" case.  Now it's just a matter of applying
3797ec681f3Smrg    * restrictions.
3807ec681f3Smrg    */
3817ec681f3Smrg
3827ec681f3Smrg   /* There are no restrictions on halign beyond what's given in the table
3837ec681f3Smrg    * above.  We set it to the minimum value of 4 because that uses the least
3847ec681f3Smrg    * memory.
3857ec681f3Smrg    */
3867ec681f3Smrg   const uint32_t halign = 4;
3877ec681f3Smrg
3887ec681f3Smrg   bool require_valign4 = false;
3897ec681f3Smrg
3907ec681f3Smrg   /* From the Ivybridge PRM, Volume 4, Part 1, Section 2.12.1:
3917ec681f3Smrg    * RENDER_SURFACE_STATE Surface Vertical Alignment:
3927ec681f3Smrg    *
3937ec681f3Smrg    *    * This field is intended to be set to VALIGN_4 if the surface was
3947ec681f3Smrg    *      rendered as a depth buffer,
3957ec681f3Smrg    *
3967ec681f3Smrg    *    * for a multisampled (4x) render target, or for a multisampled (8x)
3977ec681f3Smrg    *      render target, since these surfaces support only alignment of 4.
3987ec681f3Smrg    *
3997ec681f3Smrg    *    * This field must be set to VALIGN_4 for all tiled Y Render Target
4007ec681f3Smrg    *      surfaces
4017ec681f3Smrg    *
4027ec681f3Smrg    *    * Value of 1 is not supported for format YCRCB_NORMAL (0x182),
4037ec681f3Smrg    *      YCRCB_SWAPUVY (0x183), YCRCB_SWAPUV (0x18f), YCRCB_SWAPY (0x190)
4047ec681f3Smrg    *
4057ec681f3Smrg    *    * If Number of Multisamples is not MULTISAMPLECOUNT_1, this field
4067ec681f3Smrg    *      must be set to VALIGN_4."
4077ec681f3Smrg    *
4087ec681f3Smrg    * The first restriction is already handled by the table above and the
4097ec681f3Smrg    * second restriction is redundant with the fifth.
4107ec681f3Smrg    */
4117ec681f3Smrg   if (info->samples > 1)
4127ec681f3Smrg      require_valign4 = true;
4137ec681f3Smrg
4147ec681f3Smrg   if (tiling == ISL_TILING_Y0 &&
4157ec681f3Smrg       (info->usage & ISL_SURF_USAGE_RENDER_TARGET_BIT))
4167ec681f3Smrg      require_valign4 = true;
4177ec681f3Smrg
4187ec681f3Smrg   assert(!(require_valign4 && gfx7_format_needs_valign2(dev, info->format)));
4197ec681f3Smrg
4207ec681f3Smrg   /* We default to VALIGN_2 because it uses the least memory. */
4217ec681f3Smrg   const uint32_t valign = require_valign4 ? 4 : 2;
4227ec681f3Smrg
4237ec681f3Smrg   *image_align_el = isl_extent3d(halign, valign, 1);
4247ec681f3Smrg}
425