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_gfx8.h"
257ec681f3Smrg#include "isl_priv.h"
267ec681f3Smrg
277ec681f3Smrgbool
287ec681f3Smrgisl_gfx8_choose_msaa_layout(const struct isl_device *dev,
297ec681f3Smrg                            const struct isl_surf_init_info *info,
307ec681f3Smrg                            enum isl_tiling tiling,
317ec681f3Smrg                            enum isl_msaa_layout *msaa_layout)
327ec681f3Smrg{
337ec681f3Smrg   bool require_array = false;
347ec681f3Smrg   bool require_interleaved = false;
357ec681f3Smrg
367ec681f3Smrg   assert(info->samples >= 1);
377ec681f3Smrg
387ec681f3Smrg   if (info->samples == 1) {
397ec681f3Smrg      *msaa_layout = ISL_MSAA_LAYOUT_NONE;
407ec681f3Smrg      return true;
417ec681f3Smrg   }
427ec681f3Smrg
437ec681f3Smrg   /* From the Broadwell PRM >> Volume2d: Command Structures >>
447ec681f3Smrg    * RENDER_SURFACE_STATE Multisampled Surface Storage Format:
457ec681f3Smrg    *
467ec681f3Smrg    *    All multisampled render target surfaces must have this field set to
477ec681f3Smrg    *    MSFMT_MSS
487ec681f3Smrg    */
497ec681f3Smrg   if (info->usage & ISL_SURF_USAGE_RENDER_TARGET_BIT)
507ec681f3Smrg      require_array = true;
517ec681f3Smrg
527ec681f3Smrg   /* From the Broadwell PRM >> Volume2d: Command Structures >>
537ec681f3Smrg    * RENDER_SURFACE_STATE Number of Multisamples:
547ec681f3Smrg    *
557ec681f3Smrg    *    - If this field is any value other than MULTISAMPLECOUNT_1, the
567ec681f3Smrg    *      Surface Type must be SURFTYPE_2D This field must be set to
577ec681f3Smrg    *      MULTISAMPLECOUNT_1 unless the surface is a Sampling Engine surface
587ec681f3Smrg    *      or Render Target surface.
597ec681f3Smrg    *
607ec681f3Smrg    *    - If this field is any value other than MULTISAMPLECOUNT_1, Surface
617ec681f3Smrg    *      Min LOD, Mip Count / LOD, and Resource Min LOD must be set to zero.
627ec681f3Smrg    */
637ec681f3Smrg   if (info->dim != ISL_SURF_DIM_2D)
647ec681f3Smrg      return false;
657ec681f3Smrg   if (info->levels > 1)
667ec681f3Smrg      return false;
677ec681f3Smrg
687ec681f3Smrg   /* More obvious restrictions */
697ec681f3Smrg   if (isl_surf_usage_is_display(info->usage))
707ec681f3Smrg      return false;
717ec681f3Smrg   if (!isl_format_supports_multisampling(dev->info, info->format))
727ec681f3Smrg      return false;
737ec681f3Smrg
747ec681f3Smrg   if (isl_surf_usage_is_depth_or_stencil(info->usage) ||
757ec681f3Smrg       (info->usage & ISL_SURF_USAGE_HIZ_BIT))
767ec681f3Smrg      require_interleaved = true;
777ec681f3Smrg
787ec681f3Smrg   if (require_array && require_interleaved)
797ec681f3Smrg      return false;
807ec681f3Smrg
817ec681f3Smrg   if (require_interleaved) {
827ec681f3Smrg      *msaa_layout = ISL_MSAA_LAYOUT_INTERLEAVED;
837ec681f3Smrg      return true;
847ec681f3Smrg   }
857ec681f3Smrg
867ec681f3Smrg   *msaa_layout = ISL_MSAA_LAYOUT_ARRAY;
877ec681f3Smrg   return true;
887ec681f3Smrg}
897ec681f3Smrg
907ec681f3Smrgvoid
917ec681f3Smrgisl_gfx8_choose_image_alignment_el(const struct isl_device *dev,
927ec681f3Smrg                                   const struct isl_surf_init_info *restrict info,
937ec681f3Smrg                                   enum isl_tiling tiling,
947ec681f3Smrg                                   enum isl_dim_layout dim_layout,
957ec681f3Smrg                                   enum isl_msaa_layout msaa_layout,
967ec681f3Smrg                                   struct isl_extent3d *image_align_el)
977ec681f3Smrg{
987ec681f3Smrg   /* Handled by isl_choose_image_alignment_el */
997ec681f3Smrg   assert(info->format != ISL_FORMAT_HIZ);
1007ec681f3Smrg
1017ec681f3Smrg   assert(!isl_tiling_is_std_y(tiling));
1027ec681f3Smrg
1037ec681f3Smrg   const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
1047ec681f3Smrg   if (fmtl->txc == ISL_TXC_CCS) {
1057ec681f3Smrg      /*
1067ec681f3Smrg       * Broadwell PRM Vol 7, "MCS Buffer for Render Target(s)" (p. 676):
1077ec681f3Smrg       *
1087ec681f3Smrg       *    "Mip-mapped and arrayed surfaces are supported with MCS buffer
1097ec681f3Smrg       *    layout with these alignments in the RT space: Horizontal
1107ec681f3Smrg       *    Alignment = 256 and Vertical Alignment = 128.
1117ec681f3Smrg       */
1127ec681f3Smrg      *image_align_el = isl_extent3d(256 / fmtl->bw, 128 / fmtl->bh, 1);
1137ec681f3Smrg      return;
1147ec681f3Smrg   }
1157ec681f3Smrg
1167ec681f3Smrg   /* From the Broadwell PRM, Volume 4, "Memory Views" p. 186, the alignment
1177ec681f3Smrg    * parameters are summarized in the following table:
1187ec681f3Smrg    *
1197ec681f3Smrg    *     Surface Defined By | Surface Format  | Align Width | Align Height
1207ec681f3Smrg    *    --------------------+-----------------+-------------+--------------
1217ec681f3Smrg    *       DEPTH_BUFFER     |   D16_UNORM     |      8      |      4
1227ec681f3Smrg    *                        |     other       |      4      |      4
1237ec681f3Smrg    *    --------------------+-----------------+-------------+--------------
1247ec681f3Smrg    *       STENCIL_BUFFER   |      N/A        |      8      |      8
1257ec681f3Smrg    *    --------------------+-----------------+-------------+--------------
1267ec681f3Smrg    *       SURFACE_STATE    | BC*, ETC*, EAC* |      4      |      4
1277ec681f3Smrg    *                        |      FXT1       |      8      |      4
1287ec681f3Smrg    *                        |   all others    |   HALIGN    |   VALIGN
1297ec681f3Smrg    *    -------------------------------------------------------------------
1307ec681f3Smrg    */
1317ec681f3Smrg   if (isl_surf_usage_is_depth(info->usage)) {
1327ec681f3Smrg      *image_align_el = info->format == ISL_FORMAT_R16_UNORM ?
1337ec681f3Smrg                        isl_extent3d(8, 4, 1) : isl_extent3d(4, 4, 1);
1347ec681f3Smrg      return;
1357ec681f3Smrg   } else if (isl_surf_usage_is_stencil(info->usage)) {
1367ec681f3Smrg      *image_align_el = isl_extent3d(8, 8, 1);
1377ec681f3Smrg      return;
1387ec681f3Smrg   } else if (isl_format_is_compressed(info->format)) {
1397ec681f3Smrg      /* Compressed formats all have alignment equal to block size. */
1407ec681f3Smrg      *image_align_el = isl_extent3d(1, 1, 1);
1417ec681f3Smrg      return;
1427ec681f3Smrg   }
1437ec681f3Smrg
1447ec681f3Smrg   /* For all other formats, the alignment is determined by the horizontal and
1457ec681f3Smrg    * vertical alignment fields of RENDER_SURFACE_STATE.  There are a few
1467ec681f3Smrg    * restrictions, but we generally have a choice.
1477ec681f3Smrg    */
1487ec681f3Smrg
1497ec681f3Smrg   /* Vertical alignment is unrestricted so we choose the smallest allowed
1507ec681f3Smrg    * alignment because that will use the least memory
1517ec681f3Smrg    */
1527ec681f3Smrg   const uint32_t valign = 4;
1537ec681f3Smrg
1547ec681f3Smrg   /* XXX(chadv): I believe the hardware requires each image to be
1557ec681f3Smrg    * cache-aligned. If that's true, then defaulting to halign=4 is wrong for
1567ec681f3Smrg    * many formats. Depending on the format's block size, we may need to
1577ec681f3Smrg    * increase halign to 8.
1587ec681f3Smrg    */
1597ec681f3Smrg   uint32_t halign = 4;
1607ec681f3Smrg
1617ec681f3Smrg   if (!(info->usage & ISL_SURF_USAGE_DISABLE_AUX_BIT)) {
1627ec681f3Smrg      /* From the Broadwell PRM, Volume 2d "Command Reference: Structures",
1637ec681f3Smrg       * RENDER_SURFACE_STATE Surface Horizontal Alignment, p326:
1647ec681f3Smrg       *
1657ec681f3Smrg       *    - When Auxiliary Surface Mode is set to AUX_CCS_D or AUX_CCS_E,
1667ec681f3Smrg       *      HALIGN 16 must be used.
1677ec681f3Smrg       *
1687ec681f3Smrg       * This case handles color surfaces that may own an auxiliary MCS, CCS_D,
1697ec681f3Smrg       * or CCS_E. Depth buffers, including those that own an auxiliary HiZ
1707ec681f3Smrg       * surface, are handled above and do not require HALIGN_16.
1717ec681f3Smrg       */
1727ec681f3Smrg      assert(halign <= 16);
1737ec681f3Smrg      halign = 16;
1747ec681f3Smrg   }
1757ec681f3Smrg
1767ec681f3Smrg   if (ISL_GFX_VER(dev) >= 11 && isl_tiling_is_any_y(tiling) &&
1777ec681f3Smrg       fmtl->bpb == 32 && info->samples == 1) {
1787ec681f3Smrg      /* GEN_BUG_1406667188: Pixel Corruption in subspan combining (8x4
1797ec681f3Smrg       * combining) scenarios if halign=4.
1807ec681f3Smrg       *
1817ec681f3Smrg       * See RENDER_SURFACE_STATE in Ice Lake h/w spec:
1827ec681f3Smrg       *
1837ec681f3Smrg       *    "For surface format = 32 bpp, num_multisamples = 1 , MIpcount > 0
1847ec681f3Smrg       *     and surface walk = TiledY, HALIGN must be programmed to 8"
1857ec681f3Smrg       */
1867ec681f3Smrg      halign = MAX(halign, 8);
1877ec681f3Smrg   }
1887ec681f3Smrg
1897ec681f3Smrg   *image_align_el = isl_extent3d(halign, valign, 1);
1907ec681f3Smrg}
191