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_gen6.h" 25b8e80941Smrg#include "isl_priv.h" 26b8e80941Smrg 27b8e80941Smrgbool 28b8e80941Smrgisl_gen6_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 assert(ISL_DEV_GEN(dev) == 6); 34b8e80941Smrg assert(info->samples >= 1); 35b8e80941Smrg 36b8e80941Smrg if (info->samples == 1) { 37b8e80941Smrg *msaa_layout = ISL_MSAA_LAYOUT_NONE; 38b8e80941Smrg return true; 39b8e80941Smrg } 40b8e80941Smrg 41b8e80941Smrg if (!isl_format_supports_multisampling(dev->info, info->format)) 42b8e80941Smrg return false; 43b8e80941Smrg 44b8e80941Smrg /* From the Sandybridge PRM, Volume 4 Part 1 p85, SURFACE_STATE, Number of 45b8e80941Smrg * Multisamples: 46b8e80941Smrg * 47b8e80941Smrg * If this field is any value other than MULTISAMPLECOUNT_1 the 48b8e80941Smrg * following restrictions apply: 49b8e80941Smrg * 50b8e80941Smrg * - the Surface Type must be SURFTYPE_2D 51b8e80941Smrg * - [...] 52b8e80941Smrg */ 53b8e80941Smrg if (info->dim != ISL_SURF_DIM_2D) 54b8e80941Smrg return false; 55b8e80941Smrg 56b8e80941Smrg /* More obvious restrictions */ 57b8e80941Smrg if (isl_surf_usage_is_display(info->usage)) 58b8e80941Smrg return false; 59b8e80941Smrg if (tiling == ISL_TILING_LINEAR) 60b8e80941Smrg return false; 61b8e80941Smrg if (info->levels > 1) 62b8e80941Smrg return false; 63b8e80941Smrg 64b8e80941Smrg *msaa_layout = ISL_MSAA_LAYOUT_INTERLEAVED; 65b8e80941Smrg return true; 66b8e80941Smrg} 67b8e80941Smrg 68b8e80941Smrgvoid 69b8e80941Smrgisl_gen6_choose_image_alignment_el(const struct isl_device *dev, 70b8e80941Smrg const struct isl_surf_init_info *restrict info, 71b8e80941Smrg enum isl_tiling tiling, 72b8e80941Smrg enum isl_dim_layout dim_layout, 73b8e80941Smrg enum isl_msaa_layout msaa_layout, 74b8e80941Smrg struct isl_extent3d *image_align_el) 75b8e80941Smrg{ 76b8e80941Smrg /* Handled by isl_choose_image_alignment_el */ 77b8e80941Smrg assert(info->format != ISL_FORMAT_HIZ); 78b8e80941Smrg 79b8e80941Smrg /* Note that the surface's horizontal image alignment is not programmable 80b8e80941Smrg * on Sandybridge. 81b8e80941Smrg * 82b8e80941Smrg * From the Sandybridge PRM (2011-05), Volume 1, Part 1, Section 7.18.3.4 83b8e80941Smrg * Alignment Unit Size: 84b8e80941Smrg * 85b8e80941Smrg * Note that the compressed formats are padded to a full compression cell. 86b8e80941Smrg * 87b8e80941Smrg * +------------------------+--------+--------+ 88b8e80941Smrg * | format | halign | valign | 89b8e80941Smrg * +------------------------+--------+--------+ 90b8e80941Smrg * | YUV 4:2:2 formats | 4 | * | 91b8e80941Smrg * | BC1-5 | 4 | 4 | 92b8e80941Smrg * | FXT1 | 8 | 4 | 93b8e80941Smrg * | uncompressed formats | 4 | * | 94b8e80941Smrg * +------------------------+--------+--------+ 95b8e80941Smrg * 96b8e80941Smrg * * For these formats, the vertical alignment factor “j” is determined 97b8e80941Smrg * as follows: 98b8e80941Smrg * - j = 4 for any depth buffer 99b8e80941Smrg * - j = 2 for separate stencil buffer 100b8e80941Smrg * - j = 4 for any render target surface is multisampled (4x) 101b8e80941Smrg * - j = 2 for all other render target surface 102b8e80941Smrg * 103b8e80941Smrg * From the Sandrybridge PRM (2011-05), Volume 4, Part 1, Section 2.11.2 104b8e80941Smrg * SURFACE_STATE, Surface Vertical Alignment: 105b8e80941Smrg * 106b8e80941Smrg * - This field must be set to VALIGN_2 if the Surface Format is 96 bits 107b8e80941Smrg * per element (BPE). 108b8e80941Smrg * 109b8e80941Smrg * - Value of 1 [VALIGN_4] is not supported for format YCRCB_NORMAL 110b8e80941Smrg * (0x182), YCRCB_SWAPUVY (0x183), YCRCB_SWAPUV (0x18f), YCRCB_SWAPY 111b8e80941Smrg * (0x190) 112b8e80941Smrg */ 113b8e80941Smrg 114b8e80941Smrg if (isl_format_is_compressed(info->format)) { 115b8e80941Smrg /* Compressed formats have an alignment equal to their block size */ 116b8e80941Smrg *image_align_el = isl_extent3d(1, 1, 1); 117b8e80941Smrg return; 118b8e80941Smrg } 119b8e80941Smrg 120b8e80941Smrg /* Separate stencil requires 4x2 alignment */ 121b8e80941Smrg if (isl_surf_usage_is_stencil(info->usage) && 122b8e80941Smrg info->format == ISL_FORMAT_R8_UINT) { 123b8e80941Smrg *image_align_el = isl_extent3d(4, 2, 1); 124b8e80941Smrg return; 125b8e80941Smrg } 126b8e80941Smrg 127b8e80941Smrg /* Depth or combined depth stencil surfaces require 4x4 alignment */ 128b8e80941Smrg if (isl_surf_usage_is_depth_or_stencil(info->usage)) { 129b8e80941Smrg *image_align_el = isl_extent3d(4, 4, 1); 130b8e80941Smrg return; 131b8e80941Smrg } 132b8e80941Smrg 133b8e80941Smrg if (info->samples > 1) { 134b8e80941Smrg *image_align_el = isl_extent3d(4, 4, 1); 135b8e80941Smrg return; 136b8e80941Smrg } 137b8e80941Smrg 138b8e80941Smrg /* For everything else, 4x2 is always a valid alignment. Since this is 139b8e80941Smrg * also the smallest alignment we can specify, we use 4x2 for everything 140b8e80941Smrg * else because it uses the least memory. 141b8e80941Smrg */ 142b8e80941Smrg *image_align_el = isl_extent3d(4, 2, 1); 143b8e80941Smrg} 144