1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright 2015 Intel Corporation 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 13bf215546Sopenharmony_ci * Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21bf215546Sopenharmony_ci * IN THE SOFTWARE. 22bf215546Sopenharmony_ci */ 23bf215546Sopenharmony_ci 24bf215546Sopenharmony_ci#include "isl_gfx8.h" 25bf215546Sopenharmony_ci#include "isl_priv.h" 26bf215546Sopenharmony_ci 27bf215546Sopenharmony_cibool 28bf215546Sopenharmony_ciisl_gfx8_choose_msaa_layout(const struct isl_device *dev, 29bf215546Sopenharmony_ci const struct isl_surf_init_info *info, 30bf215546Sopenharmony_ci enum isl_tiling tiling, 31bf215546Sopenharmony_ci enum isl_msaa_layout *msaa_layout) 32bf215546Sopenharmony_ci{ 33bf215546Sopenharmony_ci bool require_array = false; 34bf215546Sopenharmony_ci bool require_interleaved = false; 35bf215546Sopenharmony_ci 36bf215546Sopenharmony_ci assert(info->samples >= 1); 37bf215546Sopenharmony_ci 38bf215546Sopenharmony_ci if (info->samples == 1) { 39bf215546Sopenharmony_ci *msaa_layout = ISL_MSAA_LAYOUT_NONE; 40bf215546Sopenharmony_ci return true; 41bf215546Sopenharmony_ci } 42bf215546Sopenharmony_ci 43bf215546Sopenharmony_ci /* From the Broadwell PRM >> Volume2d: Command Structures >> 44bf215546Sopenharmony_ci * RENDER_SURFACE_STATE Multisampled Surface Storage Format: 45bf215546Sopenharmony_ci * 46bf215546Sopenharmony_ci * All multisampled render target surfaces must have this field set to 47bf215546Sopenharmony_ci * MSFMT_MSS 48bf215546Sopenharmony_ci */ 49bf215546Sopenharmony_ci if (info->usage & ISL_SURF_USAGE_RENDER_TARGET_BIT) 50bf215546Sopenharmony_ci require_array = true; 51bf215546Sopenharmony_ci 52bf215546Sopenharmony_ci /* From the Broadwell PRM >> Volume2d: Command Structures >> 53bf215546Sopenharmony_ci * RENDER_SURFACE_STATE Number of Multisamples: 54bf215546Sopenharmony_ci * 55bf215546Sopenharmony_ci * - If this field is any value other than MULTISAMPLECOUNT_1, the 56bf215546Sopenharmony_ci * Surface Type must be SURFTYPE_2D This field must be set to 57bf215546Sopenharmony_ci * MULTISAMPLECOUNT_1 unless the surface is a Sampling Engine surface 58bf215546Sopenharmony_ci * or Render Target surface. 59bf215546Sopenharmony_ci * 60bf215546Sopenharmony_ci * - If this field is any value other than MULTISAMPLECOUNT_1, Surface 61bf215546Sopenharmony_ci * Min LOD, Mip Count / LOD, and Resource Min LOD must be set to zero. 62bf215546Sopenharmony_ci */ 63bf215546Sopenharmony_ci if (info->dim != ISL_SURF_DIM_2D) 64bf215546Sopenharmony_ci return false; 65bf215546Sopenharmony_ci if (info->levels > 1) 66bf215546Sopenharmony_ci return false; 67bf215546Sopenharmony_ci 68bf215546Sopenharmony_ci /* More obvious restrictions */ 69bf215546Sopenharmony_ci if (isl_surf_usage_is_display(info->usage)) 70bf215546Sopenharmony_ci return false; 71bf215546Sopenharmony_ci if (!isl_format_supports_multisampling(dev->info, info->format)) 72bf215546Sopenharmony_ci return false; 73bf215546Sopenharmony_ci 74bf215546Sopenharmony_ci if (isl_surf_usage_is_depth_or_stencil(info->usage) || 75bf215546Sopenharmony_ci (info->usage & ISL_SURF_USAGE_HIZ_BIT)) 76bf215546Sopenharmony_ci require_interleaved = true; 77bf215546Sopenharmony_ci 78bf215546Sopenharmony_ci if (require_array && require_interleaved) 79bf215546Sopenharmony_ci return false; 80bf215546Sopenharmony_ci 81bf215546Sopenharmony_ci if (require_interleaved) { 82bf215546Sopenharmony_ci *msaa_layout = ISL_MSAA_LAYOUT_INTERLEAVED; 83bf215546Sopenharmony_ci return true; 84bf215546Sopenharmony_ci } 85bf215546Sopenharmony_ci 86bf215546Sopenharmony_ci *msaa_layout = ISL_MSAA_LAYOUT_ARRAY; 87bf215546Sopenharmony_ci return true; 88bf215546Sopenharmony_ci} 89bf215546Sopenharmony_ci 90bf215546Sopenharmony_civoid 91bf215546Sopenharmony_ciisl_gfx8_choose_image_alignment_el(const struct isl_device *dev, 92bf215546Sopenharmony_ci const struct isl_surf_init_info *restrict info, 93bf215546Sopenharmony_ci enum isl_tiling tiling, 94bf215546Sopenharmony_ci enum isl_dim_layout dim_layout, 95bf215546Sopenharmony_ci enum isl_msaa_layout msaa_layout, 96bf215546Sopenharmony_ci struct isl_extent3d *image_align_el) 97bf215546Sopenharmony_ci{ 98bf215546Sopenharmony_ci /* Handled by isl_choose_image_alignment_el */ 99bf215546Sopenharmony_ci assert(info->format != ISL_FORMAT_HIZ); 100bf215546Sopenharmony_ci 101bf215546Sopenharmony_ci assert(!isl_tiling_is_std_y(tiling)); 102bf215546Sopenharmony_ci 103bf215546Sopenharmony_ci const struct isl_format_layout *fmtl = isl_format_get_layout(info->format); 104bf215546Sopenharmony_ci if (fmtl->txc == ISL_TXC_CCS) { 105bf215546Sopenharmony_ci /* 106bf215546Sopenharmony_ci * Broadwell PRM Vol 7, "MCS Buffer for Render Target(s)" (p. 676): 107bf215546Sopenharmony_ci * 108bf215546Sopenharmony_ci * "Mip-mapped and arrayed surfaces are supported with MCS buffer 109bf215546Sopenharmony_ci * layout with these alignments in the RT space: Horizontal 110bf215546Sopenharmony_ci * Alignment = 256 and Vertical Alignment = 128. 111bf215546Sopenharmony_ci */ 112bf215546Sopenharmony_ci *image_align_el = isl_extent3d(256 / fmtl->bw, 128 / fmtl->bh, 1); 113bf215546Sopenharmony_ci return; 114bf215546Sopenharmony_ci } 115bf215546Sopenharmony_ci 116bf215546Sopenharmony_ci /* From the Broadwell PRM, Volume 4, "Memory Views" p. 186, the alignment 117bf215546Sopenharmony_ci * parameters are summarized in the following table: 118bf215546Sopenharmony_ci * 119bf215546Sopenharmony_ci * Surface Defined By | Surface Format | Align Width | Align Height 120bf215546Sopenharmony_ci * --------------------+-----------------+-------------+-------------- 121bf215546Sopenharmony_ci * DEPTH_BUFFER | D16_UNORM | 8 | 4 122bf215546Sopenharmony_ci * | other | 4 | 4 123bf215546Sopenharmony_ci * --------------------+-----------------+-------------+-------------- 124bf215546Sopenharmony_ci * STENCIL_BUFFER | N/A | 8 | 8 125bf215546Sopenharmony_ci * --------------------+-----------------+-------------+-------------- 126bf215546Sopenharmony_ci * SURFACE_STATE | BC*, ETC*, EAC* | 4 | 4 127bf215546Sopenharmony_ci * | FXT1 | 8 | 4 128bf215546Sopenharmony_ci * | all others | HALIGN | VALIGN 129bf215546Sopenharmony_ci * ------------------------------------------------------------------- 130bf215546Sopenharmony_ci */ 131bf215546Sopenharmony_ci if (isl_surf_usage_is_depth(info->usage)) { 132bf215546Sopenharmony_ci *image_align_el = info->format == ISL_FORMAT_R16_UNORM ? 133bf215546Sopenharmony_ci isl_extent3d(8, 4, 1) : isl_extent3d(4, 4, 1); 134bf215546Sopenharmony_ci return; 135bf215546Sopenharmony_ci } else if (isl_surf_usage_is_stencil(info->usage)) { 136bf215546Sopenharmony_ci *image_align_el = isl_extent3d(8, 8, 1); 137bf215546Sopenharmony_ci return; 138bf215546Sopenharmony_ci } else if (isl_format_is_compressed(info->format)) { 139bf215546Sopenharmony_ci /* Compressed formats all have alignment equal to block size. */ 140bf215546Sopenharmony_ci *image_align_el = isl_extent3d(1, 1, 1); 141bf215546Sopenharmony_ci return; 142bf215546Sopenharmony_ci } 143bf215546Sopenharmony_ci 144bf215546Sopenharmony_ci /* For all other formats, the alignment is determined by the horizontal and 145bf215546Sopenharmony_ci * vertical alignment fields of RENDER_SURFACE_STATE. There are a few 146bf215546Sopenharmony_ci * restrictions, but we generally have a choice. 147bf215546Sopenharmony_ci */ 148bf215546Sopenharmony_ci 149bf215546Sopenharmony_ci /* Vertical alignment is unrestricted so we choose the smallest allowed 150bf215546Sopenharmony_ci * alignment because that will use the least memory 151bf215546Sopenharmony_ci */ 152bf215546Sopenharmony_ci const uint32_t valign = 4; 153bf215546Sopenharmony_ci 154bf215546Sopenharmony_ci /* XXX(chadv): I believe the hardware requires each image to be 155bf215546Sopenharmony_ci * cache-aligned. If that's true, then defaulting to halign=4 is wrong for 156bf215546Sopenharmony_ci * many formats. Depending on the format's block size, we may need to 157bf215546Sopenharmony_ci * increase halign to 8. 158bf215546Sopenharmony_ci */ 159bf215546Sopenharmony_ci uint32_t halign = 4; 160bf215546Sopenharmony_ci 161bf215546Sopenharmony_ci if (!(info->usage & ISL_SURF_USAGE_DISABLE_AUX_BIT)) { 162bf215546Sopenharmony_ci /* From the Broadwell PRM, Volume 2d "Command Reference: Structures", 163bf215546Sopenharmony_ci * RENDER_SURFACE_STATE Surface Horizontal Alignment, p326: 164bf215546Sopenharmony_ci * 165bf215546Sopenharmony_ci * - When Auxiliary Surface Mode is set to AUX_CCS_D or AUX_CCS_E, 166bf215546Sopenharmony_ci * HALIGN 16 must be used. 167bf215546Sopenharmony_ci * 168bf215546Sopenharmony_ci * This case handles color surfaces that may own an auxiliary MCS, CCS_D, 169bf215546Sopenharmony_ci * or CCS_E. Depth buffers, including those that own an auxiliary HiZ 170bf215546Sopenharmony_ci * surface, are handled above and do not require HALIGN_16. 171bf215546Sopenharmony_ci */ 172bf215546Sopenharmony_ci assert(halign <= 16); 173bf215546Sopenharmony_ci halign = 16; 174bf215546Sopenharmony_ci } 175bf215546Sopenharmony_ci 176bf215546Sopenharmony_ci if (ISL_GFX_VER(dev) >= 11 && isl_tiling_is_any_y(tiling) && 177bf215546Sopenharmony_ci fmtl->bpb == 32 && info->samples == 1) { 178bf215546Sopenharmony_ci /* GEN_BUG_1406667188: Pixel Corruption in subspan combining (8x4 179bf215546Sopenharmony_ci * combining) scenarios if halign=4. 180bf215546Sopenharmony_ci * 181bf215546Sopenharmony_ci * See RENDER_SURFACE_STATE in Ice Lake h/w spec: 182bf215546Sopenharmony_ci * 183bf215546Sopenharmony_ci * "For surface format = 32 bpp, num_multisamples = 1 , MIpcount > 0 184bf215546Sopenharmony_ci * and surface walk = TiledY, HALIGN must be programmed to 8" 185bf215546Sopenharmony_ci */ 186bf215546Sopenharmony_ci halign = MAX(halign, 8); 187bf215546Sopenharmony_ci } 188bf215546Sopenharmony_ci 189bf215546Sopenharmony_ci *image_align_el = isl_extent3d(halign, valign, 1); 190bf215546Sopenharmony_ci} 191