1*61046927SAndroid Build Coastguard Worker /*
2*61046927SAndroid Build Coastguard Worker * Copyright 2015 Intel Corporation
3*61046927SAndroid Build Coastguard Worker *
4*61046927SAndroid Build Coastguard Worker * Permission is hereby granted, free of charge, to any person obtaining a
5*61046927SAndroid Build Coastguard Worker * copy of this software and associated documentation files (the "Software"),
6*61046927SAndroid Build Coastguard Worker * to deal in the Software without restriction, including without limitation
7*61046927SAndroid Build Coastguard Worker * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*61046927SAndroid Build Coastguard Worker * and/or sell copies of the Software, and to permit persons to whom the
9*61046927SAndroid Build Coastguard Worker * Software is furnished to do so, subject to the following conditions:
10*61046927SAndroid Build Coastguard Worker *
11*61046927SAndroid Build Coastguard Worker * The above copyright notice and this permission notice (including the next
12*61046927SAndroid Build Coastguard Worker * paragraph) shall be included in all copies or substantial portions of the
13*61046927SAndroid Build Coastguard Worker * Software.
14*61046927SAndroid Build Coastguard Worker *
15*61046927SAndroid Build Coastguard Worker * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16*61046927SAndroid Build Coastguard Worker * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17*61046927SAndroid Build Coastguard Worker * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18*61046927SAndroid Build Coastguard Worker * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19*61046927SAndroid Build Coastguard Worker * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20*61046927SAndroid Build Coastguard Worker * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21*61046927SAndroid Build Coastguard Worker * IN THE SOFTWARE.
22*61046927SAndroid Build Coastguard Worker */
23*61046927SAndroid Build Coastguard Worker
24*61046927SAndroid Build Coastguard Worker #include "isl_gfx8.h"
25*61046927SAndroid Build Coastguard Worker #include "isl_gfx9.h"
26*61046927SAndroid Build Coastguard Worker #include "isl_priv.h"
27*61046927SAndroid Build Coastguard Worker
28*61046927SAndroid Build Coastguard Worker void
isl_gfx9_choose_image_alignment_el(const struct isl_device * dev,const struct isl_surf_init_info * restrict info,const struct isl_tile_info * tile_info,enum isl_dim_layout dim_layout,enum isl_msaa_layout msaa_layout,struct isl_extent3d * image_align_el)29*61046927SAndroid Build Coastguard Worker isl_gfx9_choose_image_alignment_el(const struct isl_device *dev,
30*61046927SAndroid Build Coastguard Worker const struct isl_surf_init_info *restrict info,
31*61046927SAndroid Build Coastguard Worker const struct isl_tile_info *tile_info,
32*61046927SAndroid Build Coastguard Worker enum isl_dim_layout dim_layout,
33*61046927SAndroid Build Coastguard Worker enum isl_msaa_layout msaa_layout,
34*61046927SAndroid Build Coastguard Worker struct isl_extent3d *image_align_el)
35*61046927SAndroid Build Coastguard Worker {
36*61046927SAndroid Build Coastguard Worker enum isl_tiling tiling = tile_info->tiling;
37*61046927SAndroid Build Coastguard Worker
38*61046927SAndroid Build Coastguard Worker /* Handled by isl_choose_image_alignment_el */
39*61046927SAndroid Build Coastguard Worker assert(info->format != ISL_FORMAT_HIZ);
40*61046927SAndroid Build Coastguard Worker
41*61046927SAndroid Build Coastguard Worker const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
42*61046927SAndroid Build Coastguard Worker if (fmtl->txc == ISL_TXC_CCS) {
43*61046927SAndroid Build Coastguard Worker /* Sky Lake PRM Vol. 7, "MCS Buffer for Render Target(s)" (p. 632):
44*61046927SAndroid Build Coastguard Worker *
45*61046927SAndroid Build Coastguard Worker * "Mip-mapped and arrayed surfaces are supported with MCS buffer
46*61046927SAndroid Build Coastguard Worker * layout with these alignments in the RT space: Horizontal
47*61046927SAndroid Build Coastguard Worker * Alignment = 128 and Vertical Alignment = 64."
48*61046927SAndroid Build Coastguard Worker */
49*61046927SAndroid Build Coastguard Worker *image_align_el = isl_extent3d(128 / fmtl->bw, 64 / fmtl->bh, 1);
50*61046927SAndroid Build Coastguard Worker return;
51*61046927SAndroid Build Coastguard Worker }
52*61046927SAndroid Build Coastguard Worker
53*61046927SAndroid Build Coastguard Worker /* This BSpec text provides some insight into the hardware's alignment
54*61046927SAndroid Build Coastguard Worker * requirements [Skylake BSpec > Memory Views > Common Surface Formats >
55*61046927SAndroid Build Coastguard Worker * Surface Layout and Tiling > 2D Surfaces]:
56*61046927SAndroid Build Coastguard Worker *
57*61046927SAndroid Build Coastguard Worker * An LOD must be aligned to a cache-line except for some special cases
58*61046927SAndroid Build Coastguard Worker * related to Planar YUV surfaces. In general, the cache-alignment
59*61046927SAndroid Build Coastguard Worker * restriction implies there is a minimum height for an LOD of 4 texels.
60*61046927SAndroid Build Coastguard Worker * So, LODs which are smaller than 4 high are padded.
61*61046927SAndroid Build Coastguard Worker *
62*61046927SAndroid Build Coastguard Worker * From the Skylake BSpec, RENDER_SURFACE_STATE Surface Vertical Alignment:
63*61046927SAndroid Build Coastguard Worker *
64*61046927SAndroid Build Coastguard Worker * - For Sampling Engine and Render Target Surfaces: This field
65*61046927SAndroid Build Coastguard Worker * specifies the vertical alignment requirement in elements for the
66*61046927SAndroid Build Coastguard Worker * surface. [...] An element is defined as a pixel in uncompressed
67*61046927SAndroid Build Coastguard Worker * surface formats, and as a compression block in compressed surface
68*61046927SAndroid Build Coastguard Worker * formats. For MSFMT_DEPTH_STENCIL type multisampled surfaces, an
69*61046927SAndroid Build Coastguard Worker * element is a sample.
70*61046927SAndroid Build Coastguard Worker *
71*61046927SAndroid Build Coastguard Worker * - This field is used for 2D, CUBE, and 3D surface alignment when Tiled
72*61046927SAndroid Build Coastguard Worker * Resource Mode is TRMODE_NONE (Tiled Resource Mode is disabled).
73*61046927SAndroid Build Coastguard Worker * This field is ignored for 1D surfaces and also when Tiled Resource
74*61046927SAndroid Build Coastguard Worker * Mode is not TRMODE_NONE (e.g. Tiled Resource Mode is enabled).
75*61046927SAndroid Build Coastguard Worker *
76*61046927SAndroid Build Coastguard Worker * See the appropriate Alignment table in the "Surface Layout and
77*61046927SAndroid Build Coastguard Worker * Tiling" section under Common Surface Formats for the table of
78*61046927SAndroid Build Coastguard Worker * alignment values for Tiled Resources.
79*61046927SAndroid Build Coastguard Worker *
80*61046927SAndroid Build Coastguard Worker * - For uncompressed surfaces, the units of "j" are rows of pixels on
81*61046927SAndroid Build Coastguard Worker * the physical surface. For compressed texture formats, the units of
82*61046927SAndroid Build Coastguard Worker * "j" are in compression blocks, thus each increment in "j" is equal
83*61046927SAndroid Build Coastguard Worker * to h pixels, where h is the height of the compression block in
84*61046927SAndroid Build Coastguard Worker * pixels.
85*61046927SAndroid Build Coastguard Worker *
86*61046927SAndroid Build Coastguard Worker * - Valid Values: VALIGN_4, VALIGN_8, VALIGN_16
87*61046927SAndroid Build Coastguard Worker *
88*61046927SAndroid Build Coastguard Worker * From the Skylake BSpec, RENDER_SURFACE_STATE Surface Horizontal
89*61046927SAndroid Build Coastguard Worker * Alignment:
90*61046927SAndroid Build Coastguard Worker *
91*61046927SAndroid Build Coastguard Worker * - For uncompressed surfaces, the units of "i" are pixels on the
92*61046927SAndroid Build Coastguard Worker * physical surface. For compressed texture formats, the units of "i"
93*61046927SAndroid Build Coastguard Worker * are in compression blocks, thus each increment in "i" is equal to
94*61046927SAndroid Build Coastguard Worker * w pixels, where w is the width of the compression block in pixels.
95*61046927SAndroid Build Coastguard Worker *
96*61046927SAndroid Build Coastguard Worker * - Valid Values: HALIGN_4, HALIGN_8, HALIGN_16
97*61046927SAndroid Build Coastguard Worker */
98*61046927SAndroid Build Coastguard Worker
99*61046927SAndroid Build Coastguard Worker if (isl_tiling_is_std_y(tiling)) {
100*61046927SAndroid Build Coastguard Worker /* Ys and Yf tiled images are aligned to the tile size */
101*61046927SAndroid Build Coastguard Worker *image_align_el = (struct isl_extent3d) {
102*61046927SAndroid Build Coastguard Worker .w = tile_info->logical_extent_el.w,
103*61046927SAndroid Build Coastguard Worker .h = tile_info->logical_extent_el.h,
104*61046927SAndroid Build Coastguard Worker .d = tile_info->logical_extent_el.d,
105*61046927SAndroid Build Coastguard Worker };
106*61046927SAndroid Build Coastguard Worker return;
107*61046927SAndroid Build Coastguard Worker }
108*61046927SAndroid Build Coastguard Worker
109*61046927SAndroid Build Coastguard Worker if (dim_layout == ISL_DIM_LAYOUT_GFX9_1D) {
110*61046927SAndroid Build Coastguard Worker /* See the Skylake BSpec > Memory Views > Common Surface Formats > Surface
111*61046927SAndroid Build Coastguard Worker * Layout and Tiling > 1D Surfaces > 1D Alignment Requirements.
112*61046927SAndroid Build Coastguard Worker */
113*61046927SAndroid Build Coastguard Worker *image_align_el = isl_extent3d(64, 1, 1);
114*61046927SAndroid Build Coastguard Worker return;
115*61046927SAndroid Build Coastguard Worker }
116*61046927SAndroid Build Coastguard Worker
117*61046927SAndroid Build Coastguard Worker if (isl_format_is_compressed(info->format)) {
118*61046927SAndroid Build Coastguard Worker /* On Gfx9, the meaning of RENDER_SURFACE_STATE's
119*61046927SAndroid Build Coastguard Worker * SurfaceHorizontalAlignment and SurfaceVerticalAlignment changed for
120*61046927SAndroid Build Coastguard Worker * compressed formats. They now indicate a multiple of the compression
121*61046927SAndroid Build Coastguard Worker * block. For example, if the compression mode is ETC2 then HALIGN_4
122*61046927SAndroid Build Coastguard Worker * indicates a horizontal alignment of 16 pixels.
123*61046927SAndroid Build Coastguard Worker *
124*61046927SAndroid Build Coastguard Worker * To avoid wasting memory, choose the smallest alignment possible:
125*61046927SAndroid Build Coastguard Worker * HALIGN_4 and VALIGN_4.
126*61046927SAndroid Build Coastguard Worker */
127*61046927SAndroid Build Coastguard Worker *image_align_el = isl_extent3d(4, 4, 1);
128*61046927SAndroid Build Coastguard Worker return;
129*61046927SAndroid Build Coastguard Worker }
130*61046927SAndroid Build Coastguard Worker
131*61046927SAndroid Build Coastguard Worker isl_gfx8_choose_image_alignment_el(dev, info, tiling, dim_layout,
132*61046927SAndroid Build Coastguard Worker msaa_layout, image_align_el);
133*61046927SAndroid Build Coastguard Worker }
134