2 * Copyright © 2014 Advanced Micro Devices, Inc.
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:
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.
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
28 ***************************************************************************************************
30 * @brief Contains the helper function and constants
31 ***************************************************************************************************
34 #ifndef __ADDR_COMMON_H__
35 #define __ADDR_COMMON_H__
37 #include "addrinterface.h"
40 // ADDR_LNX_KERNEL_BUILD is for internal build
41 // Moved from addrinterface.h so __KERNEL__ is not needed any more
42 #if ADDR_LNX_KERNEL_BUILD // || (defined(__GNUC__) && defined(__KERNEL__))
43 #include "lnx_common_defs.h" // ported from cmmqs
44 #elif !defined(__APPLE__) || defined(HAVE_TSERVER)
49 ///////////////////////////////////////////////////////////////////////////////////////////////////
51 ///////////////////////////////////////////////////////////////////////////////////////////////////
52 static const UINT_32 MicroTileWidth
= 8; ///< Micro tile width, for 1D and 2D tiling
53 static const UINT_32 MicroTileHeight
= 8; ///< Micro tile height, for 1D and 2D tiling
54 static const UINT_32 ThickTileThickness
= 4; ///< Micro tile thickness, for THICK modes
55 static const UINT_32 XThickTileThickness
= 8; ///< Extra thick tiling thickness
56 static const UINT_32 PowerSaveTileBytes
= 64; ///< Nuber of bytes per tile for power save 64
57 static const UINT_32 CmaskCacheBits
= 1024; ///< Number of bits for CMASK cache
58 static const UINT_32 CmaskElemBits
= 4; ///< Number of bits for CMASK element
59 static const UINT_32 HtileCacheBits
= 16384; ///< Number of bits for HTILE cache 512*32
61 static const UINT_32 MicroTilePixels
= MicroTileWidth
* MicroTileHeight
;
63 static const INT_32 TileIndexInvalid
= TILEINDEX_INVALID
;
64 static const INT_32 TileIndexLinearGeneral
= TILEINDEX_LINEAR_GENERAL
;
65 static const INT_32 TileIndexNoMacroIndex
= -3;
67 ///////////////////////////////////////////////////////////////////////////////////////////////////
69 ///////////////////////////////////////////////////////////////////////////////////////////////////
70 #define BITS_PER_BYTE 8
71 #define BITS_TO_BYTES(x) ( ((x) + (BITS_PER_BYTE-1)) / BITS_PER_BYTE )
72 #define BYTES_TO_BITS(x) ( (x) * BITS_PER_BYTE )
74 /// Helper macros to select a single bit from an int (undefined later in section)
75 #define _BIT(v,b) (((v) >> (b) ) & 1)
78 ***************************************************************************************************
79 * @brief Enums to identify AddrLib type
80 ***************************************************************************************************
92 ***************************************************************************************************
96 * Neutral enums that specifies chip family.
98 ***************************************************************************************************
102 ADDR_CHIP_FAMILY_IVLD
, ///< Invalid family
103 ADDR_CHIP_FAMILY_R6XX
,
104 ADDR_CHIP_FAMILY_R7XX
,
105 ADDR_CHIP_FAMILY_R8XX
,
113 ***************************************************************************************************
117 * This structure is used to set addr configuration flags.
118 ***************************************************************************************************
120 union ADDR_CONFIG_FLAGS
124 /// Clients do not need to set these flags except forceLinearAligned.
125 /// There flags are set up by AddrLib inside thru AddrInitGlobalParamsFromRegister
126 UINT_32 optimalBankSwap
: 1; ///< New bank tiling for RV770 only
127 UINT_32 noCubeMipSlicesPad
: 1; ///< Disables faces padding for cubemap mipmaps
128 UINT_32 fillSizeFields
: 1; ///< If clients fill size fields in all input and
130 UINT_32 ignoreTileInfo
: 1; ///< Don't use tile info structure
131 UINT_32 useTileIndex
: 1; ///< Make tileIndex field in input valid
132 UINT_32 useCombinedSwizzle
: 1; ///< Use combined swizzle
133 UINT_32 checkLast2DLevel
: 1; ///< Check the last 2D mip sub level
134 UINT_32 useHtileSliceAlign
: 1; ///< Do htile single slice alignment
135 UINT_32 allowLargeThickTile
: 1; ///< Allow 64*thickness*bytesPerPixel > rowSize
136 UINT_32 disableLinearOpt
: 1; ///< Disallow tile modes to be optimized to linear
137 UINT_32 reserved
: 22; ///< Reserved bits for future use
143 ///////////////////////////////////////////////////////////////////////////////////////////////////
144 // Platform specific debug break defines
145 ///////////////////////////////////////////////////////////////////////////////////////////////////
147 #if defined(__GNUC__)
148 #define ADDR_DBG_BREAK()
149 #elif defined(__APPLE__)
150 #define ADDR_DBG_BREAK() { IOPanic("");}
152 #define ADDR_DBG_BREAK() { __debugbreak(); }
155 #define ADDR_DBG_BREAK()
157 ///////////////////////////////////////////////////////////////////////////////////////////////////
159 ///////////////////////////////////////////////////////////////////////////////////////////////////
160 // Debug assertions used in AddrLib
161 ///////////////////////////////////////////////////////////////////////////////////////////////////
162 #if defined(_WIN32) && (_MSC_VER >= 1400)
163 #define ADDR_ANALYSIS_ASSUME(expr) __analysis_assume(expr)
165 #define ADDR_ANALYSIS_ASSUME(expr) do { } while (0)
169 #define ADDR_ASSERT(__e) \
171 ADDR_ANALYSIS_ASSUME(__e); \
172 if ( !((__e) ? TRUE : FALSE)) { ADDR_DBG_BREAK(); } \
174 #define ADDR_ASSERT_ALWAYS() ADDR_DBG_BREAK()
175 #define ADDR_UNHANDLED_CASE() ADDR_ASSERT(!"Unhandled case")
176 #define ADDR_NOT_IMPLEMENTED() ADDR_ASSERT(!"Not implemented");
178 #define ADDR_ASSERT(__e) ADDR_ANALYSIS_ASSUME(__e)
179 #define ADDR_ASSERT_ALWAYS()
180 #define ADDR_UNHANDLED_CASE()
181 #define ADDR_NOT_IMPLEMENTED()
183 ///////////////////////////////////////////////////////////////////////////////////////////////////
185 ///////////////////////////////////////////////////////////////////////////////////////////////////
186 // Debug print macro from legacy address library
187 ///////////////////////////////////////////////////////////////////////////////////////////////////
190 #define ADDR_PRNT(a) AddrObject::DebugPrint a
192 /// @brief Macro for reporting informational messages
195 /// This macro optionally prints an informational message to stdout.
196 /// The first parameter is a condition -- if it is true, nothing is done.
197 /// The second pararmeter MUST be a parenthesis-enclosed list of arguments,
198 /// starting with a string. This is passed to printf() or an equivalent
199 /// in order to format the informational message. For example,
200 /// ADDR_INFO(0, ("test %d",3) ); prints out "test 3".
202 #define ADDR_INFO(cond, a) \
203 { if (!(cond)) { ADDR_PRNT(a); } }
206 /// @brief Macro for reporting error warning messages
209 /// This macro optionally prints an error warning message to stdout,
210 /// followed by the file name and line number where the macro was called.
211 /// The first parameter is a condition -- if it is true, nothing is done.
212 /// The second pararmeter MUST be a parenthesis-enclosed list of arguments,
213 /// starting with a string. This is passed to printf() or an equivalent
214 /// in order to format the informational message. For example,
215 /// ADDR_WARN(0, ("test %d",3) ); prints out "test 3" followed by
216 /// a second line with the file name and line number.
218 #define ADDR_WARN(cond, a) \
221 ADDR_PRNT((" WARNING in file %s, line %d\n", __FILE__, __LINE__)); \
225 /// @brief Macro for reporting fatal error conditions
228 /// This macro optionally stops execution of the current routine
229 /// after printing an error warning message to stdout,
230 /// followed by the file name and line number where the macro was called.
231 /// The first parameter is a condition -- if it is true, nothing is done.
232 /// The second pararmeter MUST be a parenthesis-enclosed list of arguments,
233 /// starting with a string. This is passed to printf() or an equivalent
234 /// in order to format the informational message. For example,
235 /// ADDR_EXIT(0, ("test %d",3) ); prints out "test 3" followed by
236 /// a second line with the file name and line number, then stops execution.
238 #define ADDR_EXIT(cond, a) \
240 { ADDR_PRNT(a); ADDR_DBG_BREAK();\
245 #define ADDRDPF 1 ? (void)0 : (void)
249 #define ADDR_DBG_BREAK()
251 #define ADDR_INFO(cond, a)
253 #define ADDR_WARN(cond, a)
255 #define ADDR_EXIT(cond, a)
258 ///////////////////////////////////////////////////////////////////////////////////////////////////
260 ///////////////////////////////////////////////////////////////////////////////////////////////////
261 // Misc helper functions
262 ////////////////////////////////////////////////////////////////////////////////////////////////////
265 ***************************************************************************************************
269 * Xor the right-side numberOfBits bits of x.
270 ***************************************************************************************************
272 static inline UINT_32
XorReduce(
274 UINT_32 numberOfBits
)
277 UINT_32 result
= x
& 1;
279 for (i
=1; i
<numberOfBits
; i
++)
281 result
^= ((x
>>i
) & 1);
288 ***************************************************************************************************
292 * Check if the size (UINT_32) is pow 2
293 ***************************************************************************************************
295 static inline UINT_32
IsPow2(
296 UINT_32 dim
) ///< [in] dimension of miplevel
298 ADDR_ASSERT(dim
> 0);
299 return !(dim
& (dim
- 1));
303 ***************************************************************************************************
307 * Check if the size (UINT_64) is pow 2
308 ***************************************************************************************************
310 static inline UINT_64
IsPow2(
311 UINT_64 dim
) ///< [in] dimension of miplevel
313 ADDR_ASSERT(dim
> 0);
314 return !(dim
& (dim
- 1));
318 ***************************************************************************************************
322 * Align UINT_32 "x" to "align" alignment, "align" should be power of 2
323 ***************************************************************************************************
325 static inline UINT_32
PowTwoAlign(
330 // Assert that x is a power of two.
332 ADDR_ASSERT(IsPow2(align
));
333 return (x
+ (align
- 1)) & (~(align
- 1));
337 ***************************************************************************************************
341 * Align UINT_64 "x" to "align" alignment, "align" should be power of 2
342 ***************************************************************************************************
344 static inline UINT_64
PowTwoAlign(
349 // Assert that x is a power of two.
351 ADDR_ASSERT(IsPow2(align
));
352 return (x
+ (align
- 1)) & (~(align
- 1));
356 ***************************************************************************************************
360 * Get the min value between two unsigned values
361 ***************************************************************************************************
363 static inline UINT_32
Min(
367 return ((value1
< (value2
)) ? (value1
) : value2
);
371 ***************************************************************************************************
375 * Get the min value between two signed values
376 ***************************************************************************************************
378 static inline INT_32
Min(
382 return ((value1
< (value2
)) ? (value1
) : value2
);
386 ***************************************************************************************************
390 * Get the max value between two unsigned values
391 ***************************************************************************************************
393 static inline UINT_32
Max(
397 return ((value1
> (value2
)) ? (value1
) : value2
);
401 ***************************************************************************************************
405 * Get the max value between two signed values
406 ***************************************************************************************************
408 static inline INT_32
Max(
412 return ((value1
> (value2
)) ? (value1
) : value2
);
416 ***************************************************************************************************
420 * Compute the mipmap's next level dim size
421 ***************************************************************************************************
423 static inline UINT_32
NextPow2(
424 UINT_32 dim
) ///< [in] dimension of miplevel
430 if (dim
> 0x7fffffff)
432 ADDR_ASSERT_ALWAYS();
447 ***************************************************************************************************
451 * Compute log of base 2 no matter the target is power of 2 or not
452 ***************************************************************************************************
454 static inline UINT_32
Log2NonPow2(
455 UINT_32 x
) ///< [in] the value should calculate log based 2
470 ***************************************************************************************************
474 * Compute log of base 2
475 ***************************************************************************************************
477 static inline UINT_32
Log2(
478 UINT_32 x
) ///< [in] the value should calculate log based 2
480 // Assert that x is a power of two.
481 ADDR_ASSERT(IsPow2(x
));
483 return Log2NonPow2(x
);
487 ***************************************************************************************************
491 * Compute log of base 2 quickly (<= 16)
492 ***************************************************************************************************
494 static inline UINT_32
QLog2(
495 UINT_32 x
) ///< [in] the value should calculate log based 2
497 ADDR_ASSERT(x
<= 16);
519 ADDR_ASSERT_ALWAYS();
526 ***************************************************************************************************
530 * NULL pointer safe assignment
531 ***************************************************************************************************
533 static inline VOID
SafeAssign(
534 UINT_32
* pLVal
, ///< [in] Pointer to left val
535 UINT_32 rVal
) ///< [in] Right value
544 ***************************************************************************************************
548 * NULL pointer safe assignment for 64bit values
549 ***************************************************************************************************
551 static inline VOID
SafeAssign(
552 UINT_64
* pLVal
, ///< [in] Pointer to left val
553 UINT_64 rVal
) ///< [in] Right value
562 ***************************************************************************************************
566 * NULL pointer safe assignment for AddrTileMode
567 ***************************************************************************************************
569 static inline VOID
SafeAssign(
570 AddrTileMode
* pLVal
, ///< [in] Pointer to left val
571 AddrTileMode rVal
) ///< [in] Right value
579 #endif // __ADDR_COMMON_H__