/*1* Copyright 2015 Intel Corporation2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*/2223#include "isl_gfx8.h"24#include "isl_priv.h"2526bool27isl_gfx8_choose_msaa_layout(const struct isl_device *dev,28const struct isl_surf_init_info *info,29enum isl_tiling tiling,30enum isl_msaa_layout *msaa_layout)31{32bool require_array = false;33bool require_interleaved = false;3435assert(info->samples >= 1);3637if (info->samples == 1) {38*msaa_layout = ISL_MSAA_LAYOUT_NONE;39return true;40}4142/* From the Broadwell PRM >> Volume2d: Command Structures >>43* RENDER_SURFACE_STATE Multisampled Surface Storage Format:44*45* All multisampled render target surfaces must have this field set to46* MSFMT_MSS47*/48if (info->usage & ISL_SURF_USAGE_RENDER_TARGET_BIT)49require_array = true;5051/* From the Broadwell PRM >> Volume2d: Command Structures >>52* RENDER_SURFACE_STATE Number of Multisamples:53*54* - If this field is any value other than MULTISAMPLECOUNT_1, the55* Surface Type must be SURFTYPE_2D This field must be set to56* MULTISAMPLECOUNT_1 unless the surface is a Sampling Engine surface57* or Render Target surface.58*59* - If this field is any value other than MULTISAMPLECOUNT_1, Surface60* Min LOD, Mip Count / LOD, and Resource Min LOD must be set to zero.61*/62if (info->dim != ISL_SURF_DIM_2D)63return false;64if (info->levels > 1)65return false;6667/* More obvious restrictions */68if (isl_surf_usage_is_display(info->usage))69return false;70if (!isl_format_supports_multisampling(dev->info, info->format))71return false;7273if (isl_surf_usage_is_depth_or_stencil(info->usage) ||74(info->usage & ISL_SURF_USAGE_HIZ_BIT))75require_interleaved = true;7677if (require_array && require_interleaved)78return false;7980if (require_interleaved) {81*msaa_layout = ISL_MSAA_LAYOUT_INTERLEAVED;82return true;83}8485*msaa_layout = ISL_MSAA_LAYOUT_ARRAY;86return true;87}8889void90isl_gfx8_choose_image_alignment_el(const struct isl_device *dev,91const struct isl_surf_init_info *restrict info,92enum isl_tiling tiling,93enum isl_dim_layout dim_layout,94enum isl_msaa_layout msaa_layout,95struct isl_extent3d *image_align_el)96{97/* Handled by isl_choose_image_alignment_el */98assert(info->format != ISL_FORMAT_HIZ);99100assert(!isl_tiling_is_std_y(tiling));101102const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);103if (fmtl->txc == ISL_TXC_CCS) {104/*105* Broadwell PRM Vol 7, "MCS Buffer for Render Target(s)" (p. 676):106*107* "Mip-mapped and arrayed surfaces are supported with MCS buffer108* layout with these alignments in the RT space: Horizontal109* Alignment = 256 and Vertical Alignment = 128.110*/111*image_align_el = isl_extent3d(256 / fmtl->bw, 128 / fmtl->bh, 1);112return;113}114115/* From the Broadwell PRM, Volume 4, "Memory Views" p. 186, the alignment116* parameters are summarized in the following table:117*118* Surface Defined By | Surface Format | Align Width | Align Height119* --------------------+-----------------+-------------+--------------120* DEPTH_BUFFER | D16_UNORM | 8 | 4121* | other | 4 | 4122* --------------------+-----------------+-------------+--------------123* STENCIL_BUFFER | N/A | 8 | 8124* --------------------+-----------------+-------------+--------------125* SURFACE_STATE | BC*, ETC*, EAC* | 4 | 4126* | FXT1 | 8 | 4127* | all others | HALIGN | VALIGN128* -------------------------------------------------------------------129*/130if (isl_surf_usage_is_depth(info->usage)) {131*image_align_el = info->format == ISL_FORMAT_R16_UNORM ?132isl_extent3d(8, 4, 1) : isl_extent3d(4, 4, 1);133return;134} else if (isl_surf_usage_is_stencil(info->usage)) {135*image_align_el = isl_extent3d(8, 8, 1);136return;137} else if (isl_format_is_compressed(info->format)) {138/* Compressed formats all have alignment equal to block size. */139*image_align_el = isl_extent3d(1, 1, 1);140return;141}142143/* For all other formats, the alignment is determined by the horizontal and144* vertical alignment fields of RENDER_SURFACE_STATE. There are a few145* restrictions, but we generally have a choice.146*/147148/* Vertical alignment is unrestricted so we choose the smallest allowed149* alignment because that will use the least memory150*/151const uint32_t valign = 4;152153/* XXX(chadv): I believe the hardware requires each image to be154* cache-aligned. If that's true, then defaulting to halign=4 is wrong for155* many formats. Depending on the format's block size, we may need to156* increase halign to 8.157*/158uint32_t halign = 4;159160if (!(info->usage & ISL_SURF_USAGE_DISABLE_AUX_BIT)) {161/* From the Broadwell PRM, Volume 2d "Command Reference: Structures",162* RENDER_SURFACE_STATE Surface Horizontal Alignment, p326:163*164* - When Auxiliary Surface Mode is set to AUX_CCS_D or AUX_CCS_E,165* HALIGN 16 must be used.166*167* This case handles color surfaces that may own an auxiliary MCS, CCS_D,168* or CCS_E. Depth buffers, including those that own an auxiliary HiZ169* surface, are handled above and do not require HALIGN_16.170*/171assert(halign <= 16);172halign = 16;173}174175if (ISL_GFX_VER(dev) >= 11 && isl_tiling_is_any_y(tiling) &&176fmtl->bpb == 32 && info->samples == 1) {177/* GEN_BUG_1406667188: Pixel Corruption in subspan combining (8x4178* combining) scenarios if halign=4.179*180* See RENDER_SURFACE_STATE in Ice Lake h/w spec:181*182* "For surface format = 32 bpp, num_multisamples = 1 , MIpcount > 0183* and surface walk = TiledY, HALIGN must be programmed to 8"184*/185halign = MAX(halign, 8);186}187188*image_align_el = isl_extent3d(halign, valign, 1);189}190191192