Merge remote-tracking branch 'origin/master' into vulkan
[mesa.git] / src / intel / isl / isl.h
1 /*
2 * Copyright 2015 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 /**
25 * @file
26 * @brief Intel Surface Layout
27 *
28 * Header Layout
29 * -------------
30 * The header is ordered as:
31 * - forward declarations
32 * - macros that may be overridden at compile-time for specific gens
33 * - enums and constants
34 * - structs and unions
35 * - functions
36 */
37
38 #pragma once
39
40 #include <assert.h>
41 #include <stdbool.h>
42 #include <stdint.h>
43
44 #include "util/macros.h"
45
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49
50 struct brw_device_info;
51 struct brw_image_param;
52
53 #ifndef ISL_DEV_GEN
54 /**
55 * @brief Get the hardware generation of isl_device.
56 *
57 * You can define this as a compile-time constant in the CFLAGS. For example,
58 * `gcc -DISL_DEV_GEN(dev)=9 ...`.
59 */
60 #define ISL_DEV_GEN(__dev) ((__dev)->info->gen)
61 #endif
62
63 #ifndef ISL_DEV_USE_SEPARATE_STENCIL
64 /**
65 * You can define this as a compile-time constant in the CFLAGS. For example,
66 * `gcc -DISL_DEV_USE_SEPARATE_STENCIL(dev)=1 ...`.
67 */
68 #define ISL_DEV_USE_SEPARATE_STENCIL(__dev) ((__dev)->use_separate_stencil)
69 #endif
70
71 /**
72 * Hardware enumeration SURFACE_FORMAT.
73 *
74 * For the official list, see Broadwell PRM: Volume 2b: Command Reference:
75 * Enumerations: SURFACE_FORMAT.
76 */
77 enum isl_format {
78 ISL_FORMAT_R32G32B32A32_FLOAT = 0,
79 ISL_FORMAT_R32G32B32A32_SINT = 1,
80 ISL_FORMAT_R32G32B32A32_UINT = 2,
81 ISL_FORMAT_R32G32B32A32_UNORM = 3,
82 ISL_FORMAT_R32G32B32A32_SNORM = 4,
83 ISL_FORMAT_R64G64_FLOAT = 5,
84 ISL_FORMAT_R32G32B32X32_FLOAT = 6,
85 ISL_FORMAT_R32G32B32A32_SSCALED = 7,
86 ISL_FORMAT_R32G32B32A32_USCALED = 8,
87 ISL_FORMAT_R32G32B32A32_SFIXED = 32,
88 ISL_FORMAT_R64G64_PASSTHRU = 33,
89 ISL_FORMAT_R32G32B32_FLOAT = 64,
90 ISL_FORMAT_R32G32B32_SINT = 65,
91 ISL_FORMAT_R32G32B32_UINT = 66,
92 ISL_FORMAT_R32G32B32_UNORM = 67,
93 ISL_FORMAT_R32G32B32_SNORM = 68,
94 ISL_FORMAT_R32G32B32_SSCALED = 69,
95 ISL_FORMAT_R32G32B32_USCALED = 70,
96 ISL_FORMAT_R32G32B32_SFIXED = 80,
97 ISL_FORMAT_R16G16B16A16_UNORM = 128,
98 ISL_FORMAT_R16G16B16A16_SNORM = 129,
99 ISL_FORMAT_R16G16B16A16_SINT = 130,
100 ISL_FORMAT_R16G16B16A16_UINT = 131,
101 ISL_FORMAT_R16G16B16A16_FLOAT = 132,
102 ISL_FORMAT_R32G32_FLOAT = 133,
103 ISL_FORMAT_R32G32_SINT = 134,
104 ISL_FORMAT_R32G32_UINT = 135,
105 ISL_FORMAT_R32_FLOAT_X8X24_TYPELESS = 136,
106 ISL_FORMAT_X32_TYPELESS_G8X24_UINT = 137,
107 ISL_FORMAT_L32A32_FLOAT = 138,
108 ISL_FORMAT_R32G32_UNORM = 139,
109 ISL_FORMAT_R32G32_SNORM = 140,
110 ISL_FORMAT_R64_FLOAT = 141,
111 ISL_FORMAT_R16G16B16X16_UNORM = 142,
112 ISL_FORMAT_R16G16B16X16_FLOAT = 143,
113 ISL_FORMAT_A32X32_FLOAT = 144,
114 ISL_FORMAT_L32X32_FLOAT = 145,
115 ISL_FORMAT_I32X32_FLOAT = 146,
116 ISL_FORMAT_R16G16B16A16_SSCALED = 147,
117 ISL_FORMAT_R16G16B16A16_USCALED = 148,
118 ISL_FORMAT_R32G32_SSCALED = 149,
119 ISL_FORMAT_R32G32_USCALED = 150,
120 ISL_FORMAT_R32G32_SFIXED = 160,
121 ISL_FORMAT_R64_PASSTHRU = 161,
122 ISL_FORMAT_B8G8R8A8_UNORM = 192,
123 ISL_FORMAT_B8G8R8A8_UNORM_SRGB = 193,
124 ISL_FORMAT_R10G10B10A2_UNORM = 194,
125 ISL_FORMAT_R10G10B10A2_UNORM_SRGB = 195,
126 ISL_FORMAT_R10G10B10A2_UINT = 196,
127 ISL_FORMAT_R10G10B10_SNORM_A2_UNORM = 197,
128 ISL_FORMAT_R8G8B8A8_UNORM = 199,
129 ISL_FORMAT_R8G8B8A8_UNORM_SRGB = 200,
130 ISL_FORMAT_R8G8B8A8_SNORM = 201,
131 ISL_FORMAT_R8G8B8A8_SINT = 202,
132 ISL_FORMAT_R8G8B8A8_UINT = 203,
133 ISL_FORMAT_R16G16_UNORM = 204,
134 ISL_FORMAT_R16G16_SNORM = 205,
135 ISL_FORMAT_R16G16_SINT = 206,
136 ISL_FORMAT_R16G16_UINT = 207,
137 ISL_FORMAT_R16G16_FLOAT = 208,
138 ISL_FORMAT_B10G10R10A2_UNORM = 209,
139 ISL_FORMAT_B10G10R10A2_UNORM_SRGB = 210,
140 ISL_FORMAT_R11G11B10_FLOAT = 211,
141 ISL_FORMAT_R32_SINT = 214,
142 ISL_FORMAT_R32_UINT = 215,
143 ISL_FORMAT_R32_FLOAT = 216,
144 ISL_FORMAT_R24_UNORM_X8_TYPELESS = 217,
145 ISL_FORMAT_X24_TYPELESS_G8_UINT = 218,
146 ISL_FORMAT_L32_UNORM = 221,
147 ISL_FORMAT_A32_UNORM = 222,
148 ISL_FORMAT_L16A16_UNORM = 223,
149 ISL_FORMAT_I24X8_UNORM = 224,
150 ISL_FORMAT_L24X8_UNORM = 225,
151 ISL_FORMAT_A24X8_UNORM = 226,
152 ISL_FORMAT_I32_FLOAT = 227,
153 ISL_FORMAT_L32_FLOAT = 228,
154 ISL_FORMAT_A32_FLOAT = 229,
155 ISL_FORMAT_X8B8_UNORM_G8R8_SNORM = 230,
156 ISL_FORMAT_A8X8_UNORM_G8R8_SNORM = 231,
157 ISL_FORMAT_B8X8_UNORM_G8R8_SNORM = 232,
158 ISL_FORMAT_B8G8R8X8_UNORM = 233,
159 ISL_FORMAT_B8G8R8X8_UNORM_SRGB = 234,
160 ISL_FORMAT_R8G8B8X8_UNORM = 235,
161 ISL_FORMAT_R8G8B8X8_UNORM_SRGB = 236,
162 ISL_FORMAT_R9G9B9E5_SHAREDEXP = 237,
163 ISL_FORMAT_B10G10R10X2_UNORM = 238,
164 ISL_FORMAT_L16A16_FLOAT = 240,
165 ISL_FORMAT_R32_UNORM = 241,
166 ISL_FORMAT_R32_SNORM = 242,
167 ISL_FORMAT_R10G10B10X2_USCALED = 243,
168 ISL_FORMAT_R8G8B8A8_SSCALED = 244,
169 ISL_FORMAT_R8G8B8A8_USCALED = 245,
170 ISL_FORMAT_R16G16_SSCALED = 246,
171 ISL_FORMAT_R16G16_USCALED = 247,
172 ISL_FORMAT_R32_SSCALED = 248,
173 ISL_FORMAT_R32_USCALED = 249,
174 ISL_FORMAT_B5G6R5_UNORM = 256,
175 ISL_FORMAT_B5G6R5_UNORM_SRGB = 257,
176 ISL_FORMAT_B5G5R5A1_UNORM = 258,
177 ISL_FORMAT_B5G5R5A1_UNORM_SRGB = 259,
178 ISL_FORMAT_B4G4R4A4_UNORM = 260,
179 ISL_FORMAT_B4G4R4A4_UNORM_SRGB = 261,
180 ISL_FORMAT_R8G8_UNORM = 262,
181 ISL_FORMAT_R8G8_SNORM = 263,
182 ISL_FORMAT_R8G8_SINT = 264,
183 ISL_FORMAT_R8G8_UINT = 265,
184 ISL_FORMAT_R16_UNORM = 266,
185 ISL_FORMAT_R16_SNORM = 267,
186 ISL_FORMAT_R16_SINT = 268,
187 ISL_FORMAT_R16_UINT = 269,
188 ISL_FORMAT_R16_FLOAT = 270,
189 ISL_FORMAT_A8P8_UNORM_PALETTE0 = 271,
190 ISL_FORMAT_A8P8_UNORM_PALETTE1 = 272,
191 ISL_FORMAT_I16_UNORM = 273,
192 ISL_FORMAT_L16_UNORM = 274,
193 ISL_FORMAT_A16_UNORM = 275,
194 ISL_FORMAT_L8A8_UNORM = 276,
195 ISL_FORMAT_I16_FLOAT = 277,
196 ISL_FORMAT_L16_FLOAT = 278,
197 ISL_FORMAT_A16_FLOAT = 279,
198 ISL_FORMAT_L8A8_UNORM_SRGB = 280,
199 ISL_FORMAT_R5G5_SNORM_B6_UNORM = 281,
200 ISL_FORMAT_B5G5R5X1_UNORM = 282,
201 ISL_FORMAT_B5G5R5X1_UNORM_SRGB = 283,
202 ISL_FORMAT_R8G8_SSCALED = 284,
203 ISL_FORMAT_R8G8_USCALED = 285,
204 ISL_FORMAT_R16_SSCALED = 286,
205 ISL_FORMAT_R16_USCALED = 287,
206 ISL_FORMAT_P8A8_UNORM_PALETTE0 = 290,
207 ISL_FORMAT_P8A8_UNORM_PALETTE1 = 291,
208 ISL_FORMAT_A1B5G5R5_UNORM = 292,
209 ISL_FORMAT_A4B4G4R4_UNORM = 293,
210 ISL_FORMAT_L8A8_UINT = 294,
211 ISL_FORMAT_L8A8_SINT = 295,
212 ISL_FORMAT_R8_UNORM = 320,
213 ISL_FORMAT_R8_SNORM = 321,
214 ISL_FORMAT_R8_SINT = 322,
215 ISL_FORMAT_R8_UINT = 323,
216 ISL_FORMAT_A8_UNORM = 324,
217 ISL_FORMAT_I8_UNORM = 325,
218 ISL_FORMAT_L8_UNORM = 326,
219 ISL_FORMAT_P4A4_UNORM_PALETTE0 = 327,
220 ISL_FORMAT_A4P4_UNORM_PALETTE0 = 328,
221 ISL_FORMAT_R8_SSCALED = 329,
222 ISL_FORMAT_R8_USCALED = 330,
223 ISL_FORMAT_P8_UNORM_PALETTE0 = 331,
224 ISL_FORMAT_L8_UNORM_SRGB = 332,
225 ISL_FORMAT_P8_UNORM_PALETTE1 = 333,
226 ISL_FORMAT_P4A4_UNORM_PALETTE1 = 334,
227 ISL_FORMAT_A4P4_UNORM_PALETTE1 = 335,
228 ISL_FORMAT_Y8_UNORM = 336,
229 ISL_FORMAT_L8_UINT = 338,
230 ISL_FORMAT_L8_SINT = 339,
231 ISL_FORMAT_I8_UINT = 340,
232 ISL_FORMAT_I8_SINT = 341,
233 ISL_FORMAT_DXT1_RGB_SRGB = 384,
234 ISL_FORMAT_R1_UNORM = 385,
235 ISL_FORMAT_YCRCB_NORMAL = 386,
236 ISL_FORMAT_YCRCB_SWAPUVY = 387,
237 ISL_FORMAT_P2_UNORM_PALETTE0 = 388,
238 ISL_FORMAT_P2_UNORM_PALETTE1 = 389,
239 ISL_FORMAT_BC1_UNORM = 390,
240 ISL_FORMAT_BC2_UNORM = 391,
241 ISL_FORMAT_BC3_UNORM = 392,
242 ISL_FORMAT_BC4_UNORM = 393,
243 ISL_FORMAT_BC5_UNORM = 394,
244 ISL_FORMAT_BC1_UNORM_SRGB = 395,
245 ISL_FORMAT_BC2_UNORM_SRGB = 396,
246 ISL_FORMAT_BC3_UNORM_SRGB = 397,
247 ISL_FORMAT_MONO8 = 398,
248 ISL_FORMAT_YCRCB_SWAPUV = 399,
249 ISL_FORMAT_YCRCB_SWAPY = 400,
250 ISL_FORMAT_DXT1_RGB = 401,
251 ISL_FORMAT_FXT1 = 402,
252 ISL_FORMAT_R8G8B8_UNORM = 403,
253 ISL_FORMAT_R8G8B8_SNORM = 404,
254 ISL_FORMAT_R8G8B8_SSCALED = 405,
255 ISL_FORMAT_R8G8B8_USCALED = 406,
256 ISL_FORMAT_R64G64B64A64_FLOAT = 407,
257 ISL_FORMAT_R64G64B64_FLOAT = 408,
258 ISL_FORMAT_BC4_SNORM = 409,
259 ISL_FORMAT_BC5_SNORM = 410,
260 ISL_FORMAT_R16G16B16_FLOAT = 411,
261 ISL_FORMAT_R16G16B16_UNORM = 412,
262 ISL_FORMAT_R16G16B16_SNORM = 413,
263 ISL_FORMAT_R16G16B16_SSCALED = 414,
264 ISL_FORMAT_R16G16B16_USCALED = 415,
265 ISL_FORMAT_BC6H_SF16 = 417,
266 ISL_FORMAT_BC7_UNORM = 418,
267 ISL_FORMAT_BC7_UNORM_SRGB = 419,
268 ISL_FORMAT_BC6H_UF16 = 420,
269 ISL_FORMAT_PLANAR_420_8 = 421,
270 ISL_FORMAT_R8G8B8_UNORM_SRGB = 424,
271 ISL_FORMAT_ETC1_RGB8 = 425,
272 ISL_FORMAT_ETC2_RGB8 = 426,
273 ISL_FORMAT_EAC_R11 = 427,
274 ISL_FORMAT_EAC_RG11 = 428,
275 ISL_FORMAT_EAC_SIGNED_R11 = 429,
276 ISL_FORMAT_EAC_SIGNED_RG11 = 430,
277 ISL_FORMAT_ETC2_SRGB8 = 431,
278 ISL_FORMAT_R16G16B16_UINT = 432,
279 ISL_FORMAT_R16G16B16_SINT = 433,
280 ISL_FORMAT_R32_SFIXED = 434,
281 ISL_FORMAT_R10G10B10A2_SNORM = 435,
282 ISL_FORMAT_R10G10B10A2_USCALED = 436,
283 ISL_FORMAT_R10G10B10A2_SSCALED = 437,
284 ISL_FORMAT_R10G10B10A2_SINT = 438,
285 ISL_FORMAT_B10G10R10A2_SNORM = 439,
286 ISL_FORMAT_B10G10R10A2_USCALED = 440,
287 ISL_FORMAT_B10G10R10A2_SSCALED = 441,
288 ISL_FORMAT_B10G10R10A2_UINT = 442,
289 ISL_FORMAT_B10G10R10A2_SINT = 443,
290 ISL_FORMAT_R64G64B64A64_PASSTHRU = 444,
291 ISL_FORMAT_R64G64B64_PASSTHRU = 445,
292 ISL_FORMAT_ETC2_RGB8_PTA = 448,
293 ISL_FORMAT_ETC2_SRGB8_PTA = 449,
294 ISL_FORMAT_ETC2_EAC_RGBA8 = 450,
295 ISL_FORMAT_ETC2_EAC_SRGB8_A8 = 451,
296 ISL_FORMAT_R8G8B8_UINT = 456,
297 ISL_FORMAT_R8G8B8_SINT = 457,
298 ISL_FORMAT_RAW = 511,
299
300 /* Hardware doesn't understand this out-of-band value */
301 ISL_FORMAT_UNSUPPORTED = UINT16_MAX,
302 };
303
304 /**
305 * Numerical base type for channels of isl_format.
306 */
307 enum isl_base_type {
308 ISL_VOID,
309 ISL_RAW,
310 ISL_UNORM,
311 ISL_SNORM,
312 ISL_UFLOAT,
313 ISL_SFLOAT,
314 ISL_UFIXED,
315 ISL_SFIXED,
316 ISL_UINT,
317 ISL_SINT,
318 ISL_USCALED,
319 ISL_SSCALED,
320 };
321
322 /**
323 * Colorspace of isl_format.
324 */
325 enum isl_colorspace {
326 ISL_COLORSPACE_NONE = 0,
327 ISL_COLORSPACE_LINEAR,
328 ISL_COLORSPACE_SRGB,
329 ISL_COLORSPACE_YUV,
330 };
331
332 /**
333 * Texture compression mode of isl_format.
334 */
335 enum isl_txc {
336 ISL_TXC_NONE = 0,
337 ISL_TXC_DXT1,
338 ISL_TXC_DXT3,
339 ISL_TXC_DXT5,
340 ISL_TXC_FXT1,
341 ISL_TXC_RGTC1,
342 ISL_TXC_RGTC2,
343 ISL_TXC_BPTC,
344 ISL_TXC_ETC1,
345 ISL_TXC_ETC2,
346 };
347
348 /**
349 * @brief Hardware tile mode
350 *
351 * WARNING: These values differ from the hardware enum values, which are
352 * unstable across hardware generations.
353 *
354 * Note that legacy Y tiling is ISL_TILING_Y0 instead of ISL_TILING_Y, to
355 * clearly distinguish it from Yf and Ys.
356 */
357 enum isl_tiling {
358 ISL_TILING_LINEAR = 0,
359 ISL_TILING_W,
360 ISL_TILING_X,
361 ISL_TILING_Y0, /**< Legacy Y tiling */
362 ISL_TILING_Yf, /**< Standard 4K tiling. The 'f' means "four". */
363 ISL_TILING_Ys, /**< Standard 64K tiling. The 's' means "sixty-four". */
364 };
365
366 /**
367 * @defgroup Tiling Flags
368 * @{
369 */
370 typedef uint32_t isl_tiling_flags_t;
371 #define ISL_TILING_LINEAR_BIT (1u << ISL_TILING_LINEAR)
372 #define ISL_TILING_W_BIT (1u << ISL_TILING_W)
373 #define ISL_TILING_X_BIT (1u << ISL_TILING_X)
374 #define ISL_TILING_Y0_BIT (1u << ISL_TILING_Y0)
375 #define ISL_TILING_Yf_BIT (1u << ISL_TILING_Yf)
376 #define ISL_TILING_Ys_BIT (1u << ISL_TILING_Ys)
377 #define ISL_TILING_ANY_MASK (~0u)
378 #define ISL_TILING_NON_LINEAR_MASK (~ISL_TILING_LINEAR_BIT)
379
380 /** Any Y tiling, including legacy Y tiling. */
381 #define ISL_TILING_ANY_Y_MASK (ISL_TILING_Y0_BIT | \
382 ISL_TILING_Yf_BIT | \
383 ISL_TILING_Ys_BIT)
384
385 /** The Skylake BSpec refers to Yf and Ys as "standard tiling formats". */
386 #define ISL_TILING_STD_Y_MASK (ISL_TILING_Yf_BIT | \
387 ISL_TILING_Ys_BIT)
388 /** @} */
389
390 /**
391 * @brief Logical dimension of surface.
392 *
393 * Note: There is no dimension for cube map surfaces. ISL interprets cube maps
394 * as 2D array surfaces.
395 */
396 enum isl_surf_dim {
397 ISL_SURF_DIM_1D,
398 ISL_SURF_DIM_2D,
399 ISL_SURF_DIM_3D,
400 };
401
402 /**
403 * @brief Physical layout of the surface's dimensions.
404 */
405 enum isl_dim_layout {
406 /**
407 * For details, see the G35 PRM >> Volume 1: Graphics Core >> Section
408 * 6.17.3: 2D Surfaces.
409 *
410 * On many gens, 1D surfaces share the same layout as 2D surfaces. From
411 * the G35 PRM >> Volume 1: Graphics Core >> Section 6.17.2: 1D Surfaces:
412 *
413 * One-dimensional surfaces are identical to 2D surfaces with height of
414 * one.
415 *
416 * @invariant isl_surf::phys_level0_sa::depth == 1
417 */
418 ISL_DIM_LAYOUT_GEN4_2D,
419
420 /**
421 * For details, see the G35 PRM >> Volume 1: Graphics Core >> Section
422 * 6.17.5: 3D Surfaces.
423 *
424 * @invariant isl_surf::phys_level0_sa::array_len == 1
425 */
426 ISL_DIM_LAYOUT_GEN4_3D,
427
428 /**
429 * For details, see the Skylake BSpec >> Memory Views >> Common Surface
430 * Formats >> Surface Layout and Tiling >> » 1D Surfaces.
431 */
432 ISL_DIM_LAYOUT_GEN9_1D,
433 };
434
435 /* TODO(chadv): Explain */
436 enum isl_array_pitch_span {
437 ISL_ARRAY_PITCH_SPAN_FULL,
438 ISL_ARRAY_PITCH_SPAN_COMPACT,
439 };
440
441 /**
442 * @defgroup Surface Usage
443 * @{
444 */
445 typedef uint64_t isl_surf_usage_flags_t;
446 #define ISL_SURF_USAGE_RENDER_TARGET_BIT (1u << 0)
447 #define ISL_SURF_USAGE_DEPTH_BIT (1u << 1)
448 #define ISL_SURF_USAGE_STENCIL_BIT (1u << 2)
449 #define ISL_SURF_USAGE_TEXTURE_BIT (1u << 3)
450 #define ISL_SURF_USAGE_CUBE_BIT (1u << 4)
451 #define ISL_SURF_USAGE_DISABLE_AUX_BIT (1u << 5)
452 #define ISL_SURF_USAGE_DISPLAY_BIT (1u << 6)
453 #define ISL_SURF_USAGE_DISPLAY_ROTATE_90_BIT (1u << 7)
454 #define ISL_SURF_USAGE_DISPLAY_ROTATE_180_BIT (1u << 8)
455 #define ISL_SURF_USAGE_DISPLAY_ROTATE_270_BIT (1u << 9)
456 #define ISL_SURF_USAGE_DISPLAY_FLIP_X_BIT (1u << 10)
457 #define ISL_SURF_USAGE_DISPLAY_FLIP_Y_BIT (1u << 11)
458 /** @} */
459
460 /**
461 * Identical to VkSampleCountFlagBits.
462 */
463 enum isl_sample_count {
464 ISL_SAMPLE_COUNT_1_BIT = 1u,
465 ISL_SAMPLE_COUNT_2_BIT = 2u,
466 ISL_SAMPLE_COUNT_4_BIT = 4u,
467 ISL_SAMPLE_COUNT_8_BIT = 8u,
468 ISL_SAMPLE_COUNT_16_BIT = 16u,
469 };
470 typedef uint32_t isl_sample_count_mask_t;
471
472 /**
473 * @brief Multisample Format
474 */
475 enum isl_msaa_layout {
476 /**
477 * @brief Suface is single-sampled.
478 */
479 ISL_MSAA_LAYOUT_NONE,
480
481 /**
482 * @brief [SNB+] Interleaved Multisample Format
483 *
484 * In this format, multiple samples are interleaved into each cacheline.
485 * In other words, the sample index is swizzled into the low 6 bits of the
486 * surface's virtual address space.
487 *
488 * For example, suppose the surface is legacy Y tiled, is 4x multisampled,
489 * and its pixel format is 32bpp. Then the first cacheline is arranged
490 * thus:
491 *
492 * (0,0,0) (0,1,0) (0,0,1) (1,0,1)
493 * (1,0,0) (1,1,0) (0,1,1) (1,1,1)
494 *
495 * (0,0,2) (1,0,2) (0,0,3) (1,0,3)
496 * (0,1,2) (1,1,2) (0,1,3) (1,1,3)
497 *
498 * The hardware docs refer to this format with multiple terms. In
499 * Sandybridge, this is the only multisample format; so no term is used.
500 * The Ivybridge docs refer to surfaces in this format as IMS (Interleaved
501 * Multisample Surface). Later hardware docs additionally refer to this
502 * format as MSFMT_DEPTH_STENCIL (because the format is deprecated for
503 * color surfaces).
504 *
505 * See the Sandybridge PRM, Volume 4, Part 1, Section 2.7 "Multisampled
506 * Surface Behavior".
507 *
508 * See the Ivybridge PRM, Volume 1, Part 1, Section 6.18.4.1 "Interleaved
509 * Multisampled Surfaces".
510 */
511 ISL_MSAA_LAYOUT_INTERLEAVED,
512
513 /**
514 * @brief [IVB+] Array Multisample Format
515 *
516 * In this format, the surface's physical layout resembles that of a
517 * 2D array surface.
518 *
519 * Suppose the multisample surface's logical extent is (w, h) and its
520 * sample count is N. Then surface's physical extent is the same as
521 * a singlesample 2D surface whose logical extent is (w, h) and array
522 * length is N. Array slice `i` contains the pixel values for sample
523 * index `i`.
524 *
525 * The Ivybridge docs refer to surfaces in this format as UMS
526 * (Uncompressed Multsample Layout) and CMS (Compressed Multisample
527 * Surface). The Broadwell docs additionally refer to this format as
528 * MSFMT_MSS (MSS=Multisample Surface Storage).
529 *
530 * See the Broadwell PRM, Volume 5 "Memory Views", Section "Uncompressed
531 * Multisample Surfaces".
532 *
533 * See the Broadwell PRM, Volume 5 "Memory Views", Section "Compressed
534 * Multisample Surfaces".
535 */
536 ISL_MSAA_LAYOUT_ARRAY,
537 };
538
539
540 struct isl_device {
541 const struct brw_device_info *info;
542 bool use_separate_stencil;
543 bool has_bit6_swizzling;
544 };
545
546 struct isl_extent2d {
547 union { uint32_t w, width; };
548 union { uint32_t h, height; };
549 };
550
551 struct isl_extent3d {
552 union { uint32_t w, width; };
553 union { uint32_t h, height; };
554 union { uint32_t d, depth; };
555 };
556
557 struct isl_extent4d {
558 union { uint32_t w, width; };
559 union { uint32_t h, height; };
560 union { uint32_t d, depth; };
561 union { uint32_t a, array_len; };
562 };
563
564 struct isl_channel_layout {
565 enum isl_base_type type;
566 uint8_t bits; /**< Size in bits */
567 };
568
569 /**
570 * Each format has 3D block extent (width, height, depth). The block extent of
571 * compressed formats is that of the format's compression block. For example,
572 * the block extent of ISL_FORMAT_ETC2_RGB8 is (w=4, h=4, d=1). The block
573 * extent of uncompressed pixel formats, such as ISL_FORMAT_R8G8B8A8_UNORM, is
574 * is (w=1, h=1, d=1).
575 */
576 struct isl_format_layout {
577 enum isl_format format;
578
579 uint8_t bs; /**< Block size, in bytes, rounded towards 0 */
580 uint8_t bw; /**< Block width, in pixels */
581 uint8_t bh; /**< Block height, in pixels */
582 uint8_t bd; /**< Block depth, in pixels */
583
584 struct {
585 struct isl_channel_layout r; /**< Red channel */
586 struct isl_channel_layout g; /**< Green channel */
587 struct isl_channel_layout b; /**< Blue channel */
588 struct isl_channel_layout a; /**< Alpha channel */
589 struct isl_channel_layout l; /**< Luminance channel */
590 struct isl_channel_layout i; /**< Intensity channel */
591 struct isl_channel_layout p; /**< Palette channel */
592 } channels;
593
594 enum isl_colorspace colorspace;
595 enum isl_txc txc;
596 };
597
598 struct isl_tile_info {
599 enum isl_tiling tiling;
600 uint32_t width; /**< in bytes */
601 uint32_t height; /**< in rows of memory */
602 uint32_t size; /**< in bytes */
603 };
604
605 /**
606 * @brief Input to surface initialization
607 *
608 * @invariant width >= 1
609 * @invariant height >= 1
610 * @invariant depth >= 1
611 * @invariant levels >= 1
612 * @invariant samples >= 1
613 * @invariant array_len >= 1
614 *
615 * @invariant if 1D then height == 1 and depth == 1 and samples == 1
616 * @invariant if 2D then depth == 1
617 * @invariant if 3D then array_len == 1 and samples == 1
618 */
619 struct isl_surf_init_info {
620 enum isl_surf_dim dim;
621 enum isl_format format;
622
623 uint32_t width;
624 uint32_t height;
625 uint32_t depth;
626 uint32_t levels;
627 uint32_t array_len;
628 uint32_t samples;
629
630 /** Lower bound for isl_surf::alignment, in bytes. */
631 uint32_t min_alignment;
632
633 /** Lower bound for isl_surf::pitch, in bytes. */
634 uint32_t min_pitch;
635
636 isl_surf_usage_flags_t usage;
637
638 /** Flags that alter how ISL selects isl_surf::tiling. */
639 isl_tiling_flags_t tiling_flags;
640 };
641
642 struct isl_surf {
643 enum isl_surf_dim dim;
644 enum isl_dim_layout dim_layout;
645 enum isl_msaa_layout msaa_layout;
646 enum isl_tiling tiling;
647 enum isl_format format;
648
649 /**
650 * Alignment of the upper-left sample of each subimage, in units of surface
651 * elements.
652 */
653 struct isl_extent3d image_alignment_el;
654
655 /**
656 * Logical extent of the surface's base level, in units of pixels. This is
657 * identical to the extent defined in isl_surf_init_info.
658 */
659 struct isl_extent4d logical_level0_px;
660
661 /**
662 * Physical extent of the surface's base level, in units of physical
663 * surface samples and aligned to the format's compression block.
664 *
665 * Consider isl_dim_layout as an operator that transforms a logical surface
666 * layout to a physical surface layout. Then
667 *
668 * logical_layout := (isl_surf::dim, isl_surf::logical_level0_px)
669 * isl_surf::phys_level0_sa := isl_surf::dim_layout * logical_layout
670 */
671 struct isl_extent4d phys_level0_sa;
672
673 uint32_t levels;
674 uint32_t samples;
675
676 /** Total size of the surface, in bytes. */
677 uint32_t size;
678
679 /** Required alignment for the surface's base address. */
680 uint32_t alignment;
681
682 /**
683 * Pitch between vertically adjacent surface elements, in bytes.
684 */
685 uint32_t row_pitch;
686
687 /**
688 * Pitch between physical array slices, in rows of surface elements.
689 */
690 uint32_t array_pitch_el_rows;
691
692 enum isl_array_pitch_span array_pitch_span;
693
694 /** Copy of isl_surf_init_info::usage. */
695 isl_surf_usage_flags_t usage;
696 };
697
698 extern const struct isl_format_layout isl_format_layouts[];
699
700 void
701 isl_device_init(struct isl_device *dev,
702 const struct brw_device_info *info,
703 bool has_bit6_swizzling);
704
705 isl_sample_count_mask_t ATTRIBUTE_CONST
706 isl_device_get_sample_counts(struct isl_device *dev);
707
708 static inline const struct isl_format_layout * ATTRIBUTE_CONST
709 isl_format_get_layout(enum isl_format fmt)
710 {
711 return &isl_format_layouts[fmt];
712 }
713
714 bool
715 isl_format_has_sint_channel(enum isl_format fmt) ATTRIBUTE_CONST;
716
717 static inline bool
718 isl_format_is_compressed(enum isl_format fmt)
719 {
720 const struct isl_format_layout *fmtl = isl_format_get_layout(fmt);
721
722 return fmtl->txc != ISL_TXC_NONE;
723 }
724
725 static inline bool
726 isl_format_has_bc_compression(enum isl_format fmt)
727 {
728 switch (isl_format_get_layout(fmt)->txc) {
729 case ISL_TXC_DXT1:
730 case ISL_TXC_DXT3:
731 case ISL_TXC_DXT5:
732 return true;
733 case ISL_TXC_NONE:
734 case ISL_TXC_FXT1:
735 case ISL_TXC_RGTC1:
736 case ISL_TXC_RGTC2:
737 case ISL_TXC_BPTC:
738 case ISL_TXC_ETC1:
739 case ISL_TXC_ETC2:
740 return false;
741 }
742
743 unreachable("bad texture compression mode");
744 return false;
745 }
746
747 static inline bool
748 isl_format_is_yuv(enum isl_format fmt)
749 {
750 const struct isl_format_layout *fmtl = isl_format_get_layout(fmt);
751
752 return fmtl->colorspace == ISL_COLORSPACE_YUV;
753 }
754
755 static inline bool
756 isl_format_block_is_1x1x1(enum isl_format fmt)
757 {
758 const struct isl_format_layout *fmtl = isl_format_get_layout(fmt);
759
760 return fmtl->bw == 1 && fmtl->bh == 1 && fmtl->bd == 1;
761 }
762
763 static inline bool
764 isl_format_is_rgb(enum isl_format fmt)
765 {
766 return isl_format_layouts[fmt].channels.r.bits > 0 &&
767 isl_format_layouts[fmt].channels.g.bits > 0 &&
768 isl_format_layouts[fmt].channels.b.bits > 0 &&
769 isl_format_layouts[fmt].channels.a.bits == 0;
770 }
771
772 enum isl_format isl_format_rgb_to_rgba(enum isl_format rgb) ATTRIBUTE_CONST;
773 enum isl_format isl_format_rgb_to_rgbx(enum isl_format rgb) ATTRIBUTE_CONST;
774
775 bool isl_is_storage_image_format(enum isl_format fmt);
776
777 enum isl_format
778 isl_lower_storage_image_format(const struct isl_device *dev,
779 enum isl_format fmt);
780
781 static inline bool
782 isl_tiling_is_any_y(enum isl_tiling tiling)
783 {
784 return (1u << tiling) & ISL_TILING_ANY_MASK;
785 }
786
787 static inline bool
788 isl_tiling_is_std_y(enum isl_tiling tiling)
789 {
790 return (1u << tiling) & ISL_TILING_STD_Y_MASK;
791 }
792
793 bool
794 isl_tiling_get_info(const struct isl_device *dev,
795 enum isl_tiling tiling,
796 uint32_t format_block_size,
797 struct isl_tile_info *info);
798
799 void
800 isl_tiling_get_extent(const struct isl_device *dev,
801 enum isl_tiling tiling,
802 uint32_t format_block_size,
803 struct isl_extent2d *e);
804 bool
805 isl_surf_choose_tiling(const struct isl_device *dev,
806 const struct isl_surf_init_info *restrict info,
807 enum isl_tiling *tiling);
808
809 static inline bool
810 isl_surf_usage_is_display(isl_surf_usage_flags_t usage)
811 {
812 return usage & ISL_SURF_USAGE_DISPLAY_BIT;
813 }
814
815 static inline bool
816 isl_surf_usage_is_depth(isl_surf_usage_flags_t usage)
817 {
818 return usage & ISL_SURF_USAGE_DEPTH_BIT;
819 }
820
821 static inline bool
822 isl_surf_usage_is_stencil(isl_surf_usage_flags_t usage)
823 {
824 return usage & ISL_SURF_USAGE_STENCIL_BIT;
825 }
826
827 static inline bool
828 isl_surf_usage_is_depth_and_stencil(isl_surf_usage_flags_t usage)
829 {
830 return (usage & ISL_SURF_USAGE_DEPTH_BIT) &&
831 (usage & ISL_SURF_USAGE_STENCIL_BIT);
832 }
833
834 static inline bool
835 isl_surf_usage_is_depth_or_stencil(isl_surf_usage_flags_t usage)
836 {
837 return usage & (ISL_SURF_USAGE_DEPTH_BIT | ISL_SURF_USAGE_STENCIL_BIT);
838 }
839
840 static inline bool
841 isl_surf_info_is_z16(const struct isl_surf_init_info *info)
842 {
843 return (info->usage & ISL_SURF_USAGE_DEPTH_BIT) &&
844 (info->format == ISL_FORMAT_R16_UNORM);
845 }
846
847 static inline bool
848 isl_surf_info_is_z32_float(const struct isl_surf_init_info *info)
849 {
850 return (info->usage & ISL_SURF_USAGE_DEPTH_BIT) &&
851 (info->format == ISL_FORMAT_R32_FLOAT);
852 }
853
854 static inline struct isl_extent2d
855 isl_extent2d(uint32_t width, uint32_t height)
856 {
857 return (struct isl_extent2d) { .w = width, .h = height };
858 }
859
860 static inline struct isl_extent3d
861 isl_extent3d(uint32_t width, uint32_t height, uint32_t depth)
862 {
863 return (struct isl_extent3d) { .w = width, .h = height, .d = depth };
864 }
865
866 static inline struct isl_extent4d
867 isl_extent4d(uint32_t width, uint32_t height, uint32_t depth,
868 uint32_t array_len)
869 {
870 return (struct isl_extent4d) {
871 .w = width,
872 .h = height,
873 .d = depth,
874 .a = array_len,
875 };
876 }
877
878 #define isl_surf_init(dev, surf, ...) \
879 isl_surf_init_s((dev), (surf), \
880 &(struct isl_surf_init_info) { __VA_ARGS__ });
881
882 bool
883 isl_surf_init_s(const struct isl_device *dev,
884 struct isl_surf *surf,
885 const struct isl_surf_init_info *restrict info);
886
887 void
888 isl_surf_get_tile_info(const struct isl_device *dev,
889 const struct isl_surf *surf,
890 struct isl_tile_info *tile_info);
891
892 /**
893 * Alignment of the upper-left sample of each subimage, in units of surface
894 * elements.
895 */
896 static inline struct isl_extent3d
897 isl_surf_get_image_alignment_el(const struct isl_surf *surf)
898 {
899 return surf->image_alignment_el;
900 }
901
902 /**
903 * Alignment of the upper-left sample of each subimage, in units of surface
904 * samples.
905 */
906 static inline struct isl_extent3d
907 isl_surf_get_image_alignment_sa(const struct isl_surf *surf)
908 {
909 const struct isl_format_layout *fmtl = isl_format_get_layout(surf->format);
910
911 return (struct isl_extent3d) {
912 .w = fmtl->bw * surf->image_alignment_el.w,
913 .h = fmtl->bh * surf->image_alignment_el.h,
914 .d = fmtl->bd * surf->image_alignment_el.d,
915 };
916 }
917
918 /**
919 * Pitch between vertically adjacent surface elements, in bytes.
920 */
921 static inline uint32_t
922 isl_surf_get_row_pitch(const struct isl_surf *surf)
923 {
924 return surf->row_pitch;
925 }
926
927 /**
928 * Pitch between vertically adjacent surface elements, in units of surface elements.
929 */
930 static inline uint32_t
931 isl_surf_get_row_pitch_el(const struct isl_surf *surf)
932 {
933 const struct isl_format_layout *fmtl = isl_format_get_layout(surf->format);
934
935 assert(surf->row_pitch % fmtl->bs == 0);
936 return surf->row_pitch / fmtl->bs;
937 }
938
939 /**
940 * Pitch between physical array slices, in rows of surface elements.
941 */
942 static inline uint32_t
943 isl_surf_get_array_pitch_el_rows(const struct isl_surf *surf)
944 {
945 return surf->array_pitch_el_rows;
946 }
947
948 /**
949 * Pitch between physical array slices, in units of surface elements.
950 */
951 static inline uint32_t
952 isl_surf_get_array_pitch_el(const struct isl_surf *surf)
953 {
954 return isl_surf_get_array_pitch_el_rows(surf) *
955 isl_surf_get_row_pitch_el(surf);
956 }
957
958 /**
959 * Pitch between physical array slices, in rows of surface samples.
960 */
961 static inline uint32_t
962 isl_surf_get_array_pitch_sa_rows(const struct isl_surf *surf)
963 {
964 const struct isl_format_layout *fmtl = isl_format_get_layout(surf->format);
965 return fmtl->bh * isl_surf_get_array_pitch_el_rows(surf);
966 }
967
968 /**
969 * Pitch between physical array slices, in bytes.
970 */
971 static inline uint32_t
972 isl_surf_get_array_pitch(const struct isl_surf *surf)
973 {
974 return isl_surf_get_array_pitch_sa_rows(surf) * surf->row_pitch;
975 }
976
977 /**
978 * Calculate the offset, in units of surface elements, to a subimage in the
979 * surface.
980 *
981 * @invariant level < surface levels
982 * @invariant logical_array_layer < logical array length of surface
983 * @invariant logical_z_offset_px < logical depth of surface at level
984 */
985 void
986 isl_surf_get_image_offset_el(const struct isl_surf *surf,
987 uint32_t level,
988 uint32_t logical_array_layer,
989 uint32_t logical_z_offset_px,
990 uint32_t *x_offset_el,
991 uint32_t *y_offset_el);
992
993 /**
994 * @brief Calculate the intratile offsets to a subimage in the surface.
995 *
996 * In @a base_address_offset return the offset from the base of the surface to
997 * the base address of the first tile of the subimage. In @a x_offset_el and
998 * @a y_offset_el, return the offset, in units of surface elements, from the
999 * tile's base to the subimage's first surface element. The x and y offsets
1000 * are intratile offsets; that is, they do not exceed the boundary of the
1001 * surface's tiling format.
1002 */
1003 void
1004 isl_surf_get_image_intratile_offset_el(const struct isl_device *dev,
1005 const struct isl_surf *surf,
1006 uint32_t level,
1007 uint32_t logical_array_layer,
1008 uint32_t logical_z_offset,
1009 uint32_t *base_address_offset,
1010 uint32_t *x_offset_el,
1011 uint32_t *y_offset_el);
1012
1013 /**
1014 * @brief Get value of 3DSTATE_DEPTH_BUFFER.SurfaceFormat
1015 *
1016 * @pre surf->usage has ISL_SURF_USAGE_DEPTH_BIT
1017 * @pre surf->format must be a valid format for depth surfaces
1018 */
1019 uint32_t
1020 isl_surf_get_depth_format(const struct isl_device *dev,
1021 const struct isl_surf *surf);
1022
1023 #ifdef __cplusplus
1024 }
1025 #endif