/*1* Copyright 2015 Intel Corporation2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*/2223/**24* @file25* @brief Intel Surface Layout26*27* Header Layout28* -------------29* The header is ordered as:30* - forward declarations31* - macros that may be overridden at compile-time for specific gens32* - enums and constants33* - structs and unions34* - functions35*/3637#ifndef ISL_H38#define ISL_H3940#include <assert.h>41#include <stdbool.h>42#include <stdint.h>4344#include "c99_compat.h"45#include "util/compiler.h"46#include "util/macros.h"47#include "util/format/u_format.h"4849#ifdef __cplusplus50extern "C" {51#endif5253struct intel_device_info;54struct brw_image_param;5556#ifndef ISL_GFX_VER57/**58* @brief Get the hardware generation of isl_device.59*60* You can define this as a compile-time constant in the CFLAGS. For example,61* `gcc -DISL_GFX_VER(dev)=9 ...`.62*/63#define ISL_GFX_VER(__dev) ((__dev)->info->ver)64#define ISL_GFX_VERX10(__dev) ((__dev)->info->verx10)65#define ISL_GFX_VER_SANITIZE(__dev)66#else67#define ISL_GFX_VER_SANITIZE(__dev) \68(assert(ISL_GFX_VER(__dev) == (__dev)->info->ver) && \69ISL_GFX_VERX10(__dev) == (__dev)->info->verx10))70#endif7172#ifndef ISL_DEV_IS_G4X73#define ISL_DEV_IS_G4X(__dev) ((__dev)->info->is_g4x)74#endif7576#ifndef ISL_DEV_IS_HASWELL77/**78* @brief Get the hardware generation of isl_device.79*80* You can define this as a compile-time constant in the CFLAGS. For example,81* `gcc -DISL_GFX_VER(dev)=9 ...`.82*/83#define ISL_DEV_IS_HASWELL(__dev) ((__dev)->info->is_haswell)84#endif8586#ifndef ISL_DEV_IS_BAYTRAIL87#define ISL_DEV_IS_BAYTRAIL(__dev) ((__dev)->info->is_baytrail)88#endif8990#ifndef ISL_DEV_USE_SEPARATE_STENCIL91/**92* You can define this as a compile-time constant in the CFLAGS. For example,93* `gcc -DISL_DEV_USE_SEPARATE_STENCIL(dev)=1 ...`.94*/95#define ISL_DEV_USE_SEPARATE_STENCIL(__dev) ((__dev)->use_separate_stencil)96#define ISL_DEV_USE_SEPARATE_STENCIL_SANITIZE(__dev)97#else98#define ISL_DEV_USE_SEPARATE_STENCIL_SANITIZE(__dev) \99(assert(ISL_DEV_USE_SEPARATE_STENCIL(__dev) == (__dev)->use_separate_stencil))100#endif101102/**103* Hardware enumeration SURFACE_FORMAT.104*105* For the official list, see Broadwell PRM: Volume 2b: Command Reference:106* Enumerations: SURFACE_FORMAT.107*/108enum isl_format {109ISL_FORMAT_R32G32B32A32_FLOAT = 0,110ISL_FORMAT_R32G32B32A32_SINT = 1,111ISL_FORMAT_R32G32B32A32_UINT = 2,112ISL_FORMAT_R32G32B32A32_UNORM = 3,113ISL_FORMAT_R32G32B32A32_SNORM = 4,114ISL_FORMAT_R64G64_FLOAT = 5,115ISL_FORMAT_R32G32B32X32_FLOAT = 6,116ISL_FORMAT_R32G32B32A32_SSCALED = 7,117ISL_FORMAT_R32G32B32A32_USCALED = 8,118ISL_FORMAT_R32G32B32A32_SFIXED = 32,119ISL_FORMAT_R64G64_PASSTHRU = 33,120ISL_FORMAT_R32G32B32_FLOAT = 64,121ISL_FORMAT_R32G32B32_SINT = 65,122ISL_FORMAT_R32G32B32_UINT = 66,123ISL_FORMAT_R32G32B32_UNORM = 67,124ISL_FORMAT_R32G32B32_SNORM = 68,125ISL_FORMAT_R32G32B32_SSCALED = 69,126ISL_FORMAT_R32G32B32_USCALED = 70,127ISL_FORMAT_R32G32B32_SFIXED = 80,128ISL_FORMAT_R16G16B16A16_UNORM = 128,129ISL_FORMAT_R16G16B16A16_SNORM = 129,130ISL_FORMAT_R16G16B16A16_SINT = 130,131ISL_FORMAT_R16G16B16A16_UINT = 131,132ISL_FORMAT_R16G16B16A16_FLOAT = 132,133ISL_FORMAT_R32G32_FLOAT = 133,134ISL_FORMAT_R32G32_SINT = 134,135ISL_FORMAT_R32G32_UINT = 135,136ISL_FORMAT_R32_FLOAT_X8X24_TYPELESS = 136,137ISL_FORMAT_X32_TYPELESS_G8X24_UINT = 137,138ISL_FORMAT_L32A32_FLOAT = 138,139ISL_FORMAT_R32G32_UNORM = 139,140ISL_FORMAT_R32G32_SNORM = 140,141ISL_FORMAT_R64_FLOAT = 141,142ISL_FORMAT_R16G16B16X16_UNORM = 142,143ISL_FORMAT_R16G16B16X16_FLOAT = 143,144ISL_FORMAT_A32X32_FLOAT = 144,145ISL_FORMAT_L32X32_FLOAT = 145,146ISL_FORMAT_I32X32_FLOAT = 146,147ISL_FORMAT_R16G16B16A16_SSCALED = 147,148ISL_FORMAT_R16G16B16A16_USCALED = 148,149ISL_FORMAT_R32G32_SSCALED = 149,150ISL_FORMAT_R32G32_USCALED = 150,151ISL_FORMAT_R32G32_FLOAT_LD = 151,152ISL_FORMAT_R32G32_SFIXED = 160,153ISL_FORMAT_R64_PASSTHRU = 161,154ISL_FORMAT_B8G8R8A8_UNORM = 192,155ISL_FORMAT_B8G8R8A8_UNORM_SRGB = 193,156ISL_FORMAT_R10G10B10A2_UNORM = 194,157ISL_FORMAT_R10G10B10A2_UNORM_SRGB = 195,158ISL_FORMAT_R10G10B10A2_UINT = 196,159ISL_FORMAT_R10G10B10_SNORM_A2_UNORM = 197,160ISL_FORMAT_R8G8B8A8_UNORM = 199,161ISL_FORMAT_R8G8B8A8_UNORM_SRGB = 200,162ISL_FORMAT_R8G8B8A8_SNORM = 201,163ISL_FORMAT_R8G8B8A8_SINT = 202,164ISL_FORMAT_R8G8B8A8_UINT = 203,165ISL_FORMAT_R16G16_UNORM = 204,166ISL_FORMAT_R16G16_SNORM = 205,167ISL_FORMAT_R16G16_SINT = 206,168ISL_FORMAT_R16G16_UINT = 207,169ISL_FORMAT_R16G16_FLOAT = 208,170ISL_FORMAT_B10G10R10A2_UNORM = 209,171ISL_FORMAT_B10G10R10A2_UNORM_SRGB = 210,172ISL_FORMAT_R11G11B10_FLOAT = 211,173ISL_FORMAT_R10G10B10_FLOAT_A2_UNORM = 213,174ISL_FORMAT_R32_SINT = 214,175ISL_FORMAT_R32_UINT = 215,176ISL_FORMAT_R32_FLOAT = 216,177ISL_FORMAT_R24_UNORM_X8_TYPELESS = 217,178ISL_FORMAT_X24_TYPELESS_G8_UINT = 218,179ISL_FORMAT_L32_UNORM = 221,180ISL_FORMAT_A32_UNORM = 222,181ISL_FORMAT_L16A16_UNORM = 223,182ISL_FORMAT_I24X8_UNORM = 224,183ISL_FORMAT_L24X8_UNORM = 225,184ISL_FORMAT_A24X8_UNORM = 226,185ISL_FORMAT_I32_FLOAT = 227,186ISL_FORMAT_L32_FLOAT = 228,187ISL_FORMAT_A32_FLOAT = 229,188ISL_FORMAT_X8B8_UNORM_G8R8_SNORM = 230,189ISL_FORMAT_A8X8_UNORM_G8R8_SNORM = 231,190ISL_FORMAT_B8X8_UNORM_G8R8_SNORM = 232,191ISL_FORMAT_B8G8R8X8_UNORM = 233,192ISL_FORMAT_B8G8R8X8_UNORM_SRGB = 234,193ISL_FORMAT_R8G8B8X8_UNORM = 235,194ISL_FORMAT_R8G8B8X8_UNORM_SRGB = 236,195ISL_FORMAT_R9G9B9E5_SHAREDEXP = 237,196ISL_FORMAT_B10G10R10X2_UNORM = 238,197ISL_FORMAT_L16A16_FLOAT = 240,198ISL_FORMAT_R32_UNORM = 241,199ISL_FORMAT_R32_SNORM = 242,200ISL_FORMAT_R10G10B10X2_USCALED = 243,201ISL_FORMAT_R8G8B8A8_SSCALED = 244,202ISL_FORMAT_R8G8B8A8_USCALED = 245,203ISL_FORMAT_R16G16_SSCALED = 246,204ISL_FORMAT_R16G16_USCALED = 247,205ISL_FORMAT_R32_SSCALED = 248,206ISL_FORMAT_R32_USCALED = 249,207ISL_FORMAT_B5G6R5_UNORM = 256,208ISL_FORMAT_B5G6R5_UNORM_SRGB = 257,209ISL_FORMAT_B5G5R5A1_UNORM = 258,210ISL_FORMAT_B5G5R5A1_UNORM_SRGB = 259,211ISL_FORMAT_B4G4R4A4_UNORM = 260,212ISL_FORMAT_B4G4R4A4_UNORM_SRGB = 261,213ISL_FORMAT_R8G8_UNORM = 262,214ISL_FORMAT_R8G8_SNORM = 263,215ISL_FORMAT_R8G8_SINT = 264,216ISL_FORMAT_R8G8_UINT = 265,217ISL_FORMAT_R16_UNORM = 266,218ISL_FORMAT_R16_SNORM = 267,219ISL_FORMAT_R16_SINT = 268,220ISL_FORMAT_R16_UINT = 269,221ISL_FORMAT_R16_FLOAT = 270,222ISL_FORMAT_A8P8_UNORM_PALETTE0 = 271,223ISL_FORMAT_A8P8_UNORM_PALETTE1 = 272,224ISL_FORMAT_I16_UNORM = 273,225ISL_FORMAT_L16_UNORM = 274,226ISL_FORMAT_A16_UNORM = 275,227ISL_FORMAT_L8A8_UNORM = 276,228ISL_FORMAT_I16_FLOAT = 277,229ISL_FORMAT_L16_FLOAT = 278,230ISL_FORMAT_A16_FLOAT = 279,231ISL_FORMAT_L8A8_UNORM_SRGB = 280,232ISL_FORMAT_R5G5_SNORM_B6_UNORM = 281,233ISL_FORMAT_B5G5R5X1_UNORM = 282,234ISL_FORMAT_B5G5R5X1_UNORM_SRGB = 283,235ISL_FORMAT_R8G8_SSCALED = 284,236ISL_FORMAT_R8G8_USCALED = 285,237ISL_FORMAT_R16_SSCALED = 286,238ISL_FORMAT_R16_USCALED = 287,239ISL_FORMAT_P8A8_UNORM_PALETTE0 = 290,240ISL_FORMAT_P8A8_UNORM_PALETTE1 = 291,241ISL_FORMAT_A1B5G5R5_UNORM = 292,242ISL_FORMAT_A4B4G4R4_UNORM = 293,243ISL_FORMAT_L8A8_UINT = 294,244ISL_FORMAT_L8A8_SINT = 295,245ISL_FORMAT_R8_UNORM = 320,246ISL_FORMAT_R8_SNORM = 321,247ISL_FORMAT_R8_SINT = 322,248ISL_FORMAT_R8_UINT = 323,249ISL_FORMAT_A8_UNORM = 324,250ISL_FORMAT_I8_UNORM = 325,251ISL_FORMAT_L8_UNORM = 326,252ISL_FORMAT_P4A4_UNORM_PALETTE0 = 327,253ISL_FORMAT_A4P4_UNORM_PALETTE0 = 328,254ISL_FORMAT_R8_SSCALED = 329,255ISL_FORMAT_R8_USCALED = 330,256ISL_FORMAT_P8_UNORM_PALETTE0 = 331,257ISL_FORMAT_L8_UNORM_SRGB = 332,258ISL_FORMAT_P8_UNORM_PALETTE1 = 333,259ISL_FORMAT_P4A4_UNORM_PALETTE1 = 334,260ISL_FORMAT_A4P4_UNORM_PALETTE1 = 335,261ISL_FORMAT_Y8_UNORM = 336,262ISL_FORMAT_L8_UINT = 338,263ISL_FORMAT_L8_SINT = 339,264ISL_FORMAT_I8_UINT = 340,265ISL_FORMAT_I8_SINT = 341,266ISL_FORMAT_DXT1_RGB_SRGB = 384,267ISL_FORMAT_R1_UNORM = 385,268ISL_FORMAT_YCRCB_NORMAL = 386,269ISL_FORMAT_YCRCB_SWAPUVY = 387,270ISL_FORMAT_P2_UNORM_PALETTE0 = 388,271ISL_FORMAT_P2_UNORM_PALETTE1 = 389,272ISL_FORMAT_BC1_UNORM = 390,273ISL_FORMAT_BC2_UNORM = 391,274ISL_FORMAT_BC3_UNORM = 392,275ISL_FORMAT_BC4_UNORM = 393,276ISL_FORMAT_BC5_UNORM = 394,277ISL_FORMAT_BC1_UNORM_SRGB = 395,278ISL_FORMAT_BC2_UNORM_SRGB = 396,279ISL_FORMAT_BC3_UNORM_SRGB = 397,280ISL_FORMAT_MONO8 = 398,281ISL_FORMAT_YCRCB_SWAPUV = 399,282ISL_FORMAT_YCRCB_SWAPY = 400,283ISL_FORMAT_DXT1_RGB = 401,284ISL_FORMAT_FXT1 = 402,285ISL_FORMAT_R8G8B8_UNORM = 403,286ISL_FORMAT_R8G8B8_SNORM = 404,287ISL_FORMAT_R8G8B8_SSCALED = 405,288ISL_FORMAT_R8G8B8_USCALED = 406,289ISL_FORMAT_R64G64B64A64_FLOAT = 407,290ISL_FORMAT_R64G64B64_FLOAT = 408,291ISL_FORMAT_BC4_SNORM = 409,292ISL_FORMAT_BC5_SNORM = 410,293ISL_FORMAT_R16G16B16_FLOAT = 411,294ISL_FORMAT_R16G16B16_UNORM = 412,295ISL_FORMAT_R16G16B16_SNORM = 413,296ISL_FORMAT_R16G16B16_SSCALED = 414,297ISL_FORMAT_R16G16B16_USCALED = 415,298ISL_FORMAT_BC6H_SF16 = 417,299ISL_FORMAT_BC7_UNORM = 418,300ISL_FORMAT_BC7_UNORM_SRGB = 419,301ISL_FORMAT_BC6H_UF16 = 420,302ISL_FORMAT_PLANAR_420_8 = 421,303ISL_FORMAT_PLANAR_420_16 = 422,304ISL_FORMAT_R8G8B8_UNORM_SRGB = 424,305ISL_FORMAT_ETC1_RGB8 = 425,306ISL_FORMAT_ETC2_RGB8 = 426,307ISL_FORMAT_EAC_R11 = 427,308ISL_FORMAT_EAC_RG11 = 428,309ISL_FORMAT_EAC_SIGNED_R11 = 429,310ISL_FORMAT_EAC_SIGNED_RG11 = 430,311ISL_FORMAT_ETC2_SRGB8 = 431,312ISL_FORMAT_R16G16B16_UINT = 432,313ISL_FORMAT_R16G16B16_SINT = 433,314ISL_FORMAT_R32_SFIXED = 434,315ISL_FORMAT_R10G10B10A2_SNORM = 435,316ISL_FORMAT_R10G10B10A2_USCALED = 436,317ISL_FORMAT_R10G10B10A2_SSCALED = 437,318ISL_FORMAT_R10G10B10A2_SINT = 438,319ISL_FORMAT_B10G10R10A2_SNORM = 439,320ISL_FORMAT_B10G10R10A2_USCALED = 440,321ISL_FORMAT_B10G10R10A2_SSCALED = 441,322ISL_FORMAT_B10G10R10A2_UINT = 442,323ISL_FORMAT_B10G10R10A2_SINT = 443,324ISL_FORMAT_R64G64B64A64_PASSTHRU = 444,325ISL_FORMAT_R64G64B64_PASSTHRU = 445,326ISL_FORMAT_ETC2_RGB8_PTA = 448,327ISL_FORMAT_ETC2_SRGB8_PTA = 449,328ISL_FORMAT_ETC2_EAC_RGBA8 = 450,329ISL_FORMAT_ETC2_EAC_SRGB8_A8 = 451,330ISL_FORMAT_R8G8B8_UINT = 456,331ISL_FORMAT_R8G8B8_SINT = 457,332ISL_FORMAT_RAW = 511,333ISL_FORMAT_ASTC_LDR_2D_4X4_U8SRGB = 512,334ISL_FORMAT_ASTC_LDR_2D_5X4_U8SRGB = 520,335ISL_FORMAT_ASTC_LDR_2D_5X5_U8SRGB = 521,336ISL_FORMAT_ASTC_LDR_2D_6X5_U8SRGB = 529,337ISL_FORMAT_ASTC_LDR_2D_6X6_U8SRGB = 530,338ISL_FORMAT_ASTC_LDR_2D_8X5_U8SRGB = 545,339ISL_FORMAT_ASTC_LDR_2D_8X6_U8SRGB = 546,340ISL_FORMAT_ASTC_LDR_2D_8X8_U8SRGB = 548,341ISL_FORMAT_ASTC_LDR_2D_10X5_U8SRGB = 561,342ISL_FORMAT_ASTC_LDR_2D_10X6_U8SRGB = 562,343ISL_FORMAT_ASTC_LDR_2D_10X8_U8SRGB = 564,344ISL_FORMAT_ASTC_LDR_2D_10X10_U8SRGB = 566,345ISL_FORMAT_ASTC_LDR_2D_12X10_U8SRGB = 574,346ISL_FORMAT_ASTC_LDR_2D_12X12_U8SRGB = 575,347ISL_FORMAT_ASTC_LDR_2D_4X4_FLT16 = 576,348ISL_FORMAT_ASTC_LDR_2D_5X4_FLT16 = 584,349ISL_FORMAT_ASTC_LDR_2D_5X5_FLT16 = 585,350ISL_FORMAT_ASTC_LDR_2D_6X5_FLT16 = 593,351ISL_FORMAT_ASTC_LDR_2D_6X6_FLT16 = 594,352ISL_FORMAT_ASTC_LDR_2D_8X5_FLT16 = 609,353ISL_FORMAT_ASTC_LDR_2D_8X6_FLT16 = 610,354ISL_FORMAT_ASTC_LDR_2D_8X8_FLT16 = 612,355ISL_FORMAT_ASTC_LDR_2D_10X5_FLT16 = 625,356ISL_FORMAT_ASTC_LDR_2D_10X6_FLT16 = 626,357ISL_FORMAT_ASTC_LDR_2D_10X8_FLT16 = 628,358ISL_FORMAT_ASTC_LDR_2D_10X10_FLT16 = 630,359ISL_FORMAT_ASTC_LDR_2D_12X10_FLT16 = 638,360ISL_FORMAT_ASTC_LDR_2D_12X12_FLT16 = 639,361ISL_FORMAT_ASTC_HDR_2D_4X4_FLT16 = 832,362ISL_FORMAT_ASTC_HDR_2D_5X4_FLT16 = 840,363ISL_FORMAT_ASTC_HDR_2D_5X5_FLT16 = 841,364ISL_FORMAT_ASTC_HDR_2D_6X5_FLT16 = 849,365ISL_FORMAT_ASTC_HDR_2D_6X6_FLT16 = 850,366ISL_FORMAT_ASTC_HDR_2D_8X5_FLT16 = 865,367ISL_FORMAT_ASTC_HDR_2D_8X6_FLT16 = 866,368ISL_FORMAT_ASTC_HDR_2D_8X8_FLT16 = 868,369ISL_FORMAT_ASTC_HDR_2D_10X5_FLT16 = 881,370ISL_FORMAT_ASTC_HDR_2D_10X6_FLT16 = 882,371ISL_FORMAT_ASTC_HDR_2D_10X8_FLT16 = 884,372ISL_FORMAT_ASTC_HDR_2D_10X10_FLT16 = 886,373ISL_FORMAT_ASTC_HDR_2D_12X10_FLT16 = 894,374ISL_FORMAT_ASTC_HDR_2D_12X12_FLT16 = 895,375376/* The formats that follow are internal to ISL and as such don't have an377* explicit number. We'll just let the C compiler assign it for us. Any378* actual hardware formats *must* come before these in the list.379*/380381/* Formats for the aux-map */382ISL_FORMAT_PLANAR_420_10,383ISL_FORMAT_PLANAR_420_12,384385/* Formats for auxiliary surfaces */386ISL_FORMAT_HIZ,387ISL_FORMAT_MCS_2X,388ISL_FORMAT_MCS_4X,389ISL_FORMAT_MCS_8X,390ISL_FORMAT_MCS_16X,391ISL_FORMAT_GFX7_CCS_32BPP_X,392ISL_FORMAT_GFX7_CCS_64BPP_X,393ISL_FORMAT_GFX7_CCS_128BPP_X,394ISL_FORMAT_GFX7_CCS_32BPP_Y,395ISL_FORMAT_GFX7_CCS_64BPP_Y,396ISL_FORMAT_GFX7_CCS_128BPP_Y,397ISL_FORMAT_GFX9_CCS_32BPP,398ISL_FORMAT_GFX9_CCS_64BPP,399ISL_FORMAT_GFX9_CCS_128BPP,400ISL_FORMAT_GFX12_CCS_8BPP_Y0,401ISL_FORMAT_GFX12_CCS_16BPP_Y0,402ISL_FORMAT_GFX12_CCS_32BPP_Y0,403ISL_FORMAT_GFX12_CCS_64BPP_Y0,404ISL_FORMAT_GFX12_CCS_128BPP_Y0,405406/* An upper bound on the supported format enumerations */407ISL_NUM_FORMATS,408409/* Hardware doesn't understand this out-of-band value */410ISL_FORMAT_UNSUPPORTED = UINT16_MAX,411};412413/**414* Numerical base type for channels of isl_format.415*/416enum PACKED isl_base_type {417/** Data which takes up space but is ignored */418ISL_VOID,419420/** Data in a "raw" form and cannot be easily interpreted */421ISL_RAW,422423/**424* Unsigned normalized data425*426* Though stored as an integer, the data is interpreted as a floating-point427* number in the range [0, 1] where the conversion from the in-memory428* representation to float is given by \f$\frac{x}{2^{bits} - 1}\f$.429*/430ISL_UNORM,431432/**433* Signed normalized data434*435* Though stored as an integer, the data is interpreted as a floating-point436* number in the range [-1, 1] where the conversion from the in-memory437* representation to float is given by438* \f$max\left(\frac{x}{2^{bits - 1} - 1}, -1\right)\f$.439*/440ISL_SNORM,441442/**443* Unsigned floating-point data444*445* Unlike the standard IEEE floating-point representation, unsigned446* floating-point data has no sign bit. This saves a bit of space which is447* important if more than one float is required to represent a color value.448* As with IEEE floats, the high bits are the exponent and the low bits are449* the mantissa. The available bit sizes for unsigned floats are as450* follows:451*452* \rst453* ===== ========= =========454* Bits Mantissa Exponent455* ===== ========= =========456* 11 6 5457* 10 5 5458* ===== ========= =========459* \endrst460*461* In particular, both unsigned floating-point formats are identical to462* IEEE float16 except that the sign bit and the bottom mantissa bits are463* removed.464*/465ISL_UFLOAT,466467/** Signed floating-point data468*469* Signed floating-point data is represented as standard IEEE floats with470* the usual number of mantissa and exponent bits471*472* \rst473* ===== ========= =========474* Bits Mantissa Exponent475* ===== ========= =========476* 64 52 11477* 32 23 8478* 16 10 5479* ===== ========= =========480* \endrst481*/482ISL_SFLOAT,483484/**485* Unsigned fixed-point data486*487* This is a 32-bit unsigned integer that is interpreted as a 16.16488* fixed-point value.489*/490ISL_UFIXED,491492/**493* Signed fixed-point data494*495* This is a 32-bit signed integer that is interpreted as a 16.16496* fixed-point value.497*/498ISL_SFIXED,499500/** Unsigned integer data */501ISL_UINT,502503/** Signed integer data */504ISL_SINT,505506/**507* Unsigned scaled data508*509* This is data which is stored as an unsigned integer but interpreted as a510* floating-point value by the hardware. The re-interpretation is done via511* a simple unsigned integer to float cast. This is typically used as a512* vertex format.513*/514ISL_USCALED,515516/**517* Signed scaled data518*519* This is data which is stored as a signed integer but interpreted as a520* floating-point value by the hardware. The re-interpretation is done via521* a simple signed integer to float cast. This is typically used as a522* vertex format.523*/524ISL_SSCALED,525};526527/**528* Colorspace of isl_format.529*/530enum isl_colorspace {531ISL_COLORSPACE_NONE = 0,532ISL_COLORSPACE_LINEAR,533ISL_COLORSPACE_SRGB,534ISL_COLORSPACE_YUV,535};536537/**538* Texture compression mode of isl_format.539*/540enum isl_txc {541ISL_TXC_NONE = 0,542ISL_TXC_DXT1,543ISL_TXC_DXT3,544ISL_TXC_DXT5,545ISL_TXC_FXT1,546ISL_TXC_RGTC1,547ISL_TXC_RGTC2,548ISL_TXC_BPTC,549ISL_TXC_ETC1,550ISL_TXC_ETC2,551ISL_TXC_ASTC,552553/* Used for auxiliary surface formats */554ISL_TXC_HIZ,555ISL_TXC_MCS,556ISL_TXC_CCS,557};558559/**560* Describes the memory tiling of a surface561*562* This differs from the HW enum values used to represent tiling. The bits563* used by hardware have varried significantly over the years from the564* "Tile Walk" bit on old pre-Broadwell parts to the "Tile Mode" enum on565* Broadwell to the combination of "Tile Mode" and "Tiled Resource Mode" on566* Skylake. This enum represents them all in a consistent manner and in one567* place.568*569* Note that legacy Y tiling is ISL_TILING_Y0 instead of ISL_TILING_Y, to570* clearly distinguish it from Yf and Ys.571*/572enum isl_tiling {573ISL_TILING_LINEAR = 0, /**< Linear, or no tiling */574ISL_TILING_W, /**< W tiling */575ISL_TILING_X, /**< X tiling */576ISL_TILING_Y0, /**< Legacy Y tiling */577ISL_TILING_Yf, /**< Standard 4K tiling. The 'f' means "four". */578ISL_TILING_Ys, /**< Standard 64K tiling. The 's' means "sixty-four". */579ISL_TILING_HIZ, /**< Tiling format for HiZ surfaces */580ISL_TILING_CCS, /**< Tiling format for CCS surfaces */581ISL_TILING_GFX12_CCS, /**< Tiling format for Gfx12 CCS surfaces */582};583584/**585* @defgroup Tiling Flags586* @{587*/588typedef uint32_t isl_tiling_flags_t;589#define ISL_TILING_LINEAR_BIT (1u << ISL_TILING_LINEAR)590#define ISL_TILING_W_BIT (1u << ISL_TILING_W)591#define ISL_TILING_X_BIT (1u << ISL_TILING_X)592#define ISL_TILING_Y0_BIT (1u << ISL_TILING_Y0)593#define ISL_TILING_Yf_BIT (1u << ISL_TILING_Yf)594#define ISL_TILING_Ys_BIT (1u << ISL_TILING_Ys)595#define ISL_TILING_HIZ_BIT (1u << ISL_TILING_HIZ)596#define ISL_TILING_CCS_BIT (1u << ISL_TILING_CCS)597#define ISL_TILING_GFX12_CCS_BIT (1u << ISL_TILING_GFX12_CCS)598#define ISL_TILING_ANY_MASK (~0u)599#define ISL_TILING_NON_LINEAR_MASK (~ISL_TILING_LINEAR_BIT)600601/** Any Y tiling, including legacy Y tiling. */602#define ISL_TILING_ANY_Y_MASK (ISL_TILING_Y0_BIT | \603ISL_TILING_Yf_BIT | \604ISL_TILING_Ys_BIT)605606/** The Skylake BSpec refers to Yf and Ys as "standard tiling formats". */607#define ISL_TILING_STD_Y_MASK (ISL_TILING_Yf_BIT | \608ISL_TILING_Ys_BIT)609/** @} */610611/**612* @brief Logical dimension of surface.613*614* Note: There is no dimension for cube map surfaces. ISL interprets cube maps615* as 2D array surfaces.616*/617enum isl_surf_dim {618ISL_SURF_DIM_1D,619ISL_SURF_DIM_2D,620ISL_SURF_DIM_3D,621};622623/**624* @brief Physical layout of the surface's dimensions.625*/626enum isl_dim_layout {627/**628* For details, see the G35 PRM >> Volume 1: Graphics Core >> Section629* 6.17.3: 2D Surfaces.630*631* On many gens, 1D surfaces share the same layout as 2D surfaces. From632* the G35 PRM >> Volume 1: Graphics Core >> Section 6.17.2: 1D Surfaces:633*634* One-dimensional surfaces are identical to 2D surfaces with height of635* one.636*637* @invariant isl_surf::phys_level0_sa::depth == 1638*/639ISL_DIM_LAYOUT_GFX4_2D,640641/**642* For details, see the G35 PRM >> Volume 1: Graphics Core >> Section643* 6.17.5: 3D Surfaces.644*645* @invariant isl_surf::phys_level0_sa::array_len == 1646*/647ISL_DIM_LAYOUT_GFX4_3D,648649/**650* Special layout used for HiZ and stencil on Sandy Bridge to work around651* the hardware's lack of mipmap support. On gfx6, HiZ and stencil buffers652* work the same as on gfx7+ except that they don't technically support653* mipmapping. That does not, however, stop us from doing it. As far as654* Sandy Bridge hardware is concerned, HiZ and stencil always operates on a655* single miplevel 2D (possibly array) image. The dimensions of that image656* are NOT minified.657*658* In order to implement HiZ and stencil on Sandy Bridge, we create one659* full-sized 2D (possibly array) image for every LOD with every image660* aligned to a page boundary. When the surface is used with the stencil661* or HiZ hardware, we manually offset to the image for the given LOD.662*663* As a memory saving measure, we pretend that the width of each miplevel664* is minified and we place LOD1 and above below LOD0 but horizontally665* adjacent to each other. When considered as full-sized images, LOD1 and666* above technically overlap. However, since we only write to part of that667* image, the hardware will never notice the overlap.668*669* This layout looks something like this:670*671* +---------+672* | |673* | |674* +---------+675* | |676* | |677* +---------+678*679* +----+ +-+ .680* | | +-+681* +----+682*683* +----+ +-+ .684* | | +-+685* +----+686*/687ISL_DIM_LAYOUT_GFX6_STENCIL_HIZ,688689/**690* For details, see the Skylake BSpec >> Memory Views >> Common Surface691* Formats >> Surface Layout and Tiling >> » 1D Surfaces.692*/693ISL_DIM_LAYOUT_GFX9_1D,694};695696/**697* Enumerates the different forms of auxiliary surface compression698*/699enum isl_aux_usage {700/** No Auxiliary surface is used */701ISL_AUX_USAGE_NONE,702703/** Hierarchical depth compression704*705* First introduced on Iron Lake, this compression scheme compresses depth706* surfaces by storing alternate forms of the depth value in a HiZ surface.707* Possible (not all) compressed forms include:708*709* - An uncompressed "look at the main surface" value710*711* - A special value indicating that the main surface data should be712* ignored and considered to contain the clear value.713*714* - The depth for the entire main-surface block as a plane equation715*716* - The minimum/maximum depth for the main-surface block717*718* This second one isn't helpful for getting exact depth values but can719* still substantially accelerate depth testing if the specified range is720* sufficiently small.721*/722ISL_AUX_USAGE_HIZ,723724/** Multisampled color compression725*726* Introduced on Ivy Bridge, this compression scheme compresses727* multisampled color surfaces by storing a mapping from samples to planes728* in the MCS surface, allowing for de-duplication of identical samples.729* The MCS value of all 1's is reserved to indicate that the pixel contains730* the clear color. Exact details about the data stored in the MCS and how731* it maps samples to slices is documented in the PRMs.732*733* @invariant isl_surf::samples > 1734*/735ISL_AUX_USAGE_MCS,736737/** Single-sampled fast-clear-only color compression738*739* Introduced on Ivy Bridge, this compression scheme compresses740* single-sampled color surfaces by storing a bit for each cache line pair741* in the main surface in the CCS which indicates that the corresponding742* pair of cache lines in the main surface only contains the clear color.743* On Skylake, this is increased to two bits per cache line pair with 0x0744* meaning resolved and 0x3 meaning clear.745*746* @invariant The surface is a color surface747* @invariant isl_surf::samples == 1748*/749ISL_AUX_USAGE_CCS_D,750751/** Single-sample lossless color compression752*753* Introduced on Skylake, this compression scheme compresses single-sampled754* color surfaces by storing a 2-bit value for each cache line pair in the755* main surface which says how the corresponding pair of cache lines in the756* main surface are to be interpreted. Valid CCS values include:757*758* - `0x0`: Indicates that the corresponding pair of cache lines in the759* main surface contain valid color data760*761* - `0x1`: Indicates that the corresponding pair of cache lines in the762* main surface contain compressed color data. Typically, the763* compressed data fits in one of the two cache lines.764*765* - `0x3`: Indicates that the corresponding pair of cache lines in the766* main surface should be ignored. Those cache lines should be767* considered to contain the clear color.768*769* Starting with Tigerlake, each CCS value is 4 bits per cache line pair in770* the main surface.771*772* @invariant The surface is a color surface773* @invariant isl_surf::samples == 1774*/775ISL_AUX_USAGE_CCS_E,776777/** Single-sample lossless color compression on Tigerlake778*779* This is identical to ISL_AUX_USAGE_CCS_E except it also encodes the780* Tigerlake quirk about regular render writes possibly fast-clearing781* blocks in the surface.782*783* @invariant The surface is a color surface784* @invariant isl_surf::samples == 1785*/786ISL_AUX_USAGE_GFX12_CCS_E,787788/** Media color compression789*790* Used by the media engine on Tigerlake and above. This compression form791* is typically not produced by 3D drivers but they need to be able to792* consume it in order to get end-to-end compression when the image comes793* from media decode.794*795* @invariant The surface is a color surface796* @invariant isl_surf::samples == 1797*/798ISL_AUX_USAGE_MC,799800/** Combined HiZ+CCS in write-through mode801*802* In this mode, introduced on Tigerlake, the HiZ and CCS surfaces act as a803* single fused compression surface where resolves (but not ambiguates)804* operate on both surfaces at the same time. In this mode, the HiZ805* surface operates in write-through mode where it is only used for806* accelerating depth testing and not for actual compression. The807* CCS-compressed surface contains valid data at all times.808*809* @invariant The surface is a color surface810* @invariant isl_surf::samples == 1811*/812ISL_AUX_USAGE_HIZ_CCS_WT,813814/** Combined HiZ+CCS without write-through815*816* In this mode, introduced on Tigerlake, the HiZ and CCS surfaces act as a817* single fused compression surface where resolves (but not ambiguates)818* operate on both surfaces at the same time. In this mode, full HiZ819* compression is enabled and the CCS-compressed main surface may not820* contain valid data. The only way to read the surface outside of the821* depth hardware is to do a full resolve which resolves both HiZ and CCS822* so the surface is in the pass-through state.823*824* @invariant The surface is a depth surface825*/826ISL_AUX_USAGE_HIZ_CCS,827828/** Combined MCS+CCS without write-through829*830* In this mode, introduced on Tigerlake, we have fused MCS+CCS compression831* where the MCS is used for fast-clears and "identical samples"832* compression just like on Gfx7-11 but each plane is then CCS compressed.833*834* @invariant The surface is a depth surface835* @invariant isl_surf::samples > 1836*/837ISL_AUX_USAGE_MCS_CCS,838839/** Stencil compression840*841* Introduced on Tigerlake, this is similar to CCS_E only used to compress842* stencil surfaces.843*844* @invariant The surface is a stencil surface845* @invariant isl_surf::samples == 1846*/847ISL_AUX_USAGE_STC_CCS,848};849850/**851* Enum for keeping track of the state an auxiliary compressed surface.852*853* For any given auxiliary surface compression format (HiZ, CCS, or MCS), any854* given slice (lod + array layer) can be in one of the seven states described855* by this enum. Drawing with or without aux enabled may implicitly cause the856* surface to transition between these states. There are also four types of857* auxiliary compression operations which cause an explicit transition which858* are described by the isl_aux_op enum below.859*860* Not all operations are valid or useful in all states. The diagram below861* contains a complete description of the states and all valid and useful862* transitions except clear.863*864* Draw w/ Aux865* +----------+866* | |867* | +-------------+ Draw w/ Aux +-------------+868* +------>| Compressed |<-------------------| Clear |869* | w/ Clear |----->----+ | |870* +-------------+ | +-------------+871* | /|\ | | |872* | | | | |873* | | +------<-----+ | Draw w/874* | | | | Clear Only875* | | Full | | +----------+876* Partial | | Resolve | \|/ | |877* Resolve | | | +-------------+ |878* | | | | Partial |<------+879* | | | | Clear |<----------+880* | | | +-------------+ |881* | | | | |882* | | +------>---------+ Full |883* | | | Resolve |884* Draw w/ aux | | Partial Fast Clear | |885* +----------+ | +--------------------------+ | |886* | | \|/ | \|/ |887* | +-------------+ Full Resolve +-------------+ |888* +------>| Compressed |------------------->| Resolved | |889* | w/o Clear |<-------------------| | |890* +-------------+ Draw w/ Aux +-------------+ |891* /|\ | | |892* | Draw | | Draw |893* | w/ Aux | | w/o Aux |894* | Ambiguate | | |895* | +--------------------------+ | |896* Draw w/o Aux | | | Draw w/o Aux |897* +----------+ | | | +----------+ |898* | | | \|/ \|/ | | |899* | +-------------+ Ambiguate +-------------+ | |900* +------>| Pass- |<-------------------| Aux |<------+ |901* +------>| through | | Invalid | |902* | +-------------+ +-------------+ |903* | | | |904* +----------+ +-----------------------------------------------------+905* Draw w/ Partial Fast Clear906* Clear Only907*908*909* While the above general theory applies to all forms of auxiliary910* compression on Intel hardware, not all states and operations are available911* on all compression types. However, each of the auxiliary states and912* operations can be fairly easily mapped onto the above diagram:913*914* **HiZ:** Hierarchical depth compression is capable of being in any of915* the states above. Hardware provides three HiZ operations: "Depth916* Clear", "Depth Resolve", and "HiZ Resolve" which map to "Fast Clear",917* "Full Resolve", and "Ambiguate" respectively. The hardware provides no918* HiZ partial resolve operation so the only way to get into the919* "Compressed w/o Clear" state is to render with HiZ when the surface is920* in the resolved or pass-through states.921*922* **MCS:** Multisample compression is technically capable of being in any of923* the states above except that most of them aren't useful. Both the render924* engine and the sampler support MCS compression and, apart from clear color,925* MCS is format-unaware so we leave the surface compressed 100% of the time.926* The hardware provides no MCS operations.927*928* **CCS_D:** Single-sample fast-clears (also called CCS_D in ISL) are one of929* the simplest forms of compression since they don't do anything beyond clear930* color tracking. They really only support three of the six states: Clear,931* Partial Clear, and Pass-through. The only CCS_D operation is "Resolve"932* which maps to a full resolve followed by an ambiguate.933*934* **CCS_E:** Single-sample render target compression (also called CCS_E in935* ISL) is capable of being in almost all of the above states. THe only936* exception is that it does not have separate resolved and pass- through937* states. Instead, the CCS_E full resolve operation does both a resolve and938* an ambiguate so it goes directly into the pass-through state. CCS_E also939* provides fast clear and partial resolve operations which work as described940* above.941*942* @note943* The state machine above isn't quite correct for CCS on TGL. There is a HW944* bug (or feature, depending on who you ask) which can cause blocks to enter945* the fast-clear state as a side-effect of a regular draw call. This means946* that a draw in the resolved or compressed without clear states takes you to947* the compressed with clear state, not the compressed without clear state.948*/949enum isl_aux_state {950#ifdef IN_UNIT_TEST951ISL_AUX_STATE_ASSERT,952#endif953/** Clear954*955* In this state, each block in the auxiliary surface contains a magic956* value that indicates that the block is in the clear state. If a block957* is in the clear state, its values in the primary surface are ignored958* and the color of the samples in the block is taken either the959* RENDER_SURFACE_STATE packet for color or 3DSTATE_CLEAR_PARAMS for depth.960* Since neither the primary surface nor the auxiliary surface contains the961* clear value, the surface can be cleared to a different color by simply962* changing the clear color without modifying either surface.963*/964ISL_AUX_STATE_CLEAR,965966/** Partial Clear967*968* In this state, each block in the auxiliary surface contains either the969* magic clear or pass-through value. See Clear and Pass-through for more970* details.971*/972ISL_AUX_STATE_PARTIAL_CLEAR,973974/** Compressed with clear color975*976* In this state, neither the auxiliary surface nor the primary surface has977* a complete representation of the data. Instead, both surfaces must be978* used together or else rendering corruption may occur. Depending on the979* auxiliary compression format and the data, any given block in the980* primary surface may contain all, some, or none of the data required to981* reconstruct the actual sample values. Blocks may also be in the clear982* state (see Clear) and have their value taken from outside the surface.983*/984ISL_AUX_STATE_COMPRESSED_CLEAR,985986/** Compressed without clear color987*988* This state is identical to the state above except that no blocks are in989* the clear state. In this state, all of the data required to reconstruct990* the final sample values is contained in the auxiliary and primary991* surface and the clear value is not considered.992*/993ISL_AUX_STATE_COMPRESSED_NO_CLEAR,994995/** Resolved996*997* In this state, the primary surface contains 100% of the data. The998* auxiliary surface is also valid so the surface can be validly used with999* or without aux enabled. The auxiliary surface may, however, contain1000* non-trivial data and any update to the primary surface with aux disabled1001* will cause the two to get out of sync.1002*/1003ISL_AUX_STATE_RESOLVED,10041005/** Pass-through1006*1007* In this state, the primary surface contains 100% of the data and every1008* block in the auxiliary surface contains a magic value which indicates1009* that the auxiliary surface should be ignored and only the primary1010* surface should be considered. In this mode, the primary surface can1011* safely be written with ISL_AUX_USAGE_NONE or by something that ignores1012* compression such as the blit/copy engine or a CPU map and it will stay1013* in the pass-through state. Writing to a surface in pass-through mode1014* with aux enabled may cause the auxiliary to be updated to contain1015* non-trivial data and it will no longer be in the pass-through state.1016* Likely, it will end up compressed, with or without clear color.1017*/1018ISL_AUX_STATE_PASS_THROUGH,10191020/** Aux Invalid1021*1022* In this state, the primary surface contains 100% of the data and the1023* auxiliary surface is completely bogus. Any attempt to use the auxiliary1024* surface is liable to result in rendering corruption. The only thing1025* that one can do to re-enable aux once this state is reached is to use an1026* ambiguate pass to transition into the pass-through state.1027*/1028ISL_AUX_STATE_AUX_INVALID,1029};10301031/** Enum describing explicit aux transition operations1032*1033* These operations are used to transition from one isl_aux_state to another.1034* Even though a draw does transition the state machine, it's not included in1035* this enum as it's something of a special case.1036*/1037enum isl_aux_op {1038#ifdef IN_UNIT_TEST1039ISL_AUX_OP_ASSERT,1040#endif10411042/** Do nothing */1043ISL_AUX_OP_NONE,10441045/** Fast Clear1046*1047* This operation writes the magic "clear" value to the auxiliary surface.1048* This operation will safely transition any slice of a surface from any1049* state to the clear state so long as the entire slice is fast cleared at1050* once. A fast clear that only covers part of a slice of a surface is1051* called a partial fast clear.1052*/1053ISL_AUX_OP_FAST_CLEAR,10541055/** Full Resolve1056*1057* This operation combines the auxiliary surface data with the primary1058* surface data and writes the result to the primary. For HiZ, the docs1059* call this a depth resolve. For CCS, the hardware full resolve operation1060* does both a full resolve and an ambiguate so it actually takes you all1061* the way to the pass-through state.1062*/1063ISL_AUX_OP_FULL_RESOLVE,10641065/** Partial Resolve1066*1067* This operation considers blocks which are in the "clear" state and1068* writes the clear value directly into the primary or auxiliary surface.1069* Once this operation completes, the surface is still compressed but no1070* longer references the clear color. This operation is only available1071* for CCS_E.1072*/1073ISL_AUX_OP_PARTIAL_RESOLVE,10741075/** Ambiguate1076*1077* This operation throws away the current auxiliary data and replaces it1078* with the magic pass-through value. If an ambiguate operation is1079* performed when the primary surface does not contain 100% of the data,1080* data will be lost. This operation is only implemented in hardware for1081* depth where it is called a HiZ resolve.1082*/1083ISL_AUX_OP_AMBIGUATE,1084};10851086/* TODO(chadv): Explain */1087enum isl_array_pitch_span {1088ISL_ARRAY_PITCH_SPAN_FULL,1089ISL_ARRAY_PITCH_SPAN_COMPACT,1090};10911092/**1093* @defgroup Surface Usage1094* @{1095*/1096typedef uint64_t isl_surf_usage_flags_t;1097#define ISL_SURF_USAGE_RENDER_TARGET_BIT (1u << 0)1098#define ISL_SURF_USAGE_DEPTH_BIT (1u << 1)1099#define ISL_SURF_USAGE_STENCIL_BIT (1u << 2)1100#define ISL_SURF_USAGE_TEXTURE_BIT (1u << 3)1101#define ISL_SURF_USAGE_CUBE_BIT (1u << 4)1102#define ISL_SURF_USAGE_DISABLE_AUX_BIT (1u << 5)1103#define ISL_SURF_USAGE_DISPLAY_BIT (1u << 6)1104#define ISL_SURF_USAGE_DISPLAY_ROTATE_90_BIT (1u << 7)1105#define ISL_SURF_USAGE_DISPLAY_ROTATE_180_BIT (1u << 8)1106#define ISL_SURF_USAGE_DISPLAY_ROTATE_270_BIT (1u << 9)1107#define ISL_SURF_USAGE_DISPLAY_FLIP_X_BIT (1u << 10)1108#define ISL_SURF_USAGE_DISPLAY_FLIP_Y_BIT (1u << 11)1109#define ISL_SURF_USAGE_STORAGE_BIT (1u << 12)1110#define ISL_SURF_USAGE_HIZ_BIT (1u << 13)1111#define ISL_SURF_USAGE_MCS_BIT (1u << 14)1112#define ISL_SURF_USAGE_CCS_BIT (1u << 15)1113#define ISL_SURF_USAGE_VERTEX_BUFFER_BIT (1u << 16)1114#define ISL_SURF_USAGE_INDEX_BUFFER_BIT (1u << 17)1115#define ISL_SURF_USAGE_CONSTANT_BUFFER_BIT (1u << 18)1116#define ISL_SURF_USAGE_STAGING_BIT (1u << 19)1117/** @} */11181119/**1120* @defgroup Channel Mask1121*1122* These #define values are chosen to match the values of1123* RENDER_SURFACE_STATE::Color Buffer Component Write Disables1124*1125* @{1126*/1127typedef uint8_t isl_channel_mask_t;1128#define ISL_CHANNEL_BLUE_BIT (1 << 0)1129#define ISL_CHANNEL_GREEN_BIT (1 << 1)1130#define ISL_CHANNEL_RED_BIT (1 << 2)1131#define ISL_CHANNEL_ALPHA_BIT (1 << 3)1132/** @} */11331134/**1135* @brief A channel select (also known as texture swizzle) value1136*/1137enum PACKED isl_channel_select {1138ISL_CHANNEL_SELECT_ZERO = 0,1139ISL_CHANNEL_SELECT_ONE = 1,1140ISL_CHANNEL_SELECT_RED = 4,1141ISL_CHANNEL_SELECT_GREEN = 5,1142ISL_CHANNEL_SELECT_BLUE = 6,1143ISL_CHANNEL_SELECT_ALPHA = 7,1144};11451146/**1147* Identical to VkSampleCountFlagBits.1148*/1149enum isl_sample_count {1150ISL_SAMPLE_COUNT_1_BIT = 1u,1151ISL_SAMPLE_COUNT_2_BIT = 2u,1152ISL_SAMPLE_COUNT_4_BIT = 4u,1153ISL_SAMPLE_COUNT_8_BIT = 8u,1154ISL_SAMPLE_COUNT_16_BIT = 16u,1155};1156typedef uint32_t isl_sample_count_mask_t;11571158/**1159* @brief Multisample Format1160*/1161enum isl_msaa_layout {1162/**1163* @brief Suface is single-sampled.1164*/1165ISL_MSAA_LAYOUT_NONE,11661167/**1168* @brief [SNB+] Interleaved Multisample Format1169*1170* In this format, multiple samples are interleaved into each cacheline.1171* In other words, the sample index is swizzled into the low 6 bits of the1172* surface's virtual address space.1173*1174* For example, suppose the surface is legacy Y tiled, is 4x multisampled,1175* and its pixel format is 32bpp. Then the first cacheline is arranged1176* thus:1177*1178* (0,0,0) (0,1,0) (0,0,1) (1,0,1)1179* (1,0,0) (1,1,0) (0,1,1) (1,1,1)1180*1181* (0,0,2) (1,0,2) (0,0,3) (1,0,3)1182* (0,1,2) (1,1,2) (0,1,3) (1,1,3)1183*1184* The hardware docs refer to this format with multiple terms. In1185* Sandybridge, this is the only multisample format; so no term is used.1186* The Ivybridge docs refer to surfaces in this format as IMS (Interleaved1187* Multisample Surface). Later hardware docs additionally refer to this1188* format as MSFMT_DEPTH_STENCIL (because the format is deprecated for1189* color surfaces).1190*1191* See the Sandybridge PRM, Volume 4, Part 1, Section 2.7 "Multisampled1192* Surface Behavior".1193*1194* See the Ivybridge PRM, Volume 1, Part 1, Section 6.18.4.1 "Interleaved1195* Multisampled Surfaces".1196*/1197ISL_MSAA_LAYOUT_INTERLEAVED,11981199/**1200* @brief [IVB+] Array Multisample Format1201*1202* In this format, the surface's physical layout resembles that of a1203* 2D array surface.1204*1205* Suppose the multisample surface's logical extent is (w, h) and its1206* sample count is N. Then surface's physical extent is the same as1207* a singlesample 2D surface whose logical extent is (w, h) and array1208* length is N. Array slice `i` contains the pixel values for sample1209* index `i`.1210*1211* The Ivybridge docs refer to surfaces in this format as UMS1212* (Uncompressed Multsample Layout) and CMS (Compressed Multisample1213* Surface). The Broadwell docs additionally refer to this format as1214* MSFMT_MSS (MSS=Multisample Surface Storage).1215*1216* See the Broadwell PRM, Volume 5 "Memory Views", Section "Uncompressed1217* Multisample Surfaces".1218*1219* See the Broadwell PRM, Volume 5 "Memory Views", Section "Compressed1220* Multisample Surfaces".1221*/1222ISL_MSAA_LAYOUT_ARRAY,1223};12241225typedef enum {1226ISL_MEMCPY = 0,1227ISL_MEMCPY_BGRA8,1228ISL_MEMCPY_STREAMING_LOAD,1229ISL_MEMCPY_INVALID,1230} isl_memcpy_type;12311232struct isl_device {1233const struct intel_device_info *info;1234bool use_separate_stencil;1235bool has_bit6_swizzling;12361237/**1238* Describes the layout of a RENDER_SURFACE_STATE structure for the1239* current gen.1240*/1241struct {1242uint8_t size;1243uint8_t align;1244uint8_t addr_offset;1245uint8_t aux_addr_offset;12461247/* Rounded up to the nearest dword to simplify GPU memcpy operations. */12481249/* size of the state buffer used to store the clear color + extra1250* additional space used by the hardware */1251uint8_t clear_color_state_size;1252uint8_t clear_color_state_offset;1253/* size of the clear color itself - used to copy it to/from a BO */1254uint8_t clear_value_size;1255uint8_t clear_value_offset;1256} ss;12571258/**1259* Describes the layout of the depth/stencil/hiz commands as emitted by1260* isl_emit_depth_stencil_hiz.1261*/1262struct {1263uint8_t size;1264uint8_t depth_offset;1265uint8_t stencil_offset;1266uint8_t hiz_offset;1267} ds;12681269struct {1270uint32_t internal;1271uint32_t external;1272uint32_t l1_hdc_l3_llc;1273} mocs;1274};12751276struct isl_extent2d {1277union { uint32_t w, width; };1278union { uint32_t h, height; };1279};12801281struct isl_extent3d {1282union { uint32_t w, width; };1283union { uint32_t h, height; };1284union { uint32_t d, depth; };1285};12861287struct isl_extent4d {1288union { uint32_t w, width; };1289union { uint32_t h, height; };1290union { uint32_t d, depth; };1291union { uint32_t a, array_len; };1292};12931294/**1295* Describes a single channel of an isl_format1296*/1297struct isl_channel_layout {1298enum isl_base_type type; /**< Channel data encoding */1299uint8_t start_bit; /**< Bit at which this channel starts */1300uint8_t bits; /**< Size in bits */1301};13021303/**1304* Describes the layout of an isl_format1305*1306* Each format has 3D block extent (width, height, depth). The block extent of1307* compressed formats is that of the format's compression block. For example,1308* the block extent of `ISL_FORMAT_ETC2_RGB8` is `(w=4, h=4, d=1)`. The block1309* extent of uncompressed pixel formats, such as `ISL_FORMAT_R8G8B8A8_UNORM`,1310* is `(w=1, h=1, d=1)`.1311*/1312struct isl_format_layout {1313enum isl_format format; /**< Format */13141315uint16_t bpb; /**< Bits per block */1316uint8_t bw; /**< Block width, in pixels */1317uint8_t bh; /**< Block height, in pixels */1318uint8_t bd; /**< Block depth, in pixels */13191320union {1321struct {1322struct isl_channel_layout r; /**< Red channel */1323struct isl_channel_layout g; /**< Green channel */1324struct isl_channel_layout b; /**< Blue channel */1325struct isl_channel_layout a; /**< Alpha channel */1326struct isl_channel_layout l; /**< Luminance channel */1327struct isl_channel_layout i; /**< Intensity channel */1328struct isl_channel_layout p; /**< Palette channel */1329} channels;1330struct isl_channel_layout channels_array[7];1331};13321333/** Set if all channels have the same isl_base_type. Otherwise, ISL_VOID. */1334enum isl_base_type uniform_channel_type;13351336enum isl_colorspace colorspace;1337enum isl_txc txc;1338};13391340struct isl_tile_info {1341/** Tiling represented by this isl_tile_info */1342enum isl_tiling tiling;13431344/**1345* The size (in bits per block) of a single surface element1346*1347* For surfaces with power-of-two formats, this is the same as1348* isl_format_layout::bpb. For non-power-of-two formats it may be smaller.1349* The logical_extent_el field is in terms of elements of this size.1350*1351* For example, consider ISL_FORMAT_R32G32B32_FLOAT for which1352* isl_format_layout::bpb is 96 (a non-power-of-two). In this case, none1353* of the tiling formats can actually hold an integer number of 96-bit1354* surface elements so isl_tiling_get_info returns an isl_tile_info for a1355* 32-bit element size. It is the responsibility of the caller to1356* recognize that 32 != 96 ad adjust accordingly. For instance, to compute1357* the width of a surface in tiles, you would do:1358*1359* width_tl = DIV_ROUND_UP(width_el * (format_bpb / tile_info.format_bpb),1360* tile_info.logical_extent_el.width);1361*/1362uint32_t format_bpb;13631364/**1365* The logical size of the tile in units of format_bpb size elements1366*1367* This field determines how a given surface is cut up into tiles. It is1368* used to compute the size of a surface in tiles and can be used to1369* determine the location of the tile containing any given surface element.1370* The exact value of this field depends heavily on the bits-per-block of1371* the format being used.1372*/1373struct isl_extent4d logical_extent_el;13741375/**1376* The physical size of the tile in bytes and rows of bytes1377*1378* This field determines how the tiles of a surface are physically layed1379* out in memory. The logical and physical tile extent are frequently the1380* same but this is not always the case. For instance, a W-tile (which is1381* always used with ISL_FORMAT_R8) has a logical size of 64el x 64el but1382* its physical size is 128B x 32rows, the same as a Y-tile.1383*1384* @see isl_surf::row_pitch_B1385*/1386struct isl_extent2d phys_extent_B;1387};13881389/**1390* Metadata about a DRM format modifier.1391*/1392struct isl_drm_modifier_info {1393uint64_t modifier;13941395/** Text name of the modifier */1396const char *name;13971398/** ISL tiling implied by this modifier */1399enum isl_tiling tiling;14001401/** ISL aux usage implied by this modifier */1402enum isl_aux_usage aux_usage;14031404/** Whether or not this modifier supports clear color */1405bool supports_clear_color;1406};14071408/**1409* @brief Input to surface initialization1410*1411* @invariant width >= 11412* @invariant height >= 11413* @invariant depth >= 11414* @invariant levels >= 11415* @invariant samples >= 11416* @invariant array_len >= 11417*1418* @invariant if 1D then height == 1 and depth == 1 and samples == 11419* @invariant if 2D then depth == 11420* @invariant if 3D then array_len == 1 and samples == 11421*/1422struct isl_surf_init_info {1423enum isl_surf_dim dim;1424enum isl_format format;14251426uint32_t width;1427uint32_t height;1428uint32_t depth;1429uint32_t levels;1430uint32_t array_len;1431uint32_t samples;14321433/** Lower bound for isl_surf::alignment, in bytes. */1434uint32_t min_alignment_B;14351436/**1437* Exact value for isl_surf::row_pitch. Ignored if zero. isl_surf_init()1438* will fail if this is misaligned or out of bounds.1439*/1440uint32_t row_pitch_B;14411442isl_surf_usage_flags_t usage;14431444/** Flags that alter how ISL selects isl_surf::tiling. */1445isl_tiling_flags_t tiling_flags;1446};14471448struct isl_surf {1449/** Dimensionality of the surface */1450enum isl_surf_dim dim;14511452/**1453* Spatial layout of the surface in memory1454*1455* This is dependent on isl_surf::dim and hardware generation.1456*/1457enum isl_dim_layout dim_layout;14581459/** Spatial layout of the samples if isl_surf::samples > 1 */1460enum isl_msaa_layout msaa_layout;14611462/** Memory tiling used by the surface */1463enum isl_tiling tiling;14641465/**1466* Base image format of the surface1467*1468* This need not be the same as the format specified in isl_view::format1469* when a surface state is constructed. It must, however, have the same1470* number of bits per pixel or else memory calculations will go wrong.1471*/1472enum isl_format format;14731474/**1475* Alignment of the upper-left sample of each subimage, in units of surface1476* elements.1477*/1478struct isl_extent3d image_alignment_el;14791480/**1481* Logical extent of the surface's base level, in units of pixels. This is1482* identical to the extent defined in isl_surf_init_info.1483*/1484struct isl_extent4d logical_level0_px;14851486/**1487* Physical extent of the surface's base level, in units of physical1488* surface samples.1489*1490* Consider isl_dim_layout as an operator that transforms a logical surface1491* layout to a physical surface layout. Then1492*1493* logical_layout := (isl_surf::dim, isl_surf::logical_level0_px)1494* isl_surf::phys_level0_sa := isl_surf::dim_layout * logical_layout1495*/1496struct isl_extent4d phys_level0_sa;14971498/** Number of miplevels in the surface */1499uint32_t levels;15001501/**1502* Number of samples in the surface1503*1504* @invariant samples >= 11505*/1506uint32_t samples;15071508/** Total size of the surface, in bytes. */1509uint64_t size_B;15101511/** Required alignment for the surface's base address. */1512uint32_t alignment_B;15131514/**1515* The interpretation of this field depends on the value of1516* isl_tile_info::physical_extent_B. In particular, the width of the1517* surface in tiles is row_pitch_B / isl_tile_info::physical_extent_B.width1518* and the distance in bytes between vertically adjacent tiles in the image1519* is given by row_pitch_B * isl_tile_info::physical_extent_B.height.1520*1521* For linear images where isl_tile_info::physical_extent_B.height == 1,1522* this cleanly reduces to being the distance, in bytes, between vertically1523* adjacent surface elements.1524*1525* @see isl_tile_info::phys_extent_B;1526*/1527uint32_t row_pitch_B;15281529/**1530* Pitch between physical array slices, in rows of surface elements.1531*/1532uint32_t array_pitch_el_rows;15331534enum isl_array_pitch_span array_pitch_span;15351536/** Copy of isl_surf_init_info::usage. */1537isl_surf_usage_flags_t usage;1538};15391540struct isl_swizzle {1541enum isl_channel_select r:4;1542enum isl_channel_select g:4;1543enum isl_channel_select b:4;1544enum isl_channel_select a:4;1545};15461547#define ISL_SWIZZLE(R, G, B, A) ((struct isl_swizzle) { \1548.r = ISL_CHANNEL_SELECT_##R, \1549.g = ISL_CHANNEL_SELECT_##G, \1550.b = ISL_CHANNEL_SELECT_##B, \1551.a = ISL_CHANNEL_SELECT_##A, \1552})15531554#define ISL_SWIZZLE_IDENTITY ISL_SWIZZLE(RED, GREEN, BLUE, ALPHA)15551556struct isl_view {1557/**1558* Indicates the usage of the particular view1559*1560* Normally, this is one bit. However, for a cube map texture, it1561* should be ISL_SURF_USAGE_TEXTURE_BIT | ISL_SURF_USAGE_CUBE_BIT.1562*/1563isl_surf_usage_flags_t usage;15641565/**1566* The format to use in the view1567*1568* This may differ from the format of the actual isl_surf but must have1569* the same block size.1570*/1571enum isl_format format;15721573uint32_t base_level;1574uint32_t levels;15751576/**1577* Base array layer1578*1579* For cube maps, both base_array_layer and array_len should be1580* specified in terms of 2-D layers and must be a multiple of 6.1581*1582* 3-D textures are effectively treated as 2-D arrays when used as a1583* storage image or render target. If `usage` contains1584* ISL_SURF_USAGE_RENDER_TARGET_BIT or ISL_SURF_USAGE_STORAGE_BIT then1585* base_array_layer and array_len are applied. If the surface is only used1586* for texturing, they are ignored.1587*/1588uint32_t base_array_layer;15891590/**1591* Array Length1592*1593* Indicates the number of array elements starting at Base Array Layer.1594*/1595uint32_t array_len;15961597struct isl_swizzle swizzle;1598};15991600union isl_color_value {1601float f32[4];1602uint32_t u32[4];1603int32_t i32[4];1604};16051606struct isl_surf_fill_state_info {1607const struct isl_surf *surf;1608const struct isl_view *view;16091610/**1611* The address of the surface in GPU memory.1612*/1613uint64_t address;16141615/**1616* The Memory Object Control state for the filled surface state.1617*1618* The exact format of this value depends on hardware generation.1619*/1620uint32_t mocs;16211622/**1623* The auxilary surface or NULL if no auxilary surface is to be used.1624*/1625const struct isl_surf *aux_surf;1626enum isl_aux_usage aux_usage;1627uint64_t aux_address;16281629/**1630* The clear color for this surface1631*1632* Valid values depend on hardware generation.1633*/1634union isl_color_value clear_color;16351636/**1637* Send only the clear value address1638*1639* If set, we only pass the clear address to the GPU and it will fetch it1640* from wherever it is.1641*/1642bool use_clear_address;1643uint64_t clear_address;16441645/**1646* Surface write disables for gfx4-51647*/1648isl_channel_mask_t write_disables;16491650/**1651* blend enable for gfx4-51652*/1653bool blend_enable;16541655/* Intra-tile offset */1656uint16_t x_offset_sa, y_offset_sa;1657};16581659struct isl_buffer_fill_state_info {1660/**1661* The address of the surface in GPU memory.1662*/1663uint64_t address;16641665/**1666* The size of the buffer1667*/1668uint64_t size_B;16691670/**1671* The Memory Object Control state for the filled surface state.1672*1673* The exact format of this value depends on hardware generation.1674*/1675uint32_t mocs;16761677/**1678* The format to use in the surface state1679*1680* This may differ from the format of the actual isl_surf but have the1681* same block size.1682*/1683enum isl_format format;16841685/**1686* The swizzle to use in the surface state1687*/1688struct isl_swizzle swizzle;16891690uint32_t stride_B;16911692bool is_scratch;1693};16941695struct isl_depth_stencil_hiz_emit_info {1696/**1697* The depth surface1698*/1699const struct isl_surf *depth_surf;17001701/**1702* The stencil surface1703*1704* If separate stencil is not available, this must point to the same1705* isl_surf as depth_surf.1706*/1707const struct isl_surf *stencil_surf;17081709/**1710* The view into the depth and stencil surfaces.1711*1712* This view applies to both surfaces simultaneously.1713*/1714const struct isl_view *view;17151716/**1717* The address of the depth surface in GPU memory1718*/1719uint64_t depth_address;17201721/**1722* The address of the stencil surface in GPU memory1723*1724* If separate stencil is not available, this must have the same value as1725* depth_address.1726*/1727uint64_t stencil_address;17281729/**1730* The Memory Object Control state for depth and stencil buffers1731*1732* Both depth and stencil will get the same MOCS value. The exact format1733* of this value depends on hardware generation.1734*/1735uint32_t mocs;17361737/**1738* The HiZ surface or NULL if HiZ is disabled.1739*/1740const struct isl_surf *hiz_surf;1741enum isl_aux_usage hiz_usage;1742uint64_t hiz_address;17431744/**1745* The depth clear value1746*/1747float depth_clear_value;17481749/**1750* Track stencil aux usage for Gen >= 121751*/1752enum isl_aux_usage stencil_aux_usage;1753};17541755struct isl_null_fill_state_info {1756struct isl_extent3d size;1757uint32_t levels;1758uint32_t minimum_array_element;1759};17601761extern const struct isl_format_layout isl_format_layouts[];1762extern const char isl_format_names[];1763extern const uint16_t isl_format_name_offsets[];17641765void1766isl_device_init(struct isl_device *dev,1767const struct intel_device_info *info,1768bool has_bit6_swizzling);17691770isl_sample_count_mask_t ATTRIBUTE_CONST1771isl_device_get_sample_counts(struct isl_device *dev);17721773/**1774* \return The isl_format_layout for the given isl_format1775*/1776static inline const struct isl_format_layout * ATTRIBUTE_CONST1777isl_format_get_layout(enum isl_format fmt)1778{1779assert(fmt != ISL_FORMAT_UNSUPPORTED);1780assert(fmt < ISL_NUM_FORMATS);1781return &isl_format_layouts[fmt];1782}17831784bool isl_format_is_valid(enum isl_format);17851786static inline const char * ATTRIBUTE_CONST1787isl_format_get_name(enum isl_format fmt)1788{1789assert(fmt != ISL_FORMAT_UNSUPPORTED);1790assert(fmt < ISL_NUM_FORMATS);1791return isl_format_names + isl_format_name_offsets[fmt];1792}17931794enum isl_format isl_format_for_pipe_format(enum pipe_format pf);17951796bool isl_format_supports_rendering(const struct intel_device_info *devinfo,1797enum isl_format format);1798bool isl_format_supports_alpha_blending(const struct intel_device_info *devinfo,1799enum isl_format format);1800bool isl_format_supports_sampling(const struct intel_device_info *devinfo,1801enum isl_format format);1802bool isl_format_supports_filtering(const struct intel_device_info *devinfo,1803enum isl_format format);1804bool isl_format_supports_vertex_fetch(const struct intel_device_info *devinfo,1805enum isl_format format);1806bool isl_format_supports_typed_writes(const struct intel_device_info *devinfo,1807enum isl_format format);1808bool isl_format_supports_typed_reads(const struct intel_device_info *devinfo,1809enum isl_format format);1810bool isl_format_supports_ccs_d(const struct intel_device_info *devinfo,1811enum isl_format format);1812bool isl_format_supports_ccs_e(const struct intel_device_info *devinfo,1813enum isl_format format);1814bool isl_format_supports_multisampling(const struct intel_device_info *devinfo,1815enum isl_format format);18161817bool isl_formats_are_ccs_e_compatible(const struct intel_device_info *devinfo,1818enum isl_format format1,1819enum isl_format format2);1820uint8_t isl_format_get_aux_map_encoding(enum isl_format format);18211822bool isl_format_has_unorm_channel(enum isl_format fmt) ATTRIBUTE_CONST;1823bool isl_format_has_snorm_channel(enum isl_format fmt) ATTRIBUTE_CONST;1824bool isl_format_has_ufloat_channel(enum isl_format fmt) ATTRIBUTE_CONST;1825bool isl_format_has_sfloat_channel(enum isl_format fmt) ATTRIBUTE_CONST;1826bool isl_format_has_uint_channel(enum isl_format fmt) ATTRIBUTE_CONST;1827bool isl_format_has_sint_channel(enum isl_format fmt) ATTRIBUTE_CONST;18281829static inline bool1830isl_format_has_normalized_channel(enum isl_format fmt)1831{1832return isl_format_has_unorm_channel(fmt) ||1833isl_format_has_snorm_channel(fmt);1834}18351836static inline bool1837isl_format_has_float_channel(enum isl_format fmt)1838{1839return isl_format_has_ufloat_channel(fmt) ||1840isl_format_has_sfloat_channel(fmt);1841}18421843static inline bool1844isl_format_has_int_channel(enum isl_format fmt)1845{1846return isl_format_has_uint_channel(fmt) ||1847isl_format_has_sint_channel(fmt);1848}18491850bool isl_format_has_color_component(enum isl_format fmt,1851int component) ATTRIBUTE_CONST;18521853unsigned isl_format_get_num_channels(enum isl_format fmt);18541855uint32_t isl_format_get_depth_format(enum isl_format fmt, bool has_stencil);18561857static inline bool1858isl_format_is_compressed(enum isl_format fmt)1859{1860const struct isl_format_layout *fmtl = isl_format_get_layout(fmt);18611862return fmtl->txc != ISL_TXC_NONE;1863}18641865static inline bool1866isl_format_has_bc_compression(enum isl_format fmt)1867{1868switch (isl_format_get_layout(fmt)->txc) {1869case ISL_TXC_DXT1:1870case ISL_TXC_DXT3:1871case ISL_TXC_DXT5:1872return true;1873case ISL_TXC_NONE:1874case ISL_TXC_FXT1:1875case ISL_TXC_RGTC1:1876case ISL_TXC_RGTC2:1877case ISL_TXC_BPTC:1878case ISL_TXC_ETC1:1879case ISL_TXC_ETC2:1880case ISL_TXC_ASTC:1881return false;18821883case ISL_TXC_HIZ:1884case ISL_TXC_MCS:1885case ISL_TXC_CCS:1886unreachable("Should not be called on an aux surface");1887}18881889unreachable("bad texture compression mode");1890return false;1891}18921893static inline bool1894isl_format_is_mcs(enum isl_format fmt)1895{1896const struct isl_format_layout *fmtl = isl_format_get_layout(fmt);18971898return fmtl->txc == ISL_TXC_MCS;1899}19001901static inline bool1902isl_format_is_planar(enum isl_format fmt)1903{1904return fmt == ISL_FORMAT_PLANAR_420_8 ||1905fmt == ISL_FORMAT_PLANAR_420_10 ||1906fmt == ISL_FORMAT_PLANAR_420_12 ||1907fmt == ISL_FORMAT_PLANAR_420_16;1908}19091910static inline bool1911isl_format_is_yuv(enum isl_format fmt)1912{1913const struct isl_format_layout *fmtl = isl_format_get_layout(fmt);19141915return fmtl->colorspace == ISL_COLORSPACE_YUV;1916}19171918static inline bool1919isl_format_block_is_1x1x1(enum isl_format fmt)1920{1921const struct isl_format_layout *fmtl = isl_format_get_layout(fmt);19221923return fmtl->bw == 1 && fmtl->bh == 1 && fmtl->bd == 1;1924}19251926static inline bool1927isl_format_is_srgb(enum isl_format fmt)1928{1929return isl_format_get_layout(fmt)->colorspace == ISL_COLORSPACE_SRGB;1930}19311932enum isl_format isl_format_srgb_to_linear(enum isl_format fmt);19331934static inline bool1935isl_format_is_rgb(enum isl_format fmt)1936{1937if (isl_format_is_yuv(fmt))1938return false;19391940const struct isl_format_layout *fmtl = isl_format_get_layout(fmt);19411942return fmtl->channels.r.bits > 0 &&1943fmtl->channels.g.bits > 0 &&1944fmtl->channels.b.bits > 0 &&1945fmtl->channels.a.bits == 0;1946}19471948static inline bool1949isl_format_is_rgbx(enum isl_format fmt)1950{1951const struct isl_format_layout *fmtl = isl_format_get_layout(fmt);19521953return fmtl->channels.r.bits > 0 &&1954fmtl->channels.g.bits > 0 &&1955fmtl->channels.b.bits > 0 &&1956fmtl->channels.a.bits > 0 &&1957fmtl->channels.a.type == ISL_VOID;1958}19591960enum isl_format isl_format_rgb_to_rgba(enum isl_format rgb) ATTRIBUTE_CONST;1961enum isl_format isl_format_rgb_to_rgbx(enum isl_format rgb) ATTRIBUTE_CONST;1962enum isl_format isl_format_rgbx_to_rgba(enum isl_format rgb) ATTRIBUTE_CONST;19631964union isl_color_value1965isl_color_value_swizzle_inv(union isl_color_value src,1966struct isl_swizzle swizzle);19671968void isl_color_value_pack(const union isl_color_value *value,1969enum isl_format format,1970uint32_t *data_out);1971void isl_color_value_unpack(union isl_color_value *value,1972enum isl_format format,1973const uint32_t *data_in);19741975bool isl_is_storage_image_format(enum isl_format fmt);19761977enum isl_format1978isl_lower_storage_image_format(const struct intel_device_info *devinfo,1979enum isl_format fmt);19801981/* Returns true if this hardware supports typed load/store on a format with1982* the same size as the given format.1983*/1984bool1985isl_has_matching_typed_storage_image_format(const struct intel_device_info *devinfo,1986enum isl_format fmt);19871988void1989isl_tiling_get_info(enum isl_tiling tiling,1990uint32_t format_bpb,1991struct isl_tile_info *tile_info);19921993static inline enum isl_tiling1994isl_tiling_flag_to_enum(isl_tiling_flags_t flag)1995{1996assert(__builtin_popcount(flag) == 1);1997return (enum isl_tiling) (__builtin_ffs(flag) - 1);1998}19992000static inline bool2001isl_tiling_is_any_y(enum isl_tiling tiling)2002{2003return (1u << tiling) & ISL_TILING_ANY_Y_MASK;2004}20052006static inline bool2007isl_tiling_is_std_y(enum isl_tiling tiling)2008{2009return (1u << tiling) & ISL_TILING_STD_Y_MASK;2010}20112012uint32_t2013isl_tiling_to_i915_tiling(enum isl_tiling tiling);20142015enum isl_tiling2016isl_tiling_from_i915_tiling(uint32_t tiling);20172018/**2019* Return an isl_aux_op needed to enable an access to occur in an2020* isl_aux_state suitable for the isl_aux_usage.2021*2022* @note2023* If the access will invalidate the main surface, this function should not be2024* called and the isl_aux_op of NONE should be used instead. Otherwise, an2025* extra (but still lossless) ambiguate may occur.2026*2027* @invariant initial_state is possible with an isl_aux_usage compatible with2028* the given usage. Two usages are compatible if it's possible to2029* switch between them (e.g. CCS_E <-> CCS_D).2030* @invariant fast_clear is false if the aux doesn't support fast clears.2031*/2032enum isl_aux_op2033isl_aux_prepare_access(enum isl_aux_state initial_state,2034enum isl_aux_usage usage,2035bool fast_clear_supported);20362037/**2038* Return the isl_aux_state entered after performing an isl_aux_op.2039*2040* @invariant initial_state is possible with the given usage.2041* @invariant op is possible with the given usage.2042* @invariant op must not cause HW to read from an invalid aux.2043*/2044enum isl_aux_state2045isl_aux_state_transition_aux_op(enum isl_aux_state initial_state,2046enum isl_aux_usage usage,2047enum isl_aux_op op);20482049/**2050* Return the isl_aux_state entered after performing a write.2051*2052* @note2053* full_surface should be true if the write covers the entire slice. Setting2054* it to false in this case will still result in a correct (but imprecise) aux2055* state.2056*2057* @invariant if usage is not ISL_AUX_USAGE_NONE, then initial_state is2058* possible with the given usage.2059* @invariant usage can be ISL_AUX_USAGE_NONE iff:2060* * the main surface is valid, or2061* * the main surface is being invalidated/replaced.2062*/2063enum isl_aux_state2064isl_aux_state_transition_write(enum isl_aux_state initial_state,2065enum isl_aux_usage usage,2066bool full_surface);20672068bool2069isl_aux_usage_has_fast_clears(enum isl_aux_usage usage);20702071bool2072isl_aux_usage_has_compression(enum isl_aux_usage usage);20732074static inline bool2075isl_aux_usage_has_hiz(enum isl_aux_usage usage)2076{2077return usage == ISL_AUX_USAGE_HIZ ||2078usage == ISL_AUX_USAGE_HIZ_CCS_WT ||2079usage == ISL_AUX_USAGE_HIZ_CCS;2080}20812082static inline bool2083isl_aux_usage_has_mcs(enum isl_aux_usage usage)2084{2085return usage == ISL_AUX_USAGE_MCS ||2086usage == ISL_AUX_USAGE_MCS_CCS;2087}20882089static inline bool2090isl_aux_usage_has_ccs(enum isl_aux_usage usage)2091{2092return usage == ISL_AUX_USAGE_CCS_D ||2093usage == ISL_AUX_USAGE_CCS_E ||2094usage == ISL_AUX_USAGE_GFX12_CCS_E ||2095usage == ISL_AUX_USAGE_MC ||2096usage == ISL_AUX_USAGE_HIZ_CCS_WT ||2097usage == ISL_AUX_USAGE_HIZ_CCS ||2098usage == ISL_AUX_USAGE_MCS_CCS ||2099usage == ISL_AUX_USAGE_STC_CCS;2100}21012102static inline bool2103isl_aux_state_has_valid_primary(enum isl_aux_state state)2104{2105return state == ISL_AUX_STATE_RESOLVED ||2106state == ISL_AUX_STATE_PASS_THROUGH ||2107state == ISL_AUX_STATE_AUX_INVALID;2108}21092110static inline bool2111isl_aux_state_has_valid_aux(enum isl_aux_state state)2112{2113return state != ISL_AUX_STATE_AUX_INVALID;2114}21152116extern const struct isl_drm_modifier_info isl_drm_modifier_info_list[];21172118#define isl_drm_modifier_info_for_each(__info) \2119for (const struct isl_drm_modifier_info *__info = isl_drm_modifier_info_list; \2120__info->modifier != DRM_FORMAT_MOD_INVALID; \2121++__info)21222123const struct isl_drm_modifier_info * ATTRIBUTE_CONST2124isl_drm_modifier_get_info(uint64_t modifier);21252126static inline bool2127isl_drm_modifier_has_aux(uint64_t modifier)2128{2129return isl_drm_modifier_get_info(modifier)->aux_usage != ISL_AUX_USAGE_NONE;2130}21312132/** Returns the default isl_aux_state for the given modifier.2133*2134* If we have a modifier which supports compression, then the auxiliary data2135* could be in state other than ISL_AUX_STATE_AUX_INVALID. In particular, it2136* can be in any of the following:2137*2138* - ISL_AUX_STATE_CLEAR2139* - ISL_AUX_STATE_PARTIAL_CLEAR2140* - ISL_AUX_STATE_COMPRESSED_CLEAR2141* - ISL_AUX_STATE_COMPRESSED_NO_CLEAR2142* - ISL_AUX_STATE_RESOLVED2143* - ISL_AUX_STATE_PASS_THROUGH2144*2145* If the modifier does not support fast-clears, then we are guaranteed2146* that the surface is at least partially resolved and the first three not2147* possible. We return ISL_AUX_STATE_COMPRESSED_CLEAR if the modifier2148* supports fast clears and ISL_AUX_STATE_COMPRESSED_NO_CLEAR if it does not2149* because they are the least common denominator of the set of possible aux2150* states and will yield a valid interpretation of the aux data.2151*2152* For modifiers with no aux support, ISL_AUX_STATE_AUX_INVALID is returned.2153*/2154static inline enum isl_aux_state2155isl_drm_modifier_get_default_aux_state(uint64_t modifier)2156{2157const struct isl_drm_modifier_info *mod_info =2158isl_drm_modifier_get_info(modifier);21592160if (!mod_info || mod_info->aux_usage == ISL_AUX_USAGE_NONE)2161return ISL_AUX_STATE_AUX_INVALID;21622163assert(mod_info->aux_usage == ISL_AUX_USAGE_CCS_E ||2164mod_info->aux_usage == ISL_AUX_USAGE_GFX12_CCS_E ||2165mod_info->aux_usage == ISL_AUX_USAGE_MC);2166return mod_info->supports_clear_color ? ISL_AUX_STATE_COMPRESSED_CLEAR :2167ISL_AUX_STATE_COMPRESSED_NO_CLEAR;2168}21692170/**2171* Return the modifier's score, which indicates the driver's preference for the2172* modifier relative to others. A higher score is better. Zero means2173* unsupported.2174*2175* Intended to assist selection of a modifier from an externally provided list,2176* such as VkImageDrmFormatModifierListCreateInfoEXT.2177*/2178uint32_t2179isl_drm_modifier_get_score(const struct intel_device_info *devinfo,2180uint64_t modifier);21812182struct isl_extent2d ATTRIBUTE_CONST2183isl_get_interleaved_msaa_px_size_sa(uint32_t samples);21842185static inline bool2186isl_surf_usage_is_display(isl_surf_usage_flags_t usage)2187{2188return usage & ISL_SURF_USAGE_DISPLAY_BIT;2189}21902191static inline bool2192isl_surf_usage_is_depth(isl_surf_usage_flags_t usage)2193{2194return usage & ISL_SURF_USAGE_DEPTH_BIT;2195}21962197static inline bool2198isl_surf_usage_is_stencil(isl_surf_usage_flags_t usage)2199{2200return usage & ISL_SURF_USAGE_STENCIL_BIT;2201}22022203static inline bool2204isl_surf_usage_is_depth_and_stencil(isl_surf_usage_flags_t usage)2205{2206return (usage & ISL_SURF_USAGE_DEPTH_BIT) &&2207(usage & ISL_SURF_USAGE_STENCIL_BIT);2208}22092210static inline bool2211isl_surf_usage_is_depth_or_stencil(isl_surf_usage_flags_t usage)2212{2213return usage & (ISL_SURF_USAGE_DEPTH_BIT | ISL_SURF_USAGE_STENCIL_BIT);2214}22152216static inline bool2217isl_surf_info_is_z16(const struct isl_surf_init_info *info)2218{2219return (info->usage & ISL_SURF_USAGE_DEPTH_BIT) &&2220(info->format == ISL_FORMAT_R16_UNORM);2221}22222223static inline bool2224isl_surf_info_is_z32_float(const struct isl_surf_init_info *info)2225{2226return (info->usage & ISL_SURF_USAGE_DEPTH_BIT) &&2227(info->format == ISL_FORMAT_R32_FLOAT);2228}22292230static inline struct isl_extent2d2231isl_extent2d(uint32_t width, uint32_t height)2232{2233struct isl_extent2d e = { { 0 } };22342235e.width = width;2236e.height = height;22372238return e;2239}22402241static inline struct isl_extent3d2242isl_extent3d(uint32_t width, uint32_t height, uint32_t depth)2243{2244struct isl_extent3d e = { { 0 } };22452246e.width = width;2247e.height = height;2248e.depth = depth;22492250return e;2251}22522253static inline struct isl_extent4d2254isl_extent4d(uint32_t width, uint32_t height, uint32_t depth,2255uint32_t array_len)2256{2257struct isl_extent4d e = { { 0 } };22582259e.width = width;2260e.height = height;2261e.depth = depth;2262e.array_len = array_len;22632264return e;2265}22662267bool isl_color_value_is_zero(union isl_color_value value,2268enum isl_format format);22692270bool isl_color_value_is_zero_one(union isl_color_value value,2271enum isl_format format);22722273static inline bool2274isl_swizzle_is_identity(struct isl_swizzle swizzle)2275{2276return swizzle.r == ISL_CHANNEL_SELECT_RED &&2277swizzle.g == ISL_CHANNEL_SELECT_GREEN &&2278swizzle.b == ISL_CHANNEL_SELECT_BLUE &&2279swizzle.a == ISL_CHANNEL_SELECT_ALPHA;2280}22812282bool2283isl_swizzle_supports_rendering(const struct intel_device_info *devinfo,2284struct isl_swizzle swizzle);22852286struct isl_swizzle2287isl_swizzle_compose(struct isl_swizzle first, struct isl_swizzle second);2288struct isl_swizzle2289isl_swizzle_invert(struct isl_swizzle swizzle);22902291uint32_t isl_mocs(const struct isl_device *dev, isl_surf_usage_flags_t usage,2292bool external);22932294#define isl_surf_init(dev, surf, ...) \2295isl_surf_init_s((dev), (surf), \2296&(struct isl_surf_init_info) { __VA_ARGS__ });22972298bool2299isl_surf_init_s(const struct isl_device *dev,2300struct isl_surf *surf,2301const struct isl_surf_init_info *restrict info);23022303void2304isl_surf_get_tile_info(const struct isl_surf *surf,2305struct isl_tile_info *tile_info);23062307/**2308* @param[in] surf The main surface2309* @param[in] hiz_or_mcs_surf HiZ or MCS surface associated with the main2310* surface2311* @returns true if the given surface supports CCS.2312*/2313bool2314isl_surf_supports_ccs(const struct isl_device *dev,2315const struct isl_surf *surf,2316const struct isl_surf *hiz_or_mcs_surf);23172318/** Constructs a HiZ surface for the given main surface.2319*2320* @param[in] surf The main surface2321* @param[out] hiz_surf The HiZ surface to populate on success2322* @returns false if the main surface cannot support HiZ.2323*/2324bool2325isl_surf_get_hiz_surf(const struct isl_device *dev,2326const struct isl_surf *surf,2327struct isl_surf *hiz_surf);23282329/** Constructs a MCS for the given main surface.2330*2331* @param[in] surf The main surface2332* @param[out] mcs_surf The MCS to populate on success2333* @returns false if the main surface cannot support MCS.2334*/2335bool2336isl_surf_get_mcs_surf(const struct isl_device *dev,2337const struct isl_surf *surf,2338struct isl_surf *mcs_surf);23392340/** Constructs a CCS for the given main surface.2341*2342* @note2343* Starting with Tigerlake, the CCS is no longer really a surface. It's not2344* laid out as an independent surface and isn't referenced by2345* RENDER_SURFACE_STATE::"Auxiliary Surface Base Address" like other auxiliary2346* compression surfaces. It's a blob of memory that's a 1:256 scale-down from2347* the main surfaced that's attached side-band via a second set of page2348* tables.2349*2350* @par2351* In spite of this, it's sometimes useful to think of it as being a linear2352* buffer-like surface, at least for the purposes of allocation. When invoked2353* on Tigerlake or later, this function still works and produces such a linear2354* surface.2355*2356* @param[in] surf The main surface2357* @param[in] hiz_or_mcs_surf HiZ or MCS surface associated with the main2358* surface2359* @param[out] ccs_surf The CCS to populate on success2360* @param row_pitch_B: The row pitch for the CCS in bytes or 0 if2361* ISL should calculate the row pitch.2362* @returns false if the main surface cannot support CCS.2363*/2364bool2365isl_surf_get_ccs_surf(const struct isl_device *dev,2366const struct isl_surf *surf,2367const struct isl_surf *hiz_or_mcs_surf,2368struct isl_surf *ccs_surf,2369uint32_t row_pitch_B);23702371#define isl_surf_fill_state(dev, state, ...) \2372isl_surf_fill_state_s((dev), (state), \2373&(struct isl_surf_fill_state_info) { __VA_ARGS__ });23742375void2376isl_surf_fill_state_s(const struct isl_device *dev, void *state,2377const struct isl_surf_fill_state_info *restrict info);23782379#define isl_buffer_fill_state(dev, state, ...) \2380isl_buffer_fill_state_s((dev), (state), \2381&(struct isl_buffer_fill_state_info) { __VA_ARGS__ });23822383void2384isl_buffer_fill_state_s(const struct isl_device *dev, void *state,2385const struct isl_buffer_fill_state_info *restrict info);23862387void2388isl_null_fill_state_s(const struct isl_device *dev, void *state,2389const struct isl_null_fill_state_info *restrict info);23902391#define isl_null_fill_state(dev, state, ...) \2392isl_null_fill_state_s((dev), (state), \2393&(struct isl_null_fill_state_info) { __VA_ARGS__ });23942395#define isl_emit_depth_stencil_hiz(dev, batch, ...) \2396isl_emit_depth_stencil_hiz_s((dev), (batch), \2397&(struct isl_depth_stencil_hiz_emit_info) { __VA_ARGS__ })23982399void2400isl_emit_depth_stencil_hiz_s(const struct isl_device *dev, void *batch,2401const struct isl_depth_stencil_hiz_emit_info *restrict info);24022403void2404isl_surf_fill_image_param(const struct isl_device *dev,2405struct brw_image_param *param,2406const struct isl_surf *surf,2407const struct isl_view *view);24082409void2410isl_buffer_fill_image_param(const struct isl_device *dev,2411struct brw_image_param *param,2412enum isl_format format,2413uint64_t size);24142415/**2416* Alignment of the upper-left sample of each subimage, in units of surface2417* elements.2418*/2419static inline struct isl_extent3d2420isl_surf_get_image_alignment_el(const struct isl_surf *surf)2421{2422return surf->image_alignment_el;2423}24242425/**2426* Alignment of the upper-left sample of each subimage, in units of surface2427* samples.2428*/2429static inline struct isl_extent3d2430isl_surf_get_image_alignment_sa(const struct isl_surf *surf)2431{2432const struct isl_format_layout *fmtl = isl_format_get_layout(surf->format);24332434return isl_extent3d(fmtl->bw * surf->image_alignment_el.w,2435fmtl->bh * surf->image_alignment_el.h,2436fmtl->bd * surf->image_alignment_el.d);2437}24382439/**2440* Logical extent of level 0 in units of surface elements.2441*/2442static inline struct isl_extent4d2443isl_surf_get_logical_level0_el(const struct isl_surf *surf)2444{2445const struct isl_format_layout *fmtl = isl_format_get_layout(surf->format);24462447return isl_extent4d(DIV_ROUND_UP(surf->logical_level0_px.w, fmtl->bw),2448DIV_ROUND_UP(surf->logical_level0_px.h, fmtl->bh),2449DIV_ROUND_UP(surf->logical_level0_px.d, fmtl->bd),2450surf->logical_level0_px.a);2451}24522453/**2454* Physical extent of level 0 in units of surface elements.2455*/2456static inline struct isl_extent4d2457isl_surf_get_phys_level0_el(const struct isl_surf *surf)2458{2459const struct isl_format_layout *fmtl = isl_format_get_layout(surf->format);24602461return isl_extent4d(DIV_ROUND_UP(surf->phys_level0_sa.w, fmtl->bw),2462DIV_ROUND_UP(surf->phys_level0_sa.h, fmtl->bh),2463DIV_ROUND_UP(surf->phys_level0_sa.d, fmtl->bd),2464surf->phys_level0_sa.a);2465}24662467/**2468* Pitch between vertically adjacent surface elements, in bytes.2469*/2470static inline uint32_t2471isl_surf_get_row_pitch_B(const struct isl_surf *surf)2472{2473return surf->row_pitch_B;2474}24752476/**2477* Pitch between vertically adjacent surface elements, in units of surface elements.2478*/2479static inline uint32_t2480isl_surf_get_row_pitch_el(const struct isl_surf *surf)2481{2482const struct isl_format_layout *fmtl = isl_format_get_layout(surf->format);24832484assert(surf->row_pitch_B % (fmtl->bpb / 8) == 0);2485return surf->row_pitch_B / (fmtl->bpb / 8);2486}24872488/**2489* Pitch between physical array slices, in rows of surface elements.2490*/2491static inline uint32_t2492isl_surf_get_array_pitch_el_rows(const struct isl_surf *surf)2493{2494return surf->array_pitch_el_rows;2495}24962497/**2498* Pitch between physical array slices, in units of surface elements.2499*/2500static inline uint32_t2501isl_surf_get_array_pitch_el(const struct isl_surf *surf)2502{2503return isl_surf_get_array_pitch_el_rows(surf) *2504isl_surf_get_row_pitch_el(surf);2505}25062507/**2508* Pitch between physical array slices, in rows of surface samples.2509*/2510static inline uint32_t2511isl_surf_get_array_pitch_sa_rows(const struct isl_surf *surf)2512{2513const struct isl_format_layout *fmtl = isl_format_get_layout(surf->format);2514return fmtl->bh * isl_surf_get_array_pitch_el_rows(surf);2515}25162517/**2518* Pitch between physical array slices, in bytes.2519*/2520static inline uint32_t2521isl_surf_get_array_pitch(const struct isl_surf *surf)2522{2523return isl_surf_get_array_pitch_sa_rows(surf) * surf->row_pitch_B;2524}25252526/**2527* Calculate the offset, in units of surface samples, to a subimage in the2528* surface.2529*2530* @invariant level < surface levels2531* @invariant logical_array_layer < logical array length of surface2532* @invariant logical_z_offset_px < logical depth of surface at level2533*/2534void2535isl_surf_get_image_offset_sa(const struct isl_surf *surf,2536uint32_t level,2537uint32_t logical_array_layer,2538uint32_t logical_z_offset_px,2539uint32_t *x_offset_sa,2540uint32_t *y_offset_sa,2541uint32_t *z_offset_sa,2542uint32_t *array_offset);25432544/**2545* Calculate the offset, in units of surface elements, to a subimage in the2546* surface.2547*2548* @invariant level < surface levels2549* @invariant logical_array_layer < logical array length of surface2550* @invariant logical_z_offset_px < logical depth of surface at level2551*/2552void2553isl_surf_get_image_offset_el(const struct isl_surf *surf,2554uint32_t level,2555uint32_t logical_array_layer,2556uint32_t logical_z_offset_px,2557uint32_t *x_offset_el,2558uint32_t *y_offset_el,2559uint32_t *z_offset_el,2560uint32_t *array_offset);25612562/**2563* Calculate the offset, in bytes and intratile surface samples, to a2564* subimage in the surface.2565*2566* This is equivalent to calling isl_surf_get_image_offset_el, passing the2567* result to isl_tiling_get_intratile_offset_el, and converting the tile2568* offsets to samples.2569*2570* @invariant level < surface levels2571* @invariant logical_array_layer < logical array length of surface2572* @invariant logical_z_offset_px < logical depth of surface at level2573*/2574void2575isl_surf_get_image_offset_B_tile_sa(const struct isl_surf *surf,2576uint32_t level,2577uint32_t logical_array_layer,2578uint32_t logical_z_offset_px,2579uint32_t *offset_B,2580uint32_t *x_offset_sa,2581uint32_t *y_offset_sa);25822583/**2584* Calculate the offset, in bytes and intratile surface elements, to a2585* subimage in the surface.2586*2587* This is equivalent to calling isl_surf_get_image_offset_el, passing the2588* result to isl_tiling_get_intratile_offset_el.2589*2590* @invariant level < surface levels2591* @invariant logical_array_layer < logical array length of surface2592* @invariant logical_z_offset_px < logical depth of surface at level2593*/2594void2595isl_surf_get_image_offset_B_tile_el(const struct isl_surf *surf,2596uint32_t level,2597uint32_t logical_array_layer,2598uint32_t logical_z_offset_px,2599uint32_t *offset_B,2600uint32_t *x_offset_el,2601uint32_t *y_offset_el);26022603/**2604* Calculate the range in bytes occupied by a subimage, to the nearest tile.2605*2606* The range returned will be the smallest memory range in which the give2607* subimage fits, rounded to even tiles. Intel images do not usually have a2608* direct subimage -> range mapping so the range returned may contain data2609* from other sub-images. The returned range is a half-open interval where2610* all of the addresses within the subimage are < end_tile_B.2611*2612* @invariant level < surface levels2613* @invariant logical_array_layer < logical array length of surface2614* @invariant logical_z_offset_px < logical depth of surface at level2615*/2616void2617isl_surf_get_image_range_B_tile(const struct isl_surf *surf,2618uint32_t level,2619uint32_t logical_array_layer,2620uint32_t logical_z_offset_px,2621uint32_t *start_tile_B,2622uint32_t *end_tile_B);26232624/**2625* Create an isl_surf that represents a particular subimage in the surface.2626*2627* The newly created surface will have a single miplevel and array slice. The2628* surface lives at the returned byte and intratile offsets, in samples.2629*2630* It is safe to call this function with surf == image_surf.2631*2632* @invariant level < surface levels2633* @invariant logical_array_layer < logical array length of surface2634* @invariant logical_z_offset_px < logical depth of surface at level2635*/2636void2637isl_surf_get_image_surf(const struct isl_device *dev,2638const struct isl_surf *surf,2639uint32_t level,2640uint32_t logical_array_layer,2641uint32_t logical_z_offset_px,2642struct isl_surf *image_surf,2643uint32_t *offset_B,2644uint32_t *x_offset_sa,2645uint32_t *y_offset_sa);26462647/**2648* Create an isl_surf that is an uncompressed view of a compressed isl_surf2649*2650* The incoming surface must have a compressed format. The incoming view must2651* be a valid view for the given surface with the exception that it's format2652* is an umcompressed format with the same bpb as the surface format. The2653* incoming view must have isl_view::levels == 1.2654*2655* When the function returns, the resulting combination of uncompressed_surf2656* and uncompressed_view will be a valid view giving an uncompressed view of2657* the incoming surface. Depending on tiling, uncompressed_surf may have a2658* different isl_surf::dim from surf and uncompressed_view may or may not have2659* a zero base_array_layer. For legacy tiling (not Yf or Ys), an intratile2660* offset is returned in x_offset_sa and y_offset_sa. For standard Y tilings2661* (Yf and Ys), x_offset_sa and y_offset_sa will be set to zero.2662*2663* It is safe to call this function with surf == uncompressed_surf and2664* view == uncompressed_view.2665*/2666bool MUST_CHECK2667isl_surf_get_uncompressed_surf(const struct isl_device *dev,2668const struct isl_surf *surf,2669const struct isl_view *view,2670struct isl_surf *uncompressed_surf,2671struct isl_view *uncompressed_view,2672uint32_t *offset_B,2673uint32_t *x_offset_el,2674uint32_t *y_offset_el);26752676/**2677* @brief Calculate the intratile offsets to a surface.2678*2679* In @a base_address_offset return the offset from the base of the surface to2680* the base address of the first tile of the subimage. In @a x_offset_B and2681* @a y_offset_rows, return the offset, in units of bytes and rows, from the2682* tile's base to the subimage's first surface element. The x and y offsets2683* are intratile offsets; that is, they do not exceed the boundary of the2684* surface's tiling format.2685*/2686void2687isl_tiling_get_intratile_offset_el(enum isl_tiling tiling,2688uint32_t bpb,2689uint32_t row_pitch_B,2690uint32_t array_pitch_el_rows,2691uint32_t total_x_offset_el,2692uint32_t total_y_offset_el,2693uint32_t total_z_offset_el,2694uint32_t total_array_offset,2695uint32_t *base_address_offset,2696uint32_t *x_offset_el,2697uint32_t *y_offset_el,2698uint32_t *z_offset_el,2699uint32_t *array_offset);27002701static inline void2702isl_tiling_get_intratile_offset_sa(enum isl_tiling tiling,2703enum isl_format format,2704uint32_t row_pitch_B,2705uint32_t array_pitch_el_rows,2706uint32_t total_x_offset_sa,2707uint32_t total_y_offset_sa,2708uint32_t total_z_offset_sa,2709uint32_t total_array_offset,2710uint32_t *base_address_offset,2711uint32_t *x_offset_sa,2712uint32_t *y_offset_sa,2713uint32_t *z_offset_sa,2714uint32_t *array_offset)2715{2716const struct isl_format_layout *fmtl = isl_format_get_layout(format);27172718/* For computing the intratile offsets, we actually want a strange unit2719* which is samples for multisampled surfaces but elements for compressed2720* surfaces.2721*/2722assert(total_x_offset_sa % fmtl->bw == 0);2723assert(total_y_offset_sa % fmtl->bh == 0);2724assert(total_z_offset_sa % fmtl->bd == 0);2725const uint32_t total_x_offset_el = total_x_offset_sa / fmtl->bw;2726const uint32_t total_y_offset_el = total_y_offset_sa / fmtl->bh;2727const uint32_t total_z_offset_el = total_z_offset_sa / fmtl->bd;27282729isl_tiling_get_intratile_offset_el(tiling, fmtl->bpb, row_pitch_B,2730array_pitch_el_rows,2731total_x_offset_el,2732total_y_offset_el,2733total_z_offset_el,2734total_array_offset,2735base_address_offset,2736x_offset_sa, y_offset_sa,2737z_offset_sa, array_offset);2738*x_offset_sa *= fmtl->bw;2739*y_offset_sa *= fmtl->bh;2740*z_offset_sa *= fmtl->bd;2741}27422743/**2744* @brief Get value of 3DSTATE_DEPTH_BUFFER.SurfaceFormat2745*2746* @pre surf->usage has ISL_SURF_USAGE_DEPTH_BIT2747* @pre surf->format must be a valid format for depth surfaces2748*/2749uint32_t2750isl_surf_get_depth_format(const struct isl_device *dev,2751const struct isl_surf *surf);27522753/**2754* @brief performs a copy from linear to tiled surface2755*2756*/2757void2758isl_memcpy_linear_to_tiled(uint32_t xt1, uint32_t xt2,2759uint32_t yt1, uint32_t yt2,2760char *dst, const char *src,2761uint32_t dst_pitch, int32_t src_pitch,2762bool has_swizzling,2763enum isl_tiling tiling,2764isl_memcpy_type copy_type);27652766/**2767* @brief performs a copy from tiled to linear surface2768*2769*/2770void2771isl_memcpy_tiled_to_linear(uint32_t xt1, uint32_t xt2,2772uint32_t yt1, uint32_t yt2,2773char *dst, const char *src,2774int32_t dst_pitch, uint32_t src_pitch,2775bool has_swizzling,2776enum isl_tiling tiling,2777isl_memcpy_type copy_type);27782779/**2780* @brief computes the tile_w (in bytes) and tile_h (in rows) of2781* different tiling patterns.2782*/2783static inline void2784isl_get_tile_dims(enum isl_tiling tiling, uint32_t cpp,2785uint32_t *tile_w, uint32_t *tile_h)2786{2787switch (tiling) {2788case ISL_TILING_X:2789*tile_w = 512;2790*tile_h = 8;2791break;2792case ISL_TILING_Y0:2793*tile_w = 128;2794*tile_h = 32;2795break;2796case ISL_TILING_LINEAR:2797*tile_w = cpp;2798*tile_h = 1;2799break;2800default:2801unreachable("not reached");2802}2803}28042805/**2806* @brief Computes masks that may be used to select the bits of the X2807* and Y coordinates that indicate the offset within a tile. If the BO is2808* untiled, the masks are set to 0.2809*/2810static inline void2811isl_get_tile_masks(enum isl_tiling tiling, uint32_t cpp,2812uint32_t *mask_x, uint32_t *mask_y)2813{2814uint32_t tile_w_bytes, tile_h;28152816isl_get_tile_dims(tiling, cpp, &tile_w_bytes, &tile_h);28172818*mask_x = tile_w_bytes / cpp - 1;2819*mask_y = tile_h - 1;2820}2821#ifdef __cplusplus2822}2823#endif28242825#endif /* ISL_H */282628272828