xref: /aosp_15_r20/external/gmmlib/Source/GmmLib/ULT/GmmGen11ResourceULT.cpp (revision 35ffd701415c9e32e53136d61a677a8d0a8fc4a5)
1 /*==============================================================================
2 Copyright(c) 2016 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 "GmmGen11ResourceULT.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 CTestGen11Resource::SetUpTestCase()
36 {
37     printf("%s\n", __FUNCTION__);
38     GfxPlatform.eProductFamily    = IGFX_LAKEFIELD;
39     GfxPlatform.eRenderCoreFamily = IGFX_GEN11_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 CTestGen11Resource::TearDownTestCase()
51 {
52     printf("%s\n", __FUNCTION__);
53 
54     CommonULT::TearDownTestCase();
55 }
56 
57 /// @brief ULT for 2D TileYs Resource
TEST_F(CTestGen11Resource,TestPlanar2D_NV12_MediaCompressed)58 TEST_F(CTestGen11Resource, TestPlanar2D_NV12_MediaCompressed)
59 {
60     /* Test planar surface with hybrid UV planes where UV plane is half the size
61     of Y and U/V data is packed together */
62     // YYYYYYYY
63     // YYYYYYYY
64     // YYYYYYYY
65     // YYYYYYYY
66     // [UV-Packing]
67     // YccsYccsYccs
68     // YccsYccsYccs
69     // UVccsUVccsUVccs
70     // UVccsUVccsUVccs
71 
72     const uint32_t TileSize[2] = {128, 32}; // TileY
73 
74     GMM_RESCREATE_PARAMS gmmParams        = {};
75     gmmParams.Type                        = RESOURCE_2D;
76     gmmParams.NoGfxMemory                 = 1;
77     gmmParams.Flags.Gpu.MMC               = 1;
78     gmmParams.Flags.Gpu.Texture           = 1;
79     gmmParams.Flags.Gpu.UnifiedAuxSurface = 1;
80     gmmParams.Flags.Info.TiledY           = 1;
81     gmmParams.BaseWidth64                 = 0x2048; //8264
82     gmmParams.BaseHeight                  = 0x274;  // 628
83     gmmParams.Depth                       = 0x1;
84     SetTileFlag(gmmParams, static_cast<TEST_TILE_TYPE>(TEST_TILEY));
85     gmmParams.Format = GMM_FORMAT_NV12;
86 
87     GMM_RESOURCE_INFO *ResourceInfo;
88     //__debugbreak();
89     ResourceInfo = pGmmULTClientContext->CreateResInfoObject(&gmmParams);
90 
91     uint32_t Pitch = GMM_ULT_ALIGN(gmmParams.BaseWidth64, TileSize[0]);
92 
93     uint32_t Height = GMM_ULT_ALIGN(gmmParams.BaseHeight, TileSize[1]) +
94                    GMM_ULT_ALIGN(gmmParams.BaseHeight / 2, TileSize[1]);
95     uint32_t Size = GMM_ULT_ALIGN(Pitch * Height, GMM_KBYTE(4));
96 
97     VerifyResourcePitch<true>(ResourceInfo, Pitch);
98     VerifyResourcePitchInTiles<true>(ResourceInfo, Pitch / TileSize[0]);
99 
100     VerifyResourceSize<true>(ResourceInfo, Size);
101     VerifyResourceHAlign<false>(ResourceInfo, 0); // Same as any other 2D surface -- tested elsewhere
102     VerifyResourceVAlign<false>(ResourceInfo, 0); // Same as any other 2D surface -- tested elsewhere
103     VerifyResourceQPitch<false>(ResourceInfo, 0); // N/A for planar
104 
105     // Y plane should be at 0,0
106     EXPECT_EQ(0, ResourceInfo->GetPlanarXOffset(GMM_PLANE_Y));
107     EXPECT_EQ(0, ResourceInfo->GetPlanarYOffset(GMM_PLANE_Y));
108 
109     // U/V plane should be at end of Y plane
110     EXPECT_EQ(0, ResourceInfo->GetPlanarXOffset(GMM_PLANE_U));
111     EXPECT_EQ(GMM_ULT_ALIGN(gmmParams.BaseHeight, TileSize[1]), ResourceInfo->GetPlanarYOffset(GMM_PLANE_U));
112     EXPECT_EQ(0, ResourceInfo->GetPlanarXOffset(GMM_PLANE_V));
113 
114     EXPECT_EQ(GMM_ULT_ALIGN(gmmParams.BaseHeight, TileSize[1]), ResourceInfo->GetPlanarYOffset(GMM_PLANE_U));
115     EXPECT_EQ(GMM_ULT_ALIGN(gmmParams.BaseHeight, TileSize[1]), ResourceInfo->GetPlanarYOffset(GMM_PLANE_V));
116 
117     // Y Plane CCS should be at the end of NV12 surface.
118     EXPECT_EQ(Size, ResourceInfo->GetUnifiedAuxSurfaceOffset(GMM_AUX_CCS));
119     EXPECT_EQ(Size, ResourceInfo->GetUnifiedAuxSurfaceOffset(GMM_AUX_Y_CCS));
120 
121     // UV Plane CCS offset
122     uint32_t YCcsSize = GMM_ULT_ALIGN(((GMM_ULT_ALIGN(gmmParams.BaseHeight, TileSize[1]) * Pitch) / 1024), PAGE_SIZE);
123     EXPECT_EQ(Size + YCcsSize, ResourceInfo->GetUnifiedAuxSurfaceOffset(GMM_AUX_UV_CCS));
124 
125     uint32_t UVCcsSize        = GMM_ULT_ALIGN((Height - GFX_ALIGN(gmmParams.BaseHeight, TileSize[1])) * Pitch / 1024, PAGE_SIZE);
126     uint32_t MediaStateOffset = Size + YCcsSize + UVCcsSize;
127     EXPECT_EQ(MediaStateOffset, ResourceInfo->GetUnifiedAuxSurfaceOffset(GMM_AUX_COMP_STATE));
128 
129     pGmmULTClientContext->DestroyResInfoObject(ResourceInfo);
130 }
131 
TEST_F(CTestGen11Resource,TestPlanar2D_NV12_MediaCompressedArray)132 TEST_F(CTestGen11Resource, TestPlanar2D_NV12_MediaCompressedArray)
133 {
134     /* Test planar surface with hybrid UV planes where UV plane is half the size
135     of Y and U/V data is packed together */
136     // YYYYYYYY
137     // YYYYYYYY
138     // YYYYYYYY
139     // YYYYYYYY
140     // [UV-Packing]
141     // YccsYccsYccs
142     // YccsYccsYccs
143     // UVccsUVccsUVccs
144     // UVccsUVccsUVccs
145     // ...
146 
147     const uint32_t TileSize[2] = {128, 32}; // TileY
148 
149     GMM_RESCREATE_PARAMS gmmParams        = {};
150     gmmParams.Type                        = RESOURCE_2D;
151     gmmParams.NoGfxMemory                 = 1;
152     gmmParams.Flags.Gpu.MMC               = 1;
153     gmmParams.Flags.Gpu.Texture           = 1;
154     gmmParams.Flags.Gpu.UnifiedAuxSurface = 1;
155     gmmParams.Flags.Info.TiledY           = 1;
156     gmmParams.BaseWidth64                 = 0x2048;
157     gmmParams.BaseHeight                  = 0x274;
158     gmmParams.Depth                       = 0x1;
159     gmmParams.ArraySize                   = 20;
160     SetTileFlag(gmmParams, static_cast<TEST_TILE_TYPE>(TEST_TILEY));
161     gmmParams.Format = GMM_FORMAT_NV12;
162 
163     GMM_RESOURCE_INFO *ResourceInfo;
164     //__debugbreak();
165     ResourceInfo = pGmmULTClientContext->CreateResInfoObject(&gmmParams);
166 
167     uint32_t Pitch = GMM_ULT_ALIGN(gmmParams.BaseWidth64, TileSize[0]);
168 
169     uint32_t Height = GMM_ULT_ALIGN(gmmParams.BaseHeight, TileSize[1]) +
170                    GMM_ULT_ALIGN(gmmParams.BaseHeight / 2, TileSize[1]);
171     uint32_t Size = GMM_ULT_ALIGN(Pitch * Height, GMM_KBYTE(4)) * gmmParams.ArraySize;
172 
173     VerifyResourcePitch<true>(ResourceInfo, Pitch);
174     VerifyResourcePitchInTiles<true>(ResourceInfo, Pitch / TileSize[0]);
175 
176     VerifyResourceSize<true>(ResourceInfo, Size);
177     VerifyResourceHAlign<false>(ResourceInfo, 0); // Same as any other 2D surface -- tested elsewhere
178     VerifyResourceVAlign<false>(ResourceInfo, 0); // Same as any other 2D surface -- tested elsewhere
179     VerifyResourceQPitch<false>(ResourceInfo, 0); // N/A for planar
180 
181     // Y plane should be at 0,0
182     EXPECT_EQ(0, ResourceInfo->GetPlanarXOffset(GMM_PLANE_Y));
183     EXPECT_EQ(0, ResourceInfo->GetPlanarYOffset(GMM_PLANE_Y));
184 
185     // U/V plane should be at end of Y plane
186     EXPECT_EQ(0, ResourceInfo->GetPlanarXOffset(GMM_PLANE_U));
187     EXPECT_EQ(GMM_ULT_ALIGN(gmmParams.BaseHeight, TileSize[1]), ResourceInfo->GetPlanarYOffset(GMM_PLANE_U));
188     EXPECT_EQ(0, ResourceInfo->GetPlanarXOffset(GMM_PLANE_V));
189 
190     EXPECT_EQ(GMM_ULT_ALIGN(gmmParams.BaseHeight, TileSize[1]), ResourceInfo->GetPlanarYOffset(GMM_PLANE_U));
191     EXPECT_EQ(GMM_ULT_ALIGN(gmmParams.BaseHeight, TileSize[1]), ResourceInfo->GetPlanarYOffset(GMM_PLANE_V));
192 
193     // Y Plane CCS should be at the end of NV12 surface.
194     EXPECT_EQ(Size, ResourceInfo->GetUnifiedAuxSurfaceOffset(GMM_AUX_CCS));
195     EXPECT_EQ(Size, ResourceInfo->GetUnifiedAuxSurfaceOffset(GMM_AUX_Y_CCS));
196 
197     // UV Plane CCS offset
198     uint32_t YCcsSize = GMM_ULT_ALIGN(((GMM_ULT_ALIGN(gmmParams.BaseHeight, TileSize[1]) * Pitch) / 1024), PAGE_SIZE);
199     EXPECT_EQ(Size + YCcsSize, ResourceInfo->GetUnifiedAuxSurfaceOffset(GMM_AUX_UV_CCS));
200 
201     uint32_t UVCcsSize        = GMM_ULT_ALIGN((Height - GFX_ALIGN(gmmParams.BaseHeight, TileSize[1])) * Pitch / 1024, PAGE_SIZE);
202     uint32_t MediaStateOffset = Size + YCcsSize + UVCcsSize;
203     EXPECT_EQ(MediaStateOffset, ResourceInfo->GetUnifiedAuxSurfaceOffset(GMM_AUX_COMP_STATE));
204 
205     uint32_t AuxSize = YCcsSize + UVCcsSize + PAGE_SIZE;
206     EXPECT_EQ(AuxSize * gmmParams.ArraySize, ResourceInfo->GetSizeAuxSurface(GMM_AUX_CCS));
207 
208     for(int i = 0; i < gmmParams.ArraySize; i++)
209     {
210         EXPECT_EQ(Size + AuxSize * i, ResourceInfo->GetPlanarAuxOffset(i, GMM_AUX_Y_CCS));
211         EXPECT_EQ(Size + (AuxSize * i) + YCcsSize, ResourceInfo->GetPlanarAuxOffset(i, GMM_AUX_UV_CCS));
212         EXPECT_EQ(Size + (AuxSize * i) + (YCcsSize + UVCcsSize), ResourceInfo->GetPlanarAuxOffset(i, GMM_AUX_COMP_STATE));
213     }
214 
215     pGmmULTClientContext->DestroyResInfoObject(ResourceInfo);
216 }
217 
218 /// @brief ULT for 2D TileYf Resource
TEST_F(CTestGen11Resource,Test2DTileYfResource)219 TEST_F(CTestGen11Resource, Test2DTileYfResource)
220 {
221     printf("%s\n", __FUNCTION__);
222 }
223 
224 /// @brief ULT for Plannar 2D Resource - RGBP
TEST_F(CTestGen11Resource,TestPlanar2D_RGBP)225 TEST_F(CTestGen11Resource, TestPlanar2D_RGBP)
226 {
227     /* Test planar surfaces where all planes are full-sized */
228     // YYYYYYYY
229     // YYYYYYYY
230     // YYYYYYYY
231     // YYYYYYYY
232     // UUUUUUUU
233     // UUUUUUUU
234     // UUUUUUUU
235     // UUUUUUUU
236     // VVVVVVVV
237     // VVVVVVVV
238     // VVVVVVVV
239     // VVVVVVVV
240     const TEST_TILE_TYPE TileTypes[]       = {TEST_LINEAR, TEST_TILEX, TEST_TILEY};
241     const uint32_t          PlaneRowAlignment = 16;
242 
243     const uint32_t TileSize[3][2] = {{1, 1},     //Linear
244                                   {512, 8},   // TileX
245                                   {128, 32}}; // TileY
246     for(uint32_t TileIndex = 0; TileIndex < sizeof(TileTypes) / sizeof(TileTypes[0]); TileIndex++)
247     {
248         TEST_TILE_TYPE Tile = TileTypes[TileIndex];
249 
250         GMM_RESCREATE_PARAMS gmmParams = {};
251         gmmParams.Type                 = RESOURCE_2D;
252         gmmParams.NoGfxMemory          = 1;
253         gmmParams.Flags.Gpu.Texture    = 1;
254         gmmParams.BaseWidth64          = 0x101;
255         gmmParams.BaseHeight           = 0x101;
256         gmmParams.Depth                = 0x1;
257         SetTileFlag(gmmParams, static_cast<TEST_TILE_TYPE>(Tile));
258         gmmParams.Format = GMM_FORMAT_RGBP;
259 
260         GMM_RESOURCE_INFO *ResourceInfo;
261         ResourceInfo = pGmmULTClientContext->CreateResInfoObject(&gmmParams);
262 
263         uint32_t Pitch, Height;
264         if(Tile != TEST_LINEAR)
265         {
266             Pitch = GMM_ULT_ALIGN(gmmParams.BaseWidth64, TileSize[TileIndex][0]);
267             //Since Tile alignment factor is greater than GMM_IMCx_PLANE_ROW_ALIGNMENT=16
268             Height = GMM_ULT_ALIGN(gmmParams.BaseHeight, PlaneRowAlignment);
269             Height = GMM_ULT_ALIGN(Height, TileSize[TileIndex][1]) * 3 /*Y, U, V*/;
270         }
271         else
272         {
273             Pitch  = GMM_ULT_ALIGN(gmmParams.BaseWidth64, GMM_BYTES(64));
274             Height = gmmParams.BaseHeight * 3 /*Y, U, V*/;
275         }
276 
277         uint32_t Size = GMM_ULT_ALIGN(Pitch * Height, GMM_KBYTE(4));
278 
279         VerifyResourcePitch<true>(ResourceInfo, Pitch);
280         if(Tile != TEST_LINEAR)
281         {
282             VerifyResourcePitchInTiles<true>(ResourceInfo, Pitch / TileSize[TileIndex][0]);
283         }
284         VerifyResourceSize<true>(ResourceInfo, Size);
285         VerifyResourceHAlign<false>(ResourceInfo, 0); // Same as any other 2D surface -- tested elsewhere
286         VerifyResourceVAlign<false>(ResourceInfo, 0); // Same as any other 2D surface -- tested elsewhere
287         VerifyResourceQPitch<false>(ResourceInfo, 0); // N/A for planar
288 
289         // Y plane should be at 0,0
290         EXPECT_EQ(0, ResourceInfo->GetPlanarXOffset(GMM_PLANE_Y));
291         EXPECT_EQ(0, ResourceInfo->GetPlanarYOffset(GMM_PLANE_Y));
292 
293         // U plane should be at end of Y plane
294         EXPECT_EQ(0, ResourceInfo->GetPlanarXOffset(GMM_PLANE_U));
295         EXPECT_EQ(Height / 3, ResourceInfo->GetPlanarYOffset(GMM_PLANE_U));
296 
297         // V plane should be at end of U plane
298         EXPECT_EQ(0, ResourceInfo->GetPlanarXOffset(GMM_PLANE_V));
299         EXPECT_EQ(2 * (Height / 3), ResourceInfo->GetPlanarYOffset(GMM_PLANE_V));
300 
301         pGmmULTClientContext->DestroyResInfoObject(ResourceInfo);
302     }
303 }
304 
305 /// @brief ULT for Plannar 2D Resource - RGBP
TEST_F(CTestGen11Resource,TestPlanar2DCustom_RGBP)306 TEST_F(CTestGen11Resource, TestPlanar2DCustom_RGBP)
307 {
308     /* Test planar surfaces where all planes are full-sized */
309     // YYYYYYYY
310     // YYYYYYYY
311     // YYYYYYYY
312     // YYYYYYYY
313     // UUUUUUUU
314     // UUUUUUUU
315     // UUUUUUUU
316     // UUUUUUUU
317     // VVVVVVVV
318     // VVVVVVVV
319     // VVVVVVVV
320     // VVVVVVVV
321     const TEST_TILE_TYPE TileTypes[]          = {TEST_LINEAR, TEST_TILEX, TEST_TILEY};
322     const uint32_t          PlaneRowAlignment = 16;
323 
324     const uint32_t TileSize[3][2] = {{1, 1},     //Linear
325                                   {512, 8},   // TileX
326                                   {128, 32}}; // TileY
327     for(uint32_t TileIndex = 0; TileIndex < sizeof(TileTypes) / sizeof(TileTypes[0]); TileIndex++)
328     {
329         TEST_TILE_TYPE Tile = TileTypes[TileIndex];
330 
331         GMM_RESCREATE_CUSTOM_PARAMS gmmParams = {};
332         gmmParams.Type                        = RESOURCE_2D;
333         gmmParams.Flags.Gpu.Texture           = 1;
334         gmmParams.BaseWidth64                 = 0x101;
335         gmmParams.BaseHeight                  = GMM_ULT_ALIGN(0x101, PlaneRowAlignment);
336         SetTileFlag_Custom(gmmParams, static_cast<TEST_TILE_TYPE>(Tile));
337         gmmParams.Format = GMM_FORMAT_RGBP;
338 
339         uint32_t Pitch, Height;
340 
341         Pitch  = GMM_ULT_ALIGN(gmmParams.BaseWidth64, GMM_BYTES(64));
342         Height = GMM_ULT_ALIGN(gmmParams.BaseHeight, PlaneRowAlignment /* min16 rows*/) * 3 /*Y, U, V*/;
343 
344         uint32_t Size                        = Pitch * Height;
345         gmmParams.Pitch                      = Pitch;
346         gmmParams.Size                       = Size;
347         gmmParams.PlaneOffset.X[GMM_PLANE_Y] = 0;
348         gmmParams.PlaneOffset.Y[GMM_PLANE_Y] = 0;
349         gmmParams.PlaneOffset.X[GMM_PLANE_U] = 0;
350         gmmParams.PlaneOffset.Y[GMM_PLANE_U] = Height / 3;
351         gmmParams.PlaneOffset.X[GMM_PLANE_V] = 0;
352         gmmParams.PlaneOffset.Y[GMM_PLANE_V] = 2 * (Height / 3);
353         gmmParams.NoOfPlanes                 = 3;
354 
355         GMM_RESOURCE_INFO *ResourceInfo;
356         ResourceInfo = pGmmULTClientContext->CreateCustomResInfoObject(&gmmParams);
357 
358         VerifyResourcePitch<true>(ResourceInfo, Pitch);
359         if(Tile != TEST_LINEAR)
360         {
361             VerifyResourcePitchInTiles<true>(ResourceInfo, Pitch / TileSize[TileIndex][0]);
362         }
363         VerifyResourceSize<true>(ResourceInfo, Size);
364         VerifyResourceHAlign<false>(ResourceInfo, 0); // Same as any other 2D surface -- tested elsewhere
365         VerifyResourceVAlign<false>(ResourceInfo, 0); // Same as any other 2D surface -- tested elsewhere
366         VerifyResourceQPitch<false>(ResourceInfo, 0); // N/A for planar
367 
368         // Y plane should be at 0,0
369         EXPECT_EQ(0, ResourceInfo->GetPlanarXOffset(GMM_PLANE_Y));
370         EXPECT_EQ(0, ResourceInfo->GetPlanarYOffset(GMM_PLANE_Y));
371 
372         // U plane should be at end of Y plane
373         EXPECT_EQ(0, ResourceInfo->GetPlanarXOffset(GMM_PLANE_U));
374         EXPECT_EQ(Height / 3, ResourceInfo->GetPlanarYOffset(GMM_PLANE_U));
375 
376         // V plane should be at end of U plane
377         EXPECT_EQ(0, ResourceInfo->GetPlanarXOffset(GMM_PLANE_V));
378         EXPECT_EQ(2 * (Height / 3), ResourceInfo->GetPlanarYOffset(GMM_PLANE_V));
379 
380         pGmmULTClientContext->DestroyResInfoObject(ResourceInfo);
381     }
382 }
383 
384 /// @brief ULT for Plannar 2D Resource - MFX_JPEG_YUV422V , IMC1, IMC3
TEST_F(CTestGen11Resource,TestPlanar2D_MFX_JPEG_YUV422V)385 TEST_F(CTestGen11Resource, TestPlanar2D_MFX_JPEG_YUV422V)
386 {
387     /* Test planar surfaces where both U and V are half the size of Y */
388     // YYYYYYYY
389     // YYYYYYYY
390     // YYYYYYYY
391     // YYYYYYYY
392     // UUUUUUUU
393     // UUUUUUUU
394     // VVVVVVVV
395     // VVVVVVVV
396     const TEST_TILE_TYPE TileTypes[]       = {TEST_LINEAR, TEST_TILEX, TEST_TILEY};
397     const uint32_t          PlaneRowAlignment = 16;
398     const uint32_t          TileSize[3][2]    = {{1, 1}, //Linear
399                                   {512, 8},           // TileX
400                                   {128, 32}};         // TileY
401     for(uint32_t TileIndex = 0; TileIndex < sizeof(TileTypes) / sizeof(TileTypes[0]); TileIndex++)
402     {
403         TEST_TILE_TYPE Tile = TileTypes[TileIndex];
404 
405         GMM_RESCREATE_PARAMS gmmParams = {};
406         gmmParams.Type                 = RESOURCE_2D;
407         gmmParams.NoGfxMemory          = 1;
408         gmmParams.Flags.Gpu.Texture    = 1;
409         gmmParams.BaseWidth64          = 0x101;
410         gmmParams.BaseHeight           = 0x101;
411         gmmParams.Depth                = 0x1;
412         SetTileFlag(gmmParams, static_cast<TEST_TILE_TYPE>(Tile));
413         gmmParams.Format = GMM_FORMAT_MFX_JPEG_YUV422V;
414 
415         GMM_RESOURCE_INFO *ResourceInfo;
416         ResourceInfo = pGmmULTClientContext->CreateResInfoObject(&gmmParams);
417 
418         uint32_t Pitch, Height;
419         uint32_t YHeight, VHeight;
420         if(Tile != TEST_LINEAR)
421         {
422             Pitch   = GMM_ULT_ALIGN(gmmParams.BaseWidth64, TileSize[TileIndex][0]);
423             YHeight = GMM_ULT_ALIGN(gmmParams.BaseHeight, PlaneRowAlignment);
424             YHeight = GMM_ULT_ALIGN(YHeight, TileSize[TileIndex][1]);
425 
426             VHeight = GMM_ULT_ALIGN(GMM_ULT_ALIGN(gmmParams.BaseHeight, 2) / 2, PlaneRowAlignment);
427             VHeight = GMM_ULT_ALIGN(VHeight, TileSize[TileIndex][1]);
428         }
429         else
430         {
431             Pitch   = GMM_ULT_ALIGN(gmmParams.BaseWidth64, GMM_BYTES(64));
432             YHeight = GMM_ULT_ALIGN(gmmParams.BaseHeight, PlaneRowAlignment);
433             VHeight = GMM_ULT_ALIGN(GMM_ULT_ALIGN(gmmParams.BaseHeight, 2) / 2, PlaneRowAlignment);
434         }
435         Height = YHeight + 2 * VHeight;
436 
437         uint32_t Size = GMM_ULT_ALIGN(Pitch * Height, GMM_KBYTE(4));
438 
439         VerifyResourcePitch<true>(ResourceInfo, Pitch);
440         if(Tile != TEST_LINEAR)
441         {
442             VerifyResourcePitchInTiles<true>(ResourceInfo, Pitch / TileSize[TileIndex][0]);
443         }
444         VerifyResourceSize<true>(ResourceInfo, Size);
445         VerifyResourceHAlign<false>(ResourceInfo, 0); // Same as any other 2D surface -- tested elsewhere
446         VerifyResourceVAlign<false>(ResourceInfo, 0); // Same as any other 2D surface -- tested elsewhere
447         VerifyResourceQPitch<false>(ResourceInfo, 0); // N/A for planar
448 
449         // Y plane should be at 0,0
450         EXPECT_EQ(0, ResourceInfo->GetPlanarXOffset(GMM_PLANE_Y));
451         EXPECT_EQ(0, ResourceInfo->GetPlanarYOffset(GMM_PLANE_Y));
452 
453         // U plane should be at end of Y plane
454         EXPECT_EQ(0, ResourceInfo->GetPlanarXOffset(GMM_PLANE_U));
455         EXPECT_EQ(YHeight, ResourceInfo->GetPlanarYOffset(GMM_PLANE_U));
456 
457         // V plane should be at end of U plane
458         EXPECT_EQ(0, ResourceInfo->GetPlanarXOffset(GMM_PLANE_V));
459         EXPECT_EQ(YHeight + VHeight, ResourceInfo->GetPlanarYOffset(GMM_PLANE_V));
460 
461         pGmmULTClientContext->DestroyResInfoObject(ResourceInfo);
462     }
463 }
464 
465 /// @brief ULT for Plannar 2D Resource - MFX_JPEG_YUV411R
TEST_F(CTestGen11Resource,TestPlanar2D_MFX_JPEG_YUV411R)466 TEST_F(CTestGen11Resource, TestPlanar2D_MFX_JPEG_YUV411R)
467 {
468     /* Test planar surfaces where both U and V are quarter the size of Y */
469     //YYYYYYYY
470     //YYYYYYYY
471     //YYYYYYYY
472     //YYYYYYYY
473     //UUUUUUUU
474     //VVVVVVVV
475     const TEST_TILE_TYPE TileTypes[]       = {TEST_LINEAR, TEST_TILEX, TEST_TILEY};
476     const uint32_t          PlaneRowAlignment = 16;
477     const uint32_t          TileSize[3][2]    = {{1, 1}, //Linear
478                                   {512, 8},           // TileX
479                                   {128, 32}};         // TileY
480     for(uint32_t TileIndex = 0; TileIndex < sizeof(TileTypes) / sizeof(TileTypes[0]); TileIndex++)
481     {
482         TEST_TILE_TYPE Tile = TileTypes[TileIndex];
483 
484         GMM_RESCREATE_PARAMS gmmParams = {};
485         gmmParams.Type                 = RESOURCE_2D;
486         gmmParams.NoGfxMemory          = 1;
487         gmmParams.Flags.Gpu.Texture    = 1;
488         gmmParams.BaseWidth64          = 0x101;
489         gmmParams.BaseHeight           = 0x101;
490         gmmParams.Depth                = 0x1;
491         SetTileFlag(gmmParams, static_cast<TEST_TILE_TYPE>(Tile));
492 
493         gmmParams.Format = GMM_FORMAT_MFX_JPEG_YUV411R_TYPE;
494 
495         GMM_RESOURCE_INFO *ResourceInfo;
496         ResourceInfo = pGmmULTClientContext->CreateResInfoObject(&gmmParams);
497 
498         uint32_t Pitch, Height;
499         uint32_t YHeight, VHeight;
500         if(Tile != TEST_LINEAR)
501         {
502             Pitch   = GMM_ULT_ALIGN(gmmParams.BaseWidth64, TileSize[TileIndex][0]);
503             YHeight = GMM_ULT_ALIGN(gmmParams.BaseHeight, PlaneRowAlignment);
504             YHeight = GMM_ULT_ALIGN(YHeight, TileSize[TileIndex][1]);
505 
506             VHeight = GMM_ULT_ALIGN(GMM_ULT_ALIGN(gmmParams.BaseHeight, 4) / 4, PlaneRowAlignment);
507             VHeight = GMM_ULT_ALIGN(VHeight, TileSize[TileIndex][1]);
508         }
509         else
510         {
511             Pitch   = GMM_ULT_ALIGN(gmmParams.BaseWidth64, GMM_BYTES(64));
512             YHeight = GMM_ULT_ALIGN(gmmParams.BaseHeight, PlaneRowAlignment);
513             VHeight = GMM_ULT_ALIGN(GMM_ULT_ALIGN(gmmParams.BaseHeight, 4) / 4, PlaneRowAlignment);
514         }
515 
516         Height     = YHeight + 2 * VHeight;
517         uint32_t Size = GMM_ULT_ALIGN(Pitch * Height, GMM_KBYTE(4));
518 
519         VerifyResourcePitch<true>(ResourceInfo, Pitch);
520 
521         if(Tile != TEST_LINEAR)
522         {
523             VerifyResourcePitchInTiles<true>(ResourceInfo, Pitch / TileSize[TileIndex][0]);
524         }
525         VerifyResourceSize<true>(ResourceInfo, Size);
526         VerifyResourceHAlign<false>(ResourceInfo, 0); // Same as any other 2D surface -- tested elsewhere
527         VerifyResourceVAlign<false>(ResourceInfo, 0); // Same as any other 2D surface -- tested elsewhere
528         VerifyResourceQPitch<false>(ResourceInfo, 0); // N/A for planar
529 
530         // Y plane should be at 0,0
531         EXPECT_EQ(0, ResourceInfo->GetPlanarXOffset(GMM_PLANE_Y));
532         EXPECT_EQ(0, ResourceInfo->GetPlanarYOffset(GMM_PLANE_Y));
533 
534         // U plane should be at end of Y plane
535         EXPECT_EQ(0, ResourceInfo->GetPlanarXOffset(GMM_PLANE_U));
536         EXPECT_EQ(YHeight, ResourceInfo->GetPlanarYOffset(GMM_PLANE_U));
537 
538         // V plane should be at end of U plane
539         EXPECT_EQ(0, ResourceInfo->GetPlanarXOffset(GMM_PLANE_V));
540         EXPECT_EQ(YHeight + VHeight, ResourceInfo->GetPlanarYOffset(GMM_PLANE_V));
541 
542         pGmmULTClientContext->DestroyResInfoObject(ResourceInfo);
543     }
544 }
545 
546 /// @brief ULT for Plannar 2D Resource - NV12
TEST_F(CTestGen11Resource,TestPlanar2D_NV12)547 TEST_F(CTestGen11Resource, TestPlanar2D_NV12)
548 {
549     /* Test planar surface with hybrid UV planes where UV plane is half the size
550     of Y and U/V data is packed together */
551     // YYYYYYYY
552     // YYYYYYYY
553     // YYYYYYYY
554     // YYYYYYYY
555     // [UV-Packing]
556     const TEST_TILE_TYPE TileTypes[] = {TEST_LINEAR, TEST_TILEX, TEST_TILEY};
557 
558     const uint32_t TileSize[3][2] = {{1, 1},     //Linear
559                                   {512, 8},   // TileX
560                                   {128, 32}}; // TileY
561     for(uint32_t TileIndex = 0; TileIndex < sizeof(TileTypes) / sizeof(TileTypes[0]); TileIndex++)
562     {
563         TEST_TILE_TYPE Tile = TileTypes[TileIndex];
564 
565         GMM_RESCREATE_PARAMS gmmParams = {};
566         gmmParams.Type                 = RESOURCE_2D;
567         gmmParams.NoGfxMemory          = 1;
568         gmmParams.Flags.Gpu.Texture    = 1;
569         gmmParams.BaseWidth64          = 0x100;
570         gmmParams.BaseHeight           = 0x100;
571         gmmParams.Depth                = 0x1;
572         SetTileFlag(gmmParams, static_cast<TEST_TILE_TYPE>(Tile));
573         gmmParams.Format = GMM_FORMAT_NV12;
574 
575         GMM_RESOURCE_INFO *ResourceInfo;
576         ResourceInfo = pGmmULTClientContext->CreateResInfoObject(&gmmParams);
577 
578         uint32_t Pitch, Height;
579 
580         if(Tile != TEST_LINEAR)
581         {
582             Pitch = GMM_ULT_ALIGN(gmmParams.BaseWidth64, TileSize[TileIndex][0]);
583 
584             Height = GMM_ULT_ALIGN(gmmParams.BaseHeight, TileSize[TileIndex][1]) +
585                      GMM_ULT_ALIGN(gmmParams.BaseHeight / 2, TileSize[TileIndex][1]);
586         }
587         else
588         {
589             Pitch  = GMM_ULT_ALIGN(gmmParams.BaseWidth64, TileSize[TileIndex][0]);
590             Height = GMM_ULT_ALIGN(gmmParams.BaseHeight /*Y*/ + gmmParams.BaseHeight / 2 /*UV*/, TileSize[TileIndex][1]);
591         }
592 
593         uint32_t Size = GMM_ULT_ALIGN(Pitch * Height, GMM_KBYTE(4));
594 
595         VerifyResourcePitch<true>(ResourceInfo, Pitch);
596         if(Tile != TEST_LINEAR)
597         {
598             VerifyResourcePitchInTiles<true>(ResourceInfo, Pitch / TileSize[TileIndex][0]);
599         }
600         VerifyResourceSize<true>(ResourceInfo, Size);
601         VerifyResourceHAlign<false>(ResourceInfo, 0); // Same as any other 2D surface -- tested elsewhere
602         VerifyResourceVAlign<false>(ResourceInfo, 0); // Same as any other 2D surface -- tested elsewhere
603         VerifyResourceQPitch<false>(ResourceInfo, 0); // N/A for planar
604 
605         // Y plane should be at 0,0
606         EXPECT_EQ(0, ResourceInfo->GetPlanarXOffset(GMM_PLANE_Y));
607         EXPECT_EQ(0, ResourceInfo->GetPlanarYOffset(GMM_PLANE_Y));
608 
609         // U/V plane should be at end of Y plane
610         EXPECT_EQ(0, ResourceInfo->GetPlanarXOffset(GMM_PLANE_U));
611         EXPECT_EQ(0, ResourceInfo->GetPlanarXOffset(GMM_PLANE_V));
612 
613         if(Tile != TEST_LINEAR)
614         {
615             EXPECT_EQ(GMM_ULT_ALIGN(gmmParams.BaseHeight, TileSize[TileIndex][1]), ResourceInfo->GetPlanarYOffset(GMM_PLANE_U));
616             EXPECT_EQ(GMM_ULT_ALIGN(gmmParams.BaseHeight, TileSize[TileIndex][1]), ResourceInfo->GetPlanarYOffset(GMM_PLANE_V));
617         }
618         else
619         {
620             EXPECT_EQ(gmmParams.BaseHeight, ResourceInfo->GetPlanarYOffset(GMM_PLANE_U));
621             EXPECT_EQ(gmmParams.BaseHeight, ResourceInfo->GetPlanarYOffset(GMM_PLANE_V));
622         }
623 
624         pGmmULTClientContext->DestroyResInfoObject(ResourceInfo);
625     }
626 }
627 
628 /// @brief ULT for Planar 2D Resource - IMC4
TEST_F(CTestGen11Resource,TestPlanar2D_IMC4)629 TEST_F(CTestGen11Resource, TestPlanar2D_IMC4)
630 {
631     /* Test planar surface V surface is on the right of U */
632     // YYYYYYYY
633     // YYYYYYYY
634     // YYYYYYYY
635     // YYYYYYYY
636     // UUUUVVVV
637     // UUUUVVVV
638     const TEST_TILE_TYPE TileTypes[]       = {TEST_LINEAR, TEST_TILEX, TEST_TILEY};
639     const uint32_t          PlaneRowAlignment = 16;
640     const uint32_t          TileSize[3][2]    = {{1, 1}, //Linear
641                                   {512, 8},           // TileX
642                                   {128, 32}};         // TileY
643     for(uint32_t TileIndex = 0; TileIndex < sizeof(TileTypes) / sizeof(TileTypes[0]); TileIndex++)
644     {
645         TEST_TILE_TYPE Tile = TileTypes[TileIndex];
646 
647         GMM_RESCREATE_PARAMS gmmParams = {};
648         gmmParams.Type                 = RESOURCE_2D;
649         gmmParams.NoGfxMemory          = 1;
650         gmmParams.Flags.Gpu.Texture    = 1;
651         gmmParams.BaseWidth64          = 0x101;
652         gmmParams.BaseHeight           = 0x101;
653         gmmParams.Depth                = 0x1;
654         SetTileFlag(gmmParams, static_cast<TEST_TILE_TYPE>(Tile));
655         gmmParams.Format = GMM_FORMAT_IMC4;
656 
657         GMM_RESOURCE_INFO *ResourceInfo;
658         ResourceInfo = pGmmULTClientContext->CreateResInfoObject(&gmmParams);
659 
660         uint32_t Pitch, Height;
661         uint32_t YHeight, VHeight;
662         if(Tile != TEST_LINEAR)
663         {
664             Pitch = GMM_ULT_ALIGN(gmmParams.BaseWidth64, TileSize[TileIndex][0]);
665             if(Pitch / TileSize[TileIndex][0] % 2)
666             {
667                 Pitch += TileSize[TileIndex][0];
668             }
669 
670             YHeight = GMM_ULT_ALIGN(gmmParams.BaseHeight, PlaneRowAlignment);
671             VHeight = YHeight / 2;
672 
673             YHeight = GMM_ULT_ALIGN(YHeight, TileSize[TileIndex][1]);
674             VHeight = GMM_ULT_ALIGN(VHeight, TileSize[TileIndex][1]); // No need of PlaneRowAlignment since last plane
675         }
676         else
677         {
678             Pitch   = GMM_ULT_ALIGN(gmmParams.BaseWidth64, GMM_BYTES(64));
679             YHeight = GMM_ULT_ALIGN(gmmParams.BaseHeight, PlaneRowAlignment);
680             VHeight = YHeight / 2;
681         }
682 
683         Height = YHeight + VHeight;
684 
685         uint32_t Size = GMM_ULT_ALIGN(Pitch * Height, GMM_KBYTE(4));
686 
687         VerifyResourcePitch<true>(ResourceInfo, Pitch);
688 
689         if(Tile != TEST_LINEAR)
690         {
691             VerifyResourcePitchInTiles<true>(ResourceInfo, Pitch / TileSize[TileIndex][0]);
692         }
693         VerifyResourceSize<true>(ResourceInfo, Size);
694         VerifyResourceHAlign<false>(ResourceInfo, 0); // Same as any other 2D surface -- tested elsewhere
695         VerifyResourceVAlign<false>(ResourceInfo, 0); // Same as any other 2D surface -- tested elsewhere
696         VerifyResourceQPitch<false>(ResourceInfo, 0); // N/A for planar
697 
698         // Y plane should be at 0,0
699         EXPECT_EQ(0, ResourceInfo->GetPlanarXOffset(GMM_PLANE_Y));
700         EXPECT_EQ(0, ResourceInfo->GetPlanarYOffset(GMM_PLANE_Y));
701 
702         // U plane should be at end of Y plane
703         // V plane should be at end of U plane
704         EXPECT_EQ(0, ResourceInfo->GetPlanarXOffset(GMM_PLANE_U));
705         EXPECT_EQ(Pitch / 2, ResourceInfo->GetPlanarXOffset(GMM_PLANE_V));
706 
707         if(Tile != TEST_LINEAR)
708         {
709             EXPECT_EQ(YHeight, ResourceInfo->GetPlanarYOffset(GMM_PLANE_U));
710             EXPECT_EQ(YHeight, ResourceInfo->GetPlanarYOffset(GMM_PLANE_V));
711         }
712         else
713         {
714             EXPECT_EQ(YHeight, ResourceInfo->GetPlanarYOffset(GMM_PLANE_U));
715             EXPECT_EQ(YHeight, ResourceInfo->GetPlanarYOffset(GMM_PLANE_V));
716         }
717 
718         pGmmULTClientContext->DestroyResInfoObject(ResourceInfo);
719     }
720 }
721