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