1 /* 2 ************************************************************************************************************************ 3 * 4 * Copyright (C) 2007-2022 Advanced Micro Devices, Inc. All rights reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the "Software"), 8 * to deal in the Software without restriction, including without limitation 9 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 * and/or sell copies of the Software, and to permit persons to whom the 11 * Software is furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included in 14 * all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 * OTHER DEALINGS IN THE SOFTWARE 23 * 24 ***********************************************************************************************************************/ 25 26 27 /** 28 **************************************************************************************************** 29 * @file addrelemlib.h 30 * @brief Contains the class for element/pixel related functions. 31 **************************************************************************************************** 32 */ 33 34 #ifndef __ELEM_LIB_H__ 35 #define __ELEM_LIB_H__ 36 37 #include "addrinterface.h" 38 #include "addrobject.h" 39 #include "addrcommon.h" 40 41 namespace Addr 42 { 43 44 class Lib; 45 46 // The masks for property bits within the Properties INT_32 47 union ComponentFlags 48 { 49 struct 50 { 51 UINT_32 byteAligned : 1; ///< all components are byte aligned 52 UINT_32 exportNorm : 1; ///< components support R6xx NORM compression 53 UINT_32 floatComp : 1; ///< there is at least one floating point component 54 }; 55 56 UINT_32 value; 57 }; 58 59 // Copy from legacy lib's NumberType 60 enum NumberType 61 { 62 // The following number types have the range [-1..1] 63 ADDR_NO_NUMBER, // This component doesn't exist and has no default value 64 ADDR_EPSILON, // Force component value to integer 0x00000001 65 ADDR_ZERO, // Force component value to integer 0x00000000 66 ADDR_ONE, // Force component value to floating point 1.0 67 // Above values don't have any bits per component (keep ADDR_ONE the last of these) 68 69 ADDR_UNORM, // Unsigned normalized (repeating fraction) full precision 70 ADDR_SNORM, // Signed normalized (repeating fraction) full precision 71 ADDR_GAMMA, // Gamma-corrected, full precision 72 73 ADDR_UNORM_R5XXRB, // Unsigned normalized (repeating fraction) for r5xx RB 74 ADDR_SNORM_R5XXRB, // Signed normalized (repeating fraction) for r5xx RB 75 ADDR_GAMMA_R5XXRB, // Gamma-corrected for r5xx RB (note: unnormalized value) 76 ADDR_UNORM_R5XXBC, // Unsigned normalized (repeating fraction) for r5xx BC 77 ADDR_SNORM_R5XXBC, // Signed normalized (repeating fraction) for r5xx BC 78 ADDR_GAMMA_R5XXBC, // Gamma-corrected for r5xx BC (note: unnormalized value) 79 80 ADDR_UNORM_R6XX, // Unsigned normalized (repeating fraction) for R6xx 81 ADDR_UNORM_R6XXDB, // Unorms for 24-bit depth: one value differs from ADDR_UNORM_R6XX 82 ADDR_SNORM_R6XX, // Signed normalized (repeating fraction) for R6xx 83 ADDR_GAMMA8_R6XX, // Gamma-corrected for r6xx 84 ADDR_GAMMA8_R7XX_TP, // Gamma-corrected for r7xx TP 12bit unorm 8.4. 85 86 ADDR_U4FLOATC, // Unsigned float: 4-bit exponent, bias=15, no NaN, clamp [0..1] 87 ADDR_GAMMA_4SEG, // Gamma-corrected, four segment approximation 88 ADDR_U0FIXED, // Unsigned 0.N-bit fixed point 89 90 // The following number types have large ranges (LEAVE ADDR_USCALED first or fix Finish routine) 91 ADDR_USCALED, // Unsigned integer converted to/from floating point 92 ADDR_SSCALED, // Signed integer converted to/from floating point 93 ADDR_USCALED_R5XXRB, // Unsigned integer to/from floating point for r5xx RB 94 ADDR_SSCALED_R5XXRB, // Signed integer to/from floating point for r5xx RB 95 ADDR_UINT_BITS, // Keep in unsigned integer form, clamped to specified range 96 ADDR_SINT_BITS, // Keep in signed integer form, clamped to specified range 97 ADDR_UINTBITS, // @@ remove Keep in unsigned integer form, use modulus to reduce bits 98 ADDR_SINTBITS, // @@ remove Keep in signed integer form, use modulus to reduce bits 99 100 // The following number types and ADDR_U4FLOATC have exponents 101 // (LEAVE ADDR_S8FLOAT first or fix Finish routine) 102 ADDR_S8FLOAT, // Signed floating point with 8-bit exponent, bias=127 103 ADDR_S8FLOAT32, // 32-bit IEEE float, passes through NaN values 104 ADDR_S5FLOAT, // Signed floating point with 5-bit exponent, bias=15 105 ADDR_S5FLOATM, // Signed floating point with 5-bit exponent, bias=15, no NaN/Inf 106 ADDR_U5FLOAT, // Signed floating point with 5-bit exponent, bias=15 107 ADDR_U3FLOATM, // Unsigned floating point with 3-bit exponent, bias=3 108 109 ADDR_S5FIXED, // Signed 5.N-bit fixed point, with rounding 110 111 ADDR_END_NUMBER // Used for range comparisons 112 }; 113 114 // Copy from legacy lib's AddrElement 115 enum ElemMode 116 { 117 // These formats allow both packing an unpacking 118 ADDR_ROUND_BY_HALF, // add 1/2 and truncate when packing this element 119 ADDR_ROUND_TRUNCATE, // truncate toward 0 for sign/mag, else toward neg 120 ADDR_ROUND_DITHER, // Pack by dithering -- requires (x,y) position 121 122 // These formats only allow unpacking, no packing 123 ADDR_UNCOMPRESSED, // Elements are not compressed: one data element per pixel/texel 124 ADDR_EXPANDED, // Elements are split up and stored in multiple data elements 125 ADDR_PACKED_STD, // Elements are compressed into ExpandX by ExpandY data elements 126 ADDR_PACKED_REV, // Like ADDR_PACKED, but X order of pixels is reverved 127 ADDR_PACKED_GBGR, // Elements are compressed 4:2:2 in G1B_G0R order (high to low) 128 ADDR_PACKED_BGRG, // Elements are compressed 4:2:2 in BG1_RG0 order (high to low) 129 ADDR_PACKED_BC1, // Each data element is uncompressed to a 4x4 pixel/texel array 130 ADDR_PACKED_BC2, // Each data element is uncompressed to a 4x4 pixel/texel array 131 ADDR_PACKED_BC3, // Each data element is uncompressed to a 4x4 pixel/texel array 132 ADDR_PACKED_BC4, // Each data element is uncompressed to a 4x4 pixel/texel array 133 ADDR_PACKED_BC5, // Each data element is uncompressed to a 4x4 pixel/texel array 134 ADDR_PACKED_ETC2_64BPP, // ETC2 formats that use 64bpp to represent each 4x4 block 135 ADDR_PACKED_ETC2_128BPP, // ETC2 formats that use 128bpp to represent each 4x4 block 136 ADDR_PACKED_ASTC, // Various ASTC formats, all are 128bpp with varying block sizes 137 138 // These formats provide various kinds of compression 139 ADDR_ZPLANE_R5XX, // Compressed Zplane using r5xx architecture format 140 ADDR_ZPLANE_R6XX, // Compressed Zplane using r6xx architecture format 141 //@@ Fill in the compression modes 142 143 ADDR_END_ELEMENT // Used for range comparisons 144 }; 145 146 enum DepthPlanarType 147 { 148 ADDR_DEPTH_PLANAR_NONE = 0, // No plane z/stencl 149 ADDR_DEPTH_PLANAR_R600 = 1, // R600 z and stencil planes are store within a tile 150 ADDR_DEPTH_PLANAR_R800 = 2, // R800 has separate z and stencil planes 151 }; 152 153 /** 154 **************************************************************************************************** 155 * PixelFormatInfo 156 * 157 * @brief 158 * Per component info 159 * 160 **************************************************************************************************** 161 */ 162 struct PixelFormatInfo 163 { 164 UINT_32 compBit[4]; 165 NumberType numType[4]; 166 UINT_32 compStart[4]; 167 ElemMode elemMode; 168 UINT_32 comps; ///< Number of components 169 }; 170 171 /** 172 **************************************************************************************************** 173 * @brief This class contains asic indepentent element related attributes and operations 174 **************************************************************************************************** 175 */ 176 class ElemLib : public Object 177 { 178 protected: 179 ElemLib(Lib* pAddrLib); 180 181 public: 182 183 /// Makes this class virtual 184 virtual ~ElemLib(); 185 186 static ElemLib* Create( 187 const Lib* pAddrLib); 188 189 /// The implementation is only for R6xx/R7xx, so make it virtual in case we need for R8xx 190 BOOL_32 PixGetExportNorm( 191 AddrColorFormat colorFmt, 192 AddrSurfaceNumber numberFmt, AddrSurfaceSwap swap) const; 193 194 /// Below method are asic independent, so make them just static. 195 /// Remove static if we need different operation in hwl. 196 197 VOID Flt32ToDepthPixel( 198 AddrDepthFormat format, const ADDR_FLT_32 comps[2], UINT_8 *pPixel) const; 199 200 VOID Flt32ToColorPixel( 201 AddrColorFormat format, AddrSurfaceNumber surfNum, AddrSurfaceSwap surfSwap, 202 const ADDR_FLT_32 comps[4], UINT_8 *pPixel) const; 203 204 static VOID Flt32sToInt32s( 205 ADDR_FLT_32 value, UINT_32 bits, NumberType numberType, UINT_32* pResult); 206 207 static VOID Int32sToPixel( 208 UINT_32 numComps, UINT_32* pComps, UINT_32* pCompBits, UINT_32* pCompStart, 209 ComponentFlags properties, UINT_32 resultBits, UINT_8* pPixel); 210 211 VOID PixGetColorCompInfo( 212 AddrColorFormat format, AddrSurfaceNumber number, AddrSurfaceSwap swap, 213 PixelFormatInfo* pInfo) const; 214 215 VOID PixGetDepthCompInfo( 216 AddrDepthFormat format, PixelFormatInfo* pInfo) const; 217 218 UINT_32 GetBitsPerPixel( 219 AddrFormat format, ElemMode* pElemMode = NULL, 220 UINT_32* pExpandX = NULL, UINT_32* pExpandY = NULL, UINT_32* pBitsUnused = NULL); 221 222 static VOID SetClearComps( 223 ADDR_FLT_32 comps[4], BOOL_32 clearColor, BOOL_32 float32); 224 225 VOID AdjustSurfaceInfo( 226 ElemMode elemMode, UINT_32 expandX, UINT_32 expandY, 227 UINT_32* pBpp, UINT_32* pBasePitch, UINT_32* pWidth, UINT_32* pHeight); 228 229 VOID RestoreSurfaceInfo( 230 ElemMode elemMode, UINT_32 expandX, UINT_32 expandY, 231 UINT_32* pBpp, UINT_32* pWidth, UINT_32* pHeight); 232 233 /// Checks if depth and stencil are planar inside a tile IsDepthStencilTilePlanar()234 BOOL_32 IsDepthStencilTilePlanar() 235 { 236 return (m_depthPlanarType == ADDR_DEPTH_PLANAR_R600) ? TRUE : FALSE; 237 } 238 239 /// Sets m_configFlags, copied from AddrLib SetConfigFlags(ConfigFlags flags)240 VOID SetConfigFlags(ConfigFlags flags) 241 { 242 m_configFlags = flags; 243 } 244 245 static BOOL_32 IsCompressed(AddrFormat format); 246 static BOOL_32 IsBlockCompressed(AddrFormat format); 247 static BOOL_32 IsExpand3x(AddrFormat format); 248 static BOOL_32 IsMacroPixelPacked(AddrFormat format); 249 250 protected: 251 252 static VOID GetCompBits( 253 UINT_32 c0, UINT_32 c1, UINT_32 c2, UINT_32 c3, 254 PixelFormatInfo* pInfo, 255 ElemMode elemMode = ADDR_ROUND_BY_HALF); 256 257 static VOID GetCompType( 258 AddrColorFormat format, AddrSurfaceNumber numType, 259 PixelFormatInfo* pInfo); 260 261 static VOID GetCompSwap( 262 AddrSurfaceSwap swap, PixelFormatInfo* pInfo); 263 264 static VOID SwapComps( 265 UINT_32 c0, UINT_32 c1, PixelFormatInfo* pInfo); 266 267 private: 268 269 UINT_32 m_fp16ExportNorm; ///< If allow FP16 to be reported as EXPORT_NORM 270 DepthPlanarType m_depthPlanarType; 271 272 ConfigFlags m_configFlags; ///< Copy of AddrLib's configFlags 273 Addr::Lib* const m_pAddrLib; ///< Pointer to parent addrlib instance 274 }; 275 276 } //Addr 277 278 #endif 279 280