xref: /aosp_15_r20/external/gmmlib/Source/GmmLib/inc/Internal/Common/Texture/GmmGen11TextureCalc.h (revision 35ffd701415c9e32e53136d61a677a8d0a8fc4a5)
1 /*==============================================================================
2 Copyright(c) 2017 Intel Corporation
3 
4 Permission is hereby granted, free of charge, to any person obtaining a
5 copy of this software and associated documentation files(the "Software"),
6 to deal in the Software without restriction, including without limitation
7 the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 and / or sell copies of the Software, and to permit persons to whom the
9 Software is furnished to do so, subject to the following conditions:
10 
11 The above copyright notice and this permission notice shall be included
12 in all copies or substantial portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 OTHER DEALINGS IN THE SOFTWARE.
21 ============================================================================*/
22 
23 #pragma once
24 #ifdef __cplusplus
25 #include "GmmGen9TextureCalc.h"
26 /////////////////////////////////////////////////////////////////////////////////////
27 /// @file GmmGen11TextureCalc.h
28 /// @brief This file contains the functions and members definations for texture alloc-
29 ///        ation on all Gen11 platforms.
30 /////////////////////////////////////////////////////////////////////////////////////
31 namespace GmmLib
32 {
33     /////////////////////////////////////////////////////////////////////////
34     /// Contains texture calc functions and members for Gen11 platforms.
35     /// This class is derived from the base GmmTextureCalc class  so clients
36     /// shouldn't have to ever interact  with this class directly.
37     /////////////////////////////////////////////////////////////////////////
38     class NON_PAGED_SECTION GmmGen11TextureCalc :
39                                 public GmmGen10TextureCalc
40     {
41         private:
42 
43         protected:
44             /* Function prototypes */
45             virtual uint32_t   GetMipTailByteOffset(
46                                 GMM_TEXTURE_INFO *pTexInfo,
47                                 uint32_t            MipLevel);
48 
49             virtual void    GetMipTailGeometryOffset(
50                                 GMM_TEXTURE_INFO *pTexInfo,
51                                 uint32_t            MipLevel,
52                                 uint32_t*           OffsetX,
53                                 uint32_t*           OffsetY,
54                                 uint32_t*           OffsetZ);
55 
56             virtual GMM_STATUS  GMM_STDCALL FillTexPlanar(
57                                     GMM_TEXTURE_INFO    *pTexInfo,
58                                     __GMM_BUFFER_TYPE   *pRestrictions);
59 
60             GMM_STATUS   FillLinearCCS(
61                                     GMM_TEXTURE_INFO    *pTexInfo,
62                                     __GMM_BUFFER_TYPE   *pRestrictions);
63 
64             virtual void FillPlanarOffsetAddress(GMM_TEXTURE_INFO *pTexInfo);
65 
66         public:
67             /* Constructors */
GmmGen11TextureCalc(Context * pGmmLibContext)68             GmmGen11TextureCalc(Context *pGmmLibContext)
69                 : GmmGen10TextureCalc(pGmmLibContext)
70             {
71 
72             }
73 
~GmmGen11TextureCalc()74             ~GmmGen11TextureCalc()
75             {
76 
77             }
78 
79             /* Virtual Functions */
80             /////////////////////////////////////////////////////////////////////////
81             // Returns unaligned/unpadded width of a given LOD
82             //  Default         : WL = ((width >> L) > 0 ? width >> L : 1)
83             //  CornerTexelMode : WL = MAX(1,(width-1) >> L) + 1 or WL = MAX(1,(WLminus1-1) >> 1) + 1
84             /////////////////////////////////////////////////////////////////////////
GmmTexGetMipWidth(GMM_TEXTURE_INFO * pTexInfo,uint32_t MipLevel)85             virtual GMM_GFX_SIZE_T  GmmTexGetMipWidth(GMM_TEXTURE_INFO *pTexInfo, uint32_t MipLevel)
86             {
87                 __GMM_ASSERTPTR(pTexInfo, 0);
88 
89                 if (!pTexInfo->Flags.Info.CornerTexelMode)
90                 {
91                     return(GFX_MAX(1, pTexInfo->BaseWidth >> MipLevel));
92                 }
93                 else
94                 {
95                     if (pTexInfo->BaseWidth == 1)
96                     {
97                         return pTexInfo->BaseWidth;
98                     }
99                     else
100                     {
101                         return(GFX_MAX(1, (pTexInfo->BaseWidth - 1) >> MipLevel) + 1);
102                     }
103                 }
104             }
105 
106             /////////////////////////////////////////////////////////////////////////
107             // Returns unaligned/unpadded height of a given LOD
108             //  Default         : HL = ((height >> L) > 0 ? height >> L : 1)
109             //  CornerTexelMode : HL = MAX(1,(height-1) >> L) + 1 or HL = MAX(1,(HLminus1-1) >> 1) + 1
110             /////////////////////////////////////////////////////////////////////////
GmmTexGetMipHeight(GMM_TEXTURE_INFO * pTexInfo,uint32_t MipLevel)111             virtual uint32_t  GmmTexGetMipHeight(GMM_TEXTURE_INFO *pTexInfo, uint32_t MipLevel)
112             {
113                 __GMM_ASSERTPTR(pTexInfo, 0);
114 
115                 if (!pTexInfo->Flags.Info.CornerTexelMode)
116                 {
117                     return(GFX_MAX(1, pTexInfo->BaseHeight >> MipLevel));
118                 }
119                 else
120                 {
121                     if (pTexInfo->BaseHeight == 1)
122                     {
123                         return pTexInfo->BaseHeight;
124                     }
125                     else
126                     {
127                         return(GFX_MAX(1, (pTexInfo->BaseHeight - 1) >> MipLevel) + 1);
128                     }
129                 }
130             }
131 
132             /////////////////////////////////////////////////////////////////////////
133             // Returns unaligned/unpadded depth of a given LOD
134             //  Default         : DL = ((depth >> L) > 0 ? depth >> L : 1)
135             //  CornerTexelMode : DL = MAX(1,(depth-1) >> L) + 1 or DL = MAX(1,(DLminus1-1) >> 1) + 1
136             /////////////////////////////////////////////////////////////////////////
GmmTexGetMipDepth(GMM_TEXTURE_INFO * pTexInfo,uint32_t MipLevel)137             virtual uint32_t  GmmTexGetMipDepth(GMM_TEXTURE_INFO *pTexInfo, uint32_t MipLevel)
138             {
139                 __GMM_ASSERTPTR(pTexInfo, 0);
140 
141                 if (!pTexInfo->Flags.Info.CornerTexelMode)
142                 {
143                     return(GFX_MAX(1, pTexInfo->Depth >> MipLevel));
144                 }
145                 else
146                 {
147                     if (pTexInfo->Depth == 1)
148                     {
149                         return pTexInfo->Depth;
150                     }
151                     else
152                     {
153                         return(GFX_MAX(1, (pTexInfo->Depth - 1) >> MipLevel) + 1);
154                     }
155                 }
156             }
157 
158             /* Function prototypes */
159 
160             /* inline functions */
161     };
162 }
163 #endif // #ifdef __cplusplus
164