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/**
25b8e80941Smrg * @file
26b8e80941Smrg * @brief Intel Surface Layout
27b8e80941Smrg *
28b8e80941Smrg * Header Layout
29b8e80941Smrg * -------------
30b8e80941Smrg * The header is ordered as:
31b8e80941Smrg *    - forward declarations
32b8e80941Smrg *    - macros that may be overridden at compile-time for specific gens
33b8e80941Smrg *    - enums and constants
34b8e80941Smrg *    - structs and unions
35b8e80941Smrg *    - functions
36b8e80941Smrg */
37b8e80941Smrg
38b8e80941Smrg#ifndef ISL_H
39b8e80941Smrg#define ISL_H
40b8e80941Smrg
41b8e80941Smrg#include <assert.h>
42b8e80941Smrg#include <stdbool.h>
43b8e80941Smrg#include <stdint.h>
44b8e80941Smrg
45b8e80941Smrg#include "c99_compat.h"
46b8e80941Smrg#include "util/macros.h"
47b8e80941Smrg
48b8e80941Smrg#ifdef __cplusplus
49b8e80941Smrgextern "C" {
50b8e80941Smrg#endif
51b8e80941Smrg
52b8e80941Smrgstruct gen_device_info;
53b8e80941Smrgstruct brw_image_param;
54b8e80941Smrg
55b8e80941Smrg#ifndef ISL_DEV_GEN
56b8e80941Smrg/**
57b8e80941Smrg * @brief Get the hardware generation of isl_device.
58b8e80941Smrg *
59b8e80941Smrg * You can define this as a compile-time constant in the CFLAGS. For example,
60b8e80941Smrg * `gcc -DISL_DEV_GEN(dev)=9 ...`.
61b8e80941Smrg */
62b8e80941Smrg#define ISL_DEV_GEN(__dev) ((__dev)->info->gen)
63b8e80941Smrg#define ISL_DEV_GEN_SANITIZE(__dev)
64b8e80941Smrg#else
65b8e80941Smrg#define ISL_DEV_GEN_SANITIZE(__dev) \
66b8e80941Smrg   (assert(ISL_DEV_GEN(__dev) == (__dev)->info->gen))
67b8e80941Smrg#endif
68b8e80941Smrg
69b8e80941Smrg#ifndef ISL_DEV_IS_G4X
70b8e80941Smrg#define ISL_DEV_IS_G4X(__dev) ((__dev)->info->is_g4x)
71b8e80941Smrg#endif
72b8e80941Smrg
73b8e80941Smrg#ifndef ISL_DEV_IS_HASWELL
74b8e80941Smrg/**
75b8e80941Smrg * @brief Get the hardware generation of isl_device.
76b8e80941Smrg *
77b8e80941Smrg * You can define this as a compile-time constant in the CFLAGS. For example,
78b8e80941Smrg * `gcc -DISL_DEV_GEN(dev)=9 ...`.
79b8e80941Smrg */
80b8e80941Smrg#define ISL_DEV_IS_HASWELL(__dev) ((__dev)->info->is_haswell)
81b8e80941Smrg#endif
82b8e80941Smrg
83b8e80941Smrg#ifndef ISL_DEV_IS_BAYTRAIL
84b8e80941Smrg#define ISL_DEV_IS_BAYTRAIL(__dev) ((__dev)->info->is_baytrail)
85b8e80941Smrg#endif
86b8e80941Smrg
87b8e80941Smrg#ifndef ISL_DEV_USE_SEPARATE_STENCIL
88b8e80941Smrg/**
89b8e80941Smrg * You can define this as a compile-time constant in the CFLAGS. For example,
90b8e80941Smrg * `gcc -DISL_DEV_USE_SEPARATE_STENCIL(dev)=1 ...`.
91b8e80941Smrg */
92b8e80941Smrg#define ISL_DEV_USE_SEPARATE_STENCIL(__dev) ((__dev)->use_separate_stencil)
93b8e80941Smrg#define ISL_DEV_USE_SEPARATE_STENCIL_SANITIZE(__dev)
94b8e80941Smrg#else
95b8e80941Smrg#define ISL_DEV_USE_SEPARATE_STENCIL_SANITIZE(__dev) \
96b8e80941Smrg   (assert(ISL_DEV_USE_SEPARATE_STENCIL(__dev) == (__dev)->use_separate_stencil))
97b8e80941Smrg#endif
98b8e80941Smrg
99b8e80941Smrg/**
100b8e80941Smrg * Hardware enumeration SURFACE_FORMAT.
101b8e80941Smrg *
102b8e80941Smrg * For the official list, see Broadwell PRM: Volume 2b: Command Reference:
103b8e80941Smrg * Enumerations: SURFACE_FORMAT.
104b8e80941Smrg */
105b8e80941Smrgenum isl_format {
106b8e80941Smrg   ISL_FORMAT_R32G32B32A32_FLOAT =                               0,
107b8e80941Smrg   ISL_FORMAT_R32G32B32A32_SINT =                                1,
108b8e80941Smrg   ISL_FORMAT_R32G32B32A32_UINT =                                2,
109b8e80941Smrg   ISL_FORMAT_R32G32B32A32_UNORM =                               3,
110b8e80941Smrg   ISL_FORMAT_R32G32B32A32_SNORM =                               4,
111b8e80941Smrg   ISL_FORMAT_R64G64_FLOAT =                                     5,
112b8e80941Smrg   ISL_FORMAT_R32G32B32X32_FLOAT =                               6,
113b8e80941Smrg   ISL_FORMAT_R32G32B32A32_SSCALED =                             7,
114b8e80941Smrg   ISL_FORMAT_R32G32B32A32_USCALED =                             8,
115b8e80941Smrg   ISL_FORMAT_R32G32B32A32_SFIXED =                             32,
116b8e80941Smrg   ISL_FORMAT_R64G64_PASSTHRU =                                 33,
117b8e80941Smrg   ISL_FORMAT_R32G32B32_FLOAT =                                 64,
118b8e80941Smrg   ISL_FORMAT_R32G32B32_SINT =                                  65,
119b8e80941Smrg   ISL_FORMAT_R32G32B32_UINT =                                  66,
120b8e80941Smrg   ISL_FORMAT_R32G32B32_UNORM =                                 67,
121b8e80941Smrg   ISL_FORMAT_R32G32B32_SNORM =                                 68,
122b8e80941Smrg   ISL_FORMAT_R32G32B32_SSCALED =                               69,
123b8e80941Smrg   ISL_FORMAT_R32G32B32_USCALED =                               70,
124b8e80941Smrg   ISL_FORMAT_R32G32B32_SFIXED =                                80,
125b8e80941Smrg   ISL_FORMAT_R16G16B16A16_UNORM =                             128,
126b8e80941Smrg   ISL_FORMAT_R16G16B16A16_SNORM =                             129,
127b8e80941Smrg   ISL_FORMAT_R16G16B16A16_SINT =                              130,
128b8e80941Smrg   ISL_FORMAT_R16G16B16A16_UINT =                              131,
129b8e80941Smrg   ISL_FORMAT_R16G16B16A16_FLOAT =                             132,
130b8e80941Smrg   ISL_FORMAT_R32G32_FLOAT =                                   133,
131b8e80941Smrg   ISL_FORMAT_R32G32_SINT =                                    134,
132b8e80941Smrg   ISL_FORMAT_R32G32_UINT =                                    135,
133b8e80941Smrg   ISL_FORMAT_R32_FLOAT_X8X24_TYPELESS =                       136,
134b8e80941Smrg   ISL_FORMAT_X32_TYPELESS_G8X24_UINT =                        137,
135b8e80941Smrg   ISL_FORMAT_L32A32_FLOAT =                                   138,
136b8e80941Smrg   ISL_FORMAT_R32G32_UNORM =                                   139,
137b8e80941Smrg   ISL_FORMAT_R32G32_SNORM =                                   140,
138b8e80941Smrg   ISL_FORMAT_R64_FLOAT =                                      141,
139b8e80941Smrg   ISL_FORMAT_R16G16B16X16_UNORM =                             142,
140b8e80941Smrg   ISL_FORMAT_R16G16B16X16_FLOAT =                             143,
141b8e80941Smrg   ISL_FORMAT_A32X32_FLOAT =                                   144,
142b8e80941Smrg   ISL_FORMAT_L32X32_FLOAT =                                   145,
143b8e80941Smrg   ISL_FORMAT_I32X32_FLOAT =                                   146,
144b8e80941Smrg   ISL_FORMAT_R16G16B16A16_SSCALED =                           147,
145b8e80941Smrg   ISL_FORMAT_R16G16B16A16_USCALED =                           148,
146b8e80941Smrg   ISL_FORMAT_R32G32_SSCALED =                                 149,
147b8e80941Smrg   ISL_FORMAT_R32G32_USCALED =                                 150,
148b8e80941Smrg   ISL_FORMAT_R32G32_FLOAT_LD =                                151,
149b8e80941Smrg   ISL_FORMAT_R32G32_SFIXED =                                  160,
150b8e80941Smrg   ISL_FORMAT_R64_PASSTHRU =                                   161,
151b8e80941Smrg   ISL_FORMAT_B8G8R8A8_UNORM =                                 192,
152b8e80941Smrg   ISL_FORMAT_B8G8R8A8_UNORM_SRGB =                            193,
153b8e80941Smrg   ISL_FORMAT_R10G10B10A2_UNORM =                              194,
154b8e80941Smrg   ISL_FORMAT_R10G10B10A2_UNORM_SRGB =                         195,
155b8e80941Smrg   ISL_FORMAT_R10G10B10A2_UINT =                               196,
156b8e80941Smrg   ISL_FORMAT_R10G10B10_SNORM_A2_UNORM =                       197,
157b8e80941Smrg   ISL_FORMAT_R8G8B8A8_UNORM =                                 199,
158b8e80941Smrg   ISL_FORMAT_R8G8B8A8_UNORM_SRGB =                            200,
159b8e80941Smrg   ISL_FORMAT_R8G8B8A8_SNORM =                                 201,
160b8e80941Smrg   ISL_FORMAT_R8G8B8A8_SINT =                                  202,
161b8e80941Smrg   ISL_FORMAT_R8G8B8A8_UINT =                                  203,
162b8e80941Smrg   ISL_FORMAT_R16G16_UNORM =                                   204,
163b8e80941Smrg   ISL_FORMAT_R16G16_SNORM =                                   205,
164b8e80941Smrg   ISL_FORMAT_R16G16_SINT =                                    206,
165b8e80941Smrg   ISL_FORMAT_R16G16_UINT =                                    207,
166b8e80941Smrg   ISL_FORMAT_R16G16_FLOAT =                                   208,
167b8e80941Smrg   ISL_FORMAT_B10G10R10A2_UNORM =                              209,
168b8e80941Smrg   ISL_FORMAT_B10G10R10A2_UNORM_SRGB =                         210,
169b8e80941Smrg   ISL_FORMAT_R11G11B10_FLOAT =                                211,
170b8e80941Smrg   ISL_FORMAT_R32_SINT =                                       214,
171b8e80941Smrg   ISL_FORMAT_R32_UINT =                                       215,
172b8e80941Smrg   ISL_FORMAT_R32_FLOAT =                                      216,
173b8e80941Smrg   ISL_FORMAT_R24_UNORM_X8_TYPELESS =                          217,
174b8e80941Smrg   ISL_FORMAT_X24_TYPELESS_G8_UINT =                           218,
175b8e80941Smrg   ISL_FORMAT_L32_UNORM =                                      221,
176b8e80941Smrg   ISL_FORMAT_A32_UNORM =                                      222,
177b8e80941Smrg   ISL_FORMAT_L16A16_UNORM =                                   223,
178b8e80941Smrg   ISL_FORMAT_I24X8_UNORM =                                    224,
179b8e80941Smrg   ISL_FORMAT_L24X8_UNORM =                                    225,
180b8e80941Smrg   ISL_FORMAT_A24X8_UNORM =                                    226,
181b8e80941Smrg   ISL_FORMAT_I32_FLOAT =                                      227,
182b8e80941Smrg   ISL_FORMAT_L32_FLOAT =                                      228,
183b8e80941Smrg   ISL_FORMAT_A32_FLOAT =                                      229,
184b8e80941Smrg   ISL_FORMAT_X8B8_UNORM_G8R8_SNORM =                          230,
185b8e80941Smrg   ISL_FORMAT_A8X8_UNORM_G8R8_SNORM =                          231,
186b8e80941Smrg   ISL_FORMAT_B8X8_UNORM_G8R8_SNORM =                          232,
187b8e80941Smrg   ISL_FORMAT_B8G8R8X8_UNORM =                                 233,
188b8e80941Smrg   ISL_FORMAT_B8G8R8X8_UNORM_SRGB =                            234,
189b8e80941Smrg   ISL_FORMAT_R8G8B8X8_UNORM =                                 235,
190b8e80941Smrg   ISL_FORMAT_R8G8B8X8_UNORM_SRGB =                            236,
191b8e80941Smrg   ISL_FORMAT_R9G9B9E5_SHAREDEXP =                             237,
192b8e80941Smrg   ISL_FORMAT_B10G10R10X2_UNORM =                              238,
193b8e80941Smrg   ISL_FORMAT_L16A16_FLOAT =                                   240,
194b8e80941Smrg   ISL_FORMAT_R32_UNORM =                                      241,
195b8e80941Smrg   ISL_FORMAT_R32_SNORM =                                      242,
196b8e80941Smrg   ISL_FORMAT_R10G10B10X2_USCALED =                            243,
197b8e80941Smrg   ISL_FORMAT_R8G8B8A8_SSCALED =                               244,
198b8e80941Smrg   ISL_FORMAT_R8G8B8A8_USCALED =                               245,
199b8e80941Smrg   ISL_FORMAT_R16G16_SSCALED =                                 246,
200b8e80941Smrg   ISL_FORMAT_R16G16_USCALED =                                 247,
201b8e80941Smrg   ISL_FORMAT_R32_SSCALED =                                    248,
202b8e80941Smrg   ISL_FORMAT_R32_USCALED =                                    249,
203b8e80941Smrg   ISL_FORMAT_B5G6R5_UNORM =                                   256,
204b8e80941Smrg   ISL_FORMAT_B5G6R5_UNORM_SRGB =                              257,
205b8e80941Smrg   ISL_FORMAT_B5G5R5A1_UNORM =                                 258,
206b8e80941Smrg   ISL_FORMAT_B5G5R5A1_UNORM_SRGB =                            259,
207b8e80941Smrg   ISL_FORMAT_B4G4R4A4_UNORM =                                 260,
208b8e80941Smrg   ISL_FORMAT_B4G4R4A4_UNORM_SRGB =                            261,
209b8e80941Smrg   ISL_FORMAT_R8G8_UNORM =                                     262,
210b8e80941Smrg   ISL_FORMAT_R8G8_SNORM =                                     263,
211b8e80941Smrg   ISL_FORMAT_R8G8_SINT =                                      264,
212b8e80941Smrg   ISL_FORMAT_R8G8_UINT =                                      265,
213b8e80941Smrg   ISL_FORMAT_R16_UNORM =                                      266,
214b8e80941Smrg   ISL_FORMAT_R16_SNORM =                                      267,
215b8e80941Smrg   ISL_FORMAT_R16_SINT =                                       268,
216b8e80941Smrg   ISL_FORMAT_R16_UINT =                                       269,
217b8e80941Smrg   ISL_FORMAT_R16_FLOAT =                                      270,
218b8e80941Smrg   ISL_FORMAT_A8P8_UNORM_PALETTE0 =                            271,
219b8e80941Smrg   ISL_FORMAT_A8P8_UNORM_PALETTE1 =                            272,
220b8e80941Smrg   ISL_FORMAT_I16_UNORM =                                      273,
221b8e80941Smrg   ISL_FORMAT_L16_UNORM =                                      274,
222b8e80941Smrg   ISL_FORMAT_A16_UNORM =                                      275,
223b8e80941Smrg   ISL_FORMAT_L8A8_UNORM =                                     276,
224b8e80941Smrg   ISL_FORMAT_I16_FLOAT =                                      277,
225b8e80941Smrg   ISL_FORMAT_L16_FLOAT =                                      278,
226b8e80941Smrg   ISL_FORMAT_A16_FLOAT =                                      279,
227b8e80941Smrg   ISL_FORMAT_L8A8_UNORM_SRGB =                                280,
228b8e80941Smrg   ISL_FORMAT_R5G5_SNORM_B6_UNORM =                            281,
229b8e80941Smrg   ISL_FORMAT_B5G5R5X1_UNORM =                                 282,
230b8e80941Smrg   ISL_FORMAT_B5G5R5X1_UNORM_SRGB =                            283,
231b8e80941Smrg   ISL_FORMAT_R8G8_SSCALED =                                   284,
232b8e80941Smrg   ISL_FORMAT_R8G8_USCALED =                                   285,
233b8e80941Smrg   ISL_FORMAT_R16_SSCALED =                                    286,
234b8e80941Smrg   ISL_FORMAT_R16_USCALED =                                    287,
235b8e80941Smrg   ISL_FORMAT_P8A8_UNORM_PALETTE0 =                            290,
236b8e80941Smrg   ISL_FORMAT_P8A8_UNORM_PALETTE1 =                            291,
237b8e80941Smrg   ISL_FORMAT_A1B5G5R5_UNORM =                                 292,
238b8e80941Smrg   ISL_FORMAT_A4B4G4R4_UNORM =                                 293,
239b8e80941Smrg   ISL_FORMAT_L8A8_UINT =                                      294,
240b8e80941Smrg   ISL_FORMAT_L8A8_SINT =                                      295,
241b8e80941Smrg   ISL_FORMAT_R8_UNORM =                                       320,
242b8e80941Smrg   ISL_FORMAT_R8_SNORM =                                       321,
243b8e80941Smrg   ISL_FORMAT_R8_SINT =                                        322,
244b8e80941Smrg   ISL_FORMAT_R8_UINT =                                        323,
245b8e80941Smrg   ISL_FORMAT_A8_UNORM =                                       324,
246b8e80941Smrg   ISL_FORMAT_I8_UNORM =                                       325,
247b8e80941Smrg   ISL_FORMAT_L8_UNORM =                                       326,
248b8e80941Smrg   ISL_FORMAT_P4A4_UNORM_PALETTE0 =                            327,
249b8e80941Smrg   ISL_FORMAT_A4P4_UNORM_PALETTE0 =                            328,
250b8e80941Smrg   ISL_FORMAT_R8_SSCALED =                                     329,
251b8e80941Smrg   ISL_FORMAT_R8_USCALED =                                     330,
252b8e80941Smrg   ISL_FORMAT_P8_UNORM_PALETTE0 =                              331,
253b8e80941Smrg   ISL_FORMAT_L8_UNORM_SRGB =                                  332,
254b8e80941Smrg   ISL_FORMAT_P8_UNORM_PALETTE1 =                              333,
255b8e80941Smrg   ISL_FORMAT_P4A4_UNORM_PALETTE1 =                            334,
256b8e80941Smrg   ISL_FORMAT_A4P4_UNORM_PALETTE1 =                            335,
257b8e80941Smrg   ISL_FORMAT_Y8_UNORM =                                       336,
258b8e80941Smrg   ISL_FORMAT_L8_UINT =                                        338,
259b8e80941Smrg   ISL_FORMAT_L8_SINT =                                        339,
260b8e80941Smrg   ISL_FORMAT_I8_UINT =                                        340,
261b8e80941Smrg   ISL_FORMAT_I8_SINT =                                        341,
262b8e80941Smrg   ISL_FORMAT_DXT1_RGB_SRGB =                                  384,
263b8e80941Smrg   ISL_FORMAT_R1_UNORM =                                       385,
264b8e80941Smrg   ISL_FORMAT_YCRCB_NORMAL =                                   386,
265b8e80941Smrg   ISL_FORMAT_YCRCB_SWAPUVY =                                  387,
266b8e80941Smrg   ISL_FORMAT_P2_UNORM_PALETTE0 =                              388,
267b8e80941Smrg   ISL_FORMAT_P2_UNORM_PALETTE1 =                              389,
268b8e80941Smrg   ISL_FORMAT_BC1_UNORM =                                      390,
269b8e80941Smrg   ISL_FORMAT_BC2_UNORM =                                      391,
270b8e80941Smrg   ISL_FORMAT_BC3_UNORM =                                      392,
271b8e80941Smrg   ISL_FORMAT_BC4_UNORM =                                      393,
272b8e80941Smrg   ISL_FORMAT_BC5_UNORM =                                      394,
273b8e80941Smrg   ISL_FORMAT_BC1_UNORM_SRGB =                                 395,
274b8e80941Smrg   ISL_FORMAT_BC2_UNORM_SRGB =                                 396,
275b8e80941Smrg   ISL_FORMAT_BC3_UNORM_SRGB =                                 397,
276b8e80941Smrg   ISL_FORMAT_MONO8 =                                          398,
277b8e80941Smrg   ISL_FORMAT_YCRCB_SWAPUV =                                   399,
278b8e80941Smrg   ISL_FORMAT_YCRCB_SWAPY =                                    400,
279b8e80941Smrg   ISL_FORMAT_DXT1_RGB =                                       401,
280b8e80941Smrg   ISL_FORMAT_FXT1 =                                           402,
281b8e80941Smrg   ISL_FORMAT_R8G8B8_UNORM =                                   403,
282b8e80941Smrg   ISL_FORMAT_R8G8B8_SNORM =                                   404,
283b8e80941Smrg   ISL_FORMAT_R8G8B8_SSCALED =                                 405,
284b8e80941Smrg   ISL_FORMAT_R8G8B8_USCALED =                                 406,
285b8e80941Smrg   ISL_FORMAT_R64G64B64A64_FLOAT =                             407,
286b8e80941Smrg   ISL_FORMAT_R64G64B64_FLOAT =                                408,
287b8e80941Smrg   ISL_FORMAT_BC4_SNORM =                                      409,
288b8e80941Smrg   ISL_FORMAT_BC5_SNORM =                                      410,
289b8e80941Smrg   ISL_FORMAT_R16G16B16_FLOAT =                                411,
290b8e80941Smrg   ISL_FORMAT_R16G16B16_UNORM =                                412,
291b8e80941Smrg   ISL_FORMAT_R16G16B16_SNORM =                                413,
292b8e80941Smrg   ISL_FORMAT_R16G16B16_SSCALED =                              414,
293b8e80941Smrg   ISL_FORMAT_R16G16B16_USCALED =                              415,
294b8e80941Smrg   ISL_FORMAT_BC6H_SF16 =                                      417,
295b8e80941Smrg   ISL_FORMAT_BC7_UNORM =                                      418,
296b8e80941Smrg   ISL_FORMAT_BC7_UNORM_SRGB =                                 419,
297b8e80941Smrg   ISL_FORMAT_BC6H_UF16 =                                      420,
298b8e80941Smrg   ISL_FORMAT_PLANAR_420_8 =                                   421,
299b8e80941Smrg   ISL_FORMAT_R8G8B8_UNORM_SRGB =                              424,
300b8e80941Smrg   ISL_FORMAT_ETC1_RGB8 =                                      425,
301b8e80941Smrg   ISL_FORMAT_ETC2_RGB8 =                                      426,
302b8e80941Smrg   ISL_FORMAT_EAC_R11 =                                        427,
303b8e80941Smrg   ISL_FORMAT_EAC_RG11 =                                       428,
304b8e80941Smrg   ISL_FORMAT_EAC_SIGNED_R11 =                                 429,
305b8e80941Smrg   ISL_FORMAT_EAC_SIGNED_RG11 =                                430,
306b8e80941Smrg   ISL_FORMAT_ETC2_SRGB8 =                                     431,
307b8e80941Smrg   ISL_FORMAT_R16G16B16_UINT =                                 432,
308b8e80941Smrg   ISL_FORMAT_R16G16B16_SINT =                                 433,
309b8e80941Smrg   ISL_FORMAT_R32_SFIXED =                                     434,
310b8e80941Smrg   ISL_FORMAT_R10G10B10A2_SNORM =                              435,
311b8e80941Smrg   ISL_FORMAT_R10G10B10A2_USCALED =                            436,
312b8e80941Smrg   ISL_FORMAT_R10G10B10A2_SSCALED =                            437,
313b8e80941Smrg   ISL_FORMAT_R10G10B10A2_SINT =                               438,
314b8e80941Smrg   ISL_FORMAT_B10G10R10A2_SNORM =                              439,
315b8e80941Smrg   ISL_FORMAT_B10G10R10A2_USCALED =                            440,
316b8e80941Smrg   ISL_FORMAT_B10G10R10A2_SSCALED =                            441,
317b8e80941Smrg   ISL_FORMAT_B10G10R10A2_UINT =                               442,
318b8e80941Smrg   ISL_FORMAT_B10G10R10A2_SINT =                               443,
319b8e80941Smrg   ISL_FORMAT_R64G64B64A64_PASSTHRU =                          444,
320b8e80941Smrg   ISL_FORMAT_R64G64B64_PASSTHRU =                             445,
321b8e80941Smrg   ISL_FORMAT_ETC2_RGB8_PTA =                                  448,
322b8e80941Smrg   ISL_FORMAT_ETC2_SRGB8_PTA =                                 449,
323b8e80941Smrg   ISL_FORMAT_ETC2_EAC_RGBA8 =                                 450,
324b8e80941Smrg   ISL_FORMAT_ETC2_EAC_SRGB8_A8 =                              451,
325b8e80941Smrg   ISL_FORMAT_R8G8B8_UINT =                                    456,
326b8e80941Smrg   ISL_FORMAT_R8G8B8_SINT =                                    457,
327b8e80941Smrg   ISL_FORMAT_RAW =                                            511,
328b8e80941Smrg   ISL_FORMAT_ASTC_LDR_2D_4X4_U8SRGB =                         512,
329b8e80941Smrg   ISL_FORMAT_ASTC_LDR_2D_5X4_U8SRGB =                         520,
330b8e80941Smrg   ISL_FORMAT_ASTC_LDR_2D_5X5_U8SRGB =                         521,
331b8e80941Smrg   ISL_FORMAT_ASTC_LDR_2D_6X5_U8SRGB =                         529,
332b8e80941Smrg   ISL_FORMAT_ASTC_LDR_2D_6X6_U8SRGB =                         530,
333b8e80941Smrg   ISL_FORMAT_ASTC_LDR_2D_8X5_U8SRGB =                         545,
334b8e80941Smrg   ISL_FORMAT_ASTC_LDR_2D_8X6_U8SRGB =                         546,
335b8e80941Smrg   ISL_FORMAT_ASTC_LDR_2D_8X8_U8SRGB =                         548,
336b8e80941Smrg   ISL_FORMAT_ASTC_LDR_2D_10X5_U8SRGB =                        561,
337b8e80941Smrg   ISL_FORMAT_ASTC_LDR_2D_10X6_U8SRGB =                        562,
338b8e80941Smrg   ISL_FORMAT_ASTC_LDR_2D_10X8_U8SRGB =                        564,
339b8e80941Smrg   ISL_FORMAT_ASTC_LDR_2D_10X10_U8SRGB =                       566,
340b8e80941Smrg   ISL_FORMAT_ASTC_LDR_2D_12X10_U8SRGB =                       574,
341b8e80941Smrg   ISL_FORMAT_ASTC_LDR_2D_12X12_U8SRGB =                       575,
342b8e80941Smrg   ISL_FORMAT_ASTC_LDR_2D_4X4_FLT16 =                          576,
343b8e80941Smrg   ISL_FORMAT_ASTC_LDR_2D_5X4_FLT16 =                          584,
344b8e80941Smrg   ISL_FORMAT_ASTC_LDR_2D_5X5_FLT16 =                          585,
345b8e80941Smrg   ISL_FORMAT_ASTC_LDR_2D_6X5_FLT16 =                          593,
346b8e80941Smrg   ISL_FORMAT_ASTC_LDR_2D_6X6_FLT16 =                          594,
347b8e80941Smrg   ISL_FORMAT_ASTC_LDR_2D_8X5_FLT16 =                          609,
348b8e80941Smrg   ISL_FORMAT_ASTC_LDR_2D_8X6_FLT16 =                          610,
349b8e80941Smrg   ISL_FORMAT_ASTC_LDR_2D_8X8_FLT16 =                          612,
350b8e80941Smrg   ISL_FORMAT_ASTC_LDR_2D_10X5_FLT16 =                         625,
351b8e80941Smrg   ISL_FORMAT_ASTC_LDR_2D_10X6_FLT16 =                         626,
352b8e80941Smrg   ISL_FORMAT_ASTC_LDR_2D_10X8_FLT16 =                         628,
353b8e80941Smrg   ISL_FORMAT_ASTC_LDR_2D_10X10_FLT16 =                        630,
354b8e80941Smrg   ISL_FORMAT_ASTC_LDR_2D_12X10_FLT16 =                        638,
355b8e80941Smrg   ISL_FORMAT_ASTC_LDR_2D_12X12_FLT16 =                        639,
356b8e80941Smrg   ISL_FORMAT_ASTC_HDR_2D_4X4_FLT16 =                          832,
357b8e80941Smrg   ISL_FORMAT_ASTC_HDR_2D_5X4_FLT16 =                          840,
358b8e80941Smrg   ISL_FORMAT_ASTC_HDR_2D_5X5_FLT16 =                          841,
359b8e80941Smrg   ISL_FORMAT_ASTC_HDR_2D_6X5_FLT16 =                          849,
360b8e80941Smrg   ISL_FORMAT_ASTC_HDR_2D_6X6_FLT16 =                          850,
361b8e80941Smrg   ISL_FORMAT_ASTC_HDR_2D_8X5_FLT16 =                          865,
362b8e80941Smrg   ISL_FORMAT_ASTC_HDR_2D_8X6_FLT16 =                          866,
363b8e80941Smrg   ISL_FORMAT_ASTC_HDR_2D_8X8_FLT16 =                          868,
364b8e80941Smrg   ISL_FORMAT_ASTC_HDR_2D_10X5_FLT16 =                         881,
365b8e80941Smrg   ISL_FORMAT_ASTC_HDR_2D_10X6_FLT16 =                         882,
366b8e80941Smrg   ISL_FORMAT_ASTC_HDR_2D_10X8_FLT16 =                         884,
367b8e80941Smrg   ISL_FORMAT_ASTC_HDR_2D_10X10_FLT16 =                        886,
368b8e80941Smrg   ISL_FORMAT_ASTC_HDR_2D_12X10_FLT16 =                        894,
369b8e80941Smrg   ISL_FORMAT_ASTC_HDR_2D_12X12_FLT16 =                        895,
370b8e80941Smrg
371b8e80941Smrg   /* The formats that follow are internal to ISL and as such don't have an
372b8e80941Smrg    * explicit number.  We'll just let the C compiler assign it for us.  Any
373b8e80941Smrg    * actual hardware formats *must* come before these in the list.
374b8e80941Smrg    */
375b8e80941Smrg
376b8e80941Smrg   /* Formats for auxiliary surfaces */
377b8e80941Smrg   ISL_FORMAT_HIZ,
378b8e80941Smrg   ISL_FORMAT_MCS_2X,
379b8e80941Smrg   ISL_FORMAT_MCS_4X,
380b8e80941Smrg   ISL_FORMAT_MCS_8X,
381b8e80941Smrg   ISL_FORMAT_MCS_16X,
382b8e80941Smrg   ISL_FORMAT_GEN7_CCS_32BPP_X,
383b8e80941Smrg   ISL_FORMAT_GEN7_CCS_64BPP_X,
384b8e80941Smrg   ISL_FORMAT_GEN7_CCS_128BPP_X,
385b8e80941Smrg   ISL_FORMAT_GEN7_CCS_32BPP_Y,
386b8e80941Smrg   ISL_FORMAT_GEN7_CCS_64BPP_Y,
387b8e80941Smrg   ISL_FORMAT_GEN7_CCS_128BPP_Y,
388b8e80941Smrg   ISL_FORMAT_GEN9_CCS_32BPP,
389b8e80941Smrg   ISL_FORMAT_GEN9_CCS_64BPP,
390b8e80941Smrg   ISL_FORMAT_GEN9_CCS_128BPP,
391b8e80941Smrg
392b8e80941Smrg   /* An upper bound on the supported format enumerations */
393b8e80941Smrg   ISL_NUM_FORMATS,
394b8e80941Smrg
395b8e80941Smrg   /* Hardware doesn't understand this out-of-band value */
396b8e80941Smrg   ISL_FORMAT_UNSUPPORTED =                             UINT16_MAX,
397b8e80941Smrg};
398b8e80941Smrg
399b8e80941Smrg/**
400b8e80941Smrg * Numerical base type for channels of isl_format.
401b8e80941Smrg */
402b8e80941Smrgenum isl_base_type {
403b8e80941Smrg   ISL_VOID,
404b8e80941Smrg   ISL_RAW,
405b8e80941Smrg   ISL_UNORM,
406b8e80941Smrg   ISL_SNORM,
407b8e80941Smrg   ISL_UFLOAT,
408b8e80941Smrg   ISL_SFLOAT,
409b8e80941Smrg   ISL_UFIXED,
410b8e80941Smrg   ISL_SFIXED,
411b8e80941Smrg   ISL_UINT,
412b8e80941Smrg   ISL_SINT,
413b8e80941Smrg   ISL_USCALED,
414b8e80941Smrg   ISL_SSCALED,
415b8e80941Smrg};
416b8e80941Smrg
417b8e80941Smrg/**
418b8e80941Smrg * Colorspace of isl_format.
419b8e80941Smrg */
420b8e80941Smrgenum isl_colorspace {
421b8e80941Smrg   ISL_COLORSPACE_NONE = 0,
422b8e80941Smrg   ISL_COLORSPACE_LINEAR,
423b8e80941Smrg   ISL_COLORSPACE_SRGB,
424b8e80941Smrg   ISL_COLORSPACE_YUV,
425b8e80941Smrg};
426b8e80941Smrg
427b8e80941Smrg/**
428b8e80941Smrg * Texture compression mode of isl_format.
429b8e80941Smrg */
430b8e80941Smrgenum isl_txc {
431b8e80941Smrg   ISL_TXC_NONE = 0,
432b8e80941Smrg   ISL_TXC_DXT1,
433b8e80941Smrg   ISL_TXC_DXT3,
434b8e80941Smrg   ISL_TXC_DXT5,
435b8e80941Smrg   ISL_TXC_FXT1,
436b8e80941Smrg   ISL_TXC_RGTC1,
437b8e80941Smrg   ISL_TXC_RGTC2,
438b8e80941Smrg   ISL_TXC_BPTC,
439b8e80941Smrg   ISL_TXC_ETC1,
440b8e80941Smrg   ISL_TXC_ETC2,
441b8e80941Smrg   ISL_TXC_ASTC,
442b8e80941Smrg
443b8e80941Smrg   /* Used for auxiliary surface formats */
444b8e80941Smrg   ISL_TXC_HIZ,
445b8e80941Smrg   ISL_TXC_MCS,
446b8e80941Smrg   ISL_TXC_CCS,
447b8e80941Smrg};
448b8e80941Smrg
449b8e80941Smrg/**
450b8e80941Smrg * @brief Hardware tile mode
451b8e80941Smrg *
452b8e80941Smrg * WARNING: These values differ from the hardware enum values, which are
453b8e80941Smrg * unstable across hardware generations.
454b8e80941Smrg *
455b8e80941Smrg * Note that legacy Y tiling is ISL_TILING_Y0 instead of ISL_TILING_Y, to
456b8e80941Smrg * clearly distinguish it from Yf and Ys.
457b8e80941Smrg */
458b8e80941Smrgenum isl_tiling {
459b8e80941Smrg   ISL_TILING_LINEAR = 0,
460b8e80941Smrg   ISL_TILING_W,
461b8e80941Smrg   ISL_TILING_X,
462b8e80941Smrg   ISL_TILING_Y0, /**< Legacy Y tiling */
463b8e80941Smrg   ISL_TILING_Yf, /**< Standard 4K tiling. The 'f' means "four". */
464b8e80941Smrg   ISL_TILING_Ys, /**< Standard 64K tiling. The 's' means "sixty-four". */
465b8e80941Smrg   ISL_TILING_HIZ, /**< Tiling format for HiZ surfaces */
466b8e80941Smrg   ISL_TILING_CCS, /**< Tiling format for CCS surfaces */
467b8e80941Smrg};
468b8e80941Smrg
469b8e80941Smrg/**
470b8e80941Smrg * @defgroup Tiling Flags
471b8e80941Smrg * @{
472b8e80941Smrg */
473b8e80941Smrgtypedef uint32_t isl_tiling_flags_t;
474b8e80941Smrg#define ISL_TILING_LINEAR_BIT             (1u << ISL_TILING_LINEAR)
475b8e80941Smrg#define ISL_TILING_W_BIT                  (1u << ISL_TILING_W)
476b8e80941Smrg#define ISL_TILING_X_BIT                  (1u << ISL_TILING_X)
477b8e80941Smrg#define ISL_TILING_Y0_BIT                 (1u << ISL_TILING_Y0)
478b8e80941Smrg#define ISL_TILING_Yf_BIT                 (1u << ISL_TILING_Yf)
479b8e80941Smrg#define ISL_TILING_Ys_BIT                 (1u << ISL_TILING_Ys)
480b8e80941Smrg#define ISL_TILING_HIZ_BIT                (1u << ISL_TILING_HIZ)
481b8e80941Smrg#define ISL_TILING_CCS_BIT                (1u << ISL_TILING_CCS)
482b8e80941Smrg#define ISL_TILING_ANY_MASK               (~0u)
483b8e80941Smrg#define ISL_TILING_NON_LINEAR_MASK        (~ISL_TILING_LINEAR_BIT)
484b8e80941Smrg
485b8e80941Smrg/** Any Y tiling, including legacy Y tiling. */
486b8e80941Smrg#define ISL_TILING_ANY_Y_MASK             (ISL_TILING_Y0_BIT | \
487b8e80941Smrg                                           ISL_TILING_Yf_BIT | \
488b8e80941Smrg                                           ISL_TILING_Ys_BIT)
489b8e80941Smrg
490b8e80941Smrg/** The Skylake BSpec refers to Yf and Ys as "standard tiling formats". */
491b8e80941Smrg#define ISL_TILING_STD_Y_MASK             (ISL_TILING_Yf_BIT | \
492b8e80941Smrg                                           ISL_TILING_Ys_BIT)
493b8e80941Smrg/** @} */
494b8e80941Smrg
495b8e80941Smrg/**
496b8e80941Smrg * @brief Logical dimension of surface.
497b8e80941Smrg *
498b8e80941Smrg * Note: There is no dimension for cube map surfaces. ISL interprets cube maps
499b8e80941Smrg * as 2D array surfaces.
500b8e80941Smrg */
501b8e80941Smrgenum isl_surf_dim {
502b8e80941Smrg   ISL_SURF_DIM_1D,
503b8e80941Smrg   ISL_SURF_DIM_2D,
504b8e80941Smrg   ISL_SURF_DIM_3D,
505b8e80941Smrg};
506b8e80941Smrg
507b8e80941Smrg/**
508b8e80941Smrg * @brief Physical layout of the surface's dimensions.
509b8e80941Smrg */
510b8e80941Smrgenum isl_dim_layout {
511b8e80941Smrg   /**
512b8e80941Smrg    * For details, see the G35 PRM >> Volume 1: Graphics Core >> Section
513b8e80941Smrg    * 6.17.3: 2D Surfaces.
514b8e80941Smrg    *
515b8e80941Smrg    * On many gens, 1D surfaces share the same layout as 2D surfaces.  From
516b8e80941Smrg    * the G35 PRM >> Volume 1: Graphics Core >> Section 6.17.2: 1D Surfaces:
517b8e80941Smrg    *
518b8e80941Smrg    *    One-dimensional surfaces are identical to 2D surfaces with height of
519b8e80941Smrg    *    one.
520b8e80941Smrg    *
521b8e80941Smrg    * @invariant isl_surf::phys_level0_sa::depth == 1
522b8e80941Smrg    */
523b8e80941Smrg   ISL_DIM_LAYOUT_GEN4_2D,
524b8e80941Smrg
525b8e80941Smrg   /**
526b8e80941Smrg    * For details, see the G35 PRM >> Volume 1: Graphics Core >> Section
527b8e80941Smrg    * 6.17.5: 3D Surfaces.
528b8e80941Smrg    *
529b8e80941Smrg    * @invariant isl_surf::phys_level0_sa::array_len == 1
530b8e80941Smrg    */
531b8e80941Smrg   ISL_DIM_LAYOUT_GEN4_3D,
532b8e80941Smrg
533b8e80941Smrg   /**
534b8e80941Smrg    * Special layout used for HiZ and stencil on Sandy Bridge to work around
535b8e80941Smrg    * the hardware's lack of mipmap support.  On gen6, HiZ and stencil buffers
536b8e80941Smrg    * work the same as on gen7+ except that they don't technically support
537b8e80941Smrg    * mipmapping.  That does not, however, stop us from doing it.  As far as
538b8e80941Smrg    * Sandy Bridge hardware is concerned, HiZ and stencil always operates on a
539b8e80941Smrg    * single miplevel 2D (possibly array) image.  The dimensions of that image
540b8e80941Smrg    * are NOT minified.
541b8e80941Smrg    *
542b8e80941Smrg    * In order to implement HiZ and stencil on Sandy Bridge, we create one
543b8e80941Smrg    * full-sized 2D (possibly array) image for every LOD with every image
544b8e80941Smrg    * aligned to a page boundary.  When the surface is used with the stencil
545b8e80941Smrg    * or HiZ hardware, we manually offset to the image for the given LOD.
546b8e80941Smrg    *
547b8e80941Smrg    * As a memory saving measure,  we pretend that the width of each miplevel
548b8e80941Smrg    * is minified and we place LOD1 and above below LOD0 but horizontally
549b8e80941Smrg    * adjacent to each other.  When considered as full-sized images, LOD1 and
550b8e80941Smrg    * above technically overlap.  However, since we only write to part of that
551b8e80941Smrg    * image, the hardware will never notice the overlap.
552b8e80941Smrg    *
553b8e80941Smrg    * This layout looks something like this:
554b8e80941Smrg    *
555b8e80941Smrg    *   +---------+
556b8e80941Smrg    *   |         |
557b8e80941Smrg    *   |         |
558b8e80941Smrg    *   +---------+
559b8e80941Smrg    *   |         |
560b8e80941Smrg    *   |         |
561b8e80941Smrg    *   +---------+
562b8e80941Smrg    *
563b8e80941Smrg    *   +----+ +-+ .
564b8e80941Smrg    *   |    | +-+
565b8e80941Smrg    *   +----+
566b8e80941Smrg    *
567b8e80941Smrg    *   +----+ +-+ .
568b8e80941Smrg    *   |    | +-+
569b8e80941Smrg    *   +----+
570b8e80941Smrg    */
571b8e80941Smrg   ISL_DIM_LAYOUT_GEN6_STENCIL_HIZ,
572b8e80941Smrg
573b8e80941Smrg   /**
574b8e80941Smrg    * For details, see the Skylake BSpec >> Memory Views >> Common Surface
575b8e80941Smrg    * Formats >> Surface Layout and Tiling >> » 1D Surfaces.
576b8e80941Smrg    */
577b8e80941Smrg   ISL_DIM_LAYOUT_GEN9_1D,
578b8e80941Smrg};
579b8e80941Smrg
580b8e80941Smrgenum isl_aux_usage {
581b8e80941Smrg   /** No Auxiliary surface is used */
582b8e80941Smrg   ISL_AUX_USAGE_NONE,
583b8e80941Smrg
584b8e80941Smrg   /** The primary surface is a depth surface and the auxiliary surface is HiZ */
585b8e80941Smrg   ISL_AUX_USAGE_HIZ,
586b8e80941Smrg
587b8e80941Smrg   /** The auxiliary surface is an MCS
588b8e80941Smrg    *
589b8e80941Smrg    * @invariant isl_surf::samples > 1
590b8e80941Smrg    */
591b8e80941Smrg   ISL_AUX_USAGE_MCS,
592b8e80941Smrg
593b8e80941Smrg   /** The auxiliary surface is a fast-clear-only compression surface
594b8e80941Smrg    *
595b8e80941Smrg    * @invariant isl_surf::samples == 1
596b8e80941Smrg    */
597b8e80941Smrg   ISL_AUX_USAGE_CCS_D,
598b8e80941Smrg
599b8e80941Smrg   /** The auxiliary surface provides full lossless color compression
600b8e80941Smrg    *
601b8e80941Smrg    * @invariant isl_surf::samples == 1
602b8e80941Smrg    */
603b8e80941Smrg   ISL_AUX_USAGE_CCS_E,
604b8e80941Smrg};
605b8e80941Smrg
606b8e80941Smrg/**
607b8e80941Smrg * Enum for keeping track of the state an auxiliary compressed surface.
608b8e80941Smrg *
609b8e80941Smrg * For any given auxiliary surface compression format (HiZ, CCS, or MCS), any
610b8e80941Smrg * given slice (lod + array layer) can be in one of the six states described
611b8e80941Smrg * by this enum.  Draw and resolve operations may cause the slice to change
612b8e80941Smrg * from one state to another.  The six valid states are:
613b8e80941Smrg *
614b8e80941Smrg *    1) Clear:  In this state, each block in the auxiliary surface contains a
615b8e80941Smrg *       magic value that indicates that the block is in the clear state.  If
616b8e80941Smrg *       a block is in the clear state, it's values in the primary surface are
617b8e80941Smrg *       ignored and the color of the samples in the block is taken either the
618b8e80941Smrg *       RENDER_SURFACE_STATE packet for color or 3DSTATE_CLEAR_PARAMS for
619b8e80941Smrg *       depth.  Since neither the primary surface nor the auxiliary surface
620b8e80941Smrg *       contains the clear value, the surface can be cleared to a different
621b8e80941Smrg *       color by simply changing the clear color without modifying either
622b8e80941Smrg *       surface.
623b8e80941Smrg *
624b8e80941Smrg *    2) Partial Clear:  In this state, each block in the auxiliary surface
625b8e80941Smrg *       contains either the magic clear or pass-through value.  See Clear and
626b8e80941Smrg *       Pass-through for more details.
627b8e80941Smrg *
628b8e80941Smrg *    3) Compressed w/ Clear:  In this state, neither the auxiliary surface
629b8e80941Smrg *       nor the primary surface has a complete representation of the data.
630b8e80941Smrg *       Instead, both surfaces must be used together or else rendering
631b8e80941Smrg *       corruption may occur.  Depending on the auxiliary compression format
632b8e80941Smrg *       and the data, any given block in the primary surface may contain all,
633b8e80941Smrg *       some, or none of the data required to reconstruct the actual sample
634b8e80941Smrg *       values.  Blocks may also be in the clear state (see Clear) and have
635b8e80941Smrg *       their value taken from outside the surface.
636b8e80941Smrg *
637b8e80941Smrg *    4) Compressed w/o Clear:  This state is identical to the state above
638b8e80941Smrg *       except that no blocks are in the clear state.  In this state, all of
639b8e80941Smrg *       the data required to reconstruct the final sample values is contained
640b8e80941Smrg *       in the auxiliary and primary surface and the clear value is not
641b8e80941Smrg *       considered.
642b8e80941Smrg *
643b8e80941Smrg *    5) Resolved:  In this state, the primary surface contains 100% of the
644b8e80941Smrg *       data.  The auxiliary surface is also valid so the surface can be
645b8e80941Smrg *       validly used with or without aux enabled.  The auxiliary surface may,
646b8e80941Smrg *       however, contain non-trivial data and any update to the primary
647b8e80941Smrg *       surface with aux disabled will cause the two to get out of sync.
648b8e80941Smrg *
649b8e80941Smrg *    6) Pass-through:  In this state, the primary surface contains 100% of the
650b8e80941Smrg *       data and every block in the auxiliary surface contains a magic value
651b8e80941Smrg *       which indicates that the auxiliary surface should be ignored and the
652b8e80941Smrg *       only the primary surface should be considered.  Updating the primary
653b8e80941Smrg *       surface without aux works fine and can be done repeatedly in this
654b8e80941Smrg *       mode.  Writing to a surface in pass-through mode with aux enabled may
655b8e80941Smrg *       cause the auxiliary buffer to contain non-trivial data and no longer
656b8e80941Smrg *       be in the pass-through state.
657b8e80941Smrg *
658b8e80941Smrg *    7) Aux Invalid:  In this state, the primary surface contains 100% of the
659b8e80941Smrg *       data and the auxiliary surface is completely bogus.  Any attempt to
660b8e80941Smrg *       use the auxiliary surface is liable to result in rendering
661b8e80941Smrg *       corruption.  The only thing that one can do to re-enable aux once
662b8e80941Smrg *       this state is reached is to use an ambiguate pass to transition into
663b8e80941Smrg *       the pass-through state.
664b8e80941Smrg *
665b8e80941Smrg * Drawing with or without aux enabled may implicitly cause the surface to
666b8e80941Smrg * transition between these states.  There are also four types of auxiliary
667b8e80941Smrg * compression operations which cause an explicit transition which are
668b8e80941Smrg * described by the isl_aux_op enum below.
669b8e80941Smrg *
670b8e80941Smrg * Not all operations are valid or useful in all states.  The diagram below
671b8e80941Smrg * contains a complete description of the states and all valid and useful
672b8e80941Smrg * transitions except clear.
673b8e80941Smrg *
674b8e80941Smrg *   Draw w/ Aux
675b8e80941Smrg *   +----------+
676b8e80941Smrg *   |          |
677b8e80941Smrg *   |       +-------------+    Draw w/ Aux     +-------------+
678b8e80941Smrg *   +------>| Compressed  |<-------------------|    Clear    |
679b8e80941Smrg *           |  w/ Clear   |----->----+         |             |
680b8e80941Smrg *           +-------------+          |         +-------------+
681b8e80941Smrg *                  |  /|\            |            |   |
682b8e80941Smrg *                  |   |             |            |   |
683b8e80941Smrg *                  |   |             +------<-----+   |  Draw w/
684b8e80941Smrg *                  |   |             |                | Clear Only
685b8e80941Smrg *                  |   |      Full   |                |   +----------+
686b8e80941Smrg *          Partial |   |     Resolve |               \|/  |          |
687b8e80941Smrg *          Resolve |   |             |         +-------------+       |
688b8e80941Smrg *                  |   |             |         |   Partial   |<------+
689b8e80941Smrg *                  |   |             |         |    Clear    |<----------+
690b8e80941Smrg *                  |   |             |         +-------------+           |
691b8e80941Smrg *                  |   |             |                |                  |
692b8e80941Smrg *                  |   |             +------>---------+  Full            |
693b8e80941Smrg *                  |   |                              | Resolve          |
694b8e80941Smrg *   Draw w/ aux    |   |   Partial Fast Clear         |                  |
695b8e80941Smrg *   +----------+   |   +--------------------------+   |                  |
696b8e80941Smrg *   |          |  \|/                             |  \|/                 |
697b8e80941Smrg *   |       +-------------+    Full Resolve    +-------------+           |
698b8e80941Smrg *   +------>| Compressed  |------------------->|  Resolved   |           |
699b8e80941Smrg *           |  w/o Clear  |<-------------------|             |           |
700b8e80941Smrg *           +-------------+    Draw w/ Aux     +-------------+           |
701b8e80941Smrg *                 /|\                             |   |                  |
702b8e80941Smrg *                  |  Draw                        |   |  Draw            |
703b8e80941Smrg *                  | w/ Aux                       |   | w/o Aux          |
704b8e80941Smrg *                  |            Ambiguate         |   |                  |
705b8e80941Smrg *                  |   +--------------------------+   |                  |
706b8e80941Smrg *   Draw w/o Aux   |   |                              |   Draw w/o Aux   |
707b8e80941Smrg *   +----------+   |   |                              |   +----------+   |
708b8e80941Smrg *   |          |   |  \|/                            \|/  |          |   |
709b8e80941Smrg *   |       +-------------+     Ambiguate      +-------------+       |   |
710b8e80941Smrg *   +------>|    Pass-    |<-------------------|     Aux     |<------+   |
711b8e80941Smrg *   +------>|   through   |                    |   Invalid   |           |
712b8e80941Smrg *   |       +-------------+                    +-------------+           |
713b8e80941Smrg *   |          |   |                                                     |
714b8e80941Smrg *   +----------+   +-----------------------------------------------------+
715b8e80941Smrg *     Draw w/                       Partial Fast Clear
716b8e80941Smrg *    Clear Only
717b8e80941Smrg *
718b8e80941Smrg *
719b8e80941Smrg * While the above general theory applies to all forms of auxiliary
720b8e80941Smrg * compression on Intel hardware, not all states and operations are available
721b8e80941Smrg * on all compression types.  However, each of the auxiliary states and
722b8e80941Smrg * operations can be fairly easily mapped onto the above diagram:
723b8e80941Smrg *
724b8e80941Smrg * HiZ:     Hierarchical depth compression is capable of being in any of the
725b8e80941Smrg *          states above.  Hardware provides three HiZ operations: "Depth
726b8e80941Smrg *          Clear", "Depth Resolve", and "HiZ Resolve" which map to "Fast
727b8e80941Smrg *          Clear", "Full Resolve", and "Ambiguate" respectively.  The
728b8e80941Smrg *          hardware provides no HiZ partial resolve operation so the only way
729b8e80941Smrg *          to get into the "Compressed w/o Clear" state is to render with HiZ
730b8e80941Smrg *          when the surface is in the resolved or pass-through states.
731b8e80941Smrg *
732b8e80941Smrg * MCS:     Multisample compression is technically capable of being in any of
733b8e80941Smrg *          the states above except that most of them aren't useful.  Both the
734b8e80941Smrg *          render engine and the sampler support MCS compression and, apart
735b8e80941Smrg *          from clear color, MCS is format-unaware so we leave the surface
736b8e80941Smrg *          compressed 100% of the time.  The hardware provides no MCS
737b8e80941Smrg *          operations.
738b8e80941Smrg *
739b8e80941Smrg * CCS_D:   Single-sample fast-clears (also called CCS_D in ISL) are one of
740b8e80941Smrg *          the simplest forms of compression since they don't do anything
741b8e80941Smrg *          beyond clear color tracking.  They really only support three of
742b8e80941Smrg *          the six states: Clear, Partial Clear, and Pass-through.  The
743b8e80941Smrg *          only CCS_D operation is "Resolve" which maps to a full resolve
744b8e80941Smrg *          followed by an ambiguate.
745b8e80941Smrg *
746b8e80941Smrg * CCS_E:   Single-sample render target compression (also called CCS_E in ISL)
747b8e80941Smrg *          is capable of being in almost all of the above states.  THe only
748b8e80941Smrg *          exception is that it does not have separate resolved and pass-
749b8e80941Smrg *          through states.  Instead, the CCS_E full resolve operation does
750b8e80941Smrg *          both a resolve and an ambiguate so it goes directly into the
751b8e80941Smrg *          pass-through state.  CCS_E also provides fast clear and partial
752b8e80941Smrg *          resolve operations which work as described above.
753b8e80941Smrg *
754b8e80941Smrg *          While it is technically possible to perform a CCS_E ambiguate, it
755b8e80941Smrg *          is not provided by Sky Lake hardware so we choose to avoid the aux
756b8e80941Smrg *          invalid state.  If the aux invalid state were determined to be
757b8e80941Smrg *          useful, a CCS ambiguate could be done by carefully rendering to
758b8e80941Smrg *          the CCS and filling it with zeros.
759b8e80941Smrg */
760b8e80941Smrgenum isl_aux_state {
761b8e80941Smrg   ISL_AUX_STATE_CLEAR = 0,
762b8e80941Smrg   ISL_AUX_STATE_PARTIAL_CLEAR,
763b8e80941Smrg   ISL_AUX_STATE_COMPRESSED_CLEAR,
764b8e80941Smrg   ISL_AUX_STATE_COMPRESSED_NO_CLEAR,
765b8e80941Smrg   ISL_AUX_STATE_RESOLVED,
766b8e80941Smrg   ISL_AUX_STATE_PASS_THROUGH,
767b8e80941Smrg   ISL_AUX_STATE_AUX_INVALID,
768b8e80941Smrg};
769b8e80941Smrg
770b8e80941Smrg/**
771b8e80941Smrg * Enum which describes explicit aux transition operations.
772b8e80941Smrg */
773b8e80941Smrgenum isl_aux_op {
774b8e80941Smrg   ISL_AUX_OP_NONE,
775b8e80941Smrg
776b8e80941Smrg   /** Fast Clear
777b8e80941Smrg    *
778b8e80941Smrg    * This operation writes the magic "clear" value to the auxiliary surface.
779b8e80941Smrg    * This operation will safely transition any slice of a surface from any
780b8e80941Smrg    * state to the clear state so long as the entire slice is fast cleared at
781b8e80941Smrg    * once.  A fast clear that only covers part of a slice of a surface is
782b8e80941Smrg    * called a partial fast clear.
783b8e80941Smrg    */
784b8e80941Smrg   ISL_AUX_OP_FAST_CLEAR,
785b8e80941Smrg
786b8e80941Smrg   /** Full Resolve
787b8e80941Smrg    *
788b8e80941Smrg    * This operation combines the auxiliary surface data with the primary
789b8e80941Smrg    * surface data and writes the result to the primary.  For HiZ, the docs
790b8e80941Smrg    * call this a depth resolve.  For CCS, the hardware full resolve operation
791b8e80941Smrg    * does both a full resolve and an ambiguate so it actually takes you all
792b8e80941Smrg    * the way to the pass-through state.
793b8e80941Smrg    */
794b8e80941Smrg   ISL_AUX_OP_FULL_RESOLVE,
795b8e80941Smrg
796b8e80941Smrg   /** Partial Resolve
797b8e80941Smrg    *
798b8e80941Smrg    * This operation considers blocks which are in the "clear" state and
799b8e80941Smrg    * writes the clear value directly into the primary or auxiliary surface.
800b8e80941Smrg    * Once this operation completes, the surface is still compressed but no
801b8e80941Smrg    * longer references the clear color.  This operation is only available
802b8e80941Smrg    * for CCS_E.
803b8e80941Smrg    */
804b8e80941Smrg   ISL_AUX_OP_PARTIAL_RESOLVE,
805b8e80941Smrg
806b8e80941Smrg   /** Ambiguate
807b8e80941Smrg    *
808b8e80941Smrg    * This operation throws away the current auxiliary data and replaces it
809b8e80941Smrg    * with the magic pass-through value.  If an ambiguate operation is
810b8e80941Smrg    * performed when the primary surface does not contain 100% of the data,
811b8e80941Smrg    * data will be lost.  This operation is only implemented in hardware for
812b8e80941Smrg    * depth where it is called a HiZ resolve.
813b8e80941Smrg    */
814b8e80941Smrg   ISL_AUX_OP_AMBIGUATE,
815b8e80941Smrg};
816b8e80941Smrg
817b8e80941Smrg/* TODO(chadv): Explain */
818b8e80941Smrgenum isl_array_pitch_span {
819b8e80941Smrg   ISL_ARRAY_PITCH_SPAN_FULL,
820b8e80941Smrg   ISL_ARRAY_PITCH_SPAN_COMPACT,
821b8e80941Smrg};
822b8e80941Smrg
823b8e80941Smrg/**
824b8e80941Smrg * @defgroup Surface Usage
825b8e80941Smrg * @{
826b8e80941Smrg */
827b8e80941Smrgtypedef uint64_t isl_surf_usage_flags_t;
828b8e80941Smrg#define ISL_SURF_USAGE_RENDER_TARGET_BIT       (1u << 0)
829b8e80941Smrg#define ISL_SURF_USAGE_DEPTH_BIT               (1u << 1)
830b8e80941Smrg#define ISL_SURF_USAGE_STENCIL_BIT             (1u << 2)
831b8e80941Smrg#define ISL_SURF_USAGE_TEXTURE_BIT             (1u << 3)
832b8e80941Smrg#define ISL_SURF_USAGE_CUBE_BIT                (1u << 4)
833b8e80941Smrg#define ISL_SURF_USAGE_DISABLE_AUX_BIT         (1u << 5)
834b8e80941Smrg#define ISL_SURF_USAGE_DISPLAY_BIT             (1u << 6)
835b8e80941Smrg#define ISL_SURF_USAGE_DISPLAY_ROTATE_90_BIT   (1u << 7)
836b8e80941Smrg#define ISL_SURF_USAGE_DISPLAY_ROTATE_180_BIT  (1u << 8)
837b8e80941Smrg#define ISL_SURF_USAGE_DISPLAY_ROTATE_270_BIT  (1u << 9)
838b8e80941Smrg#define ISL_SURF_USAGE_DISPLAY_FLIP_X_BIT      (1u << 10)
839b8e80941Smrg#define ISL_SURF_USAGE_DISPLAY_FLIP_Y_BIT      (1u << 11)
840b8e80941Smrg#define ISL_SURF_USAGE_STORAGE_BIT             (1u << 12)
841b8e80941Smrg#define ISL_SURF_USAGE_HIZ_BIT                 (1u << 13)
842b8e80941Smrg#define ISL_SURF_USAGE_MCS_BIT                 (1u << 14)
843b8e80941Smrg#define ISL_SURF_USAGE_CCS_BIT                 (1u << 15)
844b8e80941Smrg/** @} */
845b8e80941Smrg
846b8e80941Smrg/**
847b8e80941Smrg * @defgroup Channel Mask
848b8e80941Smrg *
849b8e80941Smrg * These #define values are chosen to match the values of
850b8e80941Smrg * RENDER_SURFACE_STATE::Color Buffer Component Write Disables
851b8e80941Smrg *
852b8e80941Smrg * @{
853b8e80941Smrg */
854b8e80941Smrgtypedef uint8_t isl_channel_mask_t;
855b8e80941Smrg#define ISL_CHANNEL_BLUE_BIT  (1 << 0)
856b8e80941Smrg#define ISL_CHANNEL_GREEN_BIT (1 << 1)
857b8e80941Smrg#define ISL_CHANNEL_RED_BIT   (1 << 2)
858b8e80941Smrg#define ISL_CHANNEL_ALPHA_BIT (1 << 3)
859b8e80941Smrg/** @} */
860b8e80941Smrg
861b8e80941Smrg/**
862b8e80941Smrg * @brief A channel select (also known as texture swizzle) value
863b8e80941Smrg */
864b8e80941Smrgenum isl_channel_select {
865b8e80941Smrg   ISL_CHANNEL_SELECT_ZERO = 0,
866b8e80941Smrg   ISL_CHANNEL_SELECT_ONE = 1,
867b8e80941Smrg   ISL_CHANNEL_SELECT_RED = 4,
868b8e80941Smrg   ISL_CHANNEL_SELECT_GREEN = 5,
869b8e80941Smrg   ISL_CHANNEL_SELECT_BLUE = 6,
870b8e80941Smrg   ISL_CHANNEL_SELECT_ALPHA = 7,
871b8e80941Smrg};
872b8e80941Smrg
873b8e80941Smrg/**
874b8e80941Smrg * Identical to VkSampleCountFlagBits.
875b8e80941Smrg */
876b8e80941Smrgenum isl_sample_count {
877b8e80941Smrg   ISL_SAMPLE_COUNT_1_BIT     = 1u,
878b8e80941Smrg   ISL_SAMPLE_COUNT_2_BIT     = 2u,
879b8e80941Smrg   ISL_SAMPLE_COUNT_4_BIT     = 4u,
880b8e80941Smrg   ISL_SAMPLE_COUNT_8_BIT     = 8u,
881b8e80941Smrg   ISL_SAMPLE_COUNT_16_BIT    = 16u,
882b8e80941Smrg};
883b8e80941Smrgtypedef uint32_t isl_sample_count_mask_t;
884b8e80941Smrg
885b8e80941Smrg/**
886b8e80941Smrg * @brief Multisample Format
887b8e80941Smrg */
888b8e80941Smrgenum isl_msaa_layout {
889b8e80941Smrg   /**
890b8e80941Smrg    * @brief Suface is single-sampled.
891b8e80941Smrg    */
892b8e80941Smrg   ISL_MSAA_LAYOUT_NONE,
893b8e80941Smrg
894b8e80941Smrg   /**
895b8e80941Smrg    * @brief [SNB+] Interleaved Multisample Format
896b8e80941Smrg    *
897b8e80941Smrg    * In this format, multiple samples are interleaved into each cacheline.
898b8e80941Smrg    * In other words, the sample index is swizzled into the low 6 bits of the
899b8e80941Smrg    * surface's virtual address space.
900b8e80941Smrg    *
901b8e80941Smrg    * For example, suppose the surface is legacy Y tiled, is 4x multisampled,
902b8e80941Smrg    * and its pixel format is 32bpp. Then the first cacheline is arranged
903b8e80941Smrg    * thus:
904b8e80941Smrg    *
905b8e80941Smrg    *    (0,0,0) (0,1,0)   (0,0,1) (1,0,1)
906b8e80941Smrg    *    (1,0,0) (1,1,0)   (0,1,1) (1,1,1)
907b8e80941Smrg    *
908b8e80941Smrg    *    (0,0,2) (1,0,2)   (0,0,3) (1,0,3)
909b8e80941Smrg    *    (0,1,2) (1,1,2)   (0,1,3) (1,1,3)
910b8e80941Smrg    *
911b8e80941Smrg    * The hardware docs refer to this format with multiple terms.  In
912b8e80941Smrg    * Sandybridge, this is the only multisample format; so no term is used.
913b8e80941Smrg    * The Ivybridge docs refer to surfaces in this format as IMS (Interleaved
914b8e80941Smrg    * Multisample Surface). Later hardware docs additionally refer to this
915b8e80941Smrg    * format as MSFMT_DEPTH_STENCIL (because the format is deprecated for
916b8e80941Smrg    * color surfaces).
917b8e80941Smrg    *
918b8e80941Smrg    * See the Sandybridge PRM, Volume 4, Part 1, Section 2.7 "Multisampled
919b8e80941Smrg    * Surface Behavior".
920b8e80941Smrg    *
921b8e80941Smrg    * See the Ivybridge PRM, Volume 1, Part 1, Section 6.18.4.1 "Interleaved
922b8e80941Smrg    * Multisampled Surfaces".
923b8e80941Smrg    */
924b8e80941Smrg   ISL_MSAA_LAYOUT_INTERLEAVED,
925b8e80941Smrg
926b8e80941Smrg   /**
927b8e80941Smrg    * @brief [IVB+] Array Multisample Format
928b8e80941Smrg    *
929b8e80941Smrg    * In this format, the surface's physical layout resembles that of a
930b8e80941Smrg    * 2D array surface.
931b8e80941Smrg    *
932b8e80941Smrg    * Suppose the multisample surface's logical extent is (w, h) and its
933b8e80941Smrg    * sample count is N. Then surface's physical extent is the same as
934b8e80941Smrg    * a singlesample 2D surface whose logical extent is (w, h) and array
935b8e80941Smrg    * length is N.  Array slice `i` contains the pixel values for sample
936b8e80941Smrg    * index `i`.
937b8e80941Smrg    *
938b8e80941Smrg    * The Ivybridge docs refer to surfaces in this format as UMS
939b8e80941Smrg    * (Uncompressed Multsample Layout) and CMS (Compressed Multisample
940b8e80941Smrg    * Surface). The Broadwell docs additionally refer to this format as
941b8e80941Smrg    * MSFMT_MSS (MSS=Multisample Surface Storage).
942b8e80941Smrg    *
943b8e80941Smrg    * See the Broadwell PRM, Volume 5 "Memory Views", Section "Uncompressed
944b8e80941Smrg    * Multisample Surfaces".
945b8e80941Smrg    *
946b8e80941Smrg    * See the Broadwell PRM, Volume 5 "Memory Views", Section "Compressed
947b8e80941Smrg    * Multisample Surfaces".
948b8e80941Smrg    */
949b8e80941Smrg   ISL_MSAA_LAYOUT_ARRAY,
950b8e80941Smrg};
951b8e80941Smrg
952b8e80941Smrgtypedef enum {
953b8e80941Smrg  ISL_MEMCPY = 0,
954b8e80941Smrg  ISL_MEMCPY_BGRA8,
955b8e80941Smrg  ISL_MEMCPY_STREAMING_LOAD,
956b8e80941Smrg  ISL_MEMCPY_INVALID,
957b8e80941Smrg} isl_memcpy_type;
958b8e80941Smrg
959b8e80941Smrgstruct isl_device {
960b8e80941Smrg   const struct gen_device_info *info;
961b8e80941Smrg   bool use_separate_stencil;
962b8e80941Smrg   bool has_bit6_swizzling;
963b8e80941Smrg
964b8e80941Smrg   /**
965b8e80941Smrg    * Describes the layout of a RENDER_SURFACE_STATE structure for the
966b8e80941Smrg    * current gen.
967b8e80941Smrg    */
968b8e80941Smrg   struct {
969b8e80941Smrg      uint8_t size;
970b8e80941Smrg      uint8_t align;
971b8e80941Smrg      uint8_t addr_offset;
972b8e80941Smrg      uint8_t aux_addr_offset;
973b8e80941Smrg
974b8e80941Smrg      /* Rounded up to the nearest dword to simplify GPU memcpy operations. */
975b8e80941Smrg
976b8e80941Smrg      /* size of the state buffer used to store the clear color + extra
977b8e80941Smrg       * additional space used by the hardware */
978b8e80941Smrg      uint8_t clear_color_state_size;
979b8e80941Smrg      uint8_t clear_color_state_offset;
980b8e80941Smrg      /* size of the clear color itself - used to copy it to/from a BO */
981b8e80941Smrg      uint8_t clear_value_size;
982b8e80941Smrg      uint8_t clear_value_offset;
983b8e80941Smrg   } ss;
984b8e80941Smrg
985b8e80941Smrg   /**
986b8e80941Smrg    * Describes the layout of the depth/stencil/hiz commands as emitted by
987b8e80941Smrg    * isl_emit_depth_stencil_hiz.
988b8e80941Smrg    */
989b8e80941Smrg   struct {
990b8e80941Smrg      uint8_t size;
991b8e80941Smrg      uint8_t depth_offset;
992b8e80941Smrg      uint8_t stencil_offset;
993b8e80941Smrg      uint8_t hiz_offset;
994b8e80941Smrg   } ds;
995b8e80941Smrg};
996b8e80941Smrg
997b8e80941Smrgstruct isl_extent2d {
998b8e80941Smrg   union { uint32_t w, width; };
999b8e80941Smrg   union { uint32_t h, height; };
1000b8e80941Smrg};
1001b8e80941Smrg
1002b8e80941Smrgstruct isl_extent3d {
1003b8e80941Smrg   union { uint32_t w, width; };
1004b8e80941Smrg   union { uint32_t h, height; };
1005b8e80941Smrg   union { uint32_t d, depth; };
1006b8e80941Smrg};
1007b8e80941Smrg
1008b8e80941Smrgstruct isl_extent4d {
1009b8e80941Smrg   union { uint32_t w, width; };
1010b8e80941Smrg   union { uint32_t h, height; };
1011b8e80941Smrg   union { uint32_t d, depth; };
1012b8e80941Smrg   union { uint32_t a, array_len; };
1013b8e80941Smrg};
1014b8e80941Smrg
1015b8e80941Smrgstruct isl_channel_layout {
1016b8e80941Smrg   enum isl_base_type type;
1017b8e80941Smrg   uint8_t start_bit; /**< Bit at which this channel starts */
1018b8e80941Smrg   uint8_t bits; /**< Size in bits */
1019b8e80941Smrg};
1020b8e80941Smrg
1021b8e80941Smrg/**
1022b8e80941Smrg * Each format has 3D block extent (width, height, depth). The block extent of
1023b8e80941Smrg * compressed formats is that of the format's compression block. For example,
1024b8e80941Smrg * the block extent of ISL_FORMAT_ETC2_RGB8 is (w=4, h=4, d=1).  The block
1025b8e80941Smrg * extent of uncompressed pixel formats, such as ISL_FORMAT_R8G8B8A8_UNORM, is
1026b8e80941Smrg * is (w=1, h=1, d=1).
1027b8e80941Smrg */
1028b8e80941Smrgstruct isl_format_layout {
1029b8e80941Smrg   enum isl_format format;
1030b8e80941Smrg   const char *name;
1031b8e80941Smrg
1032b8e80941Smrg   uint16_t bpb; /**< Bits per block */
1033b8e80941Smrg   uint8_t bw; /**< Block width, in pixels */
1034b8e80941Smrg   uint8_t bh; /**< Block height, in pixels */
1035b8e80941Smrg   uint8_t bd; /**< Block depth, in pixels */
1036b8e80941Smrg
1037b8e80941Smrg   union {
1038b8e80941Smrg      struct {
1039b8e80941Smrg         struct isl_channel_layout r; /**< Red channel */
1040b8e80941Smrg         struct isl_channel_layout g; /**< Green channel */
1041b8e80941Smrg         struct isl_channel_layout b; /**< Blue channel */
1042b8e80941Smrg         struct isl_channel_layout a; /**< Alpha channel */
1043b8e80941Smrg         struct isl_channel_layout l; /**< Luminance channel */
1044b8e80941Smrg         struct isl_channel_layout i; /**< Intensity channel */
1045b8e80941Smrg         struct isl_channel_layout p; /**< Palette channel */
1046b8e80941Smrg      } channels;
1047b8e80941Smrg      struct isl_channel_layout channels_array[7];
1048b8e80941Smrg   };
1049b8e80941Smrg
1050b8e80941Smrg   enum isl_colorspace colorspace;
1051b8e80941Smrg   enum isl_txc txc;
1052b8e80941Smrg};
1053b8e80941Smrg
1054b8e80941Smrgstruct isl_tile_info {
1055b8e80941Smrg   enum isl_tiling tiling;
1056b8e80941Smrg
1057b8e80941Smrg   /* The size (in bits per block) of a single surface element
1058b8e80941Smrg    *
1059b8e80941Smrg    * For surfaces with power-of-two formats, this is the same as
1060b8e80941Smrg    * isl_format_layout::bpb.  For non-power-of-two formats it may be smaller.
1061b8e80941Smrg    * The logical_extent_el field is in terms of elements of this size.
1062b8e80941Smrg    *
1063b8e80941Smrg    * For example, consider ISL_FORMAT_R32G32B32_FLOAT for which
1064b8e80941Smrg    * isl_format_layout::bpb is 96 (a non-power-of-two).  In this case, none
1065b8e80941Smrg    * of the tiling formats can actually hold an integer number of 96-bit
1066b8e80941Smrg    * surface elements so isl_tiling_get_info returns an isl_tile_info for a
1067b8e80941Smrg    * 32-bit element size.  It is the responsibility of the caller to
1068b8e80941Smrg    * recognize that 32 != 96 ad adjust accordingly.  For instance, to compute
1069b8e80941Smrg    * the width of a surface in tiles, you would do:
1070b8e80941Smrg    *
1071b8e80941Smrg    * width_tl = DIV_ROUND_UP(width_el * (format_bpb / tile_info.format_bpb),
1072b8e80941Smrg    *                         tile_info.logical_extent_el.width);
1073b8e80941Smrg    */
1074b8e80941Smrg   uint32_t format_bpb;
1075b8e80941Smrg
1076b8e80941Smrg   /** The logical size of the tile in units of format_bpb size elements
1077b8e80941Smrg    *
1078b8e80941Smrg    * This field determines how a given surface is cut up into tiles.  It is
1079b8e80941Smrg    * used to compute the size of a surface in tiles and can be used to
1080b8e80941Smrg    * determine the location of the tile containing any given surface element.
1081b8e80941Smrg    * The exact value of this field depends heavily on the bits-per-block of
1082b8e80941Smrg    * the format being used.
1083b8e80941Smrg    */
1084b8e80941Smrg   struct isl_extent2d logical_extent_el;
1085b8e80941Smrg
1086b8e80941Smrg   /** The physical size of the tile in bytes and rows of bytes
1087b8e80941Smrg    *
1088b8e80941Smrg    * This field determines how the tiles of a surface are physically layed
1089b8e80941Smrg    * out in memory.  The logical and physical tile extent are frequently the
1090b8e80941Smrg    * same but this is not always the case.  For instance, a W-tile (which is
1091b8e80941Smrg    * always used with ISL_FORMAT_R8) has a logical size of 64el x 64el but
1092b8e80941Smrg    * its physical size is 128B x 32rows, the same as a Y-tile.
1093b8e80941Smrg    *
1094b8e80941Smrg    * @see isl_surf::row_pitch_B
1095b8e80941Smrg    */
1096b8e80941Smrg   struct isl_extent2d phys_extent_B;
1097b8e80941Smrg};
1098b8e80941Smrg
1099b8e80941Smrg/**
1100b8e80941Smrg * Metadata about a DRM format modifier.
1101b8e80941Smrg */
1102b8e80941Smrgstruct isl_drm_modifier_info {
1103b8e80941Smrg   uint64_t modifier;
1104b8e80941Smrg
1105b8e80941Smrg   /** Text name of the modifier */
1106b8e80941Smrg   const char *name;
1107b8e80941Smrg
1108b8e80941Smrg   /** ISL tiling implied by this modifier */
1109b8e80941Smrg   enum isl_tiling tiling;
1110b8e80941Smrg
1111b8e80941Smrg   /** ISL aux usage implied by this modifier */
1112b8e80941Smrg   enum isl_aux_usage aux_usage;
1113b8e80941Smrg
1114b8e80941Smrg   /** Whether or not this modifier supports clear color */
1115b8e80941Smrg   bool supports_clear_color;
1116b8e80941Smrg};
1117b8e80941Smrg
1118b8e80941Smrg/**
1119b8e80941Smrg * @brief Input to surface initialization
1120b8e80941Smrg *
1121b8e80941Smrg * @invariant width >= 1
1122b8e80941Smrg * @invariant height >= 1
1123b8e80941Smrg * @invariant depth >= 1
1124b8e80941Smrg * @invariant levels >= 1
1125b8e80941Smrg * @invariant samples >= 1
1126b8e80941Smrg * @invariant array_len >= 1
1127b8e80941Smrg *
1128b8e80941Smrg * @invariant if 1D then height == 1 and depth == 1 and samples == 1
1129b8e80941Smrg * @invariant if 2D then depth == 1
1130b8e80941Smrg * @invariant if 3D then array_len == 1 and samples == 1
1131b8e80941Smrg */
1132b8e80941Smrgstruct isl_surf_init_info {
1133b8e80941Smrg   enum isl_surf_dim dim;
1134b8e80941Smrg   enum isl_format format;
1135b8e80941Smrg
1136b8e80941Smrg   uint32_t width;
1137b8e80941Smrg   uint32_t height;
1138b8e80941Smrg   uint32_t depth;
1139b8e80941Smrg   uint32_t levels;
1140b8e80941Smrg   uint32_t array_len;
1141b8e80941Smrg   uint32_t samples;
1142b8e80941Smrg
1143b8e80941Smrg   /** Lower bound for isl_surf::alignment, in bytes. */
1144b8e80941Smrg   uint32_t min_alignment_B;
1145b8e80941Smrg
1146b8e80941Smrg   /**
1147b8e80941Smrg    * Exact value for isl_surf::row_pitch. Ignored if zero.  isl_surf_init()
1148b8e80941Smrg    * will fail if this is misaligned or out of bounds.
1149b8e80941Smrg    */
1150b8e80941Smrg   uint32_t row_pitch_B;
1151b8e80941Smrg
1152b8e80941Smrg   isl_surf_usage_flags_t usage;
1153b8e80941Smrg
1154b8e80941Smrg   /** Flags that alter how ISL selects isl_surf::tiling.  */
1155b8e80941Smrg   isl_tiling_flags_t tiling_flags;
1156b8e80941Smrg};
1157b8e80941Smrg
1158b8e80941Smrgstruct isl_surf {
1159b8e80941Smrg   enum isl_surf_dim dim;
1160b8e80941Smrg   enum isl_dim_layout dim_layout;
1161b8e80941Smrg   enum isl_msaa_layout msaa_layout;
1162b8e80941Smrg   enum isl_tiling tiling;
1163b8e80941Smrg   enum isl_format format;
1164b8e80941Smrg
1165b8e80941Smrg   /**
1166b8e80941Smrg    * Alignment of the upper-left sample of each subimage, in units of surface
1167b8e80941Smrg    * elements.
1168b8e80941Smrg    */
1169b8e80941Smrg   struct isl_extent3d image_alignment_el;
1170b8e80941Smrg
1171b8e80941Smrg   /**
1172b8e80941Smrg    * Logical extent of the surface's base level, in units of pixels.  This is
1173b8e80941Smrg    * identical to the extent defined in isl_surf_init_info.
1174b8e80941Smrg    */
1175b8e80941Smrg   struct isl_extent4d logical_level0_px;
1176b8e80941Smrg
1177b8e80941Smrg   /**
1178b8e80941Smrg    * Physical extent of the surface's base level, in units of physical
1179b8e80941Smrg    * surface samples.
1180b8e80941Smrg    *
1181b8e80941Smrg    * Consider isl_dim_layout as an operator that transforms a logical surface
1182b8e80941Smrg    * layout to a physical surface layout. Then
1183b8e80941Smrg    *
1184b8e80941Smrg    *    logical_layout := (isl_surf::dim, isl_surf::logical_level0_px)
1185b8e80941Smrg    *    isl_surf::phys_level0_sa := isl_surf::dim_layout * logical_layout
1186b8e80941Smrg    */
1187b8e80941Smrg   struct isl_extent4d phys_level0_sa;
1188b8e80941Smrg
1189b8e80941Smrg   uint32_t levels;
1190b8e80941Smrg   uint32_t samples;
1191b8e80941Smrg
1192b8e80941Smrg   /** Total size of the surface, in bytes. */
1193b8e80941Smrg   uint64_t size_B;
1194b8e80941Smrg
1195b8e80941Smrg   /** Required alignment for the surface's base address. */
1196b8e80941Smrg   uint32_t alignment_B;
1197b8e80941Smrg
1198b8e80941Smrg   /**
1199b8e80941Smrg    * The interpretation of this field depends on the value of
1200b8e80941Smrg    * isl_tile_info::physical_extent_B.  In particular, the width of the
1201b8e80941Smrg    * surface in tiles is row_pitch_B / isl_tile_info::physical_extent_B.width
1202b8e80941Smrg    * and the distance in bytes between vertically adjacent tiles in the image
1203b8e80941Smrg    * is given by row_pitch_B * isl_tile_info::physical_extent_B.height.
1204b8e80941Smrg    *
1205b8e80941Smrg    * For linear images where isl_tile_info::physical_extent_B.height == 1,
1206b8e80941Smrg    * this cleanly reduces to being the distance, in bytes, between vertically
1207b8e80941Smrg    * adjacent surface elements.
1208b8e80941Smrg    *
1209b8e80941Smrg    * @see isl_tile_info::phys_extent_B;
1210b8e80941Smrg    */
1211b8e80941Smrg   uint32_t row_pitch_B;
1212b8e80941Smrg
1213b8e80941Smrg   /**
1214b8e80941Smrg    * Pitch between physical array slices, in rows of surface elements.
1215b8e80941Smrg    */
1216b8e80941Smrg   uint32_t array_pitch_el_rows;
1217b8e80941Smrg
1218b8e80941Smrg   enum isl_array_pitch_span array_pitch_span;
1219b8e80941Smrg
1220b8e80941Smrg   /** Copy of isl_surf_init_info::usage. */
1221b8e80941Smrg   isl_surf_usage_flags_t usage;
1222b8e80941Smrg};
1223b8e80941Smrg
1224b8e80941Smrgstruct isl_swizzle {
1225b8e80941Smrg   enum isl_channel_select r:4;
1226b8e80941Smrg   enum isl_channel_select g:4;
1227b8e80941Smrg   enum isl_channel_select b:4;
1228b8e80941Smrg   enum isl_channel_select a:4;
1229b8e80941Smrg};
1230b8e80941Smrg
1231b8e80941Smrg#define ISL_SWIZZLE(R, G, B, A) ((struct isl_swizzle) { \
1232b8e80941Smrg      .r = ISL_CHANNEL_SELECT_##R, \
1233b8e80941Smrg      .g = ISL_CHANNEL_SELECT_##G, \
1234b8e80941Smrg      .b = ISL_CHANNEL_SELECT_##B, \
1235b8e80941Smrg      .a = ISL_CHANNEL_SELECT_##A, \
1236b8e80941Smrg   })
1237b8e80941Smrg
1238b8e80941Smrg#define ISL_SWIZZLE_IDENTITY ISL_SWIZZLE(RED, GREEN, BLUE, ALPHA)
1239b8e80941Smrg
1240b8e80941Smrgstruct isl_view {
1241b8e80941Smrg   /**
1242b8e80941Smrg    * Indicates the usage of the particular view
1243b8e80941Smrg    *
1244b8e80941Smrg    * Normally, this is one bit.  However, for a cube map texture, it
1245b8e80941Smrg    * should be ISL_SURF_USAGE_TEXTURE_BIT | ISL_SURF_USAGE_CUBE_BIT.
1246b8e80941Smrg    */
1247b8e80941Smrg   isl_surf_usage_flags_t usage;
1248b8e80941Smrg
1249b8e80941Smrg   /**
1250b8e80941Smrg    * The format to use in the view
1251b8e80941Smrg    *
1252b8e80941Smrg    * This may differ from the format of the actual isl_surf but must have
1253b8e80941Smrg    * the same block size.
1254b8e80941Smrg    */
1255b8e80941Smrg   enum isl_format format;
1256b8e80941Smrg
1257b8e80941Smrg   uint32_t base_level;
1258b8e80941Smrg   uint32_t levels;
1259b8e80941Smrg
1260b8e80941Smrg   /**
1261b8e80941Smrg    * Base array layer
1262b8e80941Smrg    *
1263b8e80941Smrg    * For cube maps, both base_array_layer and array_len should be
1264b8e80941Smrg    * specified in terms of 2-D layers and must be a multiple of 6.
1265b8e80941Smrg    *
1266b8e80941Smrg    * 3-D textures are effectively treated as 2-D arrays when used as a
1267b8e80941Smrg    * storage image or render target.  If `usage` contains
1268b8e80941Smrg    * ISL_SURF_USAGE_RENDER_TARGET_BIT or ISL_SURF_USAGE_STORAGE_BIT then
1269b8e80941Smrg    * base_array_layer and array_len are applied.  If the surface is only used
1270b8e80941Smrg    * for texturing, they are ignored.
1271b8e80941Smrg    */
1272b8e80941Smrg   uint32_t base_array_layer;
1273b8e80941Smrg
1274b8e80941Smrg   /**
1275b8e80941Smrg    * Array Length
1276b8e80941Smrg    *
1277b8e80941Smrg    * Indicates the number of array elements starting at  Base Array Layer.
1278b8e80941Smrg    */
1279b8e80941Smrg   uint32_t array_len;
1280b8e80941Smrg
1281b8e80941Smrg   struct isl_swizzle swizzle;
1282b8e80941Smrg};
1283b8e80941Smrg
1284b8e80941Smrgunion isl_color_value {
1285b8e80941Smrg   float f32[4];
1286b8e80941Smrg   uint32_t u32[4];
1287b8e80941Smrg   int32_t i32[4];
1288b8e80941Smrg};
1289b8e80941Smrg
1290b8e80941Smrgstruct isl_surf_fill_state_info {
1291b8e80941Smrg   const struct isl_surf *surf;
1292b8e80941Smrg   const struct isl_view *view;
1293b8e80941Smrg
1294b8e80941Smrg   /**
1295b8e80941Smrg    * The address of the surface in GPU memory.
1296b8e80941Smrg    */
1297b8e80941Smrg   uint64_t address;
1298b8e80941Smrg
1299b8e80941Smrg   /**
1300b8e80941Smrg    * The Memory Object Control state for the filled surface state.
1301b8e80941Smrg    *
1302b8e80941Smrg    * The exact format of this value depends on hardware generation.
1303b8e80941Smrg    */
1304b8e80941Smrg   uint32_t mocs;
1305b8e80941Smrg
1306b8e80941Smrg   /**
1307b8e80941Smrg    * The auxilary surface or NULL if no auxilary surface is to be used.
1308b8e80941Smrg    */
1309b8e80941Smrg   const struct isl_surf *aux_surf;
1310b8e80941Smrg   enum isl_aux_usage aux_usage;
1311b8e80941Smrg   uint64_t aux_address;
1312b8e80941Smrg
1313b8e80941Smrg   /**
1314b8e80941Smrg    * The clear color for this surface
1315b8e80941Smrg    *
1316b8e80941Smrg    * Valid values depend on hardware generation.
1317b8e80941Smrg    */
1318b8e80941Smrg   union isl_color_value clear_color;
1319b8e80941Smrg
1320b8e80941Smrg   /**
1321b8e80941Smrg    * Send only the clear value address
1322b8e80941Smrg    *
1323b8e80941Smrg    * If set, we only pass the clear address to the GPU and it will fetch it
1324b8e80941Smrg    * from wherever it is.
1325b8e80941Smrg    */
1326b8e80941Smrg   bool use_clear_address;
1327b8e80941Smrg   uint64_t clear_address;
1328b8e80941Smrg
1329b8e80941Smrg   /**
1330b8e80941Smrg    * Surface write disables for gen4-5
1331b8e80941Smrg    */
1332b8e80941Smrg   isl_channel_mask_t write_disables;
1333b8e80941Smrg
1334b8e80941Smrg   /* Intra-tile offset */
1335b8e80941Smrg   uint16_t x_offset_sa, y_offset_sa;
1336b8e80941Smrg};
1337b8e80941Smrg
1338b8e80941Smrgstruct isl_buffer_fill_state_info {
1339b8e80941Smrg   /**
1340b8e80941Smrg    * The address of the surface in GPU memory.
1341b8e80941Smrg    */
1342b8e80941Smrg   uint64_t address;
1343b8e80941Smrg
1344b8e80941Smrg   /**
1345b8e80941Smrg    * The size of the buffer
1346b8e80941Smrg    */
1347b8e80941Smrg   uint64_t size_B;
1348b8e80941Smrg
1349b8e80941Smrg   /**
1350b8e80941Smrg    * The Memory Object Control state for the filled surface state.
1351b8e80941Smrg    *
1352b8e80941Smrg    * The exact format of this value depends on hardware generation.
1353b8e80941Smrg    */
1354b8e80941Smrg   uint32_t mocs;
1355b8e80941Smrg
1356b8e80941Smrg   /**
1357b8e80941Smrg    * The format to use in the surface state
1358b8e80941Smrg    *
1359b8e80941Smrg    * This may differ from the format of the actual isl_surf but have the
1360b8e80941Smrg    * same block size.
1361b8e80941Smrg    */
1362b8e80941Smrg   enum isl_format format;
1363b8e80941Smrg
1364b8e80941Smrg   /**
1365b8e80941Smrg    * The swizzle to use in the surface state
1366b8e80941Smrg    */
1367b8e80941Smrg   struct isl_swizzle swizzle;
1368b8e80941Smrg
1369b8e80941Smrg   uint32_t stride_B;
1370b8e80941Smrg};
1371b8e80941Smrg
1372b8e80941Smrgstruct isl_depth_stencil_hiz_emit_info {
1373b8e80941Smrg   /**
1374b8e80941Smrg    * The depth surface
1375b8e80941Smrg    */
1376b8e80941Smrg   const struct isl_surf *depth_surf;
1377b8e80941Smrg
1378b8e80941Smrg   /**
1379b8e80941Smrg    * The stencil surface
1380b8e80941Smrg    *
1381b8e80941Smrg    * If separate stencil is not available, this must point to the same
1382b8e80941Smrg    * isl_surf as depth_surf.
1383b8e80941Smrg    */
1384b8e80941Smrg   const struct isl_surf *stencil_surf;
1385b8e80941Smrg
1386b8e80941Smrg   /**
1387b8e80941Smrg    * The view into the depth and stencil surfaces.
1388b8e80941Smrg    *
1389b8e80941Smrg    * This view applies to both surfaces simultaneously.
1390b8e80941Smrg    */
1391b8e80941Smrg   const struct isl_view *view;
1392b8e80941Smrg
1393b8e80941Smrg   /**
1394b8e80941Smrg    * The address of the depth surface in GPU memory
1395b8e80941Smrg    */
1396b8e80941Smrg   uint64_t depth_address;
1397b8e80941Smrg
1398b8e80941Smrg   /**
1399b8e80941Smrg    * The address of the stencil surface in GPU memory
1400b8e80941Smrg    *
1401b8e80941Smrg    * If separate stencil is not available, this must have the same value as
1402b8e80941Smrg    * depth_address.
1403b8e80941Smrg    */
1404b8e80941Smrg   uint64_t stencil_address;
1405b8e80941Smrg
1406b8e80941Smrg   /**
1407b8e80941Smrg    * The Memory Object Control state for depth and stencil buffers
1408b8e80941Smrg    *
1409b8e80941Smrg    * Both depth and stencil will get the same MOCS value.  The exact format
1410b8e80941Smrg    * of this value depends on hardware generation.
1411b8e80941Smrg    */
1412b8e80941Smrg   uint32_t mocs;
1413b8e80941Smrg
1414b8e80941Smrg   /**
1415b8e80941Smrg    * The HiZ surface or NULL if HiZ is disabled.
1416b8e80941Smrg    */
1417b8e80941Smrg   const struct isl_surf *hiz_surf;
1418b8e80941Smrg   enum isl_aux_usage hiz_usage;
1419b8e80941Smrg   uint64_t hiz_address;
1420b8e80941Smrg
1421b8e80941Smrg   /**
1422b8e80941Smrg    * The depth clear value
1423b8e80941Smrg    */
1424b8e80941Smrg   float depth_clear_value;
1425b8e80941Smrg};
1426b8e80941Smrg
1427b8e80941Smrgextern const struct isl_format_layout isl_format_layouts[];
1428b8e80941Smrg
1429b8e80941Smrgvoid
1430b8e80941Smrgisl_device_init(struct isl_device *dev,
1431b8e80941Smrg                const struct gen_device_info *info,
1432b8e80941Smrg                bool has_bit6_swizzling);
1433b8e80941Smrg
1434b8e80941Smrgisl_sample_count_mask_t ATTRIBUTE_CONST
1435b8e80941Smrgisl_device_get_sample_counts(struct isl_device *dev);
1436b8e80941Smrg
1437b8e80941Smrgstatic inline const struct isl_format_layout * ATTRIBUTE_CONST
1438b8e80941Smrgisl_format_get_layout(enum isl_format fmt)
1439b8e80941Smrg{
1440b8e80941Smrg   assert(fmt != ISL_FORMAT_UNSUPPORTED);
1441b8e80941Smrg   assert(fmt < ISL_NUM_FORMATS);
1442b8e80941Smrg   return &isl_format_layouts[fmt];
1443b8e80941Smrg}
1444b8e80941Smrg
1445b8e80941Smrgbool isl_format_is_valid(enum isl_format);
1446b8e80941Smrg
1447b8e80941Smrgstatic inline const char * ATTRIBUTE_CONST
1448b8e80941Smrgisl_format_get_name(enum isl_format fmt)
1449b8e80941Smrg{
1450b8e80941Smrg   return isl_format_get_layout(fmt)->name;
1451b8e80941Smrg}
1452b8e80941Smrg
1453b8e80941Smrgbool isl_format_supports_rendering(const struct gen_device_info *devinfo,
1454b8e80941Smrg                                   enum isl_format format);
1455b8e80941Smrgbool isl_format_supports_alpha_blending(const struct gen_device_info *devinfo,
1456b8e80941Smrg                                        enum isl_format format);
1457b8e80941Smrgbool isl_format_supports_sampling(const struct gen_device_info *devinfo,
1458b8e80941Smrg                                  enum isl_format format);
1459b8e80941Smrgbool isl_format_supports_filtering(const struct gen_device_info *devinfo,
1460b8e80941Smrg                                   enum isl_format format);
1461b8e80941Smrgbool isl_format_supports_vertex_fetch(const struct gen_device_info *devinfo,
1462b8e80941Smrg                                      enum isl_format format);
1463b8e80941Smrgbool isl_format_supports_typed_writes(const struct gen_device_info *devinfo,
1464b8e80941Smrg                                      enum isl_format format);
1465b8e80941Smrgbool isl_format_supports_typed_reads(const struct gen_device_info *devinfo,
1466b8e80941Smrg                                     enum isl_format format);
1467b8e80941Smrgbool isl_format_supports_ccs_d(const struct gen_device_info *devinfo,
1468b8e80941Smrg                               enum isl_format format);
1469b8e80941Smrgbool isl_format_supports_ccs_e(const struct gen_device_info *devinfo,
1470b8e80941Smrg                               enum isl_format format);
1471b8e80941Smrgbool isl_format_supports_multisampling(const struct gen_device_info *devinfo,
1472b8e80941Smrg                                       enum isl_format format);
1473b8e80941Smrg
1474b8e80941Smrgbool isl_formats_are_ccs_e_compatible(const struct gen_device_info *devinfo,
1475b8e80941Smrg                                      enum isl_format format1,
1476b8e80941Smrg                                      enum isl_format format2);
1477b8e80941Smrg
1478b8e80941Smrgbool isl_format_has_unorm_channel(enum isl_format fmt) ATTRIBUTE_CONST;
1479b8e80941Smrgbool isl_format_has_snorm_channel(enum isl_format fmt) ATTRIBUTE_CONST;
1480b8e80941Smrgbool isl_format_has_ufloat_channel(enum isl_format fmt) ATTRIBUTE_CONST;
1481b8e80941Smrgbool isl_format_has_sfloat_channel(enum isl_format fmt) ATTRIBUTE_CONST;
1482b8e80941Smrgbool isl_format_has_uint_channel(enum isl_format fmt) ATTRIBUTE_CONST;
1483b8e80941Smrgbool isl_format_has_sint_channel(enum isl_format fmt) ATTRIBUTE_CONST;
1484b8e80941Smrg
1485b8e80941Smrgstatic inline bool
1486b8e80941Smrgisl_format_has_normalized_channel(enum isl_format fmt)
1487b8e80941Smrg{
1488b8e80941Smrg   return isl_format_has_unorm_channel(fmt) ||
1489b8e80941Smrg          isl_format_has_snorm_channel(fmt);
1490b8e80941Smrg}
1491b8e80941Smrg
1492b8e80941Smrgstatic inline bool
1493b8e80941Smrgisl_format_has_float_channel(enum isl_format fmt)
1494b8e80941Smrg{
1495b8e80941Smrg   return isl_format_has_ufloat_channel(fmt) ||
1496b8e80941Smrg          isl_format_has_sfloat_channel(fmt);
1497b8e80941Smrg}
1498b8e80941Smrg
1499b8e80941Smrgstatic inline bool
1500b8e80941Smrgisl_format_has_int_channel(enum isl_format fmt)
1501b8e80941Smrg{
1502b8e80941Smrg   return isl_format_has_uint_channel(fmt) ||
1503b8e80941Smrg          isl_format_has_sint_channel(fmt);
1504b8e80941Smrg}
1505b8e80941Smrg
1506b8e80941Smrgbool isl_format_has_color_component(enum isl_format fmt,
1507b8e80941Smrg                                    int component) ATTRIBUTE_CONST;
1508b8e80941Smrg
1509b8e80941Smrgunsigned isl_format_get_num_channels(enum isl_format fmt);
1510b8e80941Smrg
1511b8e80941Smrguint32_t isl_format_get_depth_format(enum isl_format fmt, bool has_stencil);
1512b8e80941Smrg
1513b8e80941Smrgstatic inline bool
1514b8e80941Smrgisl_format_is_compressed(enum isl_format fmt)
1515b8e80941Smrg{
1516b8e80941Smrg   const struct isl_format_layout *fmtl = isl_format_get_layout(fmt);
1517b8e80941Smrg
1518b8e80941Smrg   return fmtl->txc != ISL_TXC_NONE;
1519b8e80941Smrg}
1520b8e80941Smrg
1521b8e80941Smrgstatic inline bool
1522b8e80941Smrgisl_format_has_bc_compression(enum isl_format fmt)
1523b8e80941Smrg{
1524b8e80941Smrg   switch (isl_format_get_layout(fmt)->txc) {
1525b8e80941Smrg   case ISL_TXC_DXT1:
1526b8e80941Smrg   case ISL_TXC_DXT3:
1527b8e80941Smrg   case ISL_TXC_DXT5:
1528b8e80941Smrg      return true;
1529b8e80941Smrg   case ISL_TXC_NONE:
1530b8e80941Smrg   case ISL_TXC_FXT1:
1531b8e80941Smrg   case ISL_TXC_RGTC1:
1532b8e80941Smrg   case ISL_TXC_RGTC2:
1533b8e80941Smrg   case ISL_TXC_BPTC:
1534b8e80941Smrg   case ISL_TXC_ETC1:
1535b8e80941Smrg   case ISL_TXC_ETC2:
1536b8e80941Smrg   case ISL_TXC_ASTC:
1537b8e80941Smrg      return false;
1538b8e80941Smrg
1539b8e80941Smrg   case ISL_TXC_HIZ:
1540b8e80941Smrg   case ISL_TXC_MCS:
1541b8e80941Smrg   case ISL_TXC_CCS:
1542b8e80941Smrg      unreachable("Should not be called on an aux surface");
1543b8e80941Smrg   }
1544b8e80941Smrg
1545b8e80941Smrg   unreachable("bad texture compression mode");
1546b8e80941Smrg   return false;
1547b8e80941Smrg}
1548b8e80941Smrg
1549b8e80941Smrgstatic inline bool
1550b8e80941Smrgisl_format_is_yuv(enum isl_format fmt)
1551b8e80941Smrg{
1552b8e80941Smrg   const struct isl_format_layout *fmtl = isl_format_get_layout(fmt);
1553b8e80941Smrg
1554b8e80941Smrg   return fmtl->colorspace == ISL_COLORSPACE_YUV;
1555b8e80941Smrg}
1556b8e80941Smrg
1557b8e80941Smrgstatic inline bool
1558b8e80941Smrgisl_format_block_is_1x1x1(enum isl_format fmt)
1559b8e80941Smrg{
1560b8e80941Smrg   const struct isl_format_layout *fmtl = isl_format_get_layout(fmt);
1561b8e80941Smrg
1562b8e80941Smrg   return fmtl->bw == 1 && fmtl->bh == 1 && fmtl->bd == 1;
1563b8e80941Smrg}
1564b8e80941Smrg
1565b8e80941Smrgstatic inline bool
1566b8e80941Smrgisl_format_is_srgb(enum isl_format fmt)
1567b8e80941Smrg{
1568b8e80941Smrg   return isl_format_get_layout(fmt)->colorspace == ISL_COLORSPACE_SRGB;
1569b8e80941Smrg}
1570b8e80941Smrg
1571b8e80941Smrgenum isl_format isl_format_srgb_to_linear(enum isl_format fmt);
1572b8e80941Smrg
1573b8e80941Smrgstatic inline bool
1574b8e80941Smrgisl_format_is_rgb(enum isl_format fmt)
1575b8e80941Smrg{
1576b8e80941Smrg   if (isl_format_is_yuv(fmt))
1577b8e80941Smrg      return false;
1578b8e80941Smrg
1579b8e80941Smrg   const struct isl_format_layout *fmtl = isl_format_get_layout(fmt);
1580b8e80941Smrg
1581b8e80941Smrg   return fmtl->channels.r.bits > 0 &&
1582b8e80941Smrg          fmtl->channels.g.bits > 0 &&
1583b8e80941Smrg          fmtl->channels.b.bits > 0 &&
1584b8e80941Smrg          fmtl->channels.a.bits == 0;
1585b8e80941Smrg}
1586b8e80941Smrg
1587b8e80941Smrgstatic inline bool
1588b8e80941Smrgisl_format_is_rgbx(enum isl_format fmt)
1589b8e80941Smrg{
1590b8e80941Smrg   const struct isl_format_layout *fmtl = isl_format_get_layout(fmt);
1591b8e80941Smrg
1592b8e80941Smrg   return fmtl->channels.r.bits > 0 &&
1593b8e80941Smrg          fmtl->channels.g.bits > 0 &&
1594b8e80941Smrg          fmtl->channels.b.bits > 0 &&
1595b8e80941Smrg          fmtl->channels.a.bits > 0 &&
1596b8e80941Smrg          fmtl->channels.a.type == ISL_VOID;
1597b8e80941Smrg}
1598b8e80941Smrg
1599b8e80941Smrgenum isl_format isl_format_rgb_to_rgba(enum isl_format rgb) ATTRIBUTE_CONST;
1600b8e80941Smrgenum isl_format isl_format_rgb_to_rgbx(enum isl_format rgb) ATTRIBUTE_CONST;
1601b8e80941Smrgenum isl_format isl_format_rgbx_to_rgba(enum isl_format rgb) ATTRIBUTE_CONST;
1602b8e80941Smrg
1603b8e80941Smrgvoid isl_color_value_pack(const union isl_color_value *value,
1604b8e80941Smrg                          enum isl_format format,
1605b8e80941Smrg                          uint32_t *data_out);
1606b8e80941Smrgvoid isl_color_value_unpack(union isl_color_value *value,
1607b8e80941Smrg                            enum isl_format format,
1608b8e80941Smrg                            const uint32_t *data_in);
1609b8e80941Smrg
1610b8e80941Smrgbool isl_is_storage_image_format(enum isl_format fmt);
1611b8e80941Smrg
1612b8e80941Smrgenum isl_format
1613b8e80941Smrgisl_lower_storage_image_format(const struct gen_device_info *devinfo,
1614b8e80941Smrg                               enum isl_format fmt);
1615b8e80941Smrg
1616b8e80941Smrg/* Returns true if this hardware supports typed load/store on a format with
1617b8e80941Smrg * the same size as the given format.
1618b8e80941Smrg */
1619b8e80941Smrgbool
1620b8e80941Smrgisl_has_matching_typed_storage_image_format(const struct gen_device_info *devinfo,
1621b8e80941Smrg                                            enum isl_format fmt);
1622b8e80941Smrg
1623b8e80941Smrgstatic inline bool
1624b8e80941Smrgisl_tiling_is_any_y(enum isl_tiling tiling)
1625b8e80941Smrg{
1626b8e80941Smrg   return (1u << tiling) & ISL_TILING_ANY_Y_MASK;
1627b8e80941Smrg}
1628b8e80941Smrg
1629b8e80941Smrgstatic inline bool
1630b8e80941Smrgisl_tiling_is_std_y(enum isl_tiling tiling)
1631b8e80941Smrg{
1632b8e80941Smrg   return (1u << tiling) & ISL_TILING_STD_Y_MASK;
1633b8e80941Smrg}
1634b8e80941Smrg
1635b8e80941Smrguint32_t
1636b8e80941Smrgisl_tiling_to_i915_tiling(enum isl_tiling tiling);
1637b8e80941Smrg
1638b8e80941Smrgenum isl_tiling
1639b8e80941Smrgisl_tiling_from_i915_tiling(uint32_t tiling);
1640b8e80941Smrg
1641b8e80941Smrgconst struct isl_drm_modifier_info * ATTRIBUTE_CONST
1642b8e80941Smrgisl_drm_modifier_get_info(uint64_t modifier);
1643b8e80941Smrg
1644b8e80941Smrgstatic inline bool
1645b8e80941Smrgisl_drm_modifier_has_aux(uint64_t modifier)
1646b8e80941Smrg{
1647b8e80941Smrg   return isl_drm_modifier_get_info(modifier)->aux_usage != ISL_AUX_USAGE_NONE;
1648b8e80941Smrg}
1649b8e80941Smrg
1650b8e80941Smrg/** Returns the default isl_aux_state for the given modifier.
1651b8e80941Smrg *
1652b8e80941Smrg * If we have a modifier which supports compression, then the auxiliary data
1653b8e80941Smrg * could be in state other than ISL_AUX_STATE_AUX_INVALID.  In particular, it
1654b8e80941Smrg * can be in any of the following:
1655b8e80941Smrg *
1656b8e80941Smrg *  - ISL_AUX_STATE_CLEAR
1657b8e80941Smrg *  - ISL_AUX_STATE_PARTIAL_CLEAR
1658b8e80941Smrg *  - ISL_AUX_STATE_COMPRESSED_CLEAR
1659b8e80941Smrg *  - ISL_AUX_STATE_COMPRESSED_NO_CLEAR
1660b8e80941Smrg *  - ISL_AUX_STATE_RESOLVED
1661b8e80941Smrg *  - ISL_AUX_STATE_PASS_THROUGH
1662b8e80941Smrg *
1663b8e80941Smrg * If the modifier does not support fast-clears, then we are guaranteed
1664b8e80941Smrg * that the surface is at least partially resolved and the first three not
1665b8e80941Smrg * possible.  We return ISL_AUX_STATE_COMPRESSED_CLEAR if the modifier
1666b8e80941Smrg * supports fast clears and ISL_AUX_STATE_COMPRESSED_NO_CLEAR if it does not
1667b8e80941Smrg * because they are the least common denominator of the set of possible aux
1668b8e80941Smrg * states and will yield a valid interpretation of the aux data.
1669b8e80941Smrg *
1670b8e80941Smrg * For modifiers with no aux support, ISL_AUX_STATE_AUX_INVALID is returned.
1671b8e80941Smrg */
1672b8e80941Smrgstatic inline enum isl_aux_state
1673b8e80941Smrgisl_drm_modifier_get_default_aux_state(uint64_t modifier)
1674b8e80941Smrg{
1675b8e80941Smrg   const struct isl_drm_modifier_info *mod_info =
1676b8e80941Smrg      isl_drm_modifier_get_info(modifier);
1677b8e80941Smrg
1678b8e80941Smrg   if (!mod_info || mod_info->aux_usage == ISL_AUX_USAGE_NONE)
1679b8e80941Smrg      return ISL_AUX_STATE_AUX_INVALID;
1680b8e80941Smrg
1681b8e80941Smrg   assert(mod_info->aux_usage == ISL_AUX_USAGE_CCS_E);
1682b8e80941Smrg   return mod_info->supports_clear_color ? ISL_AUX_STATE_COMPRESSED_CLEAR :
1683b8e80941Smrg                                           ISL_AUX_STATE_COMPRESSED_NO_CLEAR;
1684b8e80941Smrg}
1685b8e80941Smrg
1686b8e80941Smrgstruct isl_extent2d ATTRIBUTE_CONST
1687b8e80941Smrgisl_get_interleaved_msaa_px_size_sa(uint32_t samples);
1688b8e80941Smrg
1689b8e80941Smrgstatic inline bool
1690b8e80941Smrgisl_surf_usage_is_display(isl_surf_usage_flags_t usage)
1691b8e80941Smrg{
1692b8e80941Smrg   return usage & ISL_SURF_USAGE_DISPLAY_BIT;
1693b8e80941Smrg}
1694b8e80941Smrg
1695b8e80941Smrgstatic inline bool
1696b8e80941Smrgisl_surf_usage_is_depth(isl_surf_usage_flags_t usage)
1697b8e80941Smrg{
1698b8e80941Smrg   return usage & ISL_SURF_USAGE_DEPTH_BIT;
1699b8e80941Smrg}
1700b8e80941Smrg
1701b8e80941Smrgstatic inline bool
1702b8e80941Smrgisl_surf_usage_is_stencil(isl_surf_usage_flags_t usage)
1703b8e80941Smrg{
1704b8e80941Smrg   return usage & ISL_SURF_USAGE_STENCIL_BIT;
1705b8e80941Smrg}
1706b8e80941Smrg
1707b8e80941Smrgstatic inline bool
1708b8e80941Smrgisl_surf_usage_is_depth_and_stencil(isl_surf_usage_flags_t usage)
1709b8e80941Smrg{
1710b8e80941Smrg   return (usage & ISL_SURF_USAGE_DEPTH_BIT) &&
1711b8e80941Smrg          (usage & ISL_SURF_USAGE_STENCIL_BIT);
1712b8e80941Smrg}
1713b8e80941Smrg
1714b8e80941Smrgstatic inline bool
1715b8e80941Smrgisl_surf_usage_is_depth_or_stencil(isl_surf_usage_flags_t usage)
1716b8e80941Smrg{
1717b8e80941Smrg   return usage & (ISL_SURF_USAGE_DEPTH_BIT | ISL_SURF_USAGE_STENCIL_BIT);
1718b8e80941Smrg}
1719b8e80941Smrg
1720b8e80941Smrgstatic inline bool
1721b8e80941Smrgisl_surf_info_is_z16(const struct isl_surf_init_info *info)
1722b8e80941Smrg{
1723b8e80941Smrg   return (info->usage & ISL_SURF_USAGE_DEPTH_BIT) &&
1724b8e80941Smrg          (info->format == ISL_FORMAT_R16_UNORM);
1725b8e80941Smrg}
1726b8e80941Smrg
1727b8e80941Smrgstatic inline bool
1728b8e80941Smrgisl_surf_info_is_z32_float(const struct isl_surf_init_info *info)
1729b8e80941Smrg{
1730b8e80941Smrg   return (info->usage & ISL_SURF_USAGE_DEPTH_BIT) &&
1731b8e80941Smrg          (info->format == ISL_FORMAT_R32_FLOAT);
1732b8e80941Smrg}
1733b8e80941Smrg
1734b8e80941Smrgstatic inline struct isl_extent2d
1735b8e80941Smrgisl_extent2d(uint32_t width, uint32_t height)
1736b8e80941Smrg{
1737b8e80941Smrg   struct isl_extent2d e = { { 0 } };
1738b8e80941Smrg
1739b8e80941Smrg   e.width = width;
1740b8e80941Smrg   e.height = height;
1741b8e80941Smrg
1742b8e80941Smrg   return e;
1743b8e80941Smrg}
1744b8e80941Smrg
1745b8e80941Smrgstatic inline struct isl_extent3d
1746b8e80941Smrgisl_extent3d(uint32_t width, uint32_t height, uint32_t depth)
1747b8e80941Smrg{
1748b8e80941Smrg   struct isl_extent3d e = { { 0 } };
1749b8e80941Smrg
1750b8e80941Smrg   e.width = width;
1751b8e80941Smrg   e.height = height;
1752b8e80941Smrg   e.depth = depth;
1753b8e80941Smrg
1754b8e80941Smrg   return e;
1755b8e80941Smrg}
1756b8e80941Smrg
1757b8e80941Smrgstatic inline struct isl_extent4d
1758b8e80941Smrgisl_extent4d(uint32_t width, uint32_t height, uint32_t depth,
1759b8e80941Smrg             uint32_t array_len)
1760b8e80941Smrg{
1761b8e80941Smrg   struct isl_extent4d e = { { 0 } };
1762b8e80941Smrg
1763b8e80941Smrg   e.width = width;
1764b8e80941Smrg   e.height = height;
1765b8e80941Smrg   e.depth = depth;
1766b8e80941Smrg   e.array_len = array_len;
1767b8e80941Smrg
1768b8e80941Smrg   return e;
1769b8e80941Smrg}
1770b8e80941Smrg
1771b8e80941Smrgbool isl_color_value_is_zero(union isl_color_value value,
1772b8e80941Smrg                             enum isl_format format);
1773b8e80941Smrg
1774b8e80941Smrgbool isl_color_value_is_zero_one(union isl_color_value value,
1775b8e80941Smrg                                 enum isl_format format);
1776b8e80941Smrg
1777b8e80941Smrgstatic inline bool
1778b8e80941Smrgisl_swizzle_is_identity(struct isl_swizzle swizzle)
1779b8e80941Smrg{
1780b8e80941Smrg   return swizzle.r == ISL_CHANNEL_SELECT_RED &&
1781b8e80941Smrg          swizzle.g == ISL_CHANNEL_SELECT_GREEN &&
1782b8e80941Smrg          swizzle.b == ISL_CHANNEL_SELECT_BLUE &&
1783b8e80941Smrg          swizzle.a == ISL_CHANNEL_SELECT_ALPHA;
1784b8e80941Smrg}
1785b8e80941Smrg
1786b8e80941Smrgbool
1787b8e80941Smrgisl_swizzle_supports_rendering(const struct gen_device_info *devinfo,
1788b8e80941Smrg                               struct isl_swizzle swizzle);
1789b8e80941Smrg
1790b8e80941Smrgstruct isl_swizzle
1791b8e80941Smrgisl_swizzle_compose(struct isl_swizzle first, struct isl_swizzle second);
1792b8e80941Smrgstruct isl_swizzle
1793b8e80941Smrgisl_swizzle_invert(struct isl_swizzle swizzle);
1794b8e80941Smrg
1795b8e80941Smrg#define isl_surf_init(dev, surf, ...) \
1796b8e80941Smrg   isl_surf_init_s((dev), (surf), \
1797b8e80941Smrg                   &(struct isl_surf_init_info) {  __VA_ARGS__ });
1798b8e80941Smrg
1799b8e80941Smrgbool
1800b8e80941Smrgisl_surf_init_s(const struct isl_device *dev,
1801b8e80941Smrg                struct isl_surf *surf,
1802b8e80941Smrg                const struct isl_surf_init_info *restrict info);
1803b8e80941Smrg
1804b8e80941Smrgvoid
1805b8e80941Smrgisl_surf_get_tile_info(const struct isl_surf *surf,
1806b8e80941Smrg                       struct isl_tile_info *tile_info);
1807b8e80941Smrg
1808b8e80941Smrgbool
1809b8e80941Smrgisl_surf_get_hiz_surf(const struct isl_device *dev,
1810b8e80941Smrg                      const struct isl_surf *surf,
1811b8e80941Smrg                      struct isl_surf *hiz_surf);
1812b8e80941Smrg
1813b8e80941Smrgbool
1814b8e80941Smrgisl_surf_get_mcs_surf(const struct isl_device *dev,
1815b8e80941Smrg                      const struct isl_surf *surf,
1816b8e80941Smrg                      struct isl_surf *mcs_surf);
1817b8e80941Smrg
1818b8e80941Smrgbool
1819b8e80941Smrgisl_surf_get_ccs_surf(const struct isl_device *dev,
1820b8e80941Smrg                      const struct isl_surf *surf,
1821b8e80941Smrg                      struct isl_surf *ccs_surf,
1822b8e80941Smrg                      uint32_t row_pitch_B /**< Ignored if 0 */);
1823b8e80941Smrg
1824b8e80941Smrg#define isl_surf_fill_state(dev, state, ...) \
1825b8e80941Smrg   isl_surf_fill_state_s((dev), (state), \
1826b8e80941Smrg                         &(struct isl_surf_fill_state_info) {  __VA_ARGS__ });
1827b8e80941Smrg
1828b8e80941Smrgvoid
1829b8e80941Smrgisl_surf_fill_state_s(const struct isl_device *dev, void *state,
1830b8e80941Smrg                      const struct isl_surf_fill_state_info *restrict info);
1831b8e80941Smrg
1832b8e80941Smrg#define isl_buffer_fill_state(dev, state, ...) \
1833b8e80941Smrg   isl_buffer_fill_state_s((dev), (state), \
1834b8e80941Smrg                           &(struct isl_buffer_fill_state_info) {  __VA_ARGS__ });
1835b8e80941Smrg
1836b8e80941Smrgvoid
1837b8e80941Smrgisl_buffer_fill_state_s(const struct isl_device *dev, void *state,
1838b8e80941Smrg                        const struct isl_buffer_fill_state_info *restrict info);
1839b8e80941Smrg
1840b8e80941Smrgvoid
1841b8e80941Smrgisl_null_fill_state(const struct isl_device *dev, void *state,
1842b8e80941Smrg                    struct isl_extent3d size);
1843b8e80941Smrg
1844b8e80941Smrg#define isl_emit_depth_stencil_hiz(dev, batch, ...) \
1845b8e80941Smrg   isl_emit_depth_stencil_hiz_s((dev), (batch), \
1846b8e80941Smrg                                &(struct isl_depth_stencil_hiz_emit_info) {  __VA_ARGS__ })
1847b8e80941Smrg
1848b8e80941Smrgvoid
1849b8e80941Smrgisl_emit_depth_stencil_hiz_s(const struct isl_device *dev, void *batch,
1850b8e80941Smrg                             const struct isl_depth_stencil_hiz_emit_info *restrict info);
1851b8e80941Smrg
1852b8e80941Smrgvoid
1853b8e80941Smrgisl_surf_fill_image_param(const struct isl_device *dev,
1854b8e80941Smrg                          struct brw_image_param *param,
1855b8e80941Smrg                          const struct isl_surf *surf,
1856b8e80941Smrg                          const struct isl_view *view);
1857b8e80941Smrg
1858b8e80941Smrgvoid
1859b8e80941Smrgisl_buffer_fill_image_param(const struct isl_device *dev,
1860b8e80941Smrg                            struct brw_image_param *param,
1861b8e80941Smrg                            enum isl_format format,
1862b8e80941Smrg                            uint64_t size);
1863b8e80941Smrg
1864b8e80941Smrg/**
1865b8e80941Smrg * Alignment of the upper-left sample of each subimage, in units of surface
1866b8e80941Smrg * elements.
1867b8e80941Smrg */
1868b8e80941Smrgstatic inline struct isl_extent3d
1869b8e80941Smrgisl_surf_get_image_alignment_el(const struct isl_surf *surf)
1870b8e80941Smrg{
1871b8e80941Smrg   return surf->image_alignment_el;
1872b8e80941Smrg}
1873b8e80941Smrg
1874b8e80941Smrg/**
1875b8e80941Smrg * Alignment of the upper-left sample of each subimage, in units of surface
1876b8e80941Smrg * samples.
1877b8e80941Smrg */
1878b8e80941Smrgstatic inline struct isl_extent3d
1879b8e80941Smrgisl_surf_get_image_alignment_sa(const struct isl_surf *surf)
1880b8e80941Smrg{
1881b8e80941Smrg   const struct isl_format_layout *fmtl = isl_format_get_layout(surf->format);
1882b8e80941Smrg
1883b8e80941Smrg   return isl_extent3d(fmtl->bw * surf->image_alignment_el.w,
1884b8e80941Smrg                       fmtl->bh * surf->image_alignment_el.h,
1885b8e80941Smrg                       fmtl->bd * surf->image_alignment_el.d);
1886b8e80941Smrg}
1887b8e80941Smrg
1888b8e80941Smrg/**
1889b8e80941Smrg * Logical extent of level 0 in units of surface elements.
1890b8e80941Smrg */
1891b8e80941Smrgstatic inline struct isl_extent4d
1892b8e80941Smrgisl_surf_get_logical_level0_el(const struct isl_surf *surf)
1893b8e80941Smrg{
1894b8e80941Smrg   const struct isl_format_layout *fmtl = isl_format_get_layout(surf->format);
1895b8e80941Smrg
1896b8e80941Smrg   return isl_extent4d(DIV_ROUND_UP(surf->logical_level0_px.w, fmtl->bw),
1897b8e80941Smrg                       DIV_ROUND_UP(surf->logical_level0_px.h, fmtl->bh),
1898b8e80941Smrg                       DIV_ROUND_UP(surf->logical_level0_px.d, fmtl->bd),
1899b8e80941Smrg                       surf->logical_level0_px.a);
1900b8e80941Smrg}
1901b8e80941Smrg
1902b8e80941Smrg/**
1903b8e80941Smrg * Physical extent of level 0 in units of surface elements.
1904b8e80941Smrg */
1905b8e80941Smrgstatic inline struct isl_extent4d
1906b8e80941Smrgisl_surf_get_phys_level0_el(const struct isl_surf *surf)
1907b8e80941Smrg{
1908b8e80941Smrg   const struct isl_format_layout *fmtl = isl_format_get_layout(surf->format);
1909b8e80941Smrg
1910b8e80941Smrg   return isl_extent4d(DIV_ROUND_UP(surf->phys_level0_sa.w, fmtl->bw),
1911b8e80941Smrg                       DIV_ROUND_UP(surf->phys_level0_sa.h, fmtl->bh),
1912b8e80941Smrg                       DIV_ROUND_UP(surf->phys_level0_sa.d, fmtl->bd),
1913b8e80941Smrg                       surf->phys_level0_sa.a);
1914b8e80941Smrg}
1915b8e80941Smrg
1916b8e80941Smrg/**
1917b8e80941Smrg * Pitch between vertically adjacent surface elements, in bytes.
1918b8e80941Smrg */
1919b8e80941Smrgstatic inline uint32_t
1920b8e80941Smrgisl_surf_get_row_pitch_B(const struct isl_surf *surf)
1921b8e80941Smrg{
1922b8e80941Smrg   return surf->row_pitch_B;
1923b8e80941Smrg}
1924b8e80941Smrg
1925b8e80941Smrg/**
1926b8e80941Smrg * Pitch between vertically adjacent surface elements, in units of surface elements.
1927b8e80941Smrg */
1928b8e80941Smrgstatic inline uint32_t
1929b8e80941Smrgisl_surf_get_row_pitch_el(const struct isl_surf *surf)
1930b8e80941Smrg{
1931b8e80941Smrg   const struct isl_format_layout *fmtl = isl_format_get_layout(surf->format);
1932b8e80941Smrg
1933b8e80941Smrg   assert(surf->row_pitch_B % (fmtl->bpb / 8) == 0);
1934b8e80941Smrg   return surf->row_pitch_B / (fmtl->bpb / 8);
1935b8e80941Smrg}
1936b8e80941Smrg
1937b8e80941Smrg/**
1938b8e80941Smrg * Pitch between physical array slices, in rows of surface elements.
1939b8e80941Smrg */
1940b8e80941Smrgstatic inline uint32_t
1941b8e80941Smrgisl_surf_get_array_pitch_el_rows(const struct isl_surf *surf)
1942b8e80941Smrg{
1943b8e80941Smrg   return surf->array_pitch_el_rows;
1944b8e80941Smrg}
1945b8e80941Smrg
1946b8e80941Smrg/**
1947b8e80941Smrg * Pitch between physical array slices, in units of surface elements.
1948b8e80941Smrg */
1949b8e80941Smrgstatic inline uint32_t
1950b8e80941Smrgisl_surf_get_array_pitch_el(const struct isl_surf *surf)
1951b8e80941Smrg{
1952b8e80941Smrg   return isl_surf_get_array_pitch_el_rows(surf) *
1953b8e80941Smrg          isl_surf_get_row_pitch_el(surf);
1954b8e80941Smrg}
1955b8e80941Smrg
1956b8e80941Smrg/**
1957b8e80941Smrg * Pitch between physical array slices, in rows of surface samples.
1958b8e80941Smrg */
1959b8e80941Smrgstatic inline uint32_t
1960b8e80941Smrgisl_surf_get_array_pitch_sa_rows(const struct isl_surf *surf)
1961b8e80941Smrg{
1962b8e80941Smrg   const struct isl_format_layout *fmtl = isl_format_get_layout(surf->format);
1963b8e80941Smrg   return fmtl->bh * isl_surf_get_array_pitch_el_rows(surf);
1964b8e80941Smrg}
1965b8e80941Smrg
1966b8e80941Smrg/**
1967b8e80941Smrg * Pitch between physical array slices, in bytes.
1968b8e80941Smrg */
1969b8e80941Smrgstatic inline uint32_t
1970b8e80941Smrgisl_surf_get_array_pitch(const struct isl_surf *surf)
1971b8e80941Smrg{
1972b8e80941Smrg   return isl_surf_get_array_pitch_sa_rows(surf) * surf->row_pitch_B;
1973b8e80941Smrg}
1974b8e80941Smrg
1975b8e80941Smrg/**
1976b8e80941Smrg * Calculate the offset, in units of surface samples, to a subimage in the
1977b8e80941Smrg * surface.
1978b8e80941Smrg *
1979b8e80941Smrg * @invariant level < surface levels
1980b8e80941Smrg * @invariant logical_array_layer < logical array length of surface
1981b8e80941Smrg * @invariant logical_z_offset_px < logical depth of surface at level
1982b8e80941Smrg */
1983b8e80941Smrgvoid
1984b8e80941Smrgisl_surf_get_image_offset_sa(const struct isl_surf *surf,
1985b8e80941Smrg                             uint32_t level,
1986b8e80941Smrg                             uint32_t logical_array_layer,
1987b8e80941Smrg                             uint32_t logical_z_offset_px,
1988b8e80941Smrg                             uint32_t *x_offset_sa,
1989b8e80941Smrg                             uint32_t *y_offset_sa);
1990b8e80941Smrg
1991b8e80941Smrg/**
1992b8e80941Smrg * Calculate the offset, in units of surface elements, to a subimage in the
1993b8e80941Smrg * surface.
1994b8e80941Smrg *
1995b8e80941Smrg * @invariant level < surface levels
1996b8e80941Smrg * @invariant logical_array_layer < logical array length of surface
1997b8e80941Smrg * @invariant logical_z_offset_px < logical depth of surface at level
1998b8e80941Smrg */
1999b8e80941Smrgvoid
2000b8e80941Smrgisl_surf_get_image_offset_el(const struct isl_surf *surf,
2001b8e80941Smrg                             uint32_t level,
2002b8e80941Smrg                             uint32_t logical_array_layer,
2003b8e80941Smrg                             uint32_t logical_z_offset_px,
2004b8e80941Smrg                             uint32_t *x_offset_el,
2005b8e80941Smrg                             uint32_t *y_offset_el);
2006b8e80941Smrg
2007b8e80941Smrg/**
2008b8e80941Smrg * Calculate the offset, in bytes and intratile surface samples, to a
2009b8e80941Smrg * subimage in the surface.
2010b8e80941Smrg *
2011b8e80941Smrg * This is equivalent to calling isl_surf_get_image_offset_el, passing the
2012b8e80941Smrg * result to isl_tiling_get_intratile_offset_el, and converting the tile
2013b8e80941Smrg * offsets to samples.
2014b8e80941Smrg *
2015b8e80941Smrg * @invariant level < surface levels
2016b8e80941Smrg * @invariant logical_array_layer < logical array length of surface
2017b8e80941Smrg * @invariant logical_z_offset_px < logical depth of surface at level
2018b8e80941Smrg */
2019b8e80941Smrgvoid
2020b8e80941Smrgisl_surf_get_image_offset_B_tile_sa(const struct isl_surf *surf,
2021b8e80941Smrg                                    uint32_t level,
2022b8e80941Smrg                                    uint32_t logical_array_layer,
2023b8e80941Smrg                                    uint32_t logical_z_offset_px,
2024b8e80941Smrg                                    uint32_t *offset_B,
2025b8e80941Smrg                                    uint32_t *x_offset_sa,
2026b8e80941Smrg                                    uint32_t *y_offset_sa);
2027b8e80941Smrg
2028b8e80941Smrg/**
2029b8e80941Smrg * Create an isl_surf that represents a particular subimage in the surface.
2030b8e80941Smrg *
2031b8e80941Smrg * The newly created surface will have a single miplevel and array slice.  The
2032b8e80941Smrg * surface lives at the returned byte and intratile offsets, in samples.
2033b8e80941Smrg *
2034b8e80941Smrg * It is safe to call this function with surf == image_surf.
2035b8e80941Smrg *
2036b8e80941Smrg * @invariant level < surface levels
2037b8e80941Smrg * @invariant logical_array_layer < logical array length of surface
2038b8e80941Smrg * @invariant logical_z_offset_px < logical depth of surface at level
2039b8e80941Smrg */
2040b8e80941Smrgvoid
2041b8e80941Smrgisl_surf_get_image_surf(const struct isl_device *dev,
2042b8e80941Smrg                        const struct isl_surf *surf,
2043b8e80941Smrg                        uint32_t level,
2044b8e80941Smrg                        uint32_t logical_array_layer,
2045b8e80941Smrg                        uint32_t logical_z_offset_px,
2046b8e80941Smrg                        struct isl_surf *image_surf,
2047b8e80941Smrg                        uint32_t *offset_B,
2048b8e80941Smrg                        uint32_t *x_offset_sa,
2049b8e80941Smrg                        uint32_t *y_offset_sa);
2050b8e80941Smrg
2051b8e80941Smrg/**
2052b8e80941Smrg * @brief Calculate the intratile offsets to a surface.
2053b8e80941Smrg *
2054b8e80941Smrg * In @a base_address_offset return the offset from the base of the surface to
2055b8e80941Smrg * the base address of the first tile of the subimage. In @a x_offset_B and
2056b8e80941Smrg * @a y_offset_rows, return the offset, in units of bytes and rows, from the
2057b8e80941Smrg * tile's base to the subimage's first surface element. The x and y offsets
2058b8e80941Smrg * are intratile offsets; that is, they do not exceed the boundary of the
2059b8e80941Smrg * surface's tiling format.
2060b8e80941Smrg */
2061b8e80941Smrgvoid
2062b8e80941Smrgisl_tiling_get_intratile_offset_el(enum isl_tiling tiling,
2063b8e80941Smrg                                   uint32_t bpb,
2064b8e80941Smrg                                   uint32_t row_pitch_B,
2065b8e80941Smrg                                   uint32_t total_x_offset_el,
2066b8e80941Smrg                                   uint32_t total_y_offset_el,
2067b8e80941Smrg                                   uint32_t *base_address_offset,
2068b8e80941Smrg                                   uint32_t *x_offset_el,
2069b8e80941Smrg                                   uint32_t *y_offset_el);
2070b8e80941Smrg
2071b8e80941Smrgstatic inline void
2072b8e80941Smrgisl_tiling_get_intratile_offset_sa(enum isl_tiling tiling,
2073b8e80941Smrg                                   enum isl_format format,
2074b8e80941Smrg                                   uint32_t row_pitch_B,
2075b8e80941Smrg                                   uint32_t total_x_offset_sa,
2076b8e80941Smrg                                   uint32_t total_y_offset_sa,
2077b8e80941Smrg                                   uint32_t *base_address_offset,
2078b8e80941Smrg                                   uint32_t *x_offset_sa,
2079b8e80941Smrg                                   uint32_t *y_offset_sa)
2080b8e80941Smrg{
2081b8e80941Smrg   const struct isl_format_layout *fmtl = isl_format_get_layout(format);
2082b8e80941Smrg
2083b8e80941Smrg   /* For computing the intratile offsets, we actually want a strange unit
2084b8e80941Smrg    * which is samples for multisampled surfaces but elements for compressed
2085b8e80941Smrg    * surfaces.
2086b8e80941Smrg    */
2087b8e80941Smrg   assert(total_x_offset_sa % fmtl->bw == 0);
2088b8e80941Smrg   assert(total_y_offset_sa % fmtl->bh == 0);
2089b8e80941Smrg   const uint32_t total_x_offset = total_x_offset_sa / fmtl->bw;
2090b8e80941Smrg   const uint32_t total_y_offset = total_y_offset_sa / fmtl->bh;
2091b8e80941Smrg
2092b8e80941Smrg   isl_tiling_get_intratile_offset_el(tiling, fmtl->bpb, row_pitch_B,
2093b8e80941Smrg                                      total_x_offset, total_y_offset,
2094b8e80941Smrg                                      base_address_offset,
2095b8e80941Smrg                                      x_offset_sa, y_offset_sa);
2096b8e80941Smrg   *x_offset_sa *= fmtl->bw;
2097b8e80941Smrg   *y_offset_sa *= fmtl->bh;
2098b8e80941Smrg}
2099b8e80941Smrg
2100b8e80941Smrg/**
2101b8e80941Smrg * @brief Get value of 3DSTATE_DEPTH_BUFFER.SurfaceFormat
2102b8e80941Smrg *
2103b8e80941Smrg * @pre surf->usage has ISL_SURF_USAGE_DEPTH_BIT
2104b8e80941Smrg * @pre surf->format must be a valid format for depth surfaces
2105b8e80941Smrg */
2106b8e80941Smrguint32_t
2107b8e80941Smrgisl_surf_get_depth_format(const struct isl_device *dev,
2108b8e80941Smrg                          const struct isl_surf *surf);
2109b8e80941Smrg
2110b8e80941Smrg/**
2111b8e80941Smrg * @brief performs a copy from linear to tiled surface
2112b8e80941Smrg *
2113b8e80941Smrg */
2114b8e80941Smrgvoid
2115b8e80941Smrgisl_memcpy_linear_to_tiled(uint32_t xt1, uint32_t xt2,
2116b8e80941Smrg                           uint32_t yt1, uint32_t yt2,
2117b8e80941Smrg                           char *dst, const char *src,
2118b8e80941Smrg                           uint32_t dst_pitch, int32_t src_pitch,
2119b8e80941Smrg                           bool has_swizzling,
2120b8e80941Smrg                           enum isl_tiling tiling,
2121b8e80941Smrg                           isl_memcpy_type copy_type);
2122b8e80941Smrg
2123b8e80941Smrg/**
2124b8e80941Smrg * @brief performs a copy from tiled to linear surface
2125b8e80941Smrg *
2126b8e80941Smrg */
2127b8e80941Smrgvoid
2128b8e80941Smrgisl_memcpy_tiled_to_linear(uint32_t xt1, uint32_t xt2,
2129b8e80941Smrg                           uint32_t yt1, uint32_t yt2,
2130b8e80941Smrg                           char *dst, const char *src,
2131b8e80941Smrg                           int32_t dst_pitch, uint32_t src_pitch,
2132b8e80941Smrg                           bool has_swizzling,
2133b8e80941Smrg                           enum isl_tiling tiling,
2134b8e80941Smrg                           isl_memcpy_type copy_type);
2135b8e80941Smrg
2136b8e80941Smrg#ifdef __cplusplus
2137b8e80941Smrg}
2138b8e80941Smrg#endif
2139b8e80941Smrg
2140b8e80941Smrg#endif /* ISL_H */
2141