1 /*
2 * Copyright (C) 2021 Intel Corporation
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 */
7
8 #include "shared/source/gmm_helper/gmm.h"
9 #include "shared/source/gmm_helper/gmm_helper.h"
10 #include "shared/source/memory_manager/memory_manager.h"
11 #include "shared/source/os_interface/os_interface.h"
12 #include "shared/test/common/helpers/debug_manager_state_restore.h"
13 #include "shared/test/common/helpers/unit_test_helper.h"
14 #include "shared/test/common/helpers/variable_backup.h"
15 #include "shared/test/common/mocks/mock_allocation_properties.h"
16 #include "shared/test/common/mocks/mock_gmm.h"
17 #include "shared/test/common/mocks/mock_gmm_client_context.h"
18 #include "shared/test/common/test_macros/test.h"
19
20 #include "opencl/test/unit_test/fixtures/image_fixture.h"
21 #include "opencl/test/unit_test/mem_obj/image_compression_fixture.h"
22 #include "opencl/test/unit_test/mocks/mock_context.h"
23 #include "opencl/test/unit_test/mocks/mock_platform.h"
24
25 #include "test_traits_common.h"
26
27 #include <functional>
28
29 using namespace NEO;
30
31 using XeHPAndLaterImageTests = ::testing::Test;
32 using isXePlatform = IsWithinGfxCore<IGFX_XE_HP_CORE, IGFX_XE_HPC_CORE>;
33
HWTEST2_F(XeHPAndLaterImageTests,givenContextTypeDefaultWhenImageIsWritableAndOnlyOneTileIsAvailableThenRemainFlagsToTrue,isXePlatform)34 HWTEST2_F(XeHPAndLaterImageTests, givenContextTypeDefaultWhenImageIsWritableAndOnlyOneTileIsAvailableThenRemainFlagsToTrue, isXePlatform) {
35 DebugManagerStateRestore restorer;
36 DebugManager.flags.CreateMultipleSubDevices.set(1);
37 initPlatform();
38 EXPECT_EQ(0u, platform()->getClDevice(0)->getNumGenericSubDevices());
39 using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE;
40 MockContext context(platform()->getClDevice(0));
41 context.contextType = ContextType::CONTEXT_TYPE_DEFAULT;
42
43 cl_int retVal = CL_SUCCESS;
44 cl_image_format imageFormat = {};
45 cl_image_desc imageDesc = {};
46
47 imageFormat.image_channel_data_type = CL_UNORM_INT8;
48 imageFormat.image_channel_order = CL_RGBA;
49
50 imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
51 imageDesc.image_height = 128;
52 imageDesc.image_width = 256;
53
54 auto surfaceFormat = Image::getSurfaceFormatFromTable(
55 CL_MEM_READ_WRITE, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);
56 auto image = std::unique_ptr<Image>(Image::create(
57 &context, ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_READ_WRITE, 0, 0, &context.getDevice(0)->getDevice()),
58 CL_MEM_READ_WRITE, 0, surfaceFormat, &imageDesc, NULL, retVal));
59 auto imageHw = static_cast<ImageHw<FamilyType> *>(image.get());
60
61 RENDER_SURFACE_STATE surfaceState = FamilyType::cmdInitRenderSurfaceState;
62 EXPECT_TRUE(surfaceState.getDisableSupportForMultiGpuAtomics());
63 EXPECT_TRUE(surfaceState.getDisableSupportForMultiGpuPartialWrites());
64
65 surfaceState.setDisableSupportForMultiGpuAtomics(false);
66 surfaceState.setDisableSupportForMultiGpuPartialWrites(false);
67 imageHw->appendSurfaceStateParams(&surfaceState, context.getDevice(0)->getRootDeviceIndex(), true);
68
69 EXPECT_TRUE(surfaceState.getDisableSupportForMultiGpuAtomics());
70 EXPECT_TRUE(surfaceState.getDisableSupportForMultiGpuPartialWrites());
71 }
72
HWTEST2_F(XeHPAndLaterImageTests,givenContextTypeDefaultWhenImageIsWritableThenFlipPartialFlagsToFalse,isXePlatform)73 HWTEST2_F(XeHPAndLaterImageTests, givenContextTypeDefaultWhenImageIsWritableThenFlipPartialFlagsToFalse, isXePlatform) {
74 DebugManagerStateRestore restorer;
75 DebugManager.flags.CreateMultipleSubDevices.set(4);
76 initPlatform();
77
78 using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE;
79 MockContext context(platform()->getClDevice(0));
80 context.contextType = ContextType::CONTEXT_TYPE_DEFAULT;
81
82 cl_int retVal = CL_SUCCESS;
83 cl_image_format imageFormat = {};
84 cl_image_desc imageDesc = {};
85
86 imageFormat.image_channel_data_type = CL_UNORM_INT8;
87 imageFormat.image_channel_order = CL_RGBA;
88
89 imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
90 imageDesc.image_height = 128;
91 imageDesc.image_width = 256;
92
93 auto surfaceFormat = Image::getSurfaceFormatFromTable(
94 CL_MEM_READ_WRITE, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);
95 auto image = std::unique_ptr<Image>(Image::create(
96 &context, ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_READ_WRITE, 0, 0, &context.getDevice(0)->getDevice()),
97 CL_MEM_READ_WRITE, 0, surfaceFormat, &imageDesc, NULL, retVal));
98 auto imageHw = static_cast<ImageHw<FamilyType> *>(image.get());
99
100 RENDER_SURFACE_STATE surfaceState = FamilyType::cmdInitRenderSurfaceState;
101 EXPECT_TRUE(surfaceState.getDisableSupportForMultiGpuAtomics());
102 EXPECT_TRUE(surfaceState.getDisableSupportForMultiGpuPartialWrites());
103
104 imageHw->appendSurfaceStateParams(&surfaceState, context.getDevice(0)->getRootDeviceIndex(), true);
105
106 EXPECT_FALSE(surfaceState.getDisableSupportForMultiGpuAtomics());
107 EXPECT_FALSE(surfaceState.getDisableSupportForMultiGpuPartialWrites());
108 }
109
HWTEST2_F(XeHPAndLaterImageTests,givenDebugFlagForMultiTileSupportWhenSurfaceStateIsProgrammedThenItHasDesiredValues,isXePlatform)110 HWTEST2_F(XeHPAndLaterImageTests, givenDebugFlagForMultiTileSupportWhenSurfaceStateIsProgrammedThenItHasDesiredValues, isXePlatform) {
111 DebugManagerStateRestore restorer;
112 using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE;
113 MockContext context;
114 context.contextType = ContextType::CONTEXT_TYPE_DEFAULT;
115
116 cl_int retVal = CL_SUCCESS;
117 cl_image_format imageFormat = {};
118 cl_image_desc imageDesc = {};
119
120 imageFormat.image_channel_data_type = CL_UNORM_INT8;
121 imageFormat.image_channel_order = CL_RGBA;
122
123 imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
124 imageDesc.image_height = 128;
125 imageDesc.image_width = 256;
126
127 auto surfaceFormat = Image::getSurfaceFormatFromTable(
128 CL_MEM_READ_ONLY, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);
129 auto image = std::unique_ptr<Image>(Image::create(
130 &context, ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_READ_WRITE, 0, 0, &context.getDevice(0)->getDevice()),
131 CL_MEM_READ_WRITE, 0, surfaceFormat, &imageDesc, NULL, retVal));
132 auto imageHw = static_cast<ImageHw<FamilyType> *>(image.get());
133
134 RENDER_SURFACE_STATE surfaceState = FamilyType::cmdInitRenderSurfaceState;
135
136 DebugManager.flags.ForceMultiGpuAtomics.set(0);
137 DebugManager.flags.ForceMultiGpuPartialWrites.set(0);
138
139 imageHw->appendSurfaceStateParams(&surfaceState, context.getDevice(0)->getRootDeviceIndex(), true);
140
141 EXPECT_EQ(0u, surfaceState.getDisableSupportForMultiGpuAtomics());
142 EXPECT_EQ(0u, surfaceState.getDisableSupportForMultiGpuPartialWrites());
143
144 DebugManager.flags.ForceMultiGpuAtomics.set(1);
145 DebugManager.flags.ForceMultiGpuPartialWrites.set(1);
146
147 imageHw->appendSurfaceStateParams(&surfaceState, context.getDevice(0)->getRootDeviceIndex(), true);
148
149 EXPECT_EQ(1u, surfaceState.getDisableSupportForMultiGpuAtomics());
150 EXPECT_EQ(1u, surfaceState.getDisableSupportForMultiGpuPartialWrites());
151 }
152
HWTEST2_F(XeHPAndLaterImageTests,givenContextTypeUnrestrictiveWhenImageIsWritableThenFlipPartialFlagsToFalse,isXePlatform)153 HWTEST2_F(XeHPAndLaterImageTests, givenContextTypeUnrestrictiveWhenImageIsWritableThenFlipPartialFlagsToFalse, isXePlatform) {
154 DebugManagerStateRestore restorer;
155 DebugManager.flags.CreateMultipleSubDevices.set(4);
156 initPlatform();
157
158 using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE;
159 MockContext context(platform()->getClDevice(0));
160 context.contextType = ContextType::CONTEXT_TYPE_UNRESTRICTIVE;
161
162 cl_int retVal = CL_SUCCESS;
163 cl_image_format imageFormat = {};
164 cl_image_desc imageDesc = {};
165
166 imageFormat.image_channel_data_type = CL_UNORM_INT8;
167 imageFormat.image_channel_order = CL_RGBA;
168
169 imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
170 imageDesc.image_height = 128;
171 imageDesc.image_width = 256;
172
173 auto surfaceFormat = Image::getSurfaceFormatFromTable(
174 CL_MEM_READ_WRITE, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);
175 auto image = std::unique_ptr<Image>(Image::create(
176 &context, ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_READ_WRITE, 0, 0, &context.getDevice(0)->getDevice()),
177 CL_MEM_READ_WRITE, 0, surfaceFormat, &imageDesc, NULL, retVal));
178 auto imageHw = static_cast<ImageHw<FamilyType> *>(image.get());
179
180 RENDER_SURFACE_STATE surfaceState = FamilyType::cmdInitRenderSurfaceState;
181 EXPECT_TRUE(surfaceState.getDisableSupportForMultiGpuAtomics());
182 EXPECT_TRUE(surfaceState.getDisableSupportForMultiGpuPartialWrites());
183
184 imageHw->appendSurfaceStateParams(&surfaceState, context.getDevice(0)->getRootDeviceIndex(), true);
185
186 EXPECT_FALSE(surfaceState.getDisableSupportForMultiGpuAtomics());
187 EXPECT_FALSE(surfaceState.getDisableSupportForMultiGpuPartialWrites());
188 }
189
HWTEST2_F(XeHPAndLaterImageTests,givenContextTypeDefaultWhenImageIsNotWritableThenRemainPartialFlagsToTrue,isXePlatform)190 HWTEST2_F(XeHPAndLaterImageTests, givenContextTypeDefaultWhenImageIsNotWritableThenRemainPartialFlagsToTrue, isXePlatform) {
191 using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE;
192 MockContext context;
193 context.contextType = ContextType::CONTEXT_TYPE_DEFAULT;
194
195 cl_int retVal = CL_SUCCESS;
196 cl_image_format imageFormat = {};
197 cl_image_desc imageDesc = {};
198
199 imageFormat.image_channel_data_type = CL_UNORM_INT8;
200 imageFormat.image_channel_order = CL_RGBA;
201
202 imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
203 imageDesc.image_height = 128;
204 imageDesc.image_width = 256;
205
206 auto surfaceFormat = Image::getSurfaceFormatFromTable(
207 CL_MEM_READ_ONLY, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);
208 auto image = std::unique_ptr<Image>(Image::create(
209 &context, ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_READ_WRITE, 0, 0, &context.getDevice(0)->getDevice()),
210 CL_MEM_READ_WRITE, 0, surfaceFormat, &imageDesc, NULL, retVal));
211 auto imageHw = static_cast<ImageHw<FamilyType> *>(image.get());
212
213 RENDER_SURFACE_STATE surfaceState = FamilyType::cmdInitRenderSurfaceState;
214 EXPECT_TRUE(surfaceState.getDisableSupportForMultiGpuAtomics());
215 EXPECT_TRUE(surfaceState.getDisableSupportForMultiGpuPartialWrites());
216
217 surfaceState.setDisableSupportForMultiGpuAtomics(false);
218 surfaceState.setDisableSupportForMultiGpuPartialWrites(false);
219 imageHw->appendSurfaceStateParams(&surfaceState, context.getDevice(0)->getRootDeviceIndex(), true);
220
221 EXPECT_TRUE(surfaceState.getDisableSupportForMultiGpuAtomics());
222 EXPECT_TRUE(surfaceState.getDisableSupportForMultiGpuPartialWrites());
223 }
224
HWTEST2_F(XeHPAndLaterImageTests,givenContextTypeSpecializedWhenImageIsWritableThenRemainPartialFlagsToTrue,isXePlatform)225 HWTEST2_F(XeHPAndLaterImageTests, givenContextTypeSpecializedWhenImageIsWritableThenRemainPartialFlagsToTrue, isXePlatform) {
226 using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE;
227 MockContext context;
228 context.contextType = ContextType::CONTEXT_TYPE_SPECIALIZED;
229
230 cl_int retVal = CL_SUCCESS;
231 cl_image_format imageFormat = {};
232 cl_image_desc imageDesc = {};
233
234 imageFormat.image_channel_data_type = CL_UNORM_INT8;
235 imageFormat.image_channel_order = CL_RGBA;
236
237 imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
238 imageDesc.image_height = 128;
239 imageDesc.image_width = 256;
240
241 auto surfaceFormat = Image::getSurfaceFormatFromTable(
242 CL_MEM_READ_WRITE, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);
243 auto image = std::unique_ptr<Image>(Image::create(
244 &context, ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_READ_WRITE, 0, 0, &context.getDevice(0)->getDevice()),
245 CL_MEM_READ_WRITE, 0, surfaceFormat, &imageDesc, NULL, retVal));
246 auto imageHw = static_cast<ImageHw<FamilyType> *>(image.get());
247
248 RENDER_SURFACE_STATE surfaceState = FamilyType::cmdInitRenderSurfaceState;
249 EXPECT_TRUE(surfaceState.getDisableSupportForMultiGpuAtomics());
250 EXPECT_TRUE(surfaceState.getDisableSupportForMultiGpuPartialWrites());
251
252 surfaceState.setDisableSupportForMultiGpuAtomics(false);
253 surfaceState.setDisableSupportForMultiGpuPartialWrites(false);
254 imageHw->appendSurfaceStateParams(&surfaceState, context.getDevice(0)->getRootDeviceIndex(), true);
255
256 EXPECT_TRUE(surfaceState.getDisableSupportForMultiGpuAtomics());
257 EXPECT_TRUE(surfaceState.getDisableSupportForMultiGpuPartialWrites());
258 }
259
260 struct MultiGpuGlobalAtomicsImageTest : public XeHPAndLaterImageTests,
261 public ::testing::WithParamInterface<std::tuple<unsigned int, unsigned int, ContextType, bool, bool>> {
262 };
263
HWTEST2_P(MultiGpuGlobalAtomicsImageTest,givenAppendSurfaceStateParamCalledThenDisableSupportForMultiGpuAtomicsIsSetCorrectly,isXePlatform)264 HWTEST2_P(MultiGpuGlobalAtomicsImageTest, givenAppendSurfaceStateParamCalledThenDisableSupportForMultiGpuAtomicsIsSetCorrectly, isXePlatform) {
265 unsigned int numAvailableDevices, memFlags;
266 ContextType contextType;
267 bool useGlobalAtomics, enableMultiGpuAtomicsOptimization;
268 std::tie(numAvailableDevices, memFlags, contextType, useGlobalAtomics, enableMultiGpuAtomicsOptimization) = GetParam();
269
270 DebugManagerStateRestore restorer;
271 DebugManager.flags.EnableMultiGpuAtomicsOptimization.set(enableMultiGpuAtomicsOptimization);
272 DebugManager.flags.CreateMultipleSubDevices.set(numAvailableDevices);
273 initPlatform();
274 if (numAvailableDevices == 1) {
275 EXPECT_EQ(0u, platform()->getClDevice(0)->getNumGenericSubDevices());
276 } else {
277 EXPECT_EQ(numAvailableDevices, platform()->getClDevice(0)->getNumGenericSubDevices());
278 }
279 using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE;
280 MockContext context(platform()->getClDevice(0));
281 context.contextType = contextType;
282
283 cl_int retVal = CL_SUCCESS;
284 cl_image_format imageFormat = {};
285 cl_image_desc imageDesc = {};
286
287 imageFormat.image_channel_data_type = CL_UNORM_INT8;
288 imageFormat.image_channel_order = CL_RGBA;
289
290 imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
291 imageDesc.image_height = 128;
292 imageDesc.image_width = 256;
293
294 auto surfaceFormat = Image::getSurfaceFormatFromTable(
295 memFlags, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);
296 auto image = std::unique_ptr<Image>(Image::create(
297 &context, ClMemoryPropertiesHelper::createMemoryProperties(memFlags, 0, 0, &context.getDevice(0)->getDevice()),
298 memFlags, 0, surfaceFormat, &imageDesc, NULL, retVal));
299 auto imageHw = static_cast<ImageHw<FamilyType> *>(image.get());
300
301 RENDER_SURFACE_STATE surfaceState = FamilyType::cmdInitRenderSurfaceState;
302 EXPECT_TRUE(surfaceState.getDisableSupportForMultiGpuAtomics());
303
304 surfaceState.setDisableSupportForMultiGpuAtomics(false);
305 surfaceState.setDisableSupportForMultiGpuPartialWrites(false);
306 imageHw->appendSurfaceStateParams(&surfaceState, context.getDevice(0)->getRootDeviceIndex(), useGlobalAtomics);
307
308 bool enableGlobalAtomics = (contextType != ContextType::CONTEXT_TYPE_SPECIALIZED) && (numAvailableDevices > 1);
309 if (enableMultiGpuAtomicsOptimization) {
310 enableGlobalAtomics &= useGlobalAtomics;
311 }
312 EXPECT_EQ(!enableGlobalAtomics, surfaceState.getDisableSupportForMultiGpuAtomics());
313 }
314
315 static unsigned int numAvailableDevices[] = {1, 2};
316 static unsigned int memFlags[] = {CL_MEM_READ_ONLY, CL_MEM_READ_WRITE};
317 static ContextType contextTypes[] = {ContextType::CONTEXT_TYPE_DEFAULT, ContextType::CONTEXT_TYPE_SPECIALIZED, ContextType::CONTEXT_TYPE_UNRESTRICTIVE};
318
319 INSTANTIATE_TEST_CASE_P(MultiGpuGlobalAtomicsImageTest,
320 MultiGpuGlobalAtomicsImageTest,
321 ::testing::Combine(
322 ::testing::ValuesIn(numAvailableDevices),
323 ::testing::ValuesIn(memFlags),
324 ::testing::ValuesIn(contextTypes),
325 ::testing::Bool(),
326 ::testing::Bool()));
327
HWCMDTEST_F(IGFX_XE_HP_CORE,XeHPAndLaterImageTests,WhenAppendingSurfaceStateParamsThenDoNothing)328 HWCMDTEST_F(IGFX_XE_HP_CORE, XeHPAndLaterImageTests, WhenAppendingSurfaceStateParamsThenDoNothing) {
329 typedef typename FamilyType::RENDER_SURFACE_STATE RENDER_SURFACE_STATE;
330 MockContext context;
331 auto image = std::unique_ptr<Image>(ImageHelper<Image1dDefaults>::create(&context));
332 auto surfaceStateBefore = FamilyType::cmdInitRenderSurfaceState;
333 auto surfaceStateAfter = FamilyType::cmdInitRenderSurfaceState;
334 auto imageHw = static_cast<ImageHw<FamilyType> *>(image.get());
335
336 EXPECT_EQ(0, memcmp(&surfaceStateBefore, &surfaceStateAfter, sizeof(RENDER_SURFACE_STATE)));
337
338 imageHw->appendSurfaceStateParams(&surfaceStateAfter, context.getDevice(0)->getRootDeviceIndex(), true);
339
340 EXPECT_EQ(0, memcmp(&surfaceStateBefore, &surfaceStateAfter, sizeof(RENDER_SURFACE_STATE)));
341 }
342
HWCMDTEST_F(IGFX_XE_HP_CORE,XeHPAndLaterImageTests,givenCompressionEnabledWhenAppendingSurfaceStateParamsThenProgramCompressionFormat)343 HWCMDTEST_F(IGFX_XE_HP_CORE, XeHPAndLaterImageTests, givenCompressionEnabledWhenAppendingSurfaceStateParamsThenProgramCompressionFormat) {
344 MockContext context;
345 auto mockGmmClient = static_cast<MockGmmClientContext *>(context.getDevice(0)->getRootDeviceEnvironment().getGmmClientContext());
346 typedef typename FamilyType::RENDER_SURFACE_STATE RENDER_SURFACE_STATE;
347 auto image = std::unique_ptr<Image>(ImageHelper<Image2dDefaults>::create(&context));
348 auto imageHw = static_cast<ImageHw<FamilyType> *>(image.get());
349
350 mockGmmClient->capturedFormat = GMM_FORMAT_INVALID;
351 auto surfaceState = FamilyType::cmdInitRenderSurfaceState;
352 surfaceState.setAuxiliarySurfaceMode(RENDER_SURFACE_STATE::AUXILIARY_SURFACE_MODE::AUXILIARY_SURFACE_MODE_AUX_NONE);
353 imageHw->setImageArg(&surfaceState, false, 0, context.getDevice(0)->getRootDeviceIndex(), false);
354 EXPECT_EQ(0u, surfaceState.getCompressionFormat());
355 EXPECT_EQ(GMM_FORMAT_INVALID, mockGmmClient->capturedFormat);
356
357 auto gmm = image->getMultiGraphicsAllocation().getDefaultGraphicsAllocation()->getDefaultGmm();
358 gmm->isCompressionEnabled = true;
359
360 surfaceState = FamilyType::cmdInitRenderSurfaceState;
361 imageHw->setImageArg(&surfaceState, false, 0, context.getDevice(0)->getRootDeviceIndex(), false);
362 EXPECT_TRUE(EncodeSurfaceState<FamilyType>::isAuxModeEnabled(&surfaceState, gmm));
363
364 EXPECT_NE(0u, surfaceState.getCompressionFormat());
365 EXPECT_EQ(image->getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex())->getDefaultGmm()->gmmResourceInfo->getResourceFormat(), mockGmmClient->capturedFormat);
366 }
367
HWCMDTEST_F(IGFX_XE_HP_CORE,XeHPAndLaterImageTests,givenCompressionWhenAppendingImageFromBufferThenTwoIsSetAsCompressionFormat)368 HWCMDTEST_F(IGFX_XE_HP_CORE, XeHPAndLaterImageTests, givenCompressionWhenAppendingImageFromBufferThenTwoIsSetAsCompressionFormat) {
369 typedef typename FamilyType::RENDER_SURFACE_STATE RENDER_SURFACE_STATE;
370 MockContext context;
371
372 uint32_t compressionFormat = context.getDevice(0)->getGmmHelper()->getClientContext()->getSurfaceStateCompressionFormat(GMM_RESOURCE_FORMAT::GMM_FORMAT_GENERIC_8BIT);
373
374 cl_int retVal = CL_SUCCESS;
375 cl_image_format imageFormat = {};
376 cl_image_desc imageDesc = {};
377
378 imageFormat.image_channel_data_type = CL_UNORM_INT8;
379 imageFormat.image_channel_order = CL_RGBA;
380
381 imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
382 imageDesc.image_height = 128;
383 imageDesc.image_width = 256;
384
385 imageDesc.mem_object = clCreateBuffer(&context, CL_MEM_READ_WRITE, 128 * 256 * 4, nullptr, &retVal);
386
387 auto gmm = new Gmm(context.getDevice(0)->getGmmHelper()->getClientContext(), nullptr, 1, 0, false);
388 gmm->isCompressionEnabled = true;
389
390 auto buffer = castToObject<Buffer>(imageDesc.mem_object);
391 buffer->getGraphicsAllocation(0)->setGmm(gmm, 0);
392
393 auto surfaceFormat = Image::getSurfaceFormatFromTable(
394 CL_MEM_READ_WRITE, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);
395 auto image = std::unique_ptr<Image>(Image::create(
396 &context, ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_READ_WRITE, 0, 0, &context.getDevice(0)->getDevice()),
397 CL_MEM_READ_WRITE, 0, surfaceFormat, &imageDesc, NULL, retVal));
398 auto imageHw = static_cast<ImageHw<FamilyType> *>(image.get());
399 auto surfaceState = FamilyType::cmdInitRenderSurfaceState;
400 imageHw->setImageArg(&surfaceState, false, 0, context.getDevice(0)->getRootDeviceIndex(), false);
401 EXPECT_TRUE(EncodeSurfaceState<FamilyType>::isAuxModeEnabled(&surfaceState, gmm));
402
403 EXPECT_EQ(compressionFormat, surfaceState.getCompressionFormat());
404 clReleaseMemObject(imageDesc.mem_object);
405 }
406
HWCMDTEST_F(IGFX_XE_HP_CORE,XeHPAndLaterImageTests,givenImageFromBufferWhenSettingSurfaceStateThenPickCompressionFormatFromDebugVariable)407 HWCMDTEST_F(IGFX_XE_HP_CORE, XeHPAndLaterImageTests, givenImageFromBufferWhenSettingSurfaceStateThenPickCompressionFormatFromDebugVariable) {
408 typedef typename FamilyType::RENDER_SURFACE_STATE RENDER_SURFACE_STATE;
409 DebugManagerStateRestore restorer;
410
411 uint32_t bufferCompressionFormat = 3;
412 DebugManager.flags.ForceBufferCompressionFormat.set(bufferCompressionFormat);
413
414 MockContext context;
415 cl_int retVal = CL_SUCCESS;
416 cl_image_format imageFormat = {};
417 cl_image_desc imageDesc = {};
418
419 imageFormat.image_channel_data_type = CL_UNORM_INT8;
420 imageFormat.image_channel_order = CL_RGBA;
421
422 imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
423 imageDesc.image_height = 128;
424 imageDesc.image_width = 256;
425
426 imageDesc.mem_object = clCreateBuffer(&context, CL_MEM_READ_WRITE, 128 * 256 * 4, nullptr, &retVal);
427
428 auto gmm = new Gmm(context.getDevice(0)->getGmmHelper()->getClientContext(), nullptr, 1, 0, false);
429 gmm->isCompressionEnabled = true;
430
431 auto buffer = castToObject<Buffer>(imageDesc.mem_object);
432 buffer->getGraphicsAllocation(0)->setGmm(gmm, 0);
433
434 auto surfaceFormat = Image::getSurfaceFormatFromTable(CL_MEM_READ_WRITE, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);
435 auto image = std::unique_ptr<Image>(Image::create(&context, ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_READ_WRITE, 0, 0, &context.getDevice(0)->getDevice()),
436 CL_MEM_READ_WRITE, 0, surfaceFormat, &imageDesc, NULL, retVal));
437 auto imageHw = static_cast<ImageHw<FamilyType> *>(image.get());
438
439 auto surfaceState = FamilyType::cmdInitRenderSurfaceState;
440 imageHw->setImageArg(&surfaceState, false, 0, context.getDevice(0)->getRootDeviceIndex(), false);
441 EXPECT_TRUE(EncodeSurfaceState<FamilyType>::isAuxModeEnabled(&surfaceState, gmm));
442
443 EXPECT_EQ(bufferCompressionFormat, surfaceState.getCompressionFormat());
444 clReleaseMemObject(imageDesc.mem_object);
445 }
446
447 struct CompressionParamsSupportedMatcher {
448 template <PRODUCT_FAMILY productFamily>
isMatchedCompressionParamsSupportedMatcher449 static constexpr bool isMatched() {
450 if constexpr (HwMapper<productFamily>::GfxProduct::supportsCmdSet(IGFX_XE_HP_CORE)) {
451 return TestTraits<NEO::ToGfxCoreFamily<productFamily>::get()>::surfaceStateCompressionParamsSupported;
452 }
453 return false;
454 }
455 };
456
HWTEST2_F(XeHPAndLaterImageTests,givenMcsAllocationWhenSetArgIsCalledWithUnifiedAuxCapabilityAndMCSThenProgramAuxFieldsForCcs,CompressionParamsSupportedMatcher)457 HWTEST2_F(XeHPAndLaterImageTests, givenMcsAllocationWhenSetArgIsCalledWithUnifiedAuxCapabilityAndMCSThenProgramAuxFieldsForCcs, CompressionParamsSupportedMatcher) {
458 using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE;
459 using AUXILIARY_SURFACE_MODE = typename RENDER_SURFACE_STATE::AUXILIARY_SURFACE_MODE;
460 using SURFACE_TYPE = typename RENDER_SURFACE_STATE::SURFACE_TYPE;
461 MockContext context;
462 McsSurfaceInfo msi = {10, 20, 3};
463 auto mcsAlloc = context.getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{context.getDevice(0)->getRootDeviceIndex(), MemoryConstants::pageSize});
464
465 cl_image_desc imgDesc = Image2dDefaults::imageDesc;
466 imgDesc.num_samples = 8;
467 std::unique_ptr<Image> image(Image2dHelper<>::create(&context, &imgDesc));
468
469 auto surfaceState = FamilyType::cmdInitRenderSurfaceState;
470 auto imageHw = static_cast<ImageHw<FamilyType> *>(image.get());
471 mcsAlloc->setDefaultGmm(new Gmm(context.getDevice(0)->getRootDeviceEnvironment().getGmmClientContext(), nullptr, 1, 0, false));
472 surfaceState.setSurfaceBaseAddress(0xABCDEF1000);
473 imageHw->setMcsSurfaceInfo(msi);
474 imageHw->setMcsAllocation(mcsAlloc);
475 auto mockResource = static_cast<MockGmmResourceInfo *>(mcsAlloc->getDefaultGmm()->gmmResourceInfo.get());
476 mockResource->setUnifiedAuxTranslationCapable();
477 mockResource->setMultisampleControlSurface();
478
479 EXPECT_EQ(0u, surfaceState.getAuxiliarySurfaceBaseAddress());
480
481 imageHw->setAuxParamsForMultisamples(&surfaceState);
482
483 EXPECT_NE(0u, surfaceState.getAuxiliarySurfaceBaseAddress());
484 EXPECT_EQ(surfaceState.getAuxiliarySurfaceMode(), AUXILIARY_SURFACE_MODE::AUXILIARY_SURFACE_MODE_AUX_MCS_LCE);
485 }
486
HWTEST2_F(ImageClearColorFixture,givenImageForXeHPAndLaterWhenClearColorParametersAreSetThenClearColorSurfaceInSurfaceStateIsSet,CompressionParamsSupportedMatcher)487 HWTEST2_F(ImageClearColorFixture, givenImageForXeHPAndLaterWhenClearColorParametersAreSetThenClearColorSurfaceInSurfaceStateIsSet, CompressionParamsSupportedMatcher) {
488 this->setUpImpl<FamilyType>();
489 auto surfaceState = this->getSurfaceState<FamilyType>();
490
491 surfaceState.setSurfaceBaseAddress(0xABCDEF1000);
492
493 EXPECT_EQ(false, surfaceState.getClearValueAddressEnable());
494 EXPECT_EQ(0u, surfaceState.getClearColorAddress());
495 EXPECT_EQ(0u, surfaceState.getClearColorAddressHigh());
496
497 std::unique_ptr<ImageHw<FamilyType>> imageHw(static_cast<ImageHw<FamilyType> *>(ImageHelper<Image2dDefaults>::create(&context)));
498 auto gmm = imageHw->getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex())->getDefaultGmm();
499 gmm->gmmResourceInfo->getResourceFlags()->Gpu.IndirectClearColor = 1;
500 EncodeSurfaceState<FamilyType>::setClearColorParams(&surfaceState, gmm);
501
502 EXPECT_EQ(true, surfaceState.getClearValueAddressEnable());
503 EXPECT_NE(0u, surfaceState.getClearColorAddress());
504 EXPECT_NE(0u, surfaceState.getClearColorAddressHigh());
505 }
506
507 struct CompressionClearColorAddressMatcher {
508 template <PRODUCT_FAMILY productFamily>
isMatchedCompressionClearColorAddressMatcher509 static constexpr bool isMatched() {
510 if constexpr (HwMapper<productFamily>::GfxProduct::supportsCmdSet(IGFX_XE_HP_CORE)) {
511 return TestTraits<NEO::ToGfxCoreFamily<productFamily>::get()>::clearColorAddressMatcher;
512 }
513 return false;
514 }
515 };
516
HWTEST2_F(ImageClearColorFixture,givenImageForXeHPAndLaterWhenCanonicalAddresForClearColorIsUsedThenItsConvertedToNonCanonicalForm,CompressionClearColorAddressMatcher)517 HWTEST2_F(ImageClearColorFixture, givenImageForXeHPAndLaterWhenCanonicalAddresForClearColorIsUsedThenItsConvertedToNonCanonicalForm, CompressionClearColorAddressMatcher) {
518 this->setUpImpl<FamilyType>();
519 auto surfaceState = this->getSurfaceState<FamilyType>();
520
521 uint64_t canonicalAddress = 0xffffABCDABCDE000;
522
523 EXPECT_THROW(surfaceState.setClearColorAddressHigh(static_cast<uint32_t>(canonicalAddress >> 32)), std::exception);
524 surfaceState.setSurfaceBaseAddress(canonicalAddress);
525
526 std::unique_ptr<ImageHw<FamilyType>> imageHw(static_cast<ImageHw<FamilyType> *>(ImageHelper<Image2dDefaults>::create(&context)));
527
528 auto gmm = imageHw->getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex())->getDefaultGmm();
529 gmm->gmmResourceInfo->getResourceFlags()->Gpu.IndirectClearColor = 1;
530 EXPECT_NO_THROW(EncodeSurfaceState<FamilyType>::setClearColorParams(&surfaceState, gmm));
531 uint64_t nonCanonicalAddress = ((static_cast<uint64_t>(surfaceState.getClearColorAddressHigh()) << 32) | surfaceState.getClearColorAddress());
532 EXPECT_EQ(GmmHelper::decanonize(canonicalAddress), nonCanonicalAddress);
533 }
534
HWTEST2_F(XeHPAndLaterImageTests,givenMediaCompressionWhenAppendingNewAllocationThenNotZeroIsSetAsCompressionType,CompressionParamsSupportedMatcher)535 HWTEST2_F(XeHPAndLaterImageTests, givenMediaCompressionWhenAppendingNewAllocationThenNotZeroIsSetAsCompressionType, CompressionParamsSupportedMatcher) {
536 MockContext context;
537 using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE;
538 auto hwInfo = defaultHwInfo.get();
539 cl_image_desc imgDesc = Image2dDefaults::imageDesc;
540 imgDesc.num_samples = 8;
541 std::unique_ptr<Image> image(Image2dHelper<>::create(&context, &imgDesc));
542 auto surfaceState = FamilyType::cmdInitRenderSurfaceState;
543 auto imageHw = static_cast<ImageHw<FamilyType> *>(image.get());
544 imageHw->getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex())->getDefaultGmm()->gmmResourceInfo->getResourceFlags()->Info.MediaCompressed = true;
545 surfaceState.setAuxiliarySurfaceMode(RENDER_SURFACE_STATE::AUXILIARY_SURFACE_MODE::AUXILIARY_SURFACE_MODE_AUX_CCS_E);
546
547 EncodeSurfaceState<FamilyType>::setImageAuxParamsForCCS(&surfaceState, imageHw->getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex())->getDefaultGmm());
548
549 imageHw->setImageArg(&surfaceState, false, 0, context.getDevice(0)->getRootDeviceIndex(), false);
550
551 if (hwInfo->featureTable.flags.ftrFlatPhysCCS) {
552 EXPECT_NE(surfaceState.getCompressionFormat(), GMM_FLATCCS_FORMAT::GMM_FLATCCS_FORMAT_INVALID);
553 } else {
554 EXPECT_NE(surfaceState.getCompressionFormat(), GMM_E2ECOMP_FORMAT::GMM_E2ECOMP_FORMAT_INVALID);
555 }
556
557 EXPECT_TRUE(surfaceState.getMemoryCompressionEnable());
558 EXPECT_EQ(surfaceState.getAuxiliarySurfaceMode(), RENDER_SURFACE_STATE::AUXILIARY_SURFACE_MODE::AUXILIARY_SURFACE_MODE_AUX_NONE);
559 }
560
HWTEST2_F(XeHPAndLaterImageTests,givenCompressionWhenAppendingNewAllocationThenNotZeroIsSetAsCompressionType,CompressionParamsSupportedMatcher)561 HWTEST2_F(XeHPAndLaterImageTests, givenCompressionWhenAppendingNewAllocationThenNotZeroIsSetAsCompressionType, CompressionParamsSupportedMatcher) {
562 MockContext context;
563 using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE;
564 auto hwInfo = defaultHwInfo.get();
565 cl_image_desc imgDesc = Image2dDefaults::imageDesc;
566 imgDesc.num_samples = 8;
567 std::unique_ptr<Image> image(Image2dHelper<>::create(&context, &imgDesc));
568 auto surfaceState = FamilyType::cmdInitRenderSurfaceState;
569 auto imageHw = static_cast<ImageHw<FamilyType> *>(image.get());
570 surfaceState.setAuxiliarySurfaceMode(RENDER_SURFACE_STATE::AUXILIARY_SURFACE_MODE::AUXILIARY_SURFACE_MODE_AUX_CCS_E);
571 auto rootDeviceIndex = context.getDevice(0)->getRootDeviceIndex();
572 auto gmm = imageHw->getGraphicsAllocation(rootDeviceIndex)->getDefaultGmm();
573
574 gmm->gmmResourceInfo->getResourceFlags()->Info.RenderCompressed = true;
575 gmm->isCompressionEnabled = true;
576
577 auto mcsGmm = new MockGmm(context.getDevice(0)->getGmmClientContext());
578 mcsGmm->isCompressionEnabled = true;
579 mcsGmm->gmmResourceInfo->getResourceFlags()->Info.RenderCompressed = true;
580 mcsGmm->gmmResourceInfo->getResourceFlags()->Gpu.UnifiedAuxSurface = true;
581 mcsGmm->gmmResourceInfo->getResourceFlags()->Gpu.CCS = true;
582
583 auto mcsAlloc = context.getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{rootDeviceIndex, 1});
584 mcsAlloc->setDefaultGmm(mcsGmm);
585 imageHw->setMcsAllocation(mcsAlloc);
586
587 imageHw->setImageArg(&surfaceState, false, 0, rootDeviceIndex, false);
588
589 if (hwInfo->featureTable.flags.ftrFlatPhysCCS) {
590 EXPECT_NE(surfaceState.getCompressionFormat(), GMM_FLATCCS_FORMAT::GMM_FLATCCS_FORMAT_INVALID);
591 } else {
592 EXPECT_NE(surfaceState.getCompressionFormat(), GMM_E2ECOMP_FORMAT::GMM_E2ECOMP_FORMAT_INVALID);
593 }
594
595 EXPECT_FALSE(surfaceState.getMemoryCompressionEnable());
596 EXPECT_EQ(surfaceState.getAuxiliarySurfaceMode(), RENDER_SURFACE_STATE::AUXILIARY_SURFACE_MODE::AUXILIARY_SURFACE_MODE_AUX_CCS_E);
597 }
598
HWTEST2_F(XeHPAndLaterImageTests,givenNoCompressionWhenProgramingImageSurfaceStateThenCompressionIsDisabled,CompressionParamsSupportedMatcher)599 HWTEST2_F(XeHPAndLaterImageTests, givenNoCompressionWhenProgramingImageSurfaceStateThenCompressionIsDisabled, CompressionParamsSupportedMatcher) {
600 MockContext context;
601 using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE;
602 cl_image_desc imgDesc = Image2dDefaults::imageDesc;
603 std::unique_ptr<Image> image(Image2dHelper<>::create(&context, &imgDesc));
604 auto surfaceState = FamilyType::cmdInitRenderSurfaceState;
605 surfaceState.setMemoryCompressionEnable(true);
606 surfaceState.setAuxiliarySurfaceMode(RENDER_SURFACE_STATE::AUXILIARY_SURFACE_MODE::AUXILIARY_SURFACE_MODE_AUX_CCS_E);
607 auto imageHw = static_cast<ImageHw<FamilyType> *>(image.get());
608 imageHw->getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex())->getDefaultGmm()->isCompressionEnabled = false;
609 imageHw->setImageArg(&surfaceState, false, 0, 0, false);
610
611 EXPECT_FALSE(surfaceState.getMemoryCompressionEnable());
612 EXPECT_EQ(surfaceState.getAuxiliarySurfaceMode(), RENDER_SURFACE_STATE::AUXILIARY_SURFACE_MODE::AUXILIARY_SURFACE_MODE_AUX_NONE);
613 }
614
615 struct XeHPAndLaterImageHelperTests : ::testing::Test {
SetUpXeHPAndLaterImageHelperTests616 void SetUp() override {
617 context = std::make_unique<MockContext>();
618 image.reset(ImageHelper<Image2dDefaults>::create(context.get()));
619 mockGmmResourceInfo = static_cast<MockGmmResourceInfo *>(image->getGraphicsAllocation(context->getDevice(0)->getRootDeviceIndex())->getDefaultGmm()->gmmResourceInfo.get());
620 gmmClientContext = static_cast<MockGmmClientContext *>(context->getDevice(0)->getGmmHelper()->getClientContext());
621 }
622
623 std::unique_ptr<MockContext> context;
624 std::unique_ptr<Image> image;
625 MockGmmResourceInfo *mockGmmResourceInfo;
626 MockGmmClientContext *gmmClientContext;
627 uint8_t mockCompressionFormat = 3u;
628 };
629
HWTEST2_F(XeHPAndLaterImageHelperTests,givenMediaCompressedImageWhenAppendingSurfaceStateParamsForCompressionThenCallAppriopriateFunction,CompressionParamsSupportedMatcher)630 HWTEST2_F(XeHPAndLaterImageHelperTests, givenMediaCompressedImageWhenAppendingSurfaceStateParamsForCompressionThenCallAppriopriateFunction, CompressionParamsSupportedMatcher) {
631 using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE;
632 RENDER_SURFACE_STATE rss{};
633 platformsImpl->clear();
634 rss.setMemoryCompressionEnable(true);
635 mockGmmResourceInfo->getResourceFlags()->Info.MediaCompressed = true;
636 gmmClientContext->compressionFormatToReturn = mockCompressionFormat;
637 const auto expectedGetSurfaceStateCompressionFormatCalled = gmmClientContext->getSurfaceStateCompressionFormatCalled;
638 const auto expectedGetMediaSurfaceStateCompressionFormatCalled = gmmClientContext->getMediaSurfaceStateCompressionFormatCalled + 1;
639
640 EncodeSurfaceState<FamilyType>::appendImageCompressionParams(&rss, image->getMultiGraphicsAllocation().getDefaultGraphicsAllocation(),
641 context->getDevice(0)->getGmmHelper(), false);
642
643 EXPECT_EQ(platform(), nullptr);
644 EXPECT_EQ(mockCompressionFormat, rss.getCompressionFormat());
645 EXPECT_EQ(expectedGetSurfaceStateCompressionFormatCalled, gmmClientContext->getSurfaceStateCompressionFormatCalled);
646 EXPECT_EQ(expectedGetMediaSurfaceStateCompressionFormatCalled, gmmClientContext->getMediaSurfaceStateCompressionFormatCalled);
647 }
648
HWTEST2_F(XeHPAndLaterImageHelperTests,givenNotMediaCompressedImageWhenAppendingSurfaceStateParamsForCompressionThenCallAppriopriateFunction,CompressionParamsSupportedMatcher)649 HWTEST2_F(XeHPAndLaterImageHelperTests, givenNotMediaCompressedImageWhenAppendingSurfaceStateParamsForCompressionThenCallAppriopriateFunction, CompressionParamsSupportedMatcher) {
650 using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE;
651 RENDER_SURFACE_STATE rss{};
652 platformsImpl->clear();
653 rss.setMemoryCompressionEnable(true);
654 mockGmmResourceInfo->getResourceFlags()->Info.MediaCompressed = false;
655 gmmClientContext->compressionFormatToReturn = mockCompressionFormat;
656 const auto expectedGetSurfaceStateCompressionFormatCalled = gmmClientContext->getSurfaceStateCompressionFormatCalled + 1;
657 const auto expectedGetMediaSurfaceStateCompressionFormatCalled = gmmClientContext->getMediaSurfaceStateCompressionFormatCalled;
658
659 EncodeSurfaceState<FamilyType>::appendImageCompressionParams(&rss, image->getMultiGraphicsAllocation().getDefaultGraphicsAllocation(),
660 context->getDevice(0)->getGmmHelper(), false);
661 EXPECT_EQ(platform(), nullptr);
662 EXPECT_EQ(mockCompressionFormat, rss.getCompressionFormat());
663 EXPECT_EQ(expectedGetSurfaceStateCompressionFormatCalled, gmmClientContext->getSurfaceStateCompressionFormatCalled);
664 EXPECT_EQ(expectedGetMediaSurfaceStateCompressionFormatCalled, gmmClientContext->getMediaSurfaceStateCompressionFormatCalled);
665 }
666
HWTEST2_F(XeHPAndLaterImageHelperTests,givenAuxModeMcsLceWhenAppendingSurfaceStateParamsForCompressionThenCallAppriopriateFunction,CompressionParamsSupportedMatcher)667 HWTEST2_F(XeHPAndLaterImageHelperTests, givenAuxModeMcsLceWhenAppendingSurfaceStateParamsForCompressionThenCallAppriopriateFunction, CompressionParamsSupportedMatcher) {
668 using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE;
669 using AUXILIARY_SURFACE_MODE = typename RENDER_SURFACE_STATE::AUXILIARY_SURFACE_MODE;
670 RENDER_SURFACE_STATE rss{};
671 platformsImpl->clear();
672 rss.setMemoryCompressionEnable(false);
673 rss.setAuxiliarySurfaceMode(AUXILIARY_SURFACE_MODE::AUXILIARY_SURFACE_MODE_AUX_MCS_LCE);
674 mockGmmResourceInfo->getResourceFlags()->Info.MediaCompressed = true;
675 gmmClientContext->compressionFormatToReturn = mockCompressionFormat;
676 const auto expectedGetSurfaceStateCompressionFormatCalled = gmmClientContext->getSurfaceStateCompressionFormatCalled;
677 const auto expectedGetMediaSurfaceStateCompressionFormatCalled = gmmClientContext->getMediaSurfaceStateCompressionFormatCalled + 1;
678
679 EncodeSurfaceState<FamilyType>::appendImageCompressionParams(&rss, image->getMultiGraphicsAllocation().getDefaultGraphicsAllocation(),
680 context->getDevice(0)->getGmmHelper(), false);
681
682 EXPECT_EQ(platform(), nullptr);
683 EXPECT_EQ(mockCompressionFormat, rss.getCompressionFormat());
684 EXPECT_EQ(expectedGetSurfaceStateCompressionFormatCalled, gmmClientContext->getSurfaceStateCompressionFormatCalled);
685 EXPECT_EQ(expectedGetMediaSurfaceStateCompressionFormatCalled, gmmClientContext->getMediaSurfaceStateCompressionFormatCalled);
686 }
687
HWTEST2_F(ImageCompressionTests,givenXeHpCoreAndRedescribableFormatWhenCreatingAllocationThenDoNotPreferCompression,IsXeHpCore)688 HWTEST2_F(ImageCompressionTests, givenXeHpCoreAndRedescribableFormatWhenCreatingAllocationThenDoNotPreferCompression, IsXeHpCore) {
689 MockContext context{};
690 imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
691 imageDesc.image_width = 5;
692 imageDesc.image_height = 5;
693
694 auto surfaceFormat = Image::getSurfaceFormatFromTable(
695 flags, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);
696 auto image = std::unique_ptr<Image>(Image::create(
697 mockContext.get(), ClMemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()),
698 flags, 0, surfaceFormat, &imageDesc, nullptr, retVal));
699 ASSERT_NE(nullptr, image);
700 EXPECT_EQ(UnitTestHelper<FamilyType>::tiledImagesSupported, myMemoryManager->capturedPreferCompressed);
701
702 imageFormat.image_channel_order = CL_RG;
703 surfaceFormat = Image::getSurfaceFormatFromTable(
704 flags, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);
705 image = std::unique_ptr<Image>(Image::create(
706 mockContext.get(), ClMemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()),
707 flags, 0, surfaceFormat, &imageDesc, nullptr, retVal));
708 ASSERT_NE(nullptr, image);
709 EXPECT_TRUE(myMemoryManager->capturedPreferCompressed);
710 }
711