2
************************************************************************************************************************
4
* Copyright (C) 2007-2022 Advanced Micro Devices, Inc. All rights reserved.
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:
13
* The above copyright notice and this permission notice shall be included in
14
* all copies or substantial portions of the Software.
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
24
***********************************************************************************************************************/
28
****************************************************************************************************
30
* @brief Contains the class for element/pixel related functions.
31
****************************************************************************************************
34
#ifndef __ELEM_LIB_H__
35
#define __ELEM_LIB_H__
37
#include "addrinterface.h"
38
#include "addrobject.h"
39
#include "addrcommon.h"
46
// The masks for property bits within the Properties INT_32
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
59
// Copy from legacy lib's NumberType
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)
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
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)
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.
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
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
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
109
ADDR_S5FIXED, // Signed 5.N-bit fixed point, with rounding
111
ADDR_END_NUMBER // Used for range comparisons
114
// Copy from legacy lib's AddrElement
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
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
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
143
ADDR_END_ELEMENT // Used for range comparisons
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
154
****************************************************************************************************
160
****************************************************************************************************
162
struct PixelFormatInfo
165
NumberType numType[4];
166
UINT_32 compStart[4];
168
UINT_32 comps; ///< Number of components
172
****************************************************************************************************
173
* @brief This class contains asic indepentent element related attributes and operations
174
****************************************************************************************************
176
class ElemLib : public Object
179
ElemLib(Lib* pAddrLib);
183
/// Makes this class virtual
186
static ElemLib* Create(
187
const Lib* pAddrLib);
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;
194
/// Below method are asic independent, so make them just static.
195
/// Remove static if we need different operation in hwl.
197
VOID Flt32ToDepthPixel(
198
AddrDepthFormat format, const ADDR_FLT_32 comps[2], UINT_8 *pPixel) const;
200
VOID Flt32ToColorPixel(
201
AddrColorFormat format, AddrSurfaceNumber surfNum, AddrSurfaceSwap surfSwap,
202
const ADDR_FLT_32 comps[4], UINT_8 *pPixel) const;
204
static VOID Flt32sToInt32s(
205
ADDR_FLT_32 value, UINT_32 bits, NumberType numberType, UINT_32* pResult);
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);
211
VOID PixGetColorCompInfo(
212
AddrColorFormat format, AddrSurfaceNumber number, AddrSurfaceSwap swap,
213
PixelFormatInfo* pInfo) const;
215
VOID PixGetDepthCompInfo(
216
AddrDepthFormat format, PixelFormatInfo* pInfo) const;
218
UINT_32 GetBitsPerPixel(
219
AddrFormat format, ElemMode* pElemMode = NULL,
220
UINT_32* pExpandX = NULL, UINT_32* pExpandY = NULL, UINT_32* pBitsUnused = NULL);
222
static VOID SetClearComps(
223
ADDR_FLT_32 comps[4], BOOL_32 clearColor, BOOL_32 float32);
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);
229
VOID RestoreSurfaceInfo(
230
ElemMode elemMode, UINT_32 expandX, UINT_32 expandY,
231
UINT_32* pBpp, UINT_32* pWidth, UINT_32* pHeight);
233
/// Checks if depth and stencil are planar inside a tile
234
BOOL_32 IsDepthStencilTilePlanar()
236
return (m_depthPlanarType == ADDR_DEPTH_PLANAR_R600) ? TRUE : FALSE;
239
/// Sets m_configFlags, copied from AddrLib
240
VOID SetConfigFlags(ConfigFlags flags)
242
m_configFlags = flags;
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);
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);
257
static VOID GetCompType(
258
AddrColorFormat format, AddrSurfaceNumber numType,
259
PixelFormatInfo* pInfo);
261
static VOID GetCompSwap(
262
AddrSurfaceSwap swap, PixelFormatInfo* pInfo);
264
static VOID SwapComps(
265
UINT_32 c0, UINT_32 c1, PixelFormatInfo* pInfo);
269
UINT_32 m_fp16ExportNorm; ///< If allow FP16 to be reported as EXPORT_NORM
270
DepthPlanarType m_depthPlanarType;
272
ConfigFlags m_configFlags; ///< Copy of AddrLib's configFlags
273
Addr::Lib* const m_pAddrLib; ///< Pointer to parent addrlib instance