xref: /aosp_15_r20/external/gmmlib/Source/GmmLib/ULT/GmmGen10ResourceULT.cpp (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 #include "GmmGen10ResourceULT.h"
24 
25 using namespace std;
26 
27 /////////////////////////////////////////////////////////////////////////////////////
28 /// Sets up common environment for Resource fixture tests. this is called once per
29 /// test case before executing all tests under resource fixture test case.
30 //  It also calls SetupTestCase from CommonULT to initialize global context and others.
31 ///
32 /// @see    CTestGen9Resource::SetUpTestCase()
33 ///
34 /////////////////////////////////////////////////////////////////////////////////////
SetUpTestCase()35 void CTestGen10Resource::SetUpTestCase()
36 {
37     printf("%s\n", __FUNCTION__);
38     GfxPlatform.eProductFamily    = IGFX_CANNONLAKE;
39     GfxPlatform.eRenderCoreFamily = IGFX_GEN10_CORE;
40 
41     CommonULT::SetUpTestCase();
42 }
43 
44 /////////////////////////////////////////////////////////////////////////////////////
45 /// cleans up once all the tests finish execution.  It also calls TearDownTestCase
46 /// from CommonULT to destroy global context and others.
47 ///
48 /// @see    CTestGen10Resource::TearDownTestCase()
49 /////////////////////////////////////////////////////////////////////////////////////
TearDownTestCase()50 void CTestGen10Resource::TearDownTestCase()
51 {
52     printf("%s\n", __FUNCTION__);
53 
54     CommonULT::TearDownTestCase();
55 }
56 
57 /// @brief ULT for 2D TileYs Resource
TEST_F(CTestGen10Resource,Test2DTileYsResource)58 TEST_F(CTestGen10Resource, Test2DTileYsResource)
59 {
60     printf("%s\n", __FUNCTION__);
61 }
62 
63 /// @brief ULT for 2D TileYf Resource
TEST_F(CTestGen10Resource,Test2DTileYfResource)64 TEST_F(CTestGen10Resource, Test2DTileYfResource)
65 {
66     printf("%s\n", __FUNCTION__);
67 }
68 
TEST_F(CTestGen10Resource,TestMSAA)69 TEST_F(CTestGen10Resource, TestMSAA)
70 {
71     //Tile dimensions in Bytes
72     const uint32_t MCSTileSize[1][2] = {128, 32}; //MCS is TileY
73 
74     //Gen9: MSAA 16x no MCS for width > 8K
75     //No MSAA for YUV/compressed formats
76     //Interleaved MSS (IMS) for Depth/Stencil. Arrayed MSS (CMS) for Color RT
77     //MSS (Arrayed): px_wL, px_hL = pixel width/height of single sample at Lod L
78     //  MSS width = px_wL, MSS height = NumSamples*px_hL
79     //MSS (Interleaved): px_wL, px_hL = pixel width/height of single sample at Lod L
80     // Samples         MSS width                MSS Height
81     //   2x            4*ceil(px_wL/2)             px_hL
82     //   4x            4*ceil(px_wL/2)           4*ceil(px_hL/2)
83     //   8x            8*ceil(px_wL/2)           4*ceil(px_hL/2)
84     //  16x            8*ceil(px_wL/2)           8*ceil(px_hL/2)
85     //MCS (bpp): 2x/4x - bpp_8, 8x - bpp_32, 16x - bpp_64
86 
87     const uint32_t TestDimensions[4][2] = {
88     //Input dimensions in #Tiles
89     {15, 20}, //16 Tiles x 20 <Max Width: Depth MSS crosses Pitch limit beyond this>
90     {0, 0},   //1x1x1
91     {1, 0},   //2 Tilesx1
92     {1, 1},   //2 Tiles x 2
93     };
94 
95     uint32_t TestArraySize[2] = {1, 5};
96     uint32_t MinPitch         = 32;
97 
98     uint32_t HAlign = 0, VAlign = 0;
99     uint32_t TileDimX = 0, TileDimY = 0;
100     uint32_t MCSHAlign = 0, MCSVAlign = 0, TileSize = 0;
101     uint32_t ExpectedMCSBpp = 0;
102     std::vector<tuple<int, int, int, bool, int, int>> List; //TEST_TILE_TYPE, TEST_BPP, TEST_RESOURCE_TYPE, Depth or RT, TestDimension index, ArraySize
103     auto Size = BuildInputIterator(List, 4, 2, false);             // Size of arrays TestDimensions, TestArraySize
104 
105     for(auto element : List)
106     {
107         GMM_RESCREATE_PARAMS gmmParams = {};
108         gmmParams.Flags.Info           = {0};
109 
110         TEST_TILE_TYPE     Tiling     = (TEST_TILE_TYPE)std::get<0>(element);
111         TEST_BPP           Bpp        = (TEST_BPP)std::get<1>(element);
112         TEST_RESOURCE_TYPE ResType    = (TEST_RESOURCE_TYPE)std::get<2>(element);
113         bool               IsRT       = std::get<3>(element); // True for RT, False for Depth
114         int                TestDimIdx = std::get<4>(element); //index into TestDimensions array
115         int                ArrayIdx   = std::get<5>(element); //index into TestArraySize
116         TileSize                      = (Tiling == TEST_TILEYS) ? GMM_KBYTE(64) : GMM_KBYTE(4);
117 
118         //Discard un-supported Tiling/Res_type/bpp for this test
119         if(ResType != TEST_RESOURCE_2D ||                            //No 1D/3D/Cube. Supported 2D mip-maps/array
120            (!IsRT && (Tiling == TEST_TILEX ||
121                       !(Bpp == TEST_BPP_16 || Bpp == TEST_BPP_32)))) //depth supported on 16bit, 32bit formats only
122             continue;
123 
124         SetTileFlag(gmmParams, Tiling);
125         SetResType(gmmParams, ResType);
126         SetResGpuFlags(gmmParams, IsRT);
127         SetResArraySize(gmmParams, TestArraySize[ArrayIdx]);
128 
129         gmmParams.NoGfxMemory = 1;
130         gmmParams.Format      = SetResourceFormat(Bpp);
131         for(uint32_t k = MSAA_2x; k <= MSAA_16x; k++)
132         {
133             GetAlignmentAndTileDimensionsForMSAA(Bpp, IsRT, Tiling, (TEST_MSAA)k,
134                                                  TileDimX, TileDimY, HAlign, VAlign,
135                                                  ExpectedMCSBpp, MCSHAlign, MCSVAlign);
136 
137             gmmParams.BaseWidth64     = TestDimensions[TestDimIdx][0] * TileDimX + 0x1;
138             gmmParams.BaseHeight      = TestDimensions[TestDimIdx][1] * TileDimY + 0x1;
139             gmmParams.Depth           = 0x1;
140             gmmParams.MSAA.NumSamples = static_cast<uint32_t>(pow((double)2, k));
141             gmmParams.Flags.Gpu.MCS   = 0;
142 
143             //MSS surface
144             GMM_RESOURCE_INFO *MSSResourceInfo;
145             MSSResourceInfo = pGmmULTClientContext->CreateResInfoObject(&gmmParams);
146 
147             if(MSSResourceInfo)
148             {
149                 VerifyResourceHAlign<true>(MSSResourceInfo, HAlign);
150                 VerifyResourceVAlign<true>(MSSResourceInfo, VAlign);
151                 if(IsRT) //Arrayed MSS
152                 {
153                     uint32_t ExpectedPitch = 0, ExpectedQPitch = 0;
154                     ExpectedPitch = GMM_ULT_ALIGN(GMM_ULT_ALIGN(gmmParams.BaseWidth64, HAlign) * (uint32_t)pow(2.0, Bpp), TileDimX); // Aligned width * bpp, aligned to TileWidth
155                     ExpectedPitch = GFX_MAX(ExpectedPitch, MinPitch);
156                     VerifyResourcePitch<true>(MSSResourceInfo, ExpectedPitch);
157                     if(Tiling != TEST_LINEAR)
158                         VerifyResourcePitchInTiles<true>(MSSResourceInfo, ExpectedPitch / TileDimX);
159 
160                     ExpectedQPitch = GMM_ULT_ALIGN(gmmParams.BaseHeight, VAlign);
161                     if(gmmParams.ArraySize > 1) //Gen9: Qpitch is distance between array slices (not sample slices)
162                     {
163                         VerifyResourceQPitch<true>(MSSResourceInfo, ExpectedQPitch);
164                     }
165 
166                     uint32_t ExpectedHeight = GMM_ULT_ALIGN(ExpectedQPitch * gmmParams.MSAA.NumSamples * gmmParams.ArraySize, TileDimY); //Align Height =ExpectedPitch * NumSamples * ExpectedQPitch, to Tile-Height
167                     VerifyResourceSize<true>(MSSResourceInfo, GMM_ULT_ALIGN(ExpectedPitch * ExpectedHeight, TileSize));
168                 }
169                 else // Interleaved MSS
170                 {
171                     uint32_t WidthMultiplier, HeightMultiplier;
172                     GetInterleaveMSSPattern((TEST_MSAA)k, WidthMultiplier, HeightMultiplier, IsRT, Bpp);
173                     gmmParams.BaseWidth64 = WidthMultiplier > 1 ? GMM_ULT_ALIGN(gmmParams.BaseWidth64, 2) : gmmParams.BaseWidth64;
174                     gmmParams.BaseHeight  = HeightMultiplier > 1 ? GMM_ULT_ALIGN(gmmParams.BaseHeight, 2) : gmmParams.BaseHeight;
175 
176                     uint32_t ExpectedPitch = GMM_ULT_ALIGN(GMM_ULT_ALIGN(gmmParams.BaseWidth64 * WidthMultiplier, HAlign) * (uint32_t)pow(2.0, Bpp), TileDimX);
177                     VerifyResourcePitch<true>(MSSResourceInfo, ExpectedPitch);
178                     if(Tiling != TEST_LINEAR)
179                     {
180                         VerifyResourcePitchInTiles<true>(MSSResourceInfo, ExpectedPitch / TileDimX);
181                     }
182 
183                     uint64_t ExpectedQPitch = GMM_ULT_ALIGN(gmmParams.BaseHeight * HeightMultiplier, VAlign);
184                     if(gmmParams.ArraySize > 1)
185                     {
186                         VerifyResourceQPitch<true>(MSSResourceInfo, ExpectedQPitch);
187                     }
188                     uint64_t ExpectedHeight = GMM_ULT_ALIGN(ExpectedQPitch * gmmParams.ArraySize, TileDimY);            //Align Height = ExpectedQPitch*ArraySize, to Tile-Height
189                     VerifyResourceSize<true>(MSSResourceInfo, GMM_ULT_ALIGN(ExpectedPitch * ExpectedHeight, TileSize)); //ExpectedPitch *ExpectedHeight
190                 }
191             }
192 
193             //No MCS surface if MSS creation failed
194             if(MSSResourceInfo)
195             {
196                 gmmParams.Flags.Gpu.MCS = 1;
197                 GMM_RESOURCE_INFO *MCSResourceInfo;
198                 MCSResourceInfo = pGmmULTClientContext->CreateResInfoObject(&gmmParams);
199 
200                 VerifyResourceHAlign<true>(MCSResourceInfo, MCSHAlign);
201                 VerifyResourceVAlign<true>(MCSResourceInfo, MCSVAlign);
202 
203                 uint32_t ExpectedPitch = GMM_ULT_ALIGN(GMM_ULT_ALIGN(gmmParams.BaseWidth64, MCSHAlign) * ExpectedMCSBpp, MCSTileSize[0][0]); // Align in texels, tehn multiply w/ Bpt
204                 VerifyResourcePitch<true>(MCSResourceInfo, ExpectedPitch);
205                 VerifyResourcePitchInTiles<true>(MCSResourceInfo, ExpectedPitch / MCSTileSize[0][0]);
206 
207                 uint32_t ExpectedQPitch = GMM_ULT_ALIGN(gmmParams.BaseHeight, MCSVAlign);
208                 if(gmmParams.ArraySize > 1)
209                 {
210                     ExpectedQPitch = GMM_ULT_ALIGN(gmmParams.BaseHeight, MCSVAlign); //QPitch only for array
211                     VerifyResourceQPitch<true>(MCSResourceInfo, ExpectedQPitch);
212                 }
213 
214                 uint32_t ExpectedHeight = GMM_ULT_ALIGN(ExpectedQPitch * gmmParams.ArraySize, MCSTileSize[0][1]);
215                 VerifyResourceSize<true>(MCSResourceInfo, GMM_ULT_ALIGN(ExpectedPitch * ExpectedHeight, GMM_KBYTE(4))); //MCS Tile is TileY
216 
217                 pGmmULTClientContext->DestroyResInfoObject(MCSResourceInfo);
218             } //MCS
219 
220             pGmmULTClientContext->DestroyResInfoObject(MSSResourceInfo);
221         } //NumSamples = k
222     }     //Iterate through all Input types
223 
224     //Mip-mapped, MSAA case:
225 }
226