1 /*==============================================================================
2 Copyright(c) 2024 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 "GmmXe2_LPGResourceULT.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 ///
33 /////////////////////////////////////////////////////////////////////////////////////
SetUpTestCase()34 void CTestXe2_LPGResource::SetUpTestCase()
35 {
36 }
37
38 /////////////////////////////////////////////////////////////////////////////////////
39 /// cleans up once all the tests finish execution. It also calls TearDownTestCase
40 /// from CommonULT to destroy global context and others.
41 ///
42 /////////////////////////////////////////////////////////////////////////////////////
TearDownTestCase()43 void CTestXe2_LPGResource::TearDownTestCase()
44 {
45 }
46
SetUp_Xe2Variant(PRODUCT_FAMILY platform)47 void CTestXe2_LPGResource::SetUp_Xe2Variant(PRODUCT_FAMILY platform)
48 {
49 printf("%s\n", __FUNCTION__);
50
51 if (platform == IGFX_BMG)
52 {
53 GfxPlatform.eProductFamily = IGFX_BMG;
54 GfxPlatform.eRenderCoreFamily = IGFX_XE2_HPG_CORE;
55 }
56 else if (platform == IGFX_LUNARLAKE)
57 {
58 GfxPlatform.eProductFamily = IGFX_LUNARLAKE;
59 GfxPlatform.eRenderCoreFamily = IGFX_XE2_LPG_CORE;
60 }
61
62 pGfxAdapterInfo = (ADAPTER_INFO*)malloc(sizeof(ADAPTER_INFO));
63 if (pGfxAdapterInfo)
64 {
65 memset(pGfxAdapterInfo, 0, sizeof(ADAPTER_INFO));
66
67 pGfxAdapterInfo->SkuTable.FtrLinearCCS = 1; //legacy y =>0
68 pGfxAdapterInfo->SkuTable.FtrStandardMipTailFormat = 1;
69 pGfxAdapterInfo->SkuTable.FtrTileY = 0;
70 pGfxAdapterInfo->SkuTable.FtrXe2PlusTiling = 1;
71 pGfxAdapterInfo->SkuTable.FtrXe2Compression = 1;
72 pGfxAdapterInfo->SkuTable.FtrFlatPhysCCS = 1;
73 pGfxAdapterInfo->SkuTable.FtrLocalMemory = 0;
74 pGfxAdapterInfo->SkuTable.FtrDiscrete = 0;
75 pGfxAdapterInfo->SkuTable.FtrE2ECompression = 1;
76
77 if (platform == IGFX_BMG)
78 {
79 pGfxAdapterInfo->SkuTable.FtrLocalMemory = 1;
80 pGfxAdapterInfo->SkuTable.FtrDiscrete = 1;
81 }
82
83 if (platform == IGFX_LUNARLAKE || platform == IGFX_BMG)
84 {
85 pGfxAdapterInfo->WaTable.Wa_14018976079 = 1;
86 pGfxAdapterInfo->WaTable.Wa_14018984349 = 1;
87 pGfxAdapterInfo->SkuTable.FtrL3TransientDataFlush = 1;
88 }
89
90 CommonULT::SetUpTestCase();
91 }
92 }
93
TearDown_Xe2Variant()94 void CTestXe2_LPGResource::TearDown_Xe2Variant()
95 {
96 printf("%s\n", __FUNCTION__);
97 CommonULT::TearDownTestCase();
98 }
99
TEST_F(CTestXe2_LPGResource,TestMSAA_BMG)100 TEST_F(CTestXe2_LPGResource, TestMSAA_BMG)
101 {
102 SetUp_Xe2Variant(IGFX_BMG);
103 TestMSAA();
104 TearDown_Xe2Variant();
105 }
106
TEST_F(CTestXe2_LPGResource,TestMSAA_LNL)107 TEST_F(CTestXe2_LPGResource, TestMSAA_LNL)
108 {
109 SetUp_Xe2Variant(IGFX_LUNARLAKE);
110 TestMSAA();
111 TearDown_Xe2Variant();
112 }
113
114 /// @brief ULT for MSAA Resource - Depth and Colour MSAA verification for Tile64 resources
115 // Note: Verify with and without FtrXe2PlusTiling in Setup, Default: FtrXe2PlusTiling
TestMSAA()116 void CTestXe2_LPGResource::TestMSAA()
117 {
118 GMM_GFX_SIZE_T AuxCC, AuxCCS, AuxMCS;
119 const uint32_t TestDimensions[4][2] = {
120 //Input dimensions in #Tiles
121 {16, 4}, //occupies single tile for Depth for all MSAAs and BPPs, multiple tiles for colours
122 {128, 128}, // crosses a tile for > 4X MSAA for depth
123 {128, 257}, // Crosses a tile in Y direction and for >4X MSAA, crosses in X direction too for depth
124 {1, 1},
125 };
126
127 uint32_t TestArraySize[2] = {1, 5};
128 uint32_t MinPitch = 32;
129
130 uint32_t HAlign, VAlign, TileDimX, TileDimY, MCSHAlign, MCSVAlign, TileSize;
131 uint32_t ExpectedMCSBpp;
132 std::vector<tuple<int, int, int, bool, int, int>> List; //TEST_TILE_TYPE, TEST_BPP, TEST_RESOURCE_TYPE, Depth or RT, TestDimension index, ArraySize
133 auto Size = BuildInputIterator(List, 4, 2, true); // Size of arrays TestDimensions, TestArraySize
134
135 for(auto element : List)
136 {
137 GMM_RESCREATE_PARAMS gmmParams = {};
138 gmmParams.Flags.Info = {0};
139
140 TEST_TILE_TYPE Tiling = (TEST_TILE_TYPE)std::get<0>(element);
141 TEST_BPP Bpp = (TEST_BPP)std::get<1>(element);
142 TEST_RESOURCE_TYPE ResType = (TEST_RESOURCE_TYPE)std::get<2>(element);
143 bool IsRT = std::get<3>(element); // True for RT, False for Depth
144 int TestDimIdx = std::get<4>(element); //index into TestDimensions array
145 int ArrayIdx = std::get<5>(element); //index into TestArraySize
146 TileSize = (Tiling == TEST_TILE64) ? GMM_KBYTE(64) : GMM_KBYTE(4);
147
148 //Discard un-supported Tiling/Res_type/bpp for this test
149 if((ResType != TEST_RESOURCE_2D) || //No 1D/3D/Cube. Supported 2D mip-maps/array
150 // depth tested outside this function due to diff in halign/valign
151 (Tiling != TEST_TILE64)) // MSAA not supported on Tile4
152 continue;
153
154 SetTileFlag(gmmParams, Tiling);
155 SetResType(gmmParams, ResType);
156 SetResGpuFlags(gmmParams, IsRT);
157 SetResArraySize(gmmParams, TestArraySize[ArrayIdx]);
158
159 gmmParams.NoGfxMemory = 1;
160 gmmParams.Format = SetResourceFormat(Bpp);
161 for(uint32_t k = MSAA_2x; k <= MSAA_16x; k++)
162 {
163 GetAlignmentAndTileDimensionsForMSAA(Bpp, IsRT, Tiling, (TEST_MSAA)k,
164 TileDimX, TileDimY, HAlign, VAlign,
165 ExpectedMCSBpp, MCSHAlign, MCSVAlign);
166 gmmParams.BaseWidth64 = TestDimensions[TestDimIdx][0] * (unsigned int)pow(2.0, Bpp);
167 gmmParams.BaseHeight = TestDimensions[TestDimIdx][1];
168 gmmParams.Depth = 0x1;
169 gmmParams.MSAA.NumSamples = static_cast<uint32_t>(pow((double)2, k));
170 gmmParams.Flags.Gpu.MCS = 1;
171 gmmParams.Flags.Gpu.CCS = 1;
172 gmmParams.Flags.Gpu.UnifiedAuxSurface = 1;
173 gmmParams.Flags.Gpu.IndirectClearColor = 1;
174 //MSS surface
175 GMM_RESOURCE_INFO *MSSResourceInfo;
176 MSSResourceInfo = pGmmULTClientContext->CreateResInfoObject(&gmmParams);
177
178 if(MSSResourceInfo)
179 {
180 VerifyResourceHAlign<true>(MSSResourceInfo, HAlign);
181 VerifyResourceVAlign<true>(MSSResourceInfo, VAlign);
182
183 if (gmmParams.Flags.Gpu.IndirectClearColor && pGfxAdapterInfo->SkuTable.FtrXe2Compression && (gmmParams.MSAA.NumSamples > 1))
184 {
185 AuxCC = MSSResourceInfo->GetUnifiedAuxSurfaceOffset(GMM_AUX_CC);
186 AuxMCS = MSSResourceInfo->GetUnifiedAuxSurfaceOffset(GMM_AUX_MCS);
187 AuxCCS = MSSResourceInfo->GetUnifiedAuxSurfaceOffset(GMM_AUX_CCS);
188
189 EXPECT_EQ(AuxCC, AuxMCS);
190 EXPECT_EQ(AuxCCS, 0);
191
192 AuxCC = MSSResourceInfo->GetSizeAuxSurface(GMM_AUX_CC);
193 AuxMCS = MSSResourceInfo->GetSizeAuxSurface(GMM_AUX_MCS);
194 AuxCCS = MSSResourceInfo->GetSizeAuxSurface(GMM_AUX_CCS);
195
196 EXPECT_EQ(AuxCC, AuxMCS);
197 EXPECT_EQ(AuxCCS, 0);
198 }
199 if(IsRT) //Arrayed MSS
200 {
201 uint32_t ExpectedPitch = 0, ExpectedQPitch = 0, ExpectedHeight = 0;
202 ExpectedPitch = GMM_ULT_ALIGN(GMM_ULT_ALIGN(gmmParams.BaseWidth64, HAlign) * (unsigned int)pow(2.0, Bpp), TileDimX); // Aligned width * bpp, aligned to TileWidth
203 ExpectedPitch = GFX_MAX(ExpectedPitch, MinPitch);
204 VerifyResourcePitch<true>(MSSResourceInfo, ExpectedPitch);
205 if(Tiling != TEST_LINEAR)
206 VerifyResourcePitchInTiles<true>(MSSResourceInfo, ExpectedPitch / TileDimX);
207
208 ExpectedQPitch = GMM_ULT_ALIGN(gmmParams.BaseHeight, VAlign);
209 if(gmmParams.ArraySize > 1) //Gen9: Qpitch is distance between array slices (not sample slices)
210 {
211 VerifyResourceQPitch<true>(MSSResourceInfo, ExpectedQPitch);
212 }
213
214 ExpectedHeight = GMM_ULT_ALIGN(ExpectedQPitch * gmmParams.MSAA.NumSamples * gmmParams.ArraySize, TileDimY); // For Tile64 layout prior to Xe2Tiling, MSAA8x and 16x follows MSAA4x. MSAA4x*2 for MSAA8x and MSAA4x*4 for MSAA16x.
215 // Height getting multiplied by numsamples here is good enough for these special layouts too
216 VerifyResourceSize<true>(MSSResourceInfo, GMM_ULT_ALIGN(ExpectedPitch * ExpectedHeight, TileSize));
217 }
218 else
219 {
220 uint32_t WidthMultiplier, HeightMultiplier;
221 GetInterleaveMSSPattern((TEST_MSAA)k, WidthMultiplier, HeightMultiplier, IsRT, Bpp);
222 gmmParams.BaseWidth64 = WidthMultiplier > 1 ? GMM_ULT_ALIGN(gmmParams.BaseWidth64, 2) : gmmParams.BaseWidth64;
223 gmmParams.BaseHeight = HeightMultiplier > 1 ? GMM_ULT_ALIGN(gmmParams.BaseHeight, 2) : gmmParams.BaseHeight;
224
225 uint32_t ExpectedPitch = GMM_ULT_ALIGN(GMM_ULT_ALIGN(gmmParams.BaseWidth64 * WidthMultiplier, HAlign) * (uint32_t)pow(2.0, Bpp), TileDimX);
226 VerifyResourcePitch<true>(MSSResourceInfo, ExpectedPitch);
227 if(Tiling != TEST_LINEAR)
228 {
229 VerifyResourcePitchInTiles<true>(MSSResourceInfo, ExpectedPitch / TileDimX);
230 }
231
232 uint64_t ExpectedQPitch = GMM_ULT_ALIGN(gmmParams.BaseHeight * HeightMultiplier, VAlign);
233 uint32_t ExpandedArraySize = gmmParams.ArraySize * (((MSSResourceInfo->GetTileType() == GMM_TILED_64) && !pGfxAdapterInfo->SkuTable.FtrTileY && !pGfxAdapterInfo->SkuTable.FtrXe2PlusTiling && (gmmParams.MSAA.NumSamples == 16)) ? 4 : // MSAA x8/x16 stored as pseudo array planes each with 4x samples
234 ((MSSResourceInfo->GetTileType() == GMM_TILED_64) && !pGfxAdapterInfo->SkuTable.FtrTileY && !pGfxAdapterInfo->SkuTable.FtrXe2PlusTiling && (gmmParams.MSAA.NumSamples == 8)) ? 2 : 1);
235 if(ExpandedArraySize > 1)
236 {
237 VerifyResourceQPitch<true>(MSSResourceInfo, ExpectedQPitch);
238 }
239 uint64_t ExpectedHeight = GMM_ULT_ALIGN(ExpectedQPitch * ExpandedArraySize, TileDimY); //Align Height = ExpectedQPitch*ArraySize, to Tile-Height
240 VerifyResourceSize<true>(MSSResourceInfo, GMM_ULT_ALIGN(ExpectedPitch * ExpectedHeight, TileSize)); //ExpectedPitch *ExpectedHeight
241 }
242 }
243
244 pGmmULTClientContext->DestroyResInfoObject(MSSResourceInfo);
245 } //NumSamples = k
246 } //Iterate through all Input types{
247
248 }
249