2 * Copyright © 2007-2019 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 implementation for the SiLib class.
31 ****************************************************************************************************
34 #include "siaddrlib.h"
35 #include "si_gb_reg.h"
37 #include "amdgpu_asic_addr.h"
39 ////////////////////////////////////////////////////////////////////////////////////////////////////
40 ////////////////////////////////////////////////////////////////////////////////////////////////////
45 ****************************************************************************************************
49 * Creates an SiLib object.
52 * Returns an SiLib object pointer.
53 ****************************************************************************************************
55 Lib
* SiHwlInit(const Client
* pClient
)
57 return V1::SiLib::CreateObj(pClient
);
63 // We don't support MSAA for equation
64 const BOOL_32
SiLib::m_EquationSupport
[SiLib::TileTableSize
][SiLib::MaxNumElementBytes
] =
66 {TRUE
, TRUE
, TRUE
, FALSE
, FALSE
}, // 0, non-AA compressed depth or any stencil
67 {FALSE
, FALSE
, FALSE
, FALSE
, FALSE
}, // 1, 2xAA/4xAA compressed depth with or without stencil
68 {FALSE
, FALSE
, FALSE
, FALSE
, FALSE
}, // 2, 8xAA compressed depth with or without stencil
69 {FALSE
, TRUE
, FALSE
, FALSE
, FALSE
}, // 3, 16 bpp depth PRT (non-MSAA), don't support uncompressed depth
70 {TRUE
, TRUE
, TRUE
, FALSE
, FALSE
}, // 4, 1D depth
71 {FALSE
, FALSE
, FALSE
, FALSE
, FALSE
}, // 5, 16 bpp depth PRT (4xMSAA)
72 {FALSE
, FALSE
, TRUE
, FALSE
, FALSE
}, // 6, 32 bpp depth PRT (non-MSAA)
73 {FALSE
, FALSE
, FALSE
, FALSE
, FALSE
}, // 7, 32 bpp depth PRT (4xMSAA)
74 {TRUE
, TRUE
, TRUE
, TRUE
, TRUE
}, // 8, Linear
75 {TRUE
, TRUE
, TRUE
, TRUE
, TRUE
}, // 9, 1D display
76 {TRUE
, FALSE
, FALSE
, FALSE
, FALSE
}, // 10, 8 bpp color (displayable)
77 {FALSE
, TRUE
, FALSE
, FALSE
, FALSE
}, // 11, 16 bpp color (displayable)
78 {FALSE
, FALSE
, TRUE
, TRUE
, FALSE
}, // 12, 32/64 bpp color (displayable)
79 {TRUE
, TRUE
, TRUE
, TRUE
, TRUE
}, // 13, 1D thin
80 {TRUE
, FALSE
, FALSE
, FALSE
, FALSE
}, // 14, 8 bpp color non-displayable
81 {FALSE
, TRUE
, FALSE
, FALSE
, FALSE
}, // 15, 16 bpp color non-displayable
82 {FALSE
, FALSE
, TRUE
, FALSE
, FALSE
}, // 16, 32 bpp color non-displayable
83 {FALSE
, FALSE
, FALSE
, TRUE
, TRUE
}, // 17, 64/128 bpp color non-displayable
84 {TRUE
, TRUE
, TRUE
, TRUE
, TRUE
}, // 18, 1D THICK
85 {FALSE
, FALSE
, FALSE
, FALSE
, FALSE
}, // 19, 2D XTHICK
86 {FALSE
, FALSE
, FALSE
, FALSE
, FALSE
}, // 20, 2D THICK
87 {TRUE
, FALSE
, FALSE
, FALSE
, FALSE
}, // 21, 8 bpp 2D PRTs (non-MSAA)
88 {FALSE
, TRUE
, FALSE
, FALSE
, FALSE
}, // 22, 16 bpp 2D PRTs (non-MSAA)
89 {FALSE
, FALSE
, TRUE
, FALSE
, FALSE
}, // 23, 32 bpp 2D PRTs (non-MSAA)
90 {FALSE
, FALSE
, FALSE
, TRUE
, FALSE
}, // 24, 64 bpp 2D PRTs (non-MSAA)
91 {FALSE
, FALSE
, FALSE
, FALSE
, TRUE
}, // 25, 128bpp 2D PRTs (non-MSAA)
92 {FALSE
, FALSE
, FALSE
, FALSE
, FALSE
}, // 26, none
93 {FALSE
, FALSE
, FALSE
, FALSE
, FALSE
}, // 27, none
94 {FALSE
, FALSE
, FALSE
, FALSE
, FALSE
}, // 28, none
95 {FALSE
, FALSE
, FALSE
, FALSE
, FALSE
}, // 29, none
96 {FALSE
, FALSE
, FALSE
, FALSE
, FALSE
}, // 30, 64bpp 2D PRTs (4xMSAA)
97 {FALSE
, FALSE
, FALSE
, FALSE
, FALSE
}, // 31, none
101 ****************************************************************************************************
107 ****************************************************************************************************
109 SiLib::SiLib(const Client
* pClient
)
115 m_class
= SI_ADDRLIB
;
116 memset(&m_settings
, 0, sizeof(m_settings
));
120 ****************************************************************************************************
125 ****************************************************************************************************
132 ****************************************************************************************************
139 ****************************************************************************************************
141 UINT_32
SiLib::HwlGetPipes(
142 const ADDR_TILEINFO
* pTileInfo
///< [in] Tile info
149 numPipes
= GetPipePerSurf(pTileInfo
->pipeConfig
);
153 ADDR_ASSERT_ALWAYS();
154 numPipes
= m_pipes
; // Suppose we should still have a global pipes
161 ****************************************************************************************************
162 * SiLib::GetPipePerSurf
164 * get pipe num base on inputing tileinfo->pipeconfig
167 ****************************************************************************************************
169 UINT_32
SiLib::GetPipePerSurf(
170 AddrPipeCfg pipeConfig
///< [in] pipe config
173 UINT_32 numPipes
= 0;
177 case ADDR_PIPECFG_P2
:
180 case ADDR_PIPECFG_P4_8x16
:
181 case ADDR_PIPECFG_P4_16x16
:
182 case ADDR_PIPECFG_P4_16x32
:
183 case ADDR_PIPECFG_P4_32x32
:
186 case ADDR_PIPECFG_P8_16x16_8x16
:
187 case ADDR_PIPECFG_P8_16x32_8x16
:
188 case ADDR_PIPECFG_P8_32x32_8x16
:
189 case ADDR_PIPECFG_P8_16x32_16x16
:
190 case ADDR_PIPECFG_P8_32x32_16x16
:
191 case ADDR_PIPECFG_P8_32x32_16x32
:
192 case ADDR_PIPECFG_P8_32x64_32x32
:
195 case ADDR_PIPECFG_P16_32x32_8x16
:
196 case ADDR_PIPECFG_P16_32x32_16x16
:
200 ADDR_ASSERT(!"Invalid pipe config");
207 ****************************************************************************************************
208 * SiLib::ComputeBankEquation
211 * Compute bank equation
214 * If equation can be computed
215 ****************************************************************************************************
217 ADDR_E_RETURNCODE
SiLib::ComputeBankEquation(
218 UINT_32 log2BytesPP
, ///< [in] log2 of bytes per pixel
219 UINT_32 threshX
, ///< [in] threshold for x channel
220 UINT_32 threshY
, ///< [in] threshold for y channel
221 ADDR_TILEINFO
* pTileInfo
, ///< [in] tile info
222 ADDR_EQUATION
* pEquation
///< [out] bank equation
225 ADDR_E_RETURNCODE retCode
= ADDR_OK
;
227 UINT_32 pipes
= HwlGetPipes(pTileInfo
);
228 UINT_32 bankXStart
= 3 + Log2(pipes
) + Log2(pTileInfo
->bankWidth
);
229 UINT_32 bankYStart
= 3 + Log2(pTileInfo
->bankHeight
);
231 ADDR_CHANNEL_SETTING x3
= InitChannel(1, 0, log2BytesPP
+ bankXStart
);
232 ADDR_CHANNEL_SETTING x4
= InitChannel(1, 0, log2BytesPP
+ bankXStart
+ 1);
233 ADDR_CHANNEL_SETTING x5
= InitChannel(1, 0, log2BytesPP
+ bankXStart
+ 2);
234 ADDR_CHANNEL_SETTING x6
= InitChannel(1, 0, log2BytesPP
+ bankXStart
+ 3);
235 ADDR_CHANNEL_SETTING y3
= InitChannel(1, 1, bankYStart
);
236 ADDR_CHANNEL_SETTING y4
= InitChannel(1, 1, bankYStart
+ 1);
237 ADDR_CHANNEL_SETTING y5
= InitChannel(1, 1, bankYStart
+ 2);
238 ADDR_CHANNEL_SETTING y6
= InitChannel(1, 1, bankYStart
+ 3);
240 x3
.value
= (threshX
> bankXStart
) ? x3
.value
: 0;
241 x4
.value
= (threshX
> bankXStart
+ 1) ? x4
.value
: 0;
242 x5
.value
= (threshX
> bankXStart
+ 2) ? x5
.value
: 0;
243 x6
.value
= (threshX
> bankXStart
+ 3) ? x6
.value
: 0;
244 y3
.value
= (threshY
> bankYStart
) ? y3
.value
: 0;
245 y4
.value
= (threshY
> bankYStart
+ 1) ? y4
.value
: 0;
246 y5
.value
= (threshY
> bankYStart
+ 2) ? y5
.value
: 0;
247 y6
.value
= (threshY
> bankYStart
+ 3) ? y6
.value
: 0;
249 switch (pTileInfo
->banks
)
252 if (pTileInfo
->macroAspectRatio
== 1)
254 pEquation
->addr
[0] = y6
;
255 pEquation
->xor1
[0] = x3
;
256 pEquation
->addr
[1] = y5
;
257 pEquation
->xor1
[1] = y6
;
258 pEquation
->xor2
[1] = x4
;
259 pEquation
->addr
[2] = y4
;
260 pEquation
->xor1
[2] = x5
;
261 pEquation
->addr
[3] = y3
;
262 pEquation
->xor1
[3] = x6
;
264 else if (pTileInfo
->macroAspectRatio
== 2)
266 pEquation
->addr
[0] = x3
;
267 pEquation
->xor1
[0] = y6
;
268 pEquation
->addr
[1] = y5
;
269 pEquation
->xor1
[1] = y6
;
270 pEquation
->xor2
[1] = x4
;
271 pEquation
->addr
[2] = y4
;
272 pEquation
->xor1
[2] = x5
;
273 pEquation
->addr
[3] = y3
;
274 pEquation
->xor1
[3] = x6
;
276 else if (pTileInfo
->macroAspectRatio
== 4)
278 pEquation
->addr
[0] = x3
;
279 pEquation
->xor1
[0] = y6
;
280 pEquation
->addr
[1] = x4
;
281 pEquation
->xor1
[1] = y5
;
282 pEquation
->xor2
[1] = y6
;
283 pEquation
->addr
[2] = y4
;
284 pEquation
->xor1
[2] = x5
;
285 pEquation
->addr
[3] = y3
;
286 pEquation
->xor1
[3] = x6
;
288 else if (pTileInfo
->macroAspectRatio
== 8)
290 pEquation
->addr
[0] = x3
;
291 pEquation
->xor1
[0] = y6
;
292 pEquation
->addr
[1] = x4
;
293 pEquation
->xor1
[1] = y5
;
294 pEquation
->xor2
[1] = y6
;
295 pEquation
->addr
[2] = x5
;
296 pEquation
->xor1
[2] = y4
;
297 pEquation
->addr
[3] = y3
;
298 pEquation
->xor1
[3] = x6
;
302 ADDR_ASSERT_ALWAYS();
304 pEquation
->numBits
= 4;
307 if (pTileInfo
->macroAspectRatio
== 1)
309 pEquation
->addr
[0] = y5
;
310 pEquation
->xor1
[0] = x3
;
311 pEquation
->addr
[1] = y4
;
312 pEquation
->xor1
[1] = y5
;
313 pEquation
->xor2
[1] = x4
;
314 pEquation
->addr
[2] = y3
;
315 pEquation
->xor1
[2] = x5
;
317 else if (pTileInfo
->macroAspectRatio
== 2)
319 pEquation
->addr
[0] = x3
;
320 pEquation
->xor1
[0] = y5
;
321 pEquation
->addr
[1] = y4
;
322 pEquation
->xor1
[1] = y5
;
323 pEquation
->xor2
[1] = x4
;
324 pEquation
->addr
[2] = y3
;
325 pEquation
->xor1
[2] = x5
;
327 else if (pTileInfo
->macroAspectRatio
== 4)
329 pEquation
->addr
[0] = x3
;
330 pEquation
->xor1
[0] = y5
;
331 pEquation
->addr
[1] = x4
;
332 pEquation
->xor1
[1] = y4
;
333 pEquation
->xor2
[1] = y5
;
334 pEquation
->addr
[2] = y3
;
335 pEquation
->xor1
[2] = x5
;
339 ADDR_ASSERT_ALWAYS();
341 pEquation
->numBits
= 3;
344 if (pTileInfo
->macroAspectRatio
== 1)
346 pEquation
->addr
[0] = y4
;
347 pEquation
->xor1
[0] = x3
;
348 pEquation
->addr
[1] = y3
;
349 pEquation
->xor1
[1] = x4
;
351 else if (pTileInfo
->macroAspectRatio
== 2)
353 pEquation
->addr
[0] = x3
;
354 pEquation
->xor1
[0] = y4
;
355 pEquation
->addr
[1] = y3
;
356 pEquation
->xor1
[1] = x4
;
360 pEquation
->addr
[0] = x3
;
361 pEquation
->xor1
[0] = y4
;
362 pEquation
->addr
[1] = x4
;
363 pEquation
->xor1
[1] = y3
;
365 pEquation
->numBits
= 2;
368 if (pTileInfo
->macroAspectRatio
== 1)
370 pEquation
->addr
[0] = y3
;
371 pEquation
->xor1
[0] = x3
;
375 pEquation
->addr
[0] = x3
;
376 pEquation
->xor1
[0] = y3
;
378 pEquation
->numBits
= 1;
381 pEquation
->numBits
= 0;
382 retCode
= ADDR_NOTSUPPORTED
;
383 ADDR_ASSERT_ALWAYS();
387 for (UINT_32 i
= 0; i
< pEquation
->numBits
; i
++)
389 if (pEquation
->addr
[i
].value
== 0)
391 if (pEquation
->xor1
[i
].value
== 0)
394 pEquation
->addr
[i
].value
= pEquation
->xor2
[i
].value
;
395 pEquation
->xor2
[i
].value
= 0;
399 pEquation
->addr
[i
].value
= pEquation
->xor1
[i
].value
;
401 if (pEquation
->xor2
[i
].value
!= 0)
404 pEquation
->xor1
[i
].value
= pEquation
->xor2
[i
].value
;
405 pEquation
->xor2
[i
].value
= 0;
410 pEquation
->xor1
[i
].value
= 0;
414 else if (pEquation
->xor1
[i
].value
== 0)
416 if (pEquation
->xor2
[i
].value
!= 0)
419 pEquation
->xor1
[i
].value
= pEquation
->xor2
[i
].value
;
420 pEquation
->xor2
[i
].value
= 0;
425 if ((pTileInfo
->bankWidth
== 1) &&
426 ((pTileInfo
->pipeConfig
== ADDR_PIPECFG_P4_32x32
) ||
427 (pTileInfo
->pipeConfig
== ADDR_PIPECFG_P8_32x64_32x32
)))
429 retCode
= ADDR_NOTSUPPORTED
;
436 ****************************************************************************************************
437 * SiLib::ComputePipeEquation
440 * Compute pipe equation
443 * If equation can be computed
444 ****************************************************************************************************
446 ADDR_E_RETURNCODE
SiLib::ComputePipeEquation(
447 UINT_32 log2BytesPP
, ///< [in] Log2 of bytes per pixel
448 UINT_32 threshX
, ///< [in] Threshold for X channel
449 UINT_32 threshY
, ///< [in] Threshold for Y channel
450 ADDR_TILEINFO
* pTileInfo
, ///< [in] Tile info
451 ADDR_EQUATION
* pEquation
///< [out] Pipe configure
454 ADDR_E_RETURNCODE retCode
= ADDR_OK
;
456 ADDR_CHANNEL_SETTING
* pAddr
= pEquation
->addr
;
457 ADDR_CHANNEL_SETTING
* pXor1
= pEquation
->xor1
;
458 ADDR_CHANNEL_SETTING
* pXor2
= pEquation
->xor2
;
460 ADDR_CHANNEL_SETTING x3
= InitChannel(1, 0, 3 + log2BytesPP
);
461 ADDR_CHANNEL_SETTING x4
= InitChannel(1, 0, 4 + log2BytesPP
);
462 ADDR_CHANNEL_SETTING x5
= InitChannel(1, 0, 5 + log2BytesPP
);
463 ADDR_CHANNEL_SETTING x6
= InitChannel(1, 0, 6 + log2BytesPP
);
464 ADDR_CHANNEL_SETTING y3
= InitChannel(1, 1, 3);
465 ADDR_CHANNEL_SETTING y4
= InitChannel(1, 1, 4);
466 ADDR_CHANNEL_SETTING y5
= InitChannel(1, 1, 5);
467 ADDR_CHANNEL_SETTING y6
= InitChannel(1, 1, 6);
469 x3
.value
= (threshX
> 3) ? x3
.value
: 0;
470 x4
.value
= (threshX
> 4) ? x4
.value
: 0;
471 x5
.value
= (threshX
> 5) ? x5
.value
: 0;
472 x6
.value
= (threshX
> 6) ? x6
.value
: 0;
473 y3
.value
= (threshY
> 3) ? y3
.value
: 0;
474 y4
.value
= (threshY
> 4) ? y4
.value
: 0;
475 y5
.value
= (threshY
> 5) ? y5
.value
: 0;
476 y6
.value
= (threshY
> 6) ? y6
.value
: 0;
478 switch (pTileInfo
->pipeConfig
)
480 case ADDR_PIPECFG_P2
:
483 pEquation
->numBits
= 1;
485 case ADDR_PIPECFG_P4_8x16
:
490 pEquation
->numBits
= 2;
492 case ADDR_PIPECFG_P4_16x16
:
498 pEquation
->numBits
= 2;
500 case ADDR_PIPECFG_P4_16x32
:
506 pEquation
->numBits
= 2;
508 case ADDR_PIPECFG_P4_32x32
:
514 pEquation
->numBits
= 2;
516 case ADDR_PIPECFG_P8_16x16_8x16
:
522 pEquation
->numBits
= 3;
524 case ADDR_PIPECFG_P8_16x32_8x16
:
532 pEquation
->numBits
= 3;
534 case ADDR_PIPECFG_P8_16x32_16x16
:
542 pEquation
->numBits
= 3;
544 case ADDR_PIPECFG_P8_32x32_8x16
:
552 pEquation
->numBits
= 3;
554 case ADDR_PIPECFG_P8_32x32_16x16
:
562 pEquation
->numBits
= 3;
564 case ADDR_PIPECFG_P8_32x32_16x32
:
572 pEquation
->numBits
= 3;
574 case ADDR_PIPECFG_P8_32x64_32x32
:
582 pEquation
->numBits
= 3;
584 case ADDR_PIPECFG_P16_32x32_8x16
:
593 pEquation
->numBits
= 4;
595 case ADDR_PIPECFG_P16_32x32_16x16
:
605 pEquation
->numBits
= 4;
608 ADDR_UNHANDLED_CASE();
609 pEquation
->numBits
= 0;
610 retCode
= ADDR_NOTSUPPORTED
;
614 if (m_settings
.isVegaM
&& (pEquation
->numBits
== 4))
616 ADDR_CHANNEL_SETTING addeMsb
= pAddr
[0];
617 ADDR_CHANNEL_SETTING xor1Msb
= pXor1
[0];
618 ADDR_CHANNEL_SETTING xor2Msb
= pXor2
[0];
637 for (UINT_32 i
= 0; i
< pEquation
->numBits
; i
++)
639 if (pAddr
[i
].value
== 0)
641 if (pXor1
[i
].value
== 0)
643 pAddr
[i
].value
= pXor2
[i
].value
;
647 pAddr
[i
].value
= pXor1
[i
].value
;
657 ****************************************************************************************************
658 * SiLib::ComputePipeFromCoord
661 * Compute pipe number from coordinates
664 ****************************************************************************************************
666 UINT_32
SiLib::ComputePipeFromCoord(
667 UINT_32 x
, ///< [in] x coordinate
668 UINT_32 y
, ///< [in] y coordinate
669 UINT_32 slice
, ///< [in] slice index
670 AddrTileMode tileMode
, ///< [in] tile mode
671 UINT_32 pipeSwizzle
, ///< [in] pipe swizzle
672 BOOL_32 ignoreSE
, ///< [in] TRUE if shader engines are ignored
673 ADDR_TILEINFO
* pTileInfo
///< [in] Tile info
677 UINT_32 pipeBit0
= 0;
678 UINT_32 pipeBit1
= 0;
679 UINT_32 pipeBit2
= 0;
680 UINT_32 pipeBit3
= 0;
681 UINT_32 sliceRotation
;
682 UINT_32 numPipes
= 0;
684 UINT_32 tx
= x
/ MicroTileWidth
;
685 UINT_32 ty
= y
/ MicroTileHeight
;
686 UINT_32 x3
= _BIT(tx
,0);
687 UINT_32 x4
= _BIT(tx
,1);
688 UINT_32 x5
= _BIT(tx
,2);
689 UINT_32 x6
= _BIT(tx
,3);
690 UINT_32 y3
= _BIT(ty
,0);
691 UINT_32 y4
= _BIT(ty
,1);
692 UINT_32 y5
= _BIT(ty
,2);
693 UINT_32 y6
= _BIT(ty
,3);
695 switch (pTileInfo
->pipeConfig
)
697 case ADDR_PIPECFG_P2
:
701 case ADDR_PIPECFG_P4_8x16
:
706 case ADDR_PIPECFG_P4_16x16
:
707 pipeBit0
= x3
^ y3
^ x4
;
711 case ADDR_PIPECFG_P4_16x32
:
712 pipeBit0
= x3
^ y3
^ x4
;
716 case ADDR_PIPECFG_P4_32x32
:
717 pipeBit0
= x3
^ y3
^ x5
;
721 case ADDR_PIPECFG_P8_16x16_8x16
:
722 pipeBit0
= x4
^ y3
^ x5
;
726 case ADDR_PIPECFG_P8_16x32_8x16
:
727 pipeBit0
= x4
^ y3
^ x5
;
732 case ADDR_PIPECFG_P8_16x32_16x16
:
733 pipeBit0
= x3
^ y3
^ x4
;
738 case ADDR_PIPECFG_P8_32x32_8x16
:
739 pipeBit0
= x4
^ y3
^ x5
;
744 case ADDR_PIPECFG_P8_32x32_16x16
:
745 pipeBit0
= x3
^ y3
^ x4
;
750 case ADDR_PIPECFG_P8_32x32_16x32
:
751 pipeBit0
= x3
^ y3
^ x4
;
756 case ADDR_PIPECFG_P8_32x64_32x32
:
757 pipeBit0
= x3
^ y3
^ x5
;
762 case ADDR_PIPECFG_P16_32x32_8x16
:
769 case ADDR_PIPECFG_P16_32x32_16x16
:
770 pipeBit0
= x3
^ y3
^ x4
;
777 ADDR_UNHANDLED_CASE();
781 if (m_settings
.isVegaM
&& (numPipes
== 16))
783 UINT_32 pipeMsb
= pipeBit0
;
790 pipe
= pipeBit0
| (pipeBit1
<< 1) | (pipeBit2
<< 2) | (pipeBit3
<< 3);
792 UINT_32 microTileThickness
= Thickness(tileMode
);
795 // Apply pipe rotation for the slice.
799 case ADDR_TM_3D_TILED_THIN1
: //fall through thin
800 case ADDR_TM_3D_TILED_THICK
: //fall through thick
801 case ADDR_TM_3D_TILED_XTHICK
:
803 Max(1, static_cast<INT_32
>(numPipes
/ 2) - 1) * (slice
/ microTileThickness
);
809 pipeSwizzle
+= sliceRotation
;
810 pipeSwizzle
&= (numPipes
- 1);
812 pipe
= pipe
^ pipeSwizzle
;
818 ****************************************************************************************************
819 * SiLib::ComputeTileCoordFromPipeAndElemIdx
822 * Compute (x,y) of a tile within a macro tile from address
825 ****************************************************************************************************
827 VOID
SiLib::ComputeTileCoordFromPipeAndElemIdx(
828 UINT_32 elemIdx
, ///< [in] per pipe element index within a macro tile
829 UINT_32 pipe
, ///< [in] pipe index
830 AddrPipeCfg pipeCfg
, ///< [in] pipe config
831 UINT_32 pitchInMacroTile
, ///< [in] surface pitch in macro tile
832 UINT_32 x
, ///< [in] x coordinate of the (0,0) tile in a macro tile
833 UINT_32 y
, ///< [in] y coordinate of the (0,0) tile in a macro tile
834 UINT_32
* pX
, ///< [out] x coordinate
835 UINT_32
* pY
///< [out] y coordinate
838 UINT_32 pipebit0
= _BIT(pipe
,0);
839 UINT_32 pipebit1
= _BIT(pipe
,1);
840 UINT_32 pipebit2
= _BIT(pipe
,2);
841 UINT_32 pipebit3
= _BIT(pipe
,3);
842 UINT_32 elemIdx0
= _BIT(elemIdx
,0);
843 UINT_32 elemIdx1
= _BIT(elemIdx
,1);
844 UINT_32 elemIdx2
= _BIT(elemIdx
,2);
856 case ADDR_PIPECFG_P2
:
861 *pY
= Bits2Number(2, y4
, y3
);
862 *pX
= Bits2Number(2, x4
, x3
);
864 case ADDR_PIPECFG_P4_8x16
:
869 *pY
= Bits2Number(2, y4
, y3
);
870 *pX
= Bits2Number(2, x4
, x3
);
872 case ADDR_PIPECFG_P4_16x16
:
876 x3
= pipebit0
^ y3
^ x4
;
877 *pY
= Bits2Number(2, y4
, y3
);
878 *pX
= Bits2Number(2, x4
, x3
);
880 case ADDR_PIPECFG_P4_16x32
:
881 x3
= elemIdx0
^ pipebit0
;
884 y3
= pipebit0
^ x3
^ x4
;
886 *pY
= Bits2Number(2, y4
, y3
);
887 *pX
= Bits2Number(2, x4
, x3
);
889 case ADDR_PIPECFG_P4_32x32
:
893 if((pitchInMacroTile
% 2) == 0)
897 x3
= pipebit0
^ y3
^ x5
;
898 *pY
= Bits2Number(2, y4
, y3
);
899 *pX
= Bits2Number(3, x5
, x4
, x3
);
904 x3
= pipebit0
^ y3
^ x5
;
905 *pY
= Bits2Number(2, y4
, y3
);
906 *pX
= Bits2Number(2, x4
, x3
);
909 case ADDR_PIPECFG_P8_16x16_8x16
:
915 y3
= pipebit0
^ x5
^ x4
;
916 *pY
= Bits2Number(2, y4
, y3
);
917 *pX
= Bits2Number(2, x4
, x3
);
919 case ADDR_PIPECFG_P8_16x32_8x16
:
925 y3
= pipebit0
^ x4
^ x5
;
926 *pY
= Bits2Number(2, y4
, y3
);
927 *pX
= Bits2Number(2, x4
, x3
);
929 case ADDR_PIPECFG_P8_32x32_8x16
:
933 if((pitchInMacroTile
% 2) == 0)
938 y3
= pipebit0
^ x4
^ x5
;
939 *pY
= Bits2Number(2, y4
, y3
);
940 *pX
= Bits2Number(3, x5
, x4
, x3
);
945 y3
= pipebit0
^ x4
^ x5
;
946 *pY
= Bits2Number(2, y4
, y3
);
947 *pX
= Bits2Number(2, x4
, x3
);
950 case ADDR_PIPECFG_P8_16x32_16x16
:
956 y3
= pipebit0
^ x3
^ x4
;
957 *pY
= Bits2Number(2, y4
, y3
);
958 *pX
= Bits2Number(2, x4
, x3
);
960 case ADDR_PIPECFG_P8_32x32_16x16
:
965 if((pitchInMacroTile
% 2) == 0)
969 *pY
= Bits2Number(2, y4
, y3
);
970 *pX
= Bits2Number(3, x5
, x4
, x3
);
974 *pY
= Bits2Number(2, y4
, y3
);
975 *pX
= Bits2Number(2, x4
, x3
);
978 case ADDR_PIPECFG_P8_32x32_16x32
:
979 if((pitchInMacroTile
% 2) == 0)
986 x3
= pipebit0
^ y3
^ x4
;
988 *pY
= Bits2Number(2, y4
, y3
);
989 *pX
= Bits2Number(3, x5
, x4
, x3
);
997 x3
= pipebit0
^ y3
^ x4
;
998 *pY
= Bits2Number(2, y4
, y3
);
999 *pX
= Bits2Number(2, x4
, x3
);
1002 case ADDR_PIPECFG_P8_32x64_32x32
:
1006 if((pitchInMacroTile
% 4) == 0)
1012 x3
= pipebit0
^ y3
^ x5
;
1013 *pY
= Bits2Number(2, y4
, y3
);
1014 *pX
= Bits2Number(4, x6
, x5
, x4
, x3
);
1020 x3
= pipebit0
^ y3
^ x5
;
1021 *pY
= Bits2Number(2, y4
, y3
);
1022 *pX
= Bits2Number(3, x5
, x4
, x3
);
1025 case ADDR_PIPECFG_P16_32x32_8x16
:
1030 if((pitchInMacroTile
% 4) == 0)
1036 *pY
= Bits2Number(2, y4
, y3
);
1037 *pX
= Bits2Number(4, x6
, x5
,x4
, x3
);
1043 *pY
= Bits2Number(2, y4
, y3
);
1044 *pX
= Bits2Number(3, x5
, x4
, x3
);
1047 case ADDR_PIPECFG_P16_32x32_16x16
:
1051 x3
= pipebit0
^ y3
^ x4
;
1052 if((pitchInMacroTile
% 4) == 0)
1058 *pY
= Bits2Number(2, y4
, y3
);
1059 *pX
= Bits2Number(4, x6
, x5
, x4
, x3
);
1065 *pY
= Bits2Number(2, y4
, y3
);
1066 *pX
= Bits2Number(3, x5
, x4
, x3
);
1070 ADDR_UNHANDLED_CASE();
1075 ****************************************************************************************************
1076 * SiLib::TileCoordToMaskElementIndex
1079 * Compute element index from coordinates in tiles
1082 ****************************************************************************************************
1084 UINT_32
SiLib::TileCoordToMaskElementIndex(
1085 UINT_32 tx
, ///< [in] x coord, in Tiles
1086 UINT_32 ty
, ///< [in] y coord, in Tiles
1087 AddrPipeCfg pipeConfig
, ///< [in] pipe config
1088 UINT_32
* macroShift
, ///< [out] macro shift
1089 UINT_32
* elemIdxBits
///< [out] tile offset bits
1092 UINT_32 elemIdx
= 0;
1093 UINT_32 elemIdx0
, elemIdx1
, elemIdx2
;
1104 case ADDR_PIPECFG_P2
:
1108 elemIdx1
= tx1
^ ty1
;
1109 elemIdx0
= tx1
^ ty0
;
1110 elemIdx
= Bits2Number(3,elemIdx2
,elemIdx1
,elemIdx0
);
1112 case ADDR_PIPECFG_P4_8x16
:
1116 elemIdx0
= tx1
^ ty1
;
1117 elemIdx
= Bits2Number(2,elemIdx1
,elemIdx0
);
1119 case ADDR_PIPECFG_P4_16x16
:
1124 elemIdx
= Bits2Number(2, elemIdx1
, elemIdx0
);
1126 case ADDR_PIPECFG_P4_16x32
:
1131 elemIdx
= Bits2Number(2, elemIdx1
, elemIdx0
);
1133 case ADDR_PIPECFG_P4_32x32
:
1139 elemIdx
= Bits2Number(3, elemIdx2
, elemIdx1
, elemIdx0
);
1141 case ADDR_PIPECFG_P8_16x16_8x16
:
1147 case ADDR_PIPECFG_P8_16x32_8x16
:
1153 case ADDR_PIPECFG_P8_32x32_8x16
:
1158 elemIdx
= Bits2Number(2, elemIdx1
, elemIdx0
);
1160 case ADDR_PIPECFG_P8_16x32_16x16
:
1166 case ADDR_PIPECFG_P8_32x32_16x16
:
1171 elemIdx
= Bits2Number(2, elemIdx1
, elemIdx0
);
1173 case ADDR_PIPECFG_P8_32x32_16x32
:
1178 elemIdx
= Bits2Number(2, elemIdx1
, elemIdx0
);
1180 case ADDR_PIPECFG_P8_32x64_32x32
:
1186 elemIdx
= Bits2Number(3, elemIdx2
, elemIdx1
, elemIdx0
);
1188 case ADDR_PIPECFG_P16_32x32_8x16
:
1193 elemIdx
= Bits2Number(2, elemIdx1
, elemIdx0
);
1195 case ADDR_PIPECFG_P16_32x32_16x16
:
1200 elemIdx
= Bits2Number(2, elemIdx1
, elemIdx0
);
1203 ADDR_UNHANDLED_CASE();
1211 ****************************************************************************************************
1212 * SiLib::HwlComputeTileDataWidthAndHeightLinear
1215 * Compute the squared cache shape for per-tile data (CMASK and HTILE) for linear layout
1221 * MacroWidth and macroHeight are measured in pixels
1222 ****************************************************************************************************
1224 VOID
SiLib::HwlComputeTileDataWidthAndHeightLinear(
1225 UINT_32
* pMacroWidth
, ///< [out] macro tile width
1226 UINT_32
* pMacroHeight
, ///< [out] macro tile height
1227 UINT_32 bpp
, ///< [in] bits per pixel
1228 ADDR_TILEINFO
* pTileInfo
///< [in] tile info
1231 ADDR_ASSERT(pTileInfo
!= NULL
);
1233 UINT_32 macroHeight
;
1235 /// In linear mode, the htile or cmask buffer must be padded out to 4 tiles
1236 /// but for P8_32x64_32x32, it must be padded out to 8 tiles
1237 /// Actually there are more pipe configs which need 8-tile padding but SI family
1238 /// has a bug which is fixed in CI family
1239 if ((pTileInfo
->pipeConfig
== ADDR_PIPECFG_P8_32x64_32x32
) ||
1240 (pTileInfo
->pipeConfig
== ADDR_PIPECFG_P16_32x32_8x16
) ||
1241 (pTileInfo
->pipeConfig
== ADDR_PIPECFG_P8_32x32_16x16
))
1243 macroWidth
= 8*MicroTileWidth
;
1244 macroHeight
= 8*MicroTileHeight
;
1248 macroWidth
= 4*MicroTileWidth
;
1249 macroHeight
= 4*MicroTileHeight
;
1252 *pMacroWidth
= macroWidth
;
1253 *pMacroHeight
= macroHeight
;
1257 ****************************************************************************************************
1258 * SiLib::HwlComputeHtileBytes
1261 * Compute htile size in bytes
1264 * Htile size in bytes
1265 ****************************************************************************************************
1267 UINT_64
SiLib::HwlComputeHtileBytes(
1268 UINT_32 pitch
, ///< [in] pitch
1269 UINT_32 height
, ///< [in] height
1270 UINT_32 bpp
, ///< [in] bits per pixel
1271 BOOL_32 isLinear
, ///< [in] if it is linear mode
1272 UINT_32 numSlices
, ///< [in] number of slices
1273 UINT_64
* pSliceBytes
, ///< [out] bytes per slice
1274 UINT_32 baseAlign
///< [in] base alignments
1277 return ComputeHtileBytes(pitch
, height
, bpp
, isLinear
, numSlices
, pSliceBytes
, baseAlign
);
1281 ****************************************************************************************************
1282 * SiLib::HwlComputeXmaskAddrFromCoord
1285 * Compute address from coordinates for htile/cmask
1288 ****************************************************************************************************
1290 UINT_64
SiLib::HwlComputeXmaskAddrFromCoord(
1291 UINT_32 pitch
, ///< [in] pitch
1292 UINT_32 height
, ///< [in] height
1293 UINT_32 x
, ///< [in] x coord
1294 UINT_32 y
, ///< [in] y coord
1295 UINT_32 slice
, ///< [in] slice/depth index
1296 UINT_32 numSlices
, ///< [in] number of slices
1297 UINT_32 factor
, ///< [in] factor that indicates cmask(2) or htile(1)
1298 BOOL_32 isLinear
, ///< [in] linear or tiled HTILE layout
1299 BOOL_32 isWidth8
, ///< [in] TRUE if width is 8, FALSE means 4. It's register value
1300 BOOL_32 isHeight8
, ///< [in] TRUE if width is 8, FALSE means 4. It's register value
1301 ADDR_TILEINFO
* pTileInfo
, ///< [in] Tile info
1302 UINT_32
* pBitPosition
///< [out] bit position inside a byte
1305 UINT_32 tx
= x
/ MicroTileWidth
;
1306 UINT_32 ty
= y
/ MicroTileHeight
;
1311 UINT_32 macroHeight
;
1312 UINT_64 pSliceBytes
;
1314 UINT_32 tileNumPerPipe
;
1317 if (factor
== 2) //CMASK
1319 ADDR_CMASK_FLAGS flags
= {{0}};
1321 tileNumPerPipe
= 256;
1323 ComputeCmaskInfo(flags
,
1334 elemBits
= CmaskElemBits
;
1338 ADDR_HTILE_FLAGS flags
= {{0}};
1340 tileNumPerPipe
= 512;
1342 ComputeHtileInfo(flags
,
1360 const UINT_32 pitchInTile
= newPitch
/ MicroTileWidth
;
1361 const UINT_32 heightInTile
= newHeight
/ MicroTileWidth
;
1362 UINT_64 macroOffset
; // Per pipe starting offset of the macro tile in which this tile lies.
1363 UINT_64 microNumber
; // Per pipe starting offset of the macro tile in which this tile lies.
1366 UINT_64 microOffset
;
1368 UINT_64 totalOffset
;
1369 UINT_32 elemIdxBits
;
1371 TileCoordToMaskElementIndex(tx
, ty
, pTileInfo
->pipeConfig
, µShift
, &elemIdxBits
);
1373 UINT_32 numPipes
= HwlGetPipes(pTileInfo
);
1376 { //linear addressing
1377 // Linear addressing is extremelly wasting memory if slice > 1, since each pipe has the full
1378 // slice memory foot print instead of divided by numPipes.
1379 microX
= tx
/ 4; // Macro Tile is 4x4
1381 microNumber
= static_cast<UINT_64
>(microX
+ microY
* (pitchInTile
/ 4)) << microShift
;
1383 UINT_32 sliceBits
= pitchInTile
* heightInTile
;
1385 // do htile single slice alignment if the flag is true
1386 if (m_configFlags
.useHtileSliceAlign
&& (factor
== 1)) //Htile
1388 sliceBits
= PowTwoAlign(sliceBits
, BITS_TO_BYTES(HtileCacheBits
) * numPipes
/ elemBits
);
1390 macroOffset
= slice
* (sliceBits
/ numPipes
) * elemBits
;
1393 { //tiled addressing
1394 const UINT_32 macroWidthInTile
= macroWidth
/ MicroTileWidth
; // Now in unit of Tiles
1395 const UINT_32 macroHeightInTile
= macroHeight
/ MicroTileHeight
;
1396 const UINT_32 pitchInCL
= pitchInTile
/ macroWidthInTile
;
1397 const UINT_32 heightInCL
= heightInTile
/ macroHeightInTile
;
1399 const UINT_32 macroX
= x
/ macroWidth
;
1400 const UINT_32 macroY
= y
/ macroHeight
;
1401 const UINT_32 macroNumber
= macroX
+ macroY
* pitchInCL
+ slice
* pitchInCL
* heightInCL
;
1403 // Per pipe starting offset of the cache line in which this tile lies.
1404 microX
= (x
% macroWidth
) / MicroTileWidth
/ 4; // Macro Tile is 4x4
1405 microY
= (y
% macroHeight
) / MicroTileHeight
/ 4 ;
1406 microNumber
= static_cast<UINT_64
>(microX
+ microY
* (macroWidth
/ MicroTileWidth
/ 4)) << microShift
;
1408 macroOffset
= macroNumber
* tileNumPerPipe
* elemBits
;
1411 if(elemIdxBits
== microShift
)
1413 microNumber
+= elemIdx
;
1417 microNumber
>>= elemIdxBits
;
1418 microNumber
<<= elemIdxBits
;
1419 microNumber
+= elemIdx
;
1422 microOffset
= elemBits
* microNumber
;
1423 totalOffset
= microOffset
+ macroOffset
;
1425 UINT_32 pipe
= ComputePipeFromCoord(x
, y
, 0, ADDR_TM_2D_TILED_THIN1
, 0, FALSE
, pTileInfo
);
1426 UINT_64 addrInBits
= totalOffset
% (m_pipeInterleaveBytes
* 8) +
1427 pipe
* (m_pipeInterleaveBytes
* 8) +
1428 totalOffset
/ (m_pipeInterleaveBytes
* 8) * (m_pipeInterleaveBytes
* 8) * numPipes
;
1429 *pBitPosition
= static_cast<UINT_32
>(addrInBits
) % 8;
1430 UINT_64 addr
= addrInBits
/ 8;
1436 ****************************************************************************************************
1437 * SiLib::HwlComputeXmaskCoordFromAddr
1440 * Compute the coord from an address of a cmask/htile
1446 * This method is reused by htile, so rename to Xmask
1447 ****************************************************************************************************
1449 VOID
SiLib::HwlComputeXmaskCoordFromAddr(
1450 UINT_64 addr
, ///< [in] address
1451 UINT_32 bitPosition
, ///< [in] bitPosition in a byte
1452 UINT_32 pitch
, ///< [in] pitch
1453 UINT_32 height
, ///< [in] height
1454 UINT_32 numSlices
, ///< [in] number of slices
1455 UINT_32 factor
, ///< [in] factor that indicates cmask or htile
1456 BOOL_32 isLinear
, ///< [in] linear or tiled HTILE layout
1457 BOOL_32 isWidth8
, ///< [in] Not used by SI
1458 BOOL_32 isHeight8
, ///< [in] Not used by SI
1459 ADDR_TILEINFO
* pTileInfo
, ///< [in] Tile info
1460 UINT_32
* pX
, ///< [out] x coord
1461 UINT_32
* pY
, ///< [out] y coord
1462 UINT_32
* pSlice
///< [out] slice index
1470 UINT_32 tileNumPerPipe
;
1477 if (factor
== 2) //CMASK
1479 ADDR_CMASK_FLAGS flags
= {{0}};
1481 tileNumPerPipe
= 256;
1483 ComputeCmaskInfo(flags
,
1497 ADDR_HTILE_FLAGS flags
= {{0}};
1499 tileNumPerPipe
= 512;
1501 ComputeHtileInfo(flags
,
1517 const UINT_32 pitchInTile
= newPitch
/ MicroTileWidth
;
1518 const UINT_32 heightInTile
= newHeight
/ MicroTileWidth
;
1519 const UINT_32 pitchInMacroTile
= pitchInTile
/ 4;
1521 UINT_32 elemIdxBits
;
1522 // get macroShift and elemIdxBits
1523 TileCoordToMaskElementIndex(0, 0, pTileInfo
->pipeConfig
, ¯oShift
, &elemIdxBits
);
1525 const UINT_32 numPipes
= HwlGetPipes(pTileInfo
);
1526 const UINT_32 pipe
= (UINT_32
)((addr
/ m_pipeInterleaveBytes
) % numPipes
);
1528 UINT_64 localOffset
= (addr
% m_pipeInterleaveBytes
) +
1529 (addr
/ m_pipeInterleaveBytes
/ numPipes
)* m_pipeInterleaveBytes
;
1532 if (factor
== 2) //CMASK
1534 tileIndex
= (UINT_32
)(localOffset
* 2 + (bitPosition
!= 0));
1538 tileIndex
= (UINT_32
)(localOffset
/ 4);
1541 UINT_32 macroOffset
;
1544 UINT_32 sliceSizeInTile
= pitchInTile
* heightInTile
;
1546 // do htile single slice alignment if the flag is true
1547 if (m_configFlags
.useHtileSliceAlign
&& (factor
== 1)) //Htile
1549 sliceSizeInTile
= PowTwoAlign(sliceSizeInTile
, static_cast<UINT_32
>(sliceBytes
) / 64);
1551 *pSlice
= tileIndex
/ (sliceSizeInTile
/ numPipes
);
1552 macroOffset
= tileIndex
% (sliceSizeInTile
/ numPipes
);
1556 const UINT_32 clWidthInTile
= clWidth
/ MicroTileWidth
; // Now in unit of Tiles
1557 const UINT_32 clHeightInTile
= clHeight
/ MicroTileHeight
;
1558 const UINT_32 pitchInCL
= pitchInTile
/ clWidthInTile
;
1559 const UINT_32 heightInCL
= heightInTile
/ clHeightInTile
;
1560 const UINT_32 clIndex
= tileIndex
/ tileNumPerPipe
;
1562 UINT_32 clX
= clIndex
% pitchInCL
;
1563 UINT_32 clY
= (clIndex
% (heightInCL
* pitchInCL
)) / pitchInCL
;
1565 *pX
= clX
* clWidthInTile
* MicroTileWidth
;
1566 *pY
= clY
* clHeightInTile
* MicroTileHeight
;
1567 *pSlice
= clIndex
/ (heightInCL
* pitchInCL
);
1569 macroOffset
= tileIndex
% tileNumPerPipe
;
1572 UINT_32 elemIdx
= macroOffset
& 7;
1573 macroOffset
>>= elemIdxBits
;
1575 if (elemIdxBits
!= macroShift
)
1577 macroOffset
<<= (elemIdxBits
- macroShift
);
1579 UINT_32 pipebit1
= _BIT(pipe
,1);
1580 UINT_32 pipebit2
= _BIT(pipe
,2);
1581 UINT_32 pipebit3
= _BIT(pipe
,3);
1582 if (pitchInMacroTile
% 2)
1584 switch (pTileInfo
->pipeConfig
)
1586 case ADDR_PIPECFG_P4_32x32
:
1587 macroOffset
|= pipebit1
;
1589 case ADDR_PIPECFG_P8_32x32_8x16
:
1590 case ADDR_PIPECFG_P8_32x32_16x16
:
1591 case ADDR_PIPECFG_P8_32x32_16x32
:
1592 macroOffset
|= pipebit2
;
1600 if (pitchInMacroTile
% 4)
1602 if (pTileInfo
->pipeConfig
== ADDR_PIPECFG_P8_32x64_32x32
)
1604 macroOffset
|= (pipebit1
<<1);
1606 if ((pTileInfo
->pipeConfig
== ADDR_PIPECFG_P16_32x32_8x16
) ||
1607 (pTileInfo
->pipeConfig
== ADDR_PIPECFG_P16_32x32_16x16
)
1610 macroOffset
|= (pipebit3
<<1);
1620 macroX
= macroOffset
% pitchInMacroTile
;
1621 macroY
= macroOffset
/ pitchInMacroTile
;
1625 const UINT_32 clWidthInMacroTile
= clWidth
/ (MicroTileWidth
* 4);
1626 macroX
= macroOffset
% clWidthInMacroTile
;
1627 macroY
= macroOffset
/ clWidthInMacroTile
;
1630 *pX
+= macroX
* 4 * MicroTileWidth
;
1631 *pY
+= macroY
* 4 * MicroTileHeight
;
1635 ComputeTileCoordFromPipeAndElemIdx(elemIdx
, pipe
, pTileInfo
->pipeConfig
, pitchInMacroTile
,
1636 *pX
, *pY
, µX
, µY
);
1638 *pX
+= microX
* MicroTileWidth
;
1639 *pY
+= microY
* MicroTileWidth
;
1643 ****************************************************************************************************
1644 * SiLib::HwlGetPitchAlignmentLinear
1646 * Get pitch alignment
1649 ****************************************************************************************************
1651 UINT_32
SiLib::HwlGetPitchAlignmentLinear(
1652 UINT_32 bpp
, ///< [in] bits per pixel
1653 ADDR_SURFACE_FLAGS flags
///< [in] surface flags
1658 // Interleaved access requires a 256B aligned pitch, so fall back to pre-SI alignment
1659 if (flags
.interleaved
)
1661 pitchAlign
= Max(64u, m_pipeInterleaveBytes
/ BITS_TO_BYTES(bpp
));
1666 pitchAlign
= Max(8u, 64 / BITS_TO_BYTES(bpp
));
1673 ****************************************************************************************************
1674 * SiLib::HwlGetSizeAdjustmentLinear
1677 * Adjust linear surface pitch and slice size
1680 * Logical slice size in bytes
1681 ****************************************************************************************************
1683 UINT_64
SiLib::HwlGetSizeAdjustmentLinear(
1684 AddrTileMode tileMode
, ///< [in] tile mode
1685 UINT_32 bpp
, ///< [in] bits per pixel
1686 UINT_32 numSamples
, ///< [in] number of samples
1687 UINT_32 baseAlign
, ///< [in] base alignment
1688 UINT_32 pitchAlign
, ///< [in] pitch alignment
1689 UINT_32
* pPitch
, ///< [in,out] pointer to pitch
1690 UINT_32
* pHeight
, ///< [in,out] pointer to height
1691 UINT_32
* pHeightAlign
///< [in,out] pointer to height align
1695 if (tileMode
== ADDR_TM_LINEAR_GENERAL
)
1697 sliceSize
= BITS_TO_BYTES(static_cast<UINT_64
>(*pPitch
) * (*pHeight
) * bpp
* numSamples
);
1701 UINT_32 pitch
= *pPitch
;
1702 UINT_32 height
= *pHeight
;
1704 UINT_32 pixelsPerPipeInterleave
= m_pipeInterleaveBytes
/ BITS_TO_BYTES(bpp
);
1705 UINT_32 sliceAlignInPixel
= pixelsPerPipeInterleave
< 64 ? 64 : pixelsPerPipeInterleave
;
1707 // numSamples should be 1 in real cases (no MSAA for linear but TGL may pass non 1 value)
1708 UINT_64 pixelPerSlice
= static_cast<UINT_64
>(pitch
) * height
* numSamples
;
1710 while (pixelPerSlice
% sliceAlignInPixel
)
1712 pitch
+= pitchAlign
;
1713 pixelPerSlice
= static_cast<UINT_64
>(pitch
) * height
* numSamples
;
1718 UINT_32 heightAlign
= 1;
1720 while ((pitch
* heightAlign
) % sliceAlignInPixel
)
1725 *pHeightAlign
= heightAlign
;
1727 sliceSize
= BITS_TO_BYTES(pixelPerSlice
* bpp
);
1734 ****************************************************************************************************
1735 * SiLib::HwlPreHandleBaseLvl3xPitch
1738 * Pre-handler of 3x pitch (96 bit) adjustment
1742 ****************************************************************************************************
1744 UINT_32
SiLib::HwlPreHandleBaseLvl3xPitch(
1745 const ADDR_COMPUTE_SURFACE_INFO_INPUT
* pIn
, ///< [in] input
1746 UINT_32 expPitch
///< [in] pitch
1749 ADDR_ASSERT(pIn
->width
== expPitch
);
1751 // From SI, if pow2Pad is 1 the pitch is expanded 3x first, then padded to pow2, so nothing to
1753 if (pIn
->flags
.pow2Pad
== FALSE
)
1755 Addr::V1::Lib::HwlPreHandleBaseLvl3xPitch(pIn
, expPitch
);
1759 ADDR_ASSERT(IsPow2(expPitch
));
1766 ****************************************************************************************************
1767 * SiLib::HwlPostHandleBaseLvl3xPitch
1770 * Post-handler of 3x pitch adjustment
1774 ****************************************************************************************************
1776 UINT_32
SiLib::HwlPostHandleBaseLvl3xPitch(
1777 const ADDR_COMPUTE_SURFACE_INFO_INPUT
* pIn
, ///< [in] input
1778 UINT_32 expPitch
///< [in] pitch
1782 * @note The pitch will be divided by 3 in the end so the value will look odd but h/w should
1783 * be able to compute a correct pitch from it as h/w address library is doing the job.
1785 // From SI, the pitch is expanded 3x first, then padded to pow2, so no special handler here
1786 if (pIn
->flags
.pow2Pad
== FALSE
)
1788 Addr::V1::Lib::HwlPostHandleBaseLvl3xPitch(pIn
, expPitch
);
1795 ****************************************************************************************************
1796 * SiLib::HwlGetPitchAlignmentMicroTiled
1799 * Compute 1D tiled surface pitch alignment
1803 ****************************************************************************************************
1805 UINT_32
SiLib::HwlGetPitchAlignmentMicroTiled(
1806 AddrTileMode tileMode
, ///< [in] tile mode
1807 UINT_32 bpp
, ///< [in] bits per pixel
1808 ADDR_SURFACE_FLAGS flags
, ///< [in] surface flags
1809 UINT_32 numSamples
///< [in] number of samples
1816 pitchAlign
= EgBasedLib::HwlGetPitchAlignmentMicroTiled(tileMode
,bpp
,flags
,numSamples
);
1827 ****************************************************************************************************
1828 * SiLib::HwlGetSizeAdjustmentMicroTiled
1831 * Adjust 1D tiled surface pitch and slice size
1834 * Logical slice size in bytes
1835 ****************************************************************************************************
1837 UINT_64
SiLib::HwlGetSizeAdjustmentMicroTiled(
1838 UINT_32 thickness
, ///< [in] thickness
1839 UINT_32 bpp
, ///< [in] bits per pixel
1840 ADDR_SURFACE_FLAGS flags
, ///< [in] surface flags
1841 UINT_32 numSamples
, ///< [in] number of samples
1842 UINT_32 baseAlign
, ///< [in] base alignment
1843 UINT_32 pitchAlign
, ///< [in] pitch alignment
1844 UINT_32
* pPitch
, ///< [in,out] pointer to pitch
1845 UINT_32
* pHeight
///< [in,out] pointer to height
1848 UINT_64 logicalSliceSize
;
1849 UINT_64 physicalSliceSize
;
1851 UINT_32 pitch
= *pPitch
;
1852 UINT_32 height
= *pHeight
;
1854 // Logical slice: pitch * height * bpp * numSamples (no 1D MSAA so actually numSamples == 1)
1855 logicalSliceSize
= BITS_TO_BYTES(static_cast<UINT_64
>(pitch
) * height
* bpp
* numSamples
);
1857 // Physical slice: multiplied by thickness
1858 physicalSliceSize
= logicalSliceSize
* thickness
;
1860 // Pitch alignment is always 8, so if slice size is not padded to base alignment
1861 // (pipe_interleave_size), we need to increase pitch
1862 while ((physicalSliceSize
% baseAlign
) != 0)
1864 pitch
+= pitchAlign
;
1866 logicalSliceSize
= BITS_TO_BYTES(static_cast<UINT_64
>(pitch
) * height
* bpp
* numSamples
);
1868 physicalSliceSize
= logicalSliceSize
* thickness
;
1873 // Special workaround for depth/stencil buffer, use 8 bpp to align depth buffer again since
1874 // the stencil plane may have larger pitch if the slice size is smaller than base alignment.
1876 // Note: this actually does not work for mipmap but mipmap depth texture is not really
1877 // sampled with mipmap.
1879 if (flags
.depth
&& (flags
.noStencil
== FALSE
))
1881 ADDR_ASSERT(numSamples
== 1);
1883 UINT_64 logicalSiceSizeStencil
= static_cast<UINT_64
>(pitch
) * height
; // 1 byte stencil
1885 while ((logicalSiceSizeStencil
% baseAlign
) != 0)
1887 pitch
+= pitchAlign
; // Stencil plane's pitch alignment is the same as depth plane's
1889 logicalSiceSizeStencil
= static_cast<UINT_64
>(pitch
) * height
;
1892 if (pitch
!= *pPitch
)
1894 // If this is a mipmap, this padded one cannot be sampled as a whole mipmap!
1895 logicalSliceSize
= logicalSiceSizeStencil
* BITS_TO_BYTES(bpp
);
1901 // No adjust for pHeight
1903 return logicalSliceSize
;
1907 ****************************************************************************************************
1908 * SiLib::HwlConvertChipFamily
1911 * Convert familyID defined in atiid.h to ChipFamily and set m_chipFamily/m_chipRevision
1914 ****************************************************************************************************
1916 ChipFamily
SiLib::HwlConvertChipFamily(
1917 UINT_32 uChipFamily
, ///< [in] chip family defined in atiih.h
1918 UINT_32 uChipRevision
) ///< [in] chip revision defined in "asic_family"_id.h
1920 ChipFamily family
= ADDR_CHIP_FAMILY_SI
;
1922 switch (uChipFamily
)
1925 m_settings
.isSouthernIsland
= 1;
1926 m_settings
.isTahiti
= ASICREV_IS_TAHITI_P(uChipRevision
);
1927 m_settings
.isPitCairn
= ASICREV_IS_PITCAIRN_PM(uChipRevision
);
1928 m_settings
.isCapeVerde
= ASICREV_IS_CAPEVERDE_M(uChipRevision
);
1929 m_settings
.isOland
= ASICREV_IS_OLAND_M(uChipRevision
);
1930 m_settings
.isHainan
= ASICREV_IS_HAINAN_V(uChipRevision
);
1933 ADDR_ASSERT(!"This should be a Fusion");
1941 ****************************************************************************************************
1942 * SiLib::HwlSetupTileInfo
1945 * Setup default value of tile info for SI
1946 ****************************************************************************************************
1948 VOID
SiLib::HwlSetupTileInfo(
1949 AddrTileMode tileMode
, ///< [in] Tile mode
1950 ADDR_SURFACE_FLAGS flags
, ///< [in] Surface type flags
1951 UINT_32 bpp
, ///< [in] Bits per pixel
1952 UINT_32 pitch
, ///< [in] Pitch in pixels
1953 UINT_32 height
, ///< [in] Height in pixels
1954 UINT_32 numSamples
, ///< [in] Number of samples
1955 ADDR_TILEINFO
* pTileInfoIn
, ///< [in] Tile info input: NULL for default
1956 ADDR_TILEINFO
* pTileInfoOut
, ///< [out] Tile info output
1957 AddrTileType inTileType
, ///< [in] Tile type
1958 ADDR_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
///< [out] Output
1961 UINT_32 thickness
= Thickness(tileMode
);
1962 ADDR_TILEINFO
* pTileInfo
= pTileInfoOut
;
1963 INT index
= TileIndexInvalid
;
1966 if (IsLinear(tileMode
) == FALSE
)
1968 // 128 bpp/thick tiling must be non-displayable.
1969 // Fmask reuse color buffer's entry but bank-height field can be from another entry
1970 // To simplify the logic, fmask entry should be picked from non-displayable ones
1971 if (bpp
== 128 || thickness
> 1 || flags
.fmask
|| flags
.prt
)
1973 inTileType
= ADDR_NON_DISPLAYABLE
;
1976 if (flags
.depth
|| flags
.stencil
)
1978 inTileType
= ADDR_DEPTH_SAMPLE_ORDER
;
1982 // Partial valid fields are not allowed for SI.
1983 if (IsTileInfoAllZero(pTileInfo
))
1985 if (IsMacroTiled(tileMode
))
1989 if (numSamples
== 1)
2002 ADDR_ASSERT_ALWAYS();
2031 ADDR_ASSERT(bpp
!= 128);
2038 ADDR_ASSERT(numSamples
== 4);
2051 ADDR_ASSERT_ALWAYS();
2072 ADDR_ASSERT_ALWAYS();
2078 // See table entries 0-7
2079 else if (flags
.depth
|| flags
.stencil
)
2081 if (flags
.compressZ
)
2089 // optimal tile index for compressed depth/stencil.
2112 else //non PRT & non Depth & non Stencil
2114 // See table entries 9-12
2115 if (inTileType
== ADDR_DISPLAYABLE
)
2137 // See table entries 13-17
2142 UINT_32 fmaskPixelSize
= bpp
* numSamples
;
2144 switch (fmaskPixelSize
)
2159 ADDR_ASSERT_ALWAYS();
2186 else // thick tiling - entries 18-20
2205 if (tileMode
== ADDR_TM_LINEAR_ALIGNED
)
2209 else if (tileMode
== ADDR_TM_LINEAR_GENERAL
)
2211 index
= TileIndexLinearGeneral
;
2215 if (flags
.depth
|| flags
.stencil
)
2219 else if (inTileType
== ADDR_DISPLAYABLE
)
2223 else if (thickness
== 1)
2234 if (index
>= 0 && index
<= 31)
2236 *pTileInfo
= m_tileTable
[index
].info
;
2237 pOut
->tileType
= m_tileTable
[index
].type
;
2240 if (index
== TileIndexLinearGeneral
)
2242 *pTileInfo
= m_tileTable
[8].info
;
2243 pOut
->tileType
= m_tileTable
[8].type
;
2250 if (flags
.stencil
&& pTileInfoIn
->tileSplitBytes
== 0)
2252 // Stencil always uses index 0
2253 *pTileInfo
= m_tileTable
[0].info
;
2256 // Pass through tile type
2257 pOut
->tileType
= inTileType
;
2260 pOut
->tileIndex
= index
;
2261 pOut
->prtTileIndex
= flags
.prt
;
2265 ****************************************************************************************************
2266 * SiLib::DecodeGbRegs
2269 * Decodes GB_ADDR_CONFIG and noOfBanks/noOfRanks
2272 * TRUE if all settings are valid
2274 ****************************************************************************************************
2276 BOOL_32
SiLib::DecodeGbRegs(
2277 const ADDR_REGISTER_VALUE
* pRegValue
) ///< [in] create input
2280 BOOL_32 valid
= TRUE
;
2282 reg
.val
= pRegValue
->gbAddrConfig
;
2284 switch (reg
.f
.pipe_interleave_size
)
2286 case ADDR_CONFIG_PIPE_INTERLEAVE_256B
:
2287 m_pipeInterleaveBytes
= ADDR_PIPEINTERLEAVE_256B
;
2289 case ADDR_CONFIG_PIPE_INTERLEAVE_512B
:
2290 m_pipeInterleaveBytes
= ADDR_PIPEINTERLEAVE_512B
;
2294 ADDR_UNHANDLED_CASE();
2298 switch (reg
.f
.row_size
)
2300 case ADDR_CONFIG_1KB_ROW
:
2301 m_rowSize
= ADDR_ROWSIZE_1KB
;
2303 case ADDR_CONFIG_2KB_ROW
:
2304 m_rowSize
= ADDR_ROWSIZE_2KB
;
2306 case ADDR_CONFIG_4KB_ROW
:
2307 m_rowSize
= ADDR_ROWSIZE_4KB
;
2311 ADDR_UNHANDLED_CASE();
2315 switch (pRegValue
->noOfBanks
)
2328 ADDR_UNHANDLED_CASE();
2332 switch (pRegValue
->noOfRanks
)
2342 ADDR_UNHANDLED_CASE();
2346 m_logicalBanks
= m_banks
* m_ranks
;
2348 ADDR_ASSERT(m_logicalBanks
<= 16);
2354 ****************************************************************************************************
2355 * SiLib::HwlInitGlobalParams
2358 * Initializes global parameters
2361 * TRUE if all settings are valid
2363 ****************************************************************************************************
2365 BOOL_32
SiLib::HwlInitGlobalParams(
2366 const ADDR_CREATE_INPUT
* pCreateIn
) ///< [in] create input
2368 BOOL_32 valid
= TRUE
;
2369 const ADDR_REGISTER_VALUE
* pRegValue
= &pCreateIn
->regValue
;
2371 valid
= DecodeGbRegs(pRegValue
);
2375 if (m_settings
.isTahiti
|| m_settings
.isPitCairn
)
2379 else if (m_settings
.isCapeVerde
|| m_settings
.isOland
)
2385 // Hainan is 2-pipe (m_settings.isHainan == 1)
2389 valid
= InitTileSettingTable(pRegValue
->pTileConfig
, pRegValue
->noOfEntries
);
2393 InitEquationTable();
2403 ****************************************************************************************************
2404 * SiLib::HwlConvertTileInfoToHW
2406 * Entry of si's ConvertTileInfoToHW
2409 ****************************************************************************************************
2411 ADDR_E_RETURNCODE
SiLib::HwlConvertTileInfoToHW(
2412 const ADDR_CONVERT_TILEINFOTOHW_INPUT
* pIn
, ///< [in] input structure
2413 ADDR_CONVERT_TILEINFOTOHW_OUTPUT
* pOut
///< [out] output structure
2416 ADDR_E_RETURNCODE retCode
= ADDR_OK
;
2418 retCode
= EgBasedLib::HwlConvertTileInfoToHW(pIn
, pOut
);
2420 if (retCode
== ADDR_OK
)
2422 if (pIn
->reverse
== FALSE
)
2424 if (pIn
->pTileInfo
->pipeConfig
== ADDR_PIPECFG_INVALID
)
2426 retCode
= ADDR_INVALIDPARAMS
;
2430 pOut
->pTileInfo
->pipeConfig
=
2431 static_cast<AddrPipeCfg
>(pIn
->pTileInfo
->pipeConfig
- 1);
2436 pOut
->pTileInfo
->pipeConfig
=
2437 static_cast<AddrPipeCfg
>(pIn
->pTileInfo
->pipeConfig
+ 1);
2445 ****************************************************************************************************
2446 * SiLib::HwlComputeXmaskCoordYFrom8Pipe
2449 * Compute the Y coord which will be added to Xmask Y
2453 ****************************************************************************************************
2455 UINT_32
SiLib::HwlComputeXmaskCoordYFrom8Pipe(
2456 UINT_32 pipe
, ///< [in] pipe id
2457 UINT_32 x
///< [in] tile coord x, which is original x coord / 8
2460 // This function should never be called since it is 6xx/8xx specfic.
2461 // Keep this empty implementation to avoid any mis-use.
2462 ADDR_ASSERT_ALWAYS();
2468 ****************************************************************************************************
2469 * SiLib::HwlComputeSurfaceCoord2DFromBankPipe
2472 * Compute surface x,y coordinates from bank/pipe info
2475 ****************************************************************************************************
2477 VOID
SiLib::HwlComputeSurfaceCoord2DFromBankPipe(
2478 AddrTileMode tileMode
, ///< [in] tile mode
2479 UINT_32
* pX
, ///< [in,out] x coordinate
2480 UINT_32
* pY
, ///< [in,out] y coordinate
2481 UINT_32 slice
, ///< [in] slice index
2482 UINT_32 bank
, ///< [in] bank number
2483 UINT_32 pipe
, ///< [in] pipe number
2484 UINT_32 bankSwizzle
,///< [in] bank swizzle
2485 UINT_32 pipeSwizzle
,///< [in] pipe swizzle
2486 UINT_32 tileSlices
, ///< [in] slices in a micro tile
2487 BOOL_32 ignoreSE
, ///< [in] TRUE if shader engines are ignored
2488 ADDR_TILEINFO
* pTileInfo
///< [in] bank structure. **All fields to be valid on entry**
2502 UINT_32 numPipes
= GetPipePerSurf(pTileInfo
->pipeConfig
);
2504 CoordFromBankPipe xyBits
= {0};
2505 ComputeSurfaceCoord2DFromBankPipe(tileMode
, *pX
, *pY
, slice
, bank
, pipe
,
2506 bankSwizzle
, pipeSwizzle
, tileSlices
, pTileInfo
,
2508 yBit3
= xyBits
.yBit3
;
2509 yBit4
= xyBits
.yBit4
;
2510 yBit5
= xyBits
.yBit5
;
2511 yBit6
= xyBits
.yBit6
;
2513 xBit3
= xyBits
.xBit3
;
2514 xBit4
= xyBits
.xBit4
;
2515 xBit5
= xyBits
.xBit5
;
2517 yBit
= xyBits
.yBits
;
2519 UINT_32 yBitTemp
= 0;
2521 if ((pTileInfo
->pipeConfig
== ADDR_PIPECFG_P4_32x32
) ||
2522 (pTileInfo
->pipeConfig
== ADDR_PIPECFG_P8_32x64_32x32
))
2524 ADDR_ASSERT(pTileInfo
->bankWidth
== 1 && pTileInfo
->macroAspectRatio
> 1);
2525 UINT_32 yBitToCheck
= QLog2(pTileInfo
->banks
) - 1;
2527 ADDR_ASSERT(yBitToCheck
<= 3);
2529 yBitTemp
= _BIT(yBit
, yBitToCheck
);
2534 yBit
= Bits2Number(4, yBit6
, yBit5
, yBit4
, yBit3
);
2535 xBit
= Bits2Number(3, xBit5
, xBit4
, xBit3
);
2537 *pY
+= yBit
* pTileInfo
->bankHeight
* MicroTileHeight
;
2538 *pX
+= xBit
* numPipes
* pTileInfo
->bankWidth
* MicroTileWidth
;
2540 //calculate the bank and pipe bits in x, y
2541 UINT_32 xTile
; //x in micro tile
2548 UINT_32 pipeBit0
= _BIT(pipe
,0);
2549 UINT_32 pipeBit1
= _BIT(pipe
,1);
2550 UINT_32 pipeBit2
= _BIT(pipe
,2);
2552 UINT_32 y3
= _BIT(y
, 3);
2553 UINT_32 y4
= _BIT(y
, 4);
2554 UINT_32 y5
= _BIT(y
, 5);
2555 UINT_32 y6
= _BIT(y
, 6);
2557 // bankbit0 after ^x4^x5
2558 UINT_32 bankBit00
= _BIT(bank
,0);
2559 UINT_32 bankBit0
= 0;
2561 switch (pTileInfo
->pipeConfig
)
2563 case ADDR_PIPECFG_P2
:
2566 case ADDR_PIPECFG_P4_8x16
:
2570 case ADDR_PIPECFG_P4_16x16
:
2572 x3
= pipeBit0
^ y3
^ x4
;
2574 case ADDR_PIPECFG_P4_16x32
:
2576 x3
= pipeBit0
^ y3
^ x4
;
2578 case ADDR_PIPECFG_P4_32x32
:
2580 x3
= pipeBit0
^ y3
^ x5
;
2581 bankBit0
= yBitTemp
^ x5
;
2582 x4
= bankBit00
^ x5
^ bankBit0
;
2583 *pX
+= x5
* 4 * 1 * 8; // x5 * num_pipes * bank_width * 8;
2585 case ADDR_PIPECFG_P8_16x16_8x16
:
2588 x5
= pipeBit0
^ y3
^ x4
;
2590 case ADDR_PIPECFG_P8_16x32_8x16
:
2593 x5
= pipeBit0
^ y3
^ x4
;
2595 case ADDR_PIPECFG_P8_32x32_8x16
:
2598 x4
= pipeBit0
^ y3
^ x5
;
2600 case ADDR_PIPECFG_P8_16x32_16x16
:
2603 x3
= pipeBit0
^ y3
^ x4
;
2605 case ADDR_PIPECFG_P8_32x32_16x16
:
2608 x3
= pipeBit0
^ y3
^ x4
;
2610 case ADDR_PIPECFG_P8_32x32_16x32
:
2613 x3
= pipeBit0
^ y3
^ x4
;
2615 case ADDR_PIPECFG_P8_32x64_32x32
:
2618 x3
= pipeBit0
^ y3
^ x5
;
2619 bankBit0
= yBitTemp
^ x6
;
2620 x4
= bankBit00
^ x5
^ bankBit0
;
2621 *pX
+= x6
* 8 * 1 * 8; // x6 * num_pipes * bank_width * 8;
2624 ADDR_ASSERT_ALWAYS();
2627 xTile
= Bits2Number(3, x5
, x4
, x3
);
2633 ****************************************************************************************************
2634 * SiLib::HwlPreAdjustBank
2637 * Adjust bank before calculating address acoording to bank/pipe
2640 ****************************************************************************************************
2642 UINT_32
SiLib::HwlPreAdjustBank(
2643 UINT_32 tileX
, ///< [in] x coordinate in unit of tile
2644 UINT_32 bank
, ///< [in] bank
2645 ADDR_TILEINFO
* pTileInfo
///< [in] tile info
2648 if (((pTileInfo
->pipeConfig
== ADDR_PIPECFG_P4_32x32
) ||
2649 (pTileInfo
->pipeConfig
== ADDR_PIPECFG_P8_32x64_32x32
)) && (pTileInfo
->bankWidth
== 1))
2651 UINT_32 bankBit0
= _BIT(bank
, 0);
2652 UINT_32 x4
= _BIT(tileX
, 1);
2653 UINT_32 x5
= _BIT(tileX
, 2);
2655 bankBit0
= bankBit0
^ x4
^ x5
;
2658 ADDR_ASSERT(pTileInfo
->macroAspectRatio
> 1);
2665 ****************************************************************************************************
2666 * SiLib::HwlComputeSurfaceInfo
2669 * Entry of si's ComputeSurfaceInfo
2672 ****************************************************************************************************
2674 ADDR_E_RETURNCODE
SiLib::HwlComputeSurfaceInfo(
2675 const ADDR_COMPUTE_SURFACE_INFO_INPUT
* pIn
, ///< [in] input structure
2676 ADDR_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
///< [out] output structure
2679 pOut
->tileIndex
= pIn
->tileIndex
;
2681 ADDR_E_RETURNCODE retCode
= EgBasedLib::HwlComputeSurfaceInfo(pIn
, pOut
);
2683 UINT_32 tileIndex
= static_cast<UINT_32
>(pOut
->tileIndex
);
2685 if (((pIn
->flags
.needEquation
== TRUE
) ||
2686 (pIn
->flags
.preferEquation
== TRUE
)) &&
2687 (pIn
->numSamples
<= 1) &&
2688 (tileIndex
< TileTableSize
))
2690 static const UINT_32 SiUncompressDepthTileIndex
= 3;
2692 if ((pIn
->numSlices
> 1) &&
2693 (IsMacroTiled(pOut
->tileMode
) == TRUE
) &&
2694 ((m_chipFamily
== ADDR_CHIP_FAMILY_SI
) ||
2695 (IsPrtTileMode(pOut
->tileMode
) == FALSE
)))
2697 pOut
->equationIndex
= ADDR_INVALID_EQUATION_INDEX
;
2699 else if ((pIn
->flags
.prt
== FALSE
) &&
2700 (m_uncompressDepthEqIndex
!= 0) &&
2701 (tileIndex
== SiUncompressDepthTileIndex
))
2703 pOut
->equationIndex
= m_uncompressDepthEqIndex
+ Log2(pIn
->bpp
>> 3);
2708 pOut
->equationIndex
= m_equationLookupTable
[Log2(pIn
->bpp
>> 3)][tileIndex
];
2711 if (pOut
->equationIndex
!= ADDR_INVALID_EQUATION_INDEX
)
2713 pOut
->blockWidth
= m_blockWidth
[pOut
->equationIndex
];
2715 pOut
->blockHeight
= m_blockHeight
[pOut
->equationIndex
];
2717 pOut
->blockSlices
= m_blockSlices
[pOut
->equationIndex
];
2722 pOut
->equationIndex
= ADDR_INVALID_EQUATION_INDEX
;
2729 ****************************************************************************************************
2730 * SiLib::HwlComputeMipLevel
2732 * Compute MipLevel info (including level 0)
2734 * TRUE if HWL's handled
2735 ****************************************************************************************************
2737 BOOL_32
SiLib::HwlComputeMipLevel(
2738 ADDR_COMPUTE_SURFACE_INFO_INPUT
* pIn
///< [in,out] Input structure
2741 // basePitch is calculated from level 0 so we only check this for mipLevel > 0
2742 if (pIn
->mipLevel
> 0)
2744 // Note: Don't check expand 3x formats(96 bit) as the basePitch is not pow2 even if
2745 // we explicity set pow2Pad flag. The 3x base pitch is padded to pow2 but after being
2746 // divided by expandX factor (3) - to program texture pitch, the basePitch is never pow2.
2747 if (ElemLib::IsExpand3x(pIn
->format
) == FALSE
)
2749 // Sublevel pitches are generated from base level pitch instead of width on SI
2750 // If pow2Pad is 0, we don't assert - as this is not really used for a mip chain
2751 ADDR_ASSERT((pIn
->flags
.pow2Pad
== FALSE
) ||
2752 ((pIn
->basePitch
!= 0) && IsPow2(pIn
->basePitch
)));
2755 if (pIn
->basePitch
!= 0)
2757 pIn
->width
= Max(1u, pIn
->basePitch
>> pIn
->mipLevel
);
2761 // pow2Pad is done in PostComputeMipLevel
2767 ****************************************************************************************************
2768 * SiLib::HwlCheckLastMacroTiledLvl
2771 * Sets pOut->last2DLevel to TRUE if it is
2774 ****************************************************************************************************
2776 VOID
SiLib::HwlCheckLastMacroTiledLvl(
2777 const ADDR_COMPUTE_SURFACE_INFO_INPUT
* pIn
, ///< [in] Input structure
2778 ADDR_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
///< [in,out] Output structure (used as input, too)
2781 // pow2Pad covers all mipmap cases
2782 if (pIn
->flags
.pow2Pad
)
2784 ADDR_ASSERT(IsMacroTiled(pIn
->tileMode
));
2790 AddrTileMode nextTileMode
;
2792 if (pIn
->mipLevel
== 0 || pIn
->basePitch
== 0)
2794 // Base level or fail-safe case (basePitch == 0)
2795 nextPitch
= pOut
->pitch
>> 1;
2800 nextPitch
= pIn
->basePitch
>> (pIn
->mipLevel
+ 1);
2803 // nextHeight must be shifted from this level's original height rather than a pow2 padded
2804 // one but this requires original height stored somewhere (pOut->height)
2805 ADDR_ASSERT(pOut
->height
!= 0);
2807 // next level's height is just current level's >> 1 in pixels
2808 nextHeight
= pOut
->height
>> 1;
2809 // Special format such as FMT_1 and FMT_32_32_32 can be linear only so we consider block
2810 // compressed foramts
2811 if (ElemLib::IsBlockCompressed(pIn
->format
))
2813 nextHeight
= (nextHeight
+ 3) / 4;
2815 nextHeight
= NextPow2(nextHeight
);
2817 // nextSlices may be 0 if this level's is 1
2818 if (pIn
->flags
.volume
)
2820 nextSlices
= Max(1u, pIn
->numSlices
>> 1);
2824 nextSlices
= pIn
->numSlices
;
2827 nextTileMode
= ComputeSurfaceMipLevelTileMode(pIn
->tileMode
,
2837 pOut
->last2DLevel
= IsMicroTiled(nextTileMode
);
2842 ****************************************************************************************************
2843 * SiLib::HwlDegradeThickTileMode
2846 * Degrades valid tile mode for thick modes if needed
2849 * Suitable tile mode
2850 ****************************************************************************************************
2852 AddrTileMode
SiLib::HwlDegradeThickTileMode(
2853 AddrTileMode baseTileMode
, ///< base tile mode
2854 UINT_32 numSlices
, ///< current number of slices
2855 UINT_32
* pBytesPerTile
///< [in,out] pointer to bytes per slice
2858 return EgBasedLib::HwlDegradeThickTileMode(baseTileMode
, numSlices
, pBytesPerTile
);
2862 ****************************************************************************************************
2863 * SiLib::HwlTileInfoEqual
2866 * Return TRUE if all field are equal
2868 * Only takes care of current HWL's data
2869 ****************************************************************************************************
2871 BOOL_32
SiLib::HwlTileInfoEqual(
2872 const ADDR_TILEINFO
* pLeft
, ///<[in] Left compare operand
2873 const ADDR_TILEINFO
* pRight
///<[in] Right compare operand
2876 BOOL_32 equal
= FALSE
;
2878 if (pLeft
->pipeConfig
== pRight
->pipeConfig
)
2880 equal
= EgBasedLib::HwlTileInfoEqual(pLeft
, pRight
);
2887 ****************************************************************************************************
2888 * SiLib::GetTileSettings
2891 * Get tile setting infos by index.
2893 * Tile setting info.
2894 ****************************************************************************************************
2896 const TileConfig
* SiLib::GetTileSetting(
2897 UINT_32 index
///< [in] Tile index
2900 ADDR_ASSERT(index
< m_noOfEntries
);
2901 return &m_tileTable
[index
];
2905 ****************************************************************************************************
2906 * SiLib::HwlPostCheckTileIndex
2909 * Map a tile setting to index if curIndex is invalid, otherwise check if curIndex matches
2910 * tile mode/type/info and change the index if needed
2913 ****************************************************************************************************
2915 INT_32
SiLib::HwlPostCheckTileIndex(
2916 const ADDR_TILEINFO
* pInfo
, ///< [in] Tile Info
2917 AddrTileMode mode
, ///< [in] Tile mode
2918 AddrTileType type
, ///< [in] Tile type
2919 INT curIndex
///< [in] Current index assigned in HwlSetupTileInfo
2922 INT_32 index
= curIndex
;
2924 if (mode
== ADDR_TM_LINEAR_GENERAL
)
2926 index
= TileIndexLinearGeneral
;
2930 BOOL_32 macroTiled
= IsMacroTiled(mode
);
2932 // We need to find a new index if either of them is true
2933 // 1. curIndex is invalid
2934 // 2. tile mode is changed
2935 // 3. tile info does not match for macro tiled
2936 if ((index
== TileIndexInvalid
||
2937 (mode
!= m_tileTable
[index
].mode
) ||
2938 (macroTiled
&& (HwlTileInfoEqual(pInfo
, &m_tileTable
[index
].info
) == FALSE
))))
2940 for (index
= 0; index
< static_cast<INT_32
>(m_noOfEntries
); index
++)
2944 // macro tile modes need all to match
2945 if (HwlTileInfoEqual(pInfo
, &m_tileTable
[index
].info
) &&
2946 (mode
== m_tileTable
[index
].mode
) &&
2947 (type
== m_tileTable
[index
].type
))
2952 else if (mode
== ADDR_TM_LINEAR_ALIGNED
)
2954 // linear mode only needs tile mode to match
2955 if (mode
== m_tileTable
[index
].mode
)
2962 // micro tile modes only need tile mode and tile type to match
2963 if (mode
== m_tileTable
[index
].mode
&&
2964 type
== m_tileTable
[index
].type
)
2973 ADDR_ASSERT(index
< static_cast<INT_32
>(m_noOfEntries
));
2975 if (index
>= static_cast<INT_32
>(m_noOfEntries
))
2977 index
= TileIndexInvalid
;
2984 ****************************************************************************************************
2985 * SiLib::HwlSetupTileCfg
2988 * Map tile index to tile setting.
2991 ****************************************************************************************************
2993 ADDR_E_RETURNCODE
SiLib::HwlSetupTileCfg(
2994 UINT_32 bpp
, ///< Bits per pixel
2995 INT_32 index
, ///< Tile index
2996 INT_32 macroModeIndex
, ///< Index in macro tile mode table(CI)
2997 ADDR_TILEINFO
* pInfo
, ///< [out] Tile Info
2998 AddrTileMode
* pMode
, ///< [out] Tile mode
2999 AddrTileType
* pType
///< [out] Tile type
3002 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
3004 // Global flag to control usage of tileIndex
3005 if (UseTileIndex(index
))
3007 if (index
== TileIndexLinearGeneral
)
3011 *pMode
= ADDR_TM_LINEAR_GENERAL
;
3016 *pType
= ADDR_DISPLAYABLE
;
3022 pInfo
->bankWidth
= 1;
3023 pInfo
->bankHeight
= 1;
3024 pInfo
->macroAspectRatio
= 1;
3025 pInfo
->tileSplitBytes
= 64;
3026 pInfo
->pipeConfig
= ADDR_PIPECFG_P2
;
3029 else if (static_cast<UINT_32
>(index
) >= m_noOfEntries
)
3031 returnCode
= ADDR_INVALIDPARAMS
;
3035 const TileConfig
* pCfgTable
= GetTileSetting(index
);
3039 *pInfo
= pCfgTable
->info
;
3043 if (IsMacroTiled(pCfgTable
->mode
))
3045 returnCode
= ADDR_INVALIDPARAMS
;
3051 *pMode
= pCfgTable
->mode
;
3056 *pType
= pCfgTable
->type
;
3065 ****************************************************************************************************
3066 * SiLib::ReadGbTileMode
3069 * Convert GB_TILE_MODE HW value to TileConfig.
3072 ****************************************************************************************************
3074 VOID
SiLib::ReadGbTileMode(
3075 UINT_32 regValue
, ///< [in] GB_TILE_MODE register
3076 TileConfig
* pCfg
///< [out] output structure
3079 GB_TILE_MODE gbTileMode
;
3080 gbTileMode
.val
= regValue
;
3082 pCfg
->type
= static_cast<AddrTileType
>(gbTileMode
.f
.micro_tile_mode
);
3083 pCfg
->info
.bankHeight
= 1 << gbTileMode
.f
.bank_height
;
3084 pCfg
->info
.bankWidth
= 1 << gbTileMode
.f
.bank_width
;
3085 pCfg
->info
.banks
= 1 << (gbTileMode
.f
.num_banks
+ 1);
3086 pCfg
->info
.macroAspectRatio
= 1 << gbTileMode
.f
.macro_tile_aspect
;
3087 pCfg
->info
.tileSplitBytes
= 64 << gbTileMode
.f
.tile_split
;
3088 pCfg
->info
.pipeConfig
= static_cast<AddrPipeCfg
>(gbTileMode
.f
.pipe_config
+ 1);
3090 UINT_32 regArrayMode
= gbTileMode
.f
.array_mode
;
3092 pCfg
->mode
= static_cast<AddrTileMode
>(regArrayMode
);
3094 if (regArrayMode
== 8) //ARRAY_2D_TILED_XTHICK
3096 pCfg
->mode
= ADDR_TM_2D_TILED_XTHICK
;
3098 else if (regArrayMode
>= 14) //ARRAY_3D_TILED_XTHICK
3100 pCfg
->mode
= static_cast<AddrTileMode
>(pCfg
->mode
+ 3);
3105 ****************************************************************************************************
3106 * SiLib::InitTileSettingTable
3109 * Initialize the ADDR_TILE_CONFIG table.
3111 * TRUE if tile table is correctly initialized
3112 ****************************************************************************************************
3114 BOOL_32
SiLib::InitTileSettingTable(
3115 const UINT_32
* pCfg
, ///< [in] Pointer to table of tile configs
3116 UINT_32 noOfEntries
///< [in] Numbe of entries in the table above
3119 BOOL_32 initOk
= TRUE
;
3121 ADDR_ASSERT(noOfEntries
<= TileTableSize
);
3123 memset(m_tileTable
, 0, sizeof(m_tileTable
));
3125 if (noOfEntries
!= 0)
3127 m_noOfEntries
= noOfEntries
;
3131 m_noOfEntries
= TileTableSize
;
3134 if (pCfg
) // From Client
3136 for (UINT_32 i
= 0; i
< m_noOfEntries
; i
++)
3138 ReadGbTileMode(*(pCfg
+ i
), &m_tileTable
[i
]);
3143 ADDR_ASSERT_ALWAYS();
3149 ADDR_ASSERT(m_tileTable
[TILEINDEX_LINEAR_ALIGNED
].mode
== ADDR_TM_LINEAR_ALIGNED
);
3156 ****************************************************************************************************
3157 * SiLib::HwlGetTileIndex
3160 * Return the virtual/real index for given mode/type/info
3162 * ADDR_OK if successful.
3163 ****************************************************************************************************
3165 ADDR_E_RETURNCODE
SiLib::HwlGetTileIndex(
3166 const ADDR_GET_TILEINDEX_INPUT
* pIn
,
3167 ADDR_GET_TILEINDEX_OUTPUT
* pOut
) const
3169 ADDR_E_RETURNCODE returnCode
= ADDR_OK
;
3171 pOut
->index
= HwlPostCheckTileIndex(pIn
->pTileInfo
, pIn
->tileMode
, pIn
->tileType
);
3177 ****************************************************************************************************
3178 * SiLib::HwlFmaskPreThunkSurfInfo
3181 * Some preparation before thunking a ComputeSurfaceInfo call for Fmask
3184 ****************************************************************************************************
3186 VOID
SiLib::HwlFmaskPreThunkSurfInfo(
3187 const ADDR_COMPUTE_FMASK_INFO_INPUT
* pFmaskIn
, ///< [in] Input of fmask info
3188 const ADDR_COMPUTE_FMASK_INFO_OUTPUT
* pFmaskOut
, ///< [in] Output of fmask info
3189 ADDR_COMPUTE_SURFACE_INFO_INPUT
* pSurfIn
, ///< [out] Input of thunked surface info
3190 ADDR_COMPUTE_SURFACE_INFO_OUTPUT
* pSurfOut
///< [out] Output of thunked surface info
3193 pSurfIn
->tileIndex
= pFmaskIn
->tileIndex
;
3197 ****************************************************************************************************
3198 * SiLib::HwlFmaskPostThunkSurfInfo
3201 * Copy hwl extra field after calling thunked ComputeSurfaceInfo
3204 ****************************************************************************************************
3206 VOID
SiLib::HwlFmaskPostThunkSurfInfo(
3207 const ADDR_COMPUTE_SURFACE_INFO_OUTPUT
* pSurfOut
, ///< [in] Output of surface info
3208 ADDR_COMPUTE_FMASK_INFO_OUTPUT
* pFmaskOut
///< [out] Output of fmask info
3211 pFmaskOut
->macroModeIndex
= TileIndexInvalid
;
3212 pFmaskOut
->tileIndex
= pSurfOut
->tileIndex
;
3216 ****************************************************************************************************
3217 * SiLib::HwlComputeFmaskBits
3219 * Computes fmask bits
3222 ****************************************************************************************************
3224 UINT_32
SiLib::HwlComputeFmaskBits(
3225 const ADDR_COMPUTE_FMASK_INFO_INPUT
* pIn
,
3226 UINT_32
* pNumSamples
3229 UINT_32 numSamples
= pIn
->numSamples
;
3230 UINT_32 numFrags
= GetNumFragments(numSamples
, pIn
->numFrags
);
3233 if (numFrags
!= numSamples
) // EQAA
3235 ADDR_ASSERT(numFrags
<= 8);
3237 if (pIn
->resolved
== FALSE
)
3242 numSamples
= numSamples
== 16 ? 16 : 8;
3244 else if (numFrags
== 2)
3246 ADDR_ASSERT(numSamples
>= 4);
3249 numSamples
= numSamples
;
3251 else if (numFrags
== 4)
3253 ADDR_ASSERT(numSamples
>= 4);
3256 numSamples
= numSamples
;
3258 else // numFrags == 8
3260 ADDR_ASSERT(numSamples
== 16);
3263 numSamples
= numSamples
;
3270 bpp
= (numSamples
== 16) ? 16 : 8;
3273 else if (numFrags
== 2)
3275 ADDR_ASSERT(numSamples
>= 4);
3280 else if (numFrags
== 4)
3282 ADDR_ASSERT(numSamples
>= 4);
3287 else // numFrags == 8
3289 ADDR_ASSERT(numSamples
>= 16);
3298 if (pIn
->resolved
== FALSE
)
3300 bpp
= ComputeFmaskNumPlanesFromNumSamples(numSamples
);
3301 numSamples
= numSamples
== 2 ? 8 : numSamples
;
3306 bpp
= ComputeFmaskResolvedBppFromNumSamples(numSamples
);
3307 numSamples
= 1; // 1x sample
3311 SafeAssign(pNumSamples
, numSamples
);
3317 ****************************************************************************************************
3318 * SiLib::HwlOptimizeTileMode
3321 * Optimize tile mode on SI
3326 ****************************************************************************************************
3328 VOID
SiLib::HwlOptimizeTileMode(
3329 ADDR_COMPUTE_SURFACE_INFO_INPUT
* pInOut
///< [in,out] input output structure
3332 AddrTileMode tileMode
= pInOut
->tileMode
;
3334 if ((pInOut
->flags
.needEquation
== TRUE
) &&
3335 (IsMacroTiled(tileMode
) == TRUE
) &&
3336 (pInOut
->numSamples
<= 1))
3338 UINT_32 thickness
= Thickness(tileMode
);
3342 tileMode
= ADDR_TM_1D_TILED_THICK
;
3344 else if (pInOut
->numSlices
> 1)
3346 tileMode
= ADDR_TM_1D_TILED_THIN1
;
3350 tileMode
= ADDR_TM_2D_TILED_THIN1
;
3354 if (tileMode
!= pInOut
->tileMode
)
3356 pInOut
->tileMode
= tileMode
;
3361 ****************************************************************************************************
3362 * SiLib::HwlOverrideTileMode
3365 * Override tile modes (for PRT only, avoid client passes in an invalid PRT mode for SI.
3370 ****************************************************************************************************
3372 VOID
SiLib::HwlOverrideTileMode(
3373 ADDR_COMPUTE_SURFACE_INFO_INPUT
* pInOut
///< [in,out] input output structure
3376 AddrTileMode tileMode
= pInOut
->tileMode
;
3380 case ADDR_TM_PRT_TILED_THIN1
:
3381 tileMode
= ADDR_TM_2D_TILED_THIN1
;
3384 case ADDR_TM_PRT_TILED_THICK
:
3385 tileMode
= ADDR_TM_2D_TILED_THICK
;
3388 case ADDR_TM_PRT_2D_TILED_THICK
:
3389 tileMode
= ADDR_TM_2D_TILED_THICK
;
3392 case ADDR_TM_PRT_3D_TILED_THICK
:
3393 tileMode
= ADDR_TM_3D_TILED_THICK
;
3400 if (tileMode
!= pInOut
->tileMode
)
3402 pInOut
->tileMode
= tileMode
;
3403 // Only PRT tile modes are overridden for now. Revisit this once new modes are added above.
3404 pInOut
->flags
.prt
= TRUE
;
3409 ****************************************************************************************************
3410 * SiLib::HwlSetPrtTileMode
3413 * Set prt tile modes.
3418 ****************************************************************************************************
3420 VOID
SiLib::HwlSetPrtTileMode(
3421 ADDR_COMPUTE_SURFACE_INFO_INPUT
* pInOut
///< [in,out] input output structure
3424 pInOut
->tileMode
= ADDR_TM_2D_TILED_THIN1
;
3425 pInOut
->tileType
= (pInOut
->tileType
== ADDR_DEPTH_SAMPLE_ORDER
) ?
3426 ADDR_DEPTH_SAMPLE_ORDER
: ADDR_NON_DISPLAYABLE
;
3427 pInOut
->flags
.prt
= TRUE
;
3431 ****************************************************************************************************
3432 * SiLib::HwlSelectTileMode
3435 * Select tile modes.
3440 ****************************************************************************************************
3442 VOID
SiLib::HwlSelectTileMode(
3443 ADDR_COMPUTE_SURFACE_INFO_INPUT
* pInOut
///< [in,out] input output structure
3446 AddrTileMode tileMode
;
3447 AddrTileType tileType
;
3449 if (pInOut
->flags
.volume
)
3451 if (pInOut
->numSlices
>= 8)
3453 tileMode
= ADDR_TM_2D_TILED_XTHICK
;
3455 else if (pInOut
->numSlices
>= 4)
3457 tileMode
= ADDR_TM_2D_TILED_THICK
;
3461 tileMode
= ADDR_TM_2D_TILED_THIN1
;
3463 tileType
= ADDR_NON_DISPLAYABLE
;
3467 tileMode
= ADDR_TM_2D_TILED_THIN1
;
3469 if (pInOut
->flags
.depth
|| pInOut
->flags
.stencil
)
3471 tileType
= ADDR_DEPTH_SAMPLE_ORDER
;
3473 else if ((pInOut
->bpp
<= 32) ||
3474 (pInOut
->flags
.display
== TRUE
) ||
3475 (pInOut
->flags
.overlay
== TRUE
))
3477 tileType
= ADDR_DISPLAYABLE
;
3481 tileType
= ADDR_NON_DISPLAYABLE
;
3485 if (pInOut
->flags
.prt
)
3487 tileMode
= ADDR_TM_2D_TILED_THIN1
;
3488 tileType
= (tileType
== ADDR_DISPLAYABLE
) ? ADDR_NON_DISPLAYABLE
: tileType
;
3491 pInOut
->tileMode
= tileMode
;
3492 pInOut
->tileType
= tileType
;
3494 // Optimize tile mode if possible
3495 pInOut
->flags
.opt4Space
= TRUE
;
3497 // Optimize tile mode if possible
3498 OptimizeTileMode(pInOut
);
3500 HwlOverrideTileMode(pInOut
);
3504 ****************************************************************************************************
3505 * SiLib::HwlComputeMaxBaseAlignments
3508 * Gets maximum alignments
3510 * maximum alignments
3511 ****************************************************************************************************
3513 UINT_32
SiLib::HwlComputeMaxBaseAlignments() const
3515 const UINT_32 pipes
= HwlGetPipes(&m_tileTable
[0].info
);
3517 // Initial size is 64 KiB for PRT.
3518 UINT_32 maxBaseAlign
= 64 * 1024;
3520 for (UINT_32 i
= 0; i
< m_noOfEntries
; i
++)
3522 if ((IsMacroTiled(m_tileTable
[i
].mode
) == TRUE
) &&
3523 (IsPrtTileMode(m_tileTable
[i
].mode
) == FALSE
))
3525 // The maximum tile size is 16 byte-per-pixel and either 8-sample or 8-slice.
3526 UINT_32 tileSize
= Min(m_tileTable
[i
].info
.tileSplitBytes
,
3527 MicroTilePixels
* 8 * 16);
3529 UINT_32 baseAlign
= tileSize
* pipes
* m_tileTable
[i
].info
.banks
*
3530 m_tileTable
[i
].info
.bankWidth
* m_tileTable
[i
].info
.bankHeight
;
3532 if (baseAlign
> maxBaseAlign
)
3534 maxBaseAlign
= baseAlign
;
3539 return maxBaseAlign
;
3543 ****************************************************************************************************
3544 * SiLib::HwlComputeMaxMetaBaseAlignments
3547 * Gets maximum alignments for metadata
3549 * maximum alignments for metadata
3550 ****************************************************************************************************
3552 UINT_32
SiLib::HwlComputeMaxMetaBaseAlignments() const
3554 UINT_32 maxPipe
= 1;
3556 for (UINT_32 i
= 0; i
< m_noOfEntries
; i
++)
3558 maxPipe
= Max(maxPipe
, HwlGetPipes(&m_tileTable
[i
].info
));
3561 return m_pipeInterleaveBytes
* maxPipe
;
3565 ****************************************************************************************************
3566 * SiLib::HwlComputeSurfaceAlignmentsMacroTiled
3569 * Hardware layer function to compute alignment request for macro tile mode
3574 ****************************************************************************************************
3576 VOID
SiLib::HwlComputeSurfaceAlignmentsMacroTiled(
3577 AddrTileMode tileMode
, ///< [in] tile mode
3578 UINT_32 bpp
, ///< [in] bits per pixel
3579 ADDR_SURFACE_FLAGS flags
, ///< [in] surface flags
3580 UINT_32 mipLevel
, ///< [in] mip level
3581 UINT_32 numSamples
, ///< [in] number of samples
3582 ADDR_COMPUTE_SURFACE_INFO_OUTPUT
* pOut
///< [in,out] Surface output
3585 if ((mipLevel
== 0) && (flags
.prt
))
3587 UINT_32 macroTileSize
= pOut
->blockWidth
* pOut
->blockHeight
* numSamples
* bpp
/ 8;
3589 if (macroTileSize
< PrtTileSize
)
3591 UINT_32 numMacroTiles
= PrtTileSize
/ macroTileSize
;
3593 ADDR_ASSERT((PrtTileSize
% macroTileSize
) == 0);
3595 pOut
->pitchAlign
*= numMacroTiles
;
3596 pOut
->baseAlign
*= numMacroTiles
;
3602 ****************************************************************************************************
3603 * SiLib::InitEquationTable
3606 * Initialize Equation table.
3610 ****************************************************************************************************
3612 VOID
SiLib::InitEquationTable()
3614 ADDR_EQUATION_KEY equationKeyTable
[EquationTableSize
];
3615 memset(equationKeyTable
, 0, sizeof(equationKeyTable
));
3617 memset(m_equationTable
, 0, sizeof(m_equationTable
));
3619 memset(m_blockWidth
, 0, sizeof(m_blockWidth
));
3621 memset(m_blockHeight
, 0, sizeof(m_blockHeight
));
3623 memset(m_blockSlices
, 0, sizeof(m_blockSlices
));
3625 // Loop all possible bpp
3626 for (UINT_32 log2ElementBytes
= 0; log2ElementBytes
< MaxNumElementBytes
; log2ElementBytes
++)
3628 // Get bits per pixel
3629 UINT_32 bpp
= 1 << (log2ElementBytes
+ 3);
3631 // Loop all possible tile index
3632 for (INT_32 tileIndex
= 0; tileIndex
< static_cast<INT_32
>(m_noOfEntries
); tileIndex
++)
3634 UINT_32 equationIndex
= ADDR_INVALID_EQUATION_INDEX
;
3636 TileConfig tileConfig
= m_tileTable
[tileIndex
];
3638 ADDR_SURFACE_FLAGS flags
= {{0}};
3640 // Compute tile info, hardcode numSamples to 1 because MSAA is not supported
3641 // in swizzle pattern equation
3642 HwlComputeMacroModeIndex(tileIndex
, flags
, bpp
, 1, &tileConfig
.info
, NULL
, NULL
);
3644 // Check if the input is supported
3645 if (IsEquationSupported(bpp
, tileConfig
, tileIndex
, log2ElementBytes
) == TRUE
)
3647 ADDR_EQUATION_KEY key
= {{0}};
3649 // Generate swizzle equation key from bpp and tile config
3650 key
.fields
.log2ElementBytes
= log2ElementBytes
;
3651 key
.fields
.tileMode
= tileConfig
.mode
;
3652 // Treat depth micro tile type and non-display micro tile type as the same key
3653 // because they have the same equation actually
3654 key
.fields
.microTileType
= (tileConfig
.type
== ADDR_DEPTH_SAMPLE_ORDER
) ?
3655 ADDR_NON_DISPLAYABLE
: tileConfig
.type
;
3656 key
.fields
.pipeConfig
= tileConfig
.info
.pipeConfig
;
3657 key
.fields
.numBanksLog2
= Log2(tileConfig
.info
.banks
);
3658 key
.fields
.bankWidth
= tileConfig
.info
.bankWidth
;
3659 key
.fields
.bankHeight
= tileConfig
.info
.bankHeight
;
3660 key
.fields
.macroAspectRatio
= tileConfig
.info
.macroAspectRatio
;
3661 key
.fields
.prt
= ((m_chipFamily
== ADDR_CHIP_FAMILY_SI
) &&
3662 ((1 << tileIndex
) & SiPrtTileIndexMask
)) ? 1 : 0;
3664 // Find in the table if the equation has been built based on the key
3665 for (UINT_32 i
= 0; i
< m_numEquations
; i
++)
3667 if (key
.value
== equationKeyTable
[i
].value
)
3674 // If found, just fill the index into the lookup table and no need
3675 // to generate the equation again. Otherwise, generate the equation.
3676 if (equationIndex
== ADDR_INVALID_EQUATION_INDEX
)
3678 ADDR_EQUATION equation
;
3679 ADDR_E_RETURNCODE retCode
;
3681 memset(&equation
, 0, sizeof(ADDR_EQUATION
));
3683 // Generate the equation
3684 if (IsMicroTiled(tileConfig
.mode
))
3686 retCode
= ComputeMicroTileEquation(log2ElementBytes
,
3693 retCode
= ComputeMacroTileEquation(log2ElementBytes
,
3699 // Only fill the equation into the table if the return code is ADDR_OK,
3700 // otherwise if the return code is not ADDR_OK, it indicates this is not
3701 // a valid input, we do nothing but just fill invalid equation index
3702 // into the lookup table.
3703 if (retCode
== ADDR_OK
)
3705 equationIndex
= m_numEquations
;
3706 ADDR_ASSERT(equationIndex
< EquationTableSize
);
3708 m_blockSlices
[equationIndex
] = Thickness(tileConfig
.mode
);
3710 if (IsMicroTiled(tileConfig
.mode
))
3712 m_blockWidth
[equationIndex
] = MicroTileWidth
;
3713 m_blockHeight
[equationIndex
] = MicroTileHeight
;
3717 const ADDR_TILEINFO
* pTileInfo
= &tileConfig
.info
;
3719 m_blockWidth
[equationIndex
] =
3720 HwlGetPipes(pTileInfo
) * MicroTileWidth
* pTileInfo
->bankWidth
*
3721 pTileInfo
->macroAspectRatio
;
3722 m_blockHeight
[equationIndex
] =
3723 MicroTileHeight
* pTileInfo
->bankHeight
* pTileInfo
->banks
/
3724 pTileInfo
->macroAspectRatio
;
3728 UINT_32 macroTileSize
=
3729 m_blockWidth
[equationIndex
] * m_blockHeight
[equationIndex
] *
3732 if (macroTileSize
< PrtTileSize
)
3734 UINT_32 numMacroTiles
= PrtTileSize
/ macroTileSize
;
3736 ADDR_ASSERT(macroTileSize
== (1u << equation
.numBits
));
3737 ADDR_ASSERT((PrtTileSize
% macroTileSize
) == 0);
3739 UINT_32 numBits
= Log2(numMacroTiles
);
3741 UINT_32 xStart
= Log2(m_blockWidth
[equationIndex
]) +
3744 m_blockWidth
[equationIndex
] *= numMacroTiles
;
3746 for (UINT_32 i
= 0; i
< numBits
; i
++)
3748 equation
.addr
[equation
.numBits
+ i
].valid
= 1;
3749 equation
.addr
[equation
.numBits
+ i
].index
= xStart
+ i
;
3752 equation
.numBits
+= numBits
;
3757 equationKeyTable
[equationIndex
] = key
;
3758 m_equationTable
[equationIndex
] = equation
;
3765 // Fill the index into the lookup table, if the combination is not supported
3766 // fill the invalid equation index
3767 m_equationLookupTable
[log2ElementBytes
][tileIndex
] = equationIndex
;
3770 if (m_chipFamily
== ADDR_CHIP_FAMILY_SI
)
3772 // For tile index 3 which is shared between PRT depth and uncompressed depth
3773 m_uncompressDepthEqIndex
= m_numEquations
;
3775 for (UINT_32 log2ElemBytes
= 0; log2ElemBytes
< MaxNumElementBytes
; log2ElemBytes
++)
3777 TileConfig tileConfig
= m_tileTable
[3];
3778 ADDR_EQUATION equation
;
3779 ADDR_E_RETURNCODE retCode
;
3781 memset(&equation
, 0, sizeof(ADDR_EQUATION
));
3783 retCode
= ComputeMacroTileEquation(log2ElemBytes
,
3789 if (retCode
== ADDR_OK
)
3791 UINT_32 equationIndex
= m_numEquations
;
3792 ADDR_ASSERT(equationIndex
< EquationTableSize
);
3794 m_blockSlices
[equationIndex
] = 1;
3796 const ADDR_TILEINFO
* pTileInfo
= &tileConfig
.info
;
3798 m_blockWidth
[equationIndex
] =
3799 HwlGetPipes(pTileInfo
) * MicroTileWidth
* pTileInfo
->bankWidth
*
3800 pTileInfo
->macroAspectRatio
;
3801 m_blockHeight
[equationIndex
] =
3802 MicroTileHeight
* pTileInfo
->bankHeight
* pTileInfo
->banks
/
3803 pTileInfo
->macroAspectRatio
;
3805 m_equationTable
[equationIndex
] = equation
;
3815 ****************************************************************************************************
3816 * SiLib::IsEquationSupported
3819 * Check if it is supported for given bpp and tile config to generate a equation.
3823 ****************************************************************************************************
3825 BOOL_32
SiLib::IsEquationSupported(
3826 UINT_32 bpp
, ///< Bits per pixel
3827 TileConfig tileConfig
, ///< Tile config
3828 INT_32 tileIndex
, ///< Tile index
3829 UINT_32 elementBytesLog2
///< Log2 of element bytes
3832 BOOL_32 supported
= TRUE
;
3834 // Linear tile mode is not supported in swizzle pattern equation
3835 if (IsLinear(tileConfig
.mode
))
3839 // These tile modes are for Tex2DArray and Tex3D which has depth (num_slice > 1) use,
3840 // which is not supported in swizzle pattern equation due to slice rotation
3841 else if ((tileConfig
.mode
== ADDR_TM_2D_TILED_THICK
) ||
3842 (tileConfig
.mode
== ADDR_TM_2D_TILED_XTHICK
) ||
3843 (tileConfig
.mode
== ADDR_TM_3D_TILED_THIN1
) ||
3844 (tileConfig
.mode
== ADDR_TM_3D_TILED_THICK
) ||
3845 (tileConfig
.mode
== ADDR_TM_3D_TILED_XTHICK
))
3849 // Only 8bpp(stencil), 16bpp and 32bpp is supported for depth
3850 else if ((tileConfig
.type
== ADDR_DEPTH_SAMPLE_ORDER
) && (bpp
> 32))
3854 // Tile split is not supported in swizzle pattern equation
3855 else if (IsMacroTiled(tileConfig
.mode
))
3857 UINT_32 thickness
= Thickness(tileConfig
.mode
);
3858 if (((bpp
>> 3) * MicroTilePixels
* thickness
) > tileConfig
.info
.tileSplitBytes
)
3863 if ((supported
== TRUE
) && (m_chipFamily
== ADDR_CHIP_FAMILY_SI
))
3865 supported
= m_EquationSupport
[tileIndex
][elementBytesLog2
];