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