xref: /aosp_15_r20/external/mesa3d/src/intel/isl/isl_gfx12.c (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright (c) 2018 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_gfx9.h"
25 #include "isl_gfx12.h"
26 #include "isl_priv.h"
27 
28 /**
29  * @brief Filter out tiling flags that are incompatible with the surface.
30  *
31  * The resultant outgoing @a flags is a subset of the incoming @a flags. The
32  * outgoing flags may be empty (0x0) if the incoming flags were too
33  * restrictive.
34  *
35  * For example, if the surface will be used for a display
36  * (ISL_SURF_USAGE_DISPLAY_BIT), then this function filters out all tiling
37  * flags except ISL_TILING_4_BIT, ISL_TILING_X_BIT, and ISL_TILING_LINEAR_BIT.
38  */
39 void
isl_gfx125_filter_tiling(const struct isl_device * dev,const struct isl_surf_init_info * restrict info,isl_tiling_flags_t * flags)40 isl_gfx125_filter_tiling(const struct isl_device *dev,
41                          const struct isl_surf_init_info *restrict info,
42                          isl_tiling_flags_t *flags)
43 {
44    /* Clear flags unsupported on this hardware */
45    assert(ISL_GFX_VERX10(dev) == 125);
46 
47    *flags &= ISL_TILING_LINEAR_BIT |
48              ISL_TILING_X_BIT |
49              ISL_TILING_4_BIT |
50              ISL_TILING_64_BIT;
51 
52    if (isl_surf_usage_is_depth_or_stencil(info->usage)) {
53       *flags &= ISL_TILING_4_BIT | ISL_TILING_64_BIT;
54 
55       /* We choose to avoid Tile64 for 3D depth/stencil buffers. The swizzle
56        * for Tile64 is dependent on the image dimension. So, reads and writes
57        * should specify the same dimension to consistently interpret the data.
58        * This is not possible for 3D depth/stencil buffers however. Such
59        * buffers can be sampled from with a 3D view, but rendering is only
60        * possible with a 2D view due to the limitations of
61        * 3DSTATE_(DEPTH|STENCIL)_BUFFER.
62        */
63       if (info->dim == ISL_SURF_DIM_3D)
64          *flags &= ~ISL_TILING_64_BIT;
65    }
66 
67    if (info->usage & ISL_SURF_USAGE_DISPLAY_BIT)
68       *flags &= ~ISL_TILING_64_BIT;
69 
70    /* From RENDER_SURFACE_STATE::AuxiliarySurfaceMode,
71     *
72     *    MCS tiling format is always Tile4
73     */
74    if (info->usage & ISL_SURF_USAGE_MCS_BIT)
75       *flags &= ISL_TILING_4_BIT;
76 
77    /* From RENDER_SURFACE_STATE::TileMode,
78     *
79     *    TILEMODE_XMAJOR is only allowed if Surface Type is SURFTYPE_2D.
80     *
81     * X-tiling is only allowed for 2D surfaces.
82     */
83    if (info->dim != ISL_SURF_DIM_2D)
84       *flags &= ~ISL_TILING_X_BIT;
85 
86    /* From ATS-M PRMs, Volume 2d: Command Reference: Structures,
87     * RENDER_SURFACE_STATE:TileMode :
88     *
89     *    "If Surface Type is SURFTYPE_1D this field must be TILEMODE_LINEAR,
90     *     unless Sampler Legacy 1D Map Layout Disable is set to 0, in which
91     *     case TILEMODE_YMAJOR is also allowed. Horizontal Alignment must be
92     *     programmed for the required alignment between MIPs. MIP tails are
93     *     not supported."
94     *
95     * Tile4 is the replacement for TileY0 on ACM.
96     */
97    if (info->dim == ISL_SURF_DIM_1D)
98       *flags &= ISL_TILING_LINEAR_BIT | ISL_TILING_4_BIT;
99 
100    /* TILE64 does not work with YCRCB formats, according to bspec 58767:
101     * "Packed YUV surface formats such as YCRCB_NORMAL, YCRCB_SWAPUVY etc.
102     * will not support as Tile64"
103     */
104    if (isl_format_is_yuv(info->format))
105       *flags &= ~ISL_TILING_64_BIT;
106 
107    /* Tile64 tilings for 3D have a different swizzling than a 2D surface. So
108     * filter them out if the usage wants 2D/3D compatibility.
109     */
110    if (info->usage & ISL_SURF_USAGE_2D_3D_COMPATIBLE_BIT)
111       *flags &= ~ISL_TILING_64_BIT;
112 
113    /* From RENDER_SURFACE_STATE::NumberofMultisamples,
114     *
115     *    This field must not be programmed to anything other than
116     *    [MULTISAMPLECOUNT_1] unless the Tile Mode field is programmed to
117     *    Tile64.
118     *
119     * Tile64 is required for multisampling.
120     */
121    if (info->samples > 1)
122       *flags &= ISL_TILING_64_BIT;
123 
124    /* Tile64 is not defined for format sizes that are 24, 48, and 96 bpb. */
125    if (isl_format_get_layout(info->format)->bpb % 3 == 0)
126       *flags &= ~ISL_TILING_64_BIT;
127 
128    /* From 3DSTATE_CPSIZE_CONTROL_BUFFER::TiledMode,
129     *
130     *    - 3h       Tile4      4KB tile mode
131     *    - 1h       Tile64     64KB tile mode
132     *    - 2h, 0h   Reserved
133     *
134     * Tile4 and Tile64 are the only two valid values.
135     */
136    if (info->usage & ISL_SURF_USAGE_CPB_BIT)
137       *flags &= ISL_TILING_4_BIT | ISL_TILING_64_BIT;
138 }
139 
140 void
isl_gfx125_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)141 isl_gfx125_choose_image_alignment_el(const struct isl_device *dev,
142                                      const struct isl_surf_init_info *restrict info,
143                                      const struct isl_tile_info *tile_info,
144                                      enum isl_dim_layout dim_layout,
145                                      enum isl_msaa_layout msaa_layout,
146                                      struct isl_extent3d *image_align_el)
147 {
148    enum isl_tiling tiling = tile_info->tiling;
149 
150    /* Handled by isl_choose_image_alignment_el */
151    assert(info->format != ISL_FORMAT_GFX125_HIZ);
152 
153    const struct isl_format_layout *fmtl = isl_format_get_layout(info->format);
154 
155    if (tiling == ISL_TILING_64) {
156       /* From RENDER_SURFACE_STATE::SurfaceHorizontalAlignment,
157        *
158        *   This field is ignored for Tile64 surface formats because horizontal
159        *   alignment is always to the start of the next tile in that case.
160        *
161        * From RENDER_SURFACE_STATE::SurfaceQPitch,
162        *
163        *   Because MSAA is only supported for Tile64, QPitch must also be
164        *   programmed to an aligned tile boundary for MSAA surfaces.
165        *
166        * Images in this surface must be tile-aligned.  The table on the Bspec
167        * page, "2D/CUBE Alignment Requirement", shows that the vertical
168        * alignment is also a tile height for non-MSAA as well.
169        */
170       *image_align_el = isl_extent3d(tile_info->logical_extent_el.w,
171                                      tile_info->logical_extent_el.h,
172                                      1);
173    } else if (isl_surf_usage_is_depth(info->usage)) {
174       /* From RENDER_SURFACE_STATE::SurfaceHorizontalAlignment,
175        *
176        *    - 16b Depth Surfaces Must Be HALIGN=16Bytes (8texels)
177        *    - 32b Depth Surfaces Must Be HALIGN=32Bytes (8texels)
178        *
179        * From RENDER_SURFACE_STATE::SurfaceVerticalAlignment,
180        *
181        *    This field is intended to be set to VALIGN_4 if the surface
182        *    was rendered as a depth buffer [...]
183        *
184        * and
185        *
186        *    This field should also be set to VALIGN_8 if the surface was
187        *    rendered as a D16_UNORM depth buffer [...]
188        */
189       *image_align_el =
190          info->format != ISL_FORMAT_R16_UNORM ?
191          isl_extent3d(8, 4, 1) :
192          isl_extent3d(8, 8, 1);
193    } else if (isl_surf_usage_is_stencil(info->usage) ||
194               isl_surf_usage_is_cpb(info->usage)) {
195       /* From RENDER_SURFACE_STATE::SurfaceHorizontalAlignment,
196        *
197        *    - Stencil Surfaces (8b) Must be HALIGN=16Bytes (16texels)
198        *
199        * From RENDER_SURFACE_STATE::SurfaceVerticalAlignment,
200        *
201        *    This field is intended to be set to VALIGN_8 only if
202        *    the surface was rendered as a stencil buffer, since stencil buffer
203        *    surfaces support only alignment of 8.
204        *
205        * TODO: Cite docs for CPB.
206        */
207       *image_align_el = isl_extent3d(16, 8, 1);
208    } else if (!isl_is_pow2(fmtl->bpb)) {
209       /* From RENDER_SURFACE_STATE::SurfaceHorizontalAlignment,
210        *
211        *    - Linear Surfaces surfaces must use HALIGN=128, including 1D which
212        *      is always Linear. For 24,48 and 96bpp this means 128texels.
213        *    - Tiled 24bpp, 48bpp and 96bpp surfaces must use HALIGN=16
214        */
215       *image_align_el = tiling == ISL_TILING_LINEAR ?
216          isl_extent3d(128, 4, 1) :
217          isl_extent3d(16, 4, 1);
218    } else if (_isl_surf_info_supports_ccs(dev, info->format, info->usage) ||
219               tiling == ISL_TILING_LINEAR) {
220       /* From RENDER_SURFACE_STATE::SurfaceHorizontalAlignment,
221        *
222        *    - Losslessly Compressed Surfaces Must be HALIGN=128 for all
223        *      supported Bpp, if other restriction are not applied
224        *    - Linear Surfaces surfaces must use HALIGN=128, including 1D which
225        *      is always Linear.
226        */
227       *image_align_el = isl_extent3d(128 * 8 / fmtl->bpb, 4, 1);
228    } else if (fmtl->bpb >= 64) {
229       assert(fmtl->bpb == 64 || fmtl->bpb == 128);
230       /* From RENDER_SURFACE_STATE::SurfaceHorizontalAlignment,
231        *
232        *    - 64bpe and 128bpe Surfaces Must Be HALIGN=64Bytes or 128Bytes (4,
233        *      8 texels or 16 texels)
234        *
235        * HALIGN=128 is used for losslessly compressed or linear surfaces. For
236        * other surface types, pick the smaller alignment of HALIGN=64 to save
237        * space.
238        */
239       *image_align_el = isl_extent3d(64 * 8 / fmtl->bpb, 4, 1);
240    } else {
241       /* From RENDER_SURFACE_STATE::SurfaceHorizontalAlignment,
242        *
243        *    HALIGN=16Bytes(8 texels) is allowed only for 16b Depth, Stencil
244        *    Surfaces (8b) and Tiled 24bpp, 48bpp and 96bpp surfaces
245        *
246        * HALIGN=16 would save the most space, but it is reserved for the cases
247        * handled earlier in this if-ladder. Choose the next smallest alignment
248        * possible, HALIGN=32.
249        */
250       *image_align_el = isl_extent3d(32 * 8 / fmtl->bpb, 4, 1);
251    }
252 }
253 
254 void
isl_gfx12_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)255 isl_gfx12_choose_image_alignment_el(const struct isl_device *dev,
256                                     const struct isl_surf_init_info *restrict info,
257                                     const struct isl_tile_info *tile_info,
258                                     enum isl_dim_layout dim_layout,
259                                     enum isl_msaa_layout msaa_layout,
260                                     struct isl_extent3d *image_align_el)
261 {
262    enum isl_tiling tiling = tile_info->tiling;
263 
264    /* Handled by isl_choose_image_alignment_el */
265    assert(info->format != ISL_FORMAT_HIZ);
266 
267    if (isl_tiling_is_std_y(tiling)) {
268       /* From RENDER_SURFACE_STATE::SurfaceHorizontalAlignment,
269        *
270        *   This field is ignored for Tile64 surface formats because horizontal
271        *   alignment is always to the start of the next tile in that case.
272        *
273        * From RENDER_SURFACE_STATE::SurfaceQPitch,
274        *
275        *   Because MSAA is only supported for Tile64, QPitch must also be
276        *   programmed to an aligned tile boundary for MSAA surfaces.
277        *
278        * Images in this surface must be tile-aligned.  The table on the Bspec
279        * page, "2D/CUBE Alignment Requirement", shows that the vertical
280        * alignment is also a tile height for non-MSAA as well.
281        */
282       *image_align_el = isl_extent3d(tile_info->logical_extent_el.w,
283                                      tile_info->logical_extent_el.h,
284                                      1);
285    } else if (isl_surf_usage_is_depth(info->usage)) {
286       /* The alignment parameters for depth buffers are summarized in the
287        * following table:
288        *
289        *     Surface Format  |    MSAA     | Align Width | Align Height
290        *    -----------------+-------------+-------------+--------------
291        *       D16_UNORM     | 1x, 4x, 16x |      8      |      8
292        *     ----------------+-------------+-------------+--------------
293        *       D16_UNORM     |   2x, 8x    |     16      |      4
294        *     ----------------+-------------+-------------+--------------
295        *         other       |     any     |      8      |      4
296        *    -----------------+-------------+-------------+--------------
297        */
298       assert(isl_is_pow2(info->samples));
299       *image_align_el =
300          info->format != ISL_FORMAT_R16_UNORM ?
301          isl_extent3d(8, 4, 1) :
302          (info->samples == 2 || info->samples == 8 ?
303           isl_extent3d(16, 4, 1) : isl_extent3d(8, 8, 1));
304    } else if (isl_surf_usage_is_stencil(info->usage)) {
305       *image_align_el = isl_extent3d(16, 8, 1);
306    } else {
307       isl_gfx9_choose_image_alignment_el(dev, info, tile_info, dim_layout,
308                                          msaa_layout, image_align_el);
309    }
310 }
311