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