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