/*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_gfx6.h"24#include "isl_priv.h"2526bool27isl_gfx6_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{32assert(ISL_GFX_VER(dev) == 6);33assert(info->samples >= 1);3435if (info->samples == 1) {36*msaa_layout = ISL_MSAA_LAYOUT_NONE;37return true;38}3940if (!isl_format_supports_multisampling(dev->info, info->format))41return false;4243/* From the Sandybridge PRM, Volume 4 Part 1 p85, SURFACE_STATE, Number of44* Multisamples:45*46* If this field is any value other than MULTISAMPLECOUNT_1 the47* following restrictions apply:48*49* - the Surface Type must be SURFTYPE_2D50* - [...]51*/52if (info->dim != ISL_SURF_DIM_2D)53return false;5455/* More obvious restrictions */56if (isl_surf_usage_is_display(info->usage))57return false;58if (tiling == ISL_TILING_LINEAR)59return false;60if (info->levels > 1)61return false;6263*msaa_layout = ISL_MSAA_LAYOUT_INTERLEAVED;64return true;65}6667void68isl_gfx6_choose_image_alignment_el(const struct isl_device *dev,69const struct isl_surf_init_info *restrict info,70enum isl_tiling tiling,71enum isl_dim_layout dim_layout,72enum isl_msaa_layout msaa_layout,73struct isl_extent3d *image_align_el)74{75/* Handled by isl_choose_image_alignment_el */76assert(info->format != ISL_FORMAT_HIZ);7778/* Note that the surface's horizontal image alignment is not programmable79* on Sandybridge.80*81* From the Sandybridge PRM (2011-05), Volume 1, Part 1, Section 7.18.3.482* Alignment Unit Size:83*84* Note that the compressed formats are padded to a full compression cell.85*86* +------------------------+--------+--------+87* | format | halign | valign |88* +------------------------+--------+--------+89* | YUV 4:2:2 formats | 4 | * |90* | BC1-5 | 4 | 4 |91* | FXT1 | 8 | 4 |92* | uncompressed formats | 4 | * |93* +------------------------+--------+--------+94*95* * For these formats, the vertical alignment factor “j” is determined96* as follows:97* - j = 4 for any depth buffer98* - j = 2 for separate stencil buffer99* - j = 4 for any render target surface is multisampled (4x)100* - j = 2 for all other render target surface101*102* From the Sandrybridge PRM (2011-05), Volume 4, Part 1, Section 2.11.2103* SURFACE_STATE, Surface Vertical Alignment:104*105* - This field must be set to VALIGN_2 if the Surface Format is 96 bits106* per element (BPE).107*108* - Value of 1 [VALIGN_4] is not supported for format YCRCB_NORMAL109* (0x182), YCRCB_SWAPUVY (0x183), YCRCB_SWAPUV (0x18f), YCRCB_SWAPY110* (0x190)111*/112113if (isl_format_is_compressed(info->format)) {114/* Compressed formats have an alignment equal to their block size */115*image_align_el = isl_extent3d(1, 1, 1);116return;117}118119/* Separate stencil requires 4x2 alignment */120if (isl_surf_usage_is_stencil(info->usage) &&121info->format == ISL_FORMAT_R8_UINT) {122*image_align_el = isl_extent3d(4, 2, 1);123return;124}125126/* Depth or combined depth stencil surfaces require 4x4 alignment */127if (isl_surf_usage_is_depth_or_stencil(info->usage)) {128*image_align_el = isl_extent3d(4, 4, 1);129return;130}131132if (info->samples > 1) {133*image_align_el = isl_extent3d(4, 4, 1);134return;135}136137/* For everything else, 4x2 is always a valid alignment. Since this is138* also the smallest alignment we can specify, we use 4x2 for everything139* else because it uses the least memory.140*/141*image_align_el = isl_extent3d(4, 2, 1);142}143144145