1 /*
2  * Copyright (C) 2021 Intel Corporation
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  */
7 
8 #include "shared/source/gmm_helper/client_context/gmm_client_context.h"
9 #include "shared/source/gmm_helper/gmm_helper.h"
10 #include "shared/source/helpers/state_base_address.h"
11 #include "shared/test/common/helpers/debug_manager_state_restore.h"
12 #include "shared/test/common/test_macros/test.h"
13 #include "shared/test/unit_test/preamble/preamble_fixture.h"
14 
15 #include "opencl/source/helpers/cl_memory_properties_helpers.h"
16 #include "opencl/source/mem_obj/buffer.h"
17 #include "opencl/source/mem_obj/image.h"
18 #include "opencl/test/unit_test/fixtures/ult_command_stream_receiver_fixture.h"
19 #include "opencl/test/unit_test/mocks/mock_context.h"
20 
21 using namespace NEO;
22 using CmdsProgrammingTestsXeHpgCore = UltCommandStreamReceiverTest;
23 
XE_HPG_CORETEST_F(CmdsProgrammingTestsXeHpgCore,givenL3ToL1DebugFlagWhenStatelessMocsIsProgrammedThenItHasL1CachingOn)24 XE_HPG_CORETEST_F(CmdsProgrammingTestsXeHpgCore, givenL3ToL1DebugFlagWhenStatelessMocsIsProgrammedThenItHasL1CachingOn) {
25     using STATE_BASE_ADDRESS = typename FamilyType::STATE_BASE_ADDRESS;
26 
27     DebugManagerStateRestore restore;
28     DebugManager.flags.ForceL1Caching.set(1u);
29 
30     auto &commandStreamReceiver = pDevice->getUltCommandStreamReceiver<FamilyType>();
31     flushTask(commandStreamReceiver);
32 
33     HardwareParse hwParserCsr;
34     hwParserCsr.parseCommands<FamilyType>(commandStreamReceiver.commandStream, 0);
35     hwParserCsr.findHardwareCommands<FamilyType>();
36     ASSERT_NE(nullptr, hwParserCsr.cmdStateBaseAddress);
37 
38     auto stateBaseAddress = static_cast<STATE_BASE_ADDRESS *>(hwParserCsr.cmdStateBaseAddress);
39 
40     auto actualL1CachePolocy = static_cast<uint8_t>(stateBaseAddress->getL1CachePolicyL1CacheControl());
41 
42     const uint8_t expectedL1CachePolicy = 0;
43     EXPECT_EQ(expectedL1CachePolicy, actualL1CachePolocy);
44 }
45 
XE_HPG_CORETEST_F(CmdsProgrammingTestsXeHpgCore,givenSpecificProductFamilyWhenAppendingSbaThenProgramWtL1CachePolicy)46 XE_HPG_CORETEST_F(CmdsProgrammingTestsXeHpgCore, givenSpecificProductFamilyWhenAppendingSbaThenProgramWtL1CachePolicy) {
47     auto memoryManager = pDevice->getExecutionEnvironment()->memoryManager.get();
48     AllocationProperties properties(pDevice->getRootDeviceIndex(), 1, GraphicsAllocation::AllocationType::BUFFER, pDevice->getDeviceBitfield());
49     auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(properties);
50 
51     IndirectHeap indirectHeap(allocation, 1);
52     DispatchFlags flags = DispatchFlagsHelper::createDefaultDispatchFlags();
53     auto sbaCmd = FamilyType::cmdInitStateBaseAddress;
54 
55     StateBaseAddressHelper<FamilyType>::appendStateBaseAddressParameters(&sbaCmd, &indirectHeap, true, 0,
56                                                                          pDevice->getRootDeviceEnvironment().getGmmHelper(), false,
57                                                                          MemoryCompressionState::NotApplicable, true, false, 1u);
58 
59     EXPECT_EQ(FamilyType::STATE_BASE_ADDRESS::L1_CACHE_POLICY_WBP, sbaCmd.getL1CachePolicyL1CacheControl());
60 
61     memoryManager->freeGraphicsMemory(allocation);
62 }
63 
XE_HPG_CORETEST_F(CmdsProgrammingTestsXeHpgCore,givenL1CachingOverrideWhenStateBaseAddressIsProgrammedThenItMatchesTheOverrideValue)64 XE_HPG_CORETEST_F(CmdsProgrammingTestsXeHpgCore, givenL1CachingOverrideWhenStateBaseAddressIsProgrammedThenItMatchesTheOverrideValue) {
65     DebugManagerStateRestore restorer;
66     DebugManager.flags.ForceStatelessL1CachingPolicy.set(0u);
67     auto memoryManager = pDevice->getExecutionEnvironment()->memoryManager.get();
68     AllocationProperties properties(pDevice->getRootDeviceIndex(), 1, GraphicsAllocation::AllocationType::BUFFER, pDevice->getDeviceBitfield());
69     auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(properties);
70 
71     IndirectHeap indirectHeap(allocation, 1);
72     DispatchFlags flags = DispatchFlagsHelper::createDefaultDispatchFlags();
73     auto sbaCmd = FamilyType::cmdInitStateBaseAddress;
74 
75     StateBaseAddressHelper<FamilyType>::appendStateBaseAddressParameters(&sbaCmd, &indirectHeap, true, 0,
76                                                                          pDevice->getRootDeviceEnvironment().getGmmHelper(), false,
77                                                                          MemoryCompressionState::NotApplicable, true, false, 1u);
78 
79     EXPECT_EQ(0u, sbaCmd.getL1CachePolicyL1CacheControl());
80 
81     DebugManager.flags.ForceStatelessL1CachingPolicy.set(1u);
82 
83     StateBaseAddressHelper<FamilyType>::appendStateBaseAddressParameters(&sbaCmd, &indirectHeap, true, 0,
84                                                                          pDevice->getRootDeviceEnvironment().getGmmHelper(), false,
85                                                                          MemoryCompressionState::NotApplicable, true, false, 1u);
86 
87     EXPECT_EQ(1u, sbaCmd.getL1CachePolicyL1CacheControl());
88 
89     memoryManager->freeGraphicsMemory(allocation);
90 }
91 
XE_HPG_CORETEST_F(CmdsProgrammingTestsXeHpgCore,whenAppendingRssThenProgramWtL1CachePolicy)92 XE_HPG_CORETEST_F(CmdsProgrammingTestsXeHpgCore, whenAppendingRssThenProgramWtL1CachePolicy) {
93     auto memoryManager = pDevice->getExecutionEnvironment()->memoryManager.get();
94     size_t allocationSize = MemoryConstants::pageSize;
95     AllocationProperties properties(pDevice->getRootDeviceIndex(), allocationSize, GraphicsAllocation::AllocationType::BUFFER, pDevice->getDeviceBitfield());
96     auto allocation = memoryManager->allocateGraphicsMemoryWithProperties(properties);
97 
98     auto rssCmd = FamilyType::cmdInitRenderSurfaceState;
99 
100     MockContext context(pClDevice);
101     auto multiGraphicsAllocation = MultiGraphicsAllocation(pClDevice->getRootDeviceIndex());
102     multiGraphicsAllocation.addAllocation(allocation);
103 
104     std::unique_ptr<BufferHw<FamilyType>> buffer(static_cast<BufferHw<FamilyType> *>(
105         BufferHw<FamilyType>::create(&context, {}, 0, 0, allocationSize, nullptr, nullptr, multiGraphicsAllocation, false, false, false)));
106 
107     NEO::EncodeSurfaceStateArgs args;
108     args.outMemory = &rssCmd;
109     args.graphicsAddress = allocation->getGpuAddress();
110     args.size = allocation->getUnderlyingBufferSize();
111     args.mocs = buffer->getMocsValue(false, false, pClDevice->getRootDeviceIndex());
112     args.numAvailableDevices = pClDevice->getNumGenericSubDevices();
113     args.allocation = allocation;
114     args.gmmHelper = pClDevice->getGmmHelper();
115     args.areMultipleSubDevicesInContext = true;
116 
117     EncodeSurfaceState<FamilyType>::encodeBuffer(args);
118 
119     EXPECT_EQ(FamilyType::RENDER_SURFACE_STATE::L1_CACHE_POLICY_WBP, rssCmd.getL1CachePolicyL1CacheControl());
120 }
121 
XE_HPG_CORETEST_F(CmdsProgrammingTestsXeHpgCore,givenAlignedCacheableReadOnlyBufferThenChoseOclBufferConstPolicy)122 XE_HPG_CORETEST_F(CmdsProgrammingTestsXeHpgCore, givenAlignedCacheableReadOnlyBufferThenChoseOclBufferConstPolicy) {
123     MockContext context;
124     const auto size = MemoryConstants::pageSize;
125     const auto ptr = (void *)alignedMalloc(size * 2, MemoryConstants::pageSize);
126     const auto flags = CL_MEM_USE_HOST_PTR | CL_MEM_READ_ONLY;
127 
128     auto retVal = CL_SUCCESS;
129     auto buffer = std::unique_ptr<Buffer>(Buffer::create(
130         &context,
131         flags,
132         size,
133         ptr,
134         retVal));
135     EXPECT_EQ(CL_SUCCESS, retVal);
136 
137     typename FamilyType::RENDER_SURFACE_STATE surfaceState = {};
138     buffer->setArgStateful(&surfaceState, false, false, false, false, context.getDevice(0)->getDevice(), false, false);
139 
140     const auto expectedMocs = context.getDevice(0)->getGmmHelper()->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER_CONST);
141     const auto actualMocs = surfaceState.getMemoryObjectControlState();
142     EXPECT_EQ(expectedMocs, actualMocs);
143 
144     auto actualL1CachePolocy = static_cast<uint8_t>(surfaceState.getL1CachePolicyL1CacheControl());
145 
146     const uint8_t expectedL1CachePolicy = 0;
147     EXPECT_EQ(expectedL1CachePolicy, actualL1CachePolocy);
148 
149     alignedFree(ptr);
150 }
151 
XE_HPG_CORETEST_F(CmdsProgrammingTestsXeHpgCore,givenDecompressInL3ForImage2dFromBufferEnabledWhenProgrammingStateForImage2dFrom3dCompressedBufferThenCorrectFlagsAreSet)152 XE_HPG_CORETEST_F(CmdsProgrammingTestsXeHpgCore, givenDecompressInL3ForImage2dFromBufferEnabledWhenProgrammingStateForImage2dFrom3dCompressedBufferThenCorrectFlagsAreSet) {
153     using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE;
154     using AUXILIARY_SURFACE_MODE = typename RENDER_SURFACE_STATE::AUXILIARY_SURFACE_MODE;
155 
156     MockContext context;
157     cl_int retVal = CL_SUCCESS;
158     cl_image_format imageFormat = {};
159     cl_image_desc imageDesc = {};
160 
161     imageFormat.image_channel_data_type = CL_UNORM_INT8;
162     imageFormat.image_channel_order = CL_R;
163 
164     imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
165     imageDesc.image_height = 128;
166     imageDesc.image_width = 256;
167 
168     imageDesc.mem_object = clCreateBuffer(&context, CL_MEM_READ_WRITE, imageDesc.image_height * imageDesc.image_width, nullptr, &retVal);
169 
170     auto gmm = new Gmm(context.getDevice(0)->getGmmHelper()->getClientContext(), nullptr, 1, 0, false);
171     gmm->isCompressionEnabled = true;
172 
173     auto buffer = castToObject<Buffer>(imageDesc.mem_object);
174     buffer->getGraphicsAllocation(0)->setGmm(gmm, 0);
175 
176     auto gmmResourceInfo = buffer->getMultiGraphicsAllocation().getDefaultGraphicsAllocation()->getDefaultGmm()->gmmResourceInfo.get();
177     auto bufferCompressionFormat = context.getDevice(0)->getGmmClientContext()->getSurfaceStateCompressionFormat(gmmResourceInfo->getResourceFormat());
178 
179     auto surfaceFormat = Image::getSurfaceFormatFromTable(CL_MEM_READ_WRITE, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);
180     auto image = std::unique_ptr<Image>(Image::create(&context, ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_READ_WRITE, 0, 0, &context.getDevice(0)->getDevice()),
181                                                       CL_MEM_READ_WRITE, 0, surfaceFormat, &imageDesc, NULL, retVal));
182     auto imageHw = static_cast<ImageHw<FamilyType> *>(image.get());
183 
184     {
185         DebugManagerStateRestore restorer;
186         DebugManager.flags.DecompressInL3ForImage2dFromBuffer.set(-1);
187         uint32_t forcedCompressionFormat = 3;
188         DebugManager.flags.ForceBufferCompressionFormat.set(forcedCompressionFormat);
189         auto surfaceState = FamilyType::cmdInitRenderSurfaceState;
190         imageHw->setImageArg(&surfaceState, false, 0, context.getDevice(0)->getRootDeviceIndex(), false);
191         EXPECT_EQ(AUXILIARY_SURFACE_MODE::AUXILIARY_SURFACE_MODE_AUX_NONE, surfaceState.getAuxiliarySurfaceMode());
192         EXPECT_EQ(1u, surfaceState.getDecompressInL3());
193         EXPECT_EQ(1u, surfaceState.getMemoryCompressionEnable());
194         EXPECT_EQ(RENDER_SURFACE_STATE::MEMORY_COMPRESSION_TYPE::MEMORY_COMPRESSION_TYPE_3D_COMPRESSION, surfaceState.getMemoryCompressionType());
195         EXPECT_EQ(forcedCompressionFormat, surfaceState.getCompressionFormat());
196     }
197 
198     {
199         DebugManagerStateRestore restorer;
200         DebugManager.flags.DecompressInL3ForImage2dFromBuffer.set(1);
201 
202         auto surfaceState = FamilyType::cmdInitRenderSurfaceState;
203         imageHw->setImageArg(&surfaceState, false, 0, context.getDevice(0)->getRootDeviceIndex(), false);
204         EXPECT_EQ(AUXILIARY_SURFACE_MODE::AUXILIARY_SURFACE_MODE_AUX_NONE, surfaceState.getAuxiliarySurfaceMode());
205         EXPECT_EQ(1u, surfaceState.getDecompressInL3());
206         EXPECT_EQ(1u, surfaceState.getMemoryCompressionEnable());
207         EXPECT_EQ(RENDER_SURFACE_STATE::MEMORY_COMPRESSION_TYPE::MEMORY_COMPRESSION_TYPE_3D_COMPRESSION, surfaceState.getMemoryCompressionType());
208         EXPECT_EQ(bufferCompressionFormat, surfaceState.getCompressionFormat());
209     }
210 
211     {
212         DebugManagerStateRestore restorer;
213         DebugManager.flags.DecompressInL3ForImage2dFromBuffer.set(0);
214 
215         auto surfaceState = FamilyType::cmdInitRenderSurfaceState;
216         imageHw->setImageArg(&surfaceState, false, 0, context.getDevice(0)->getRootDeviceIndex(), false);
217         EXPECT_EQ(AUXILIARY_SURFACE_MODE::AUXILIARY_SURFACE_MODE_AUX_CCS_E, surfaceState.getAuxiliarySurfaceMode());
218         EXPECT_EQ(0u, surfaceState.getDecompressInL3());
219         EXPECT_EQ(0u, surfaceState.getMemoryCompressionEnable());
220         EXPECT_EQ(RENDER_SURFACE_STATE::MEMORY_COMPRESSION_TYPE::MEMORY_COMPRESSION_TYPE_MEDIA_COMPRESSION, surfaceState.getMemoryCompressionType());
221         EXPECT_EQ(bufferCompressionFormat, surfaceState.getCompressionFormat());
222     }
223 
224     clReleaseMemObject(imageDesc.mem_object);
225 }
226 
XE_HPG_CORETEST_F(CmdsProgrammingTestsXeHpgCore,givenDecompressInL3ForImage2dFromBufferEnabledWhenProgrammingStateForImage1dFromCompressedBufferThenCorrectFlagsAreSet)227 XE_HPG_CORETEST_F(CmdsProgrammingTestsXeHpgCore, givenDecompressInL3ForImage2dFromBufferEnabledWhenProgrammingStateForImage1dFromCompressedBufferThenCorrectFlagsAreSet) {
228     using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE;
229     using AUXILIARY_SURFACE_MODE = typename RENDER_SURFACE_STATE::AUXILIARY_SURFACE_MODE;
230     MockContext context;
231     cl_int retVal = CL_SUCCESS;
232     cl_image_format imageFormat = {};
233     cl_image_desc imageDesc = {};
234 
235     imageFormat.image_channel_data_type = CL_UNORM_INT8;
236     imageFormat.image_channel_order = CL_R;
237 
238     imageDesc.image_type = CL_MEM_OBJECT_IMAGE1D_BUFFER;
239     imageDesc.image_height = 1;
240     imageDesc.image_width = 256;
241 
242     imageDesc.mem_object = clCreateBuffer(&context, CL_MEM_READ_WRITE, imageDesc.image_height * imageDesc.image_width, nullptr, &retVal);
243 
244     auto gmm = new Gmm(context.getDevice(0)->getGmmHelper()->getClientContext(), nullptr, 1, 0, false);
245     gmm->isCompressionEnabled = true;
246 
247     auto buffer = castToObject<Buffer>(imageDesc.mem_object);
248     buffer->getGraphicsAllocation(0)->setGmm(gmm, 0);
249 
250     auto surfaceFormat = Image::getSurfaceFormatFromTable(CL_MEM_READ_WRITE, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);
251     auto image = std::unique_ptr<Image>(Image::create(&context, ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_READ_WRITE, 0, 0, &context.getDevice(0)->getDevice()),
252                                                       CL_MEM_READ_WRITE, 0, surfaceFormat, &imageDesc, NULL, retVal));
253     auto imageHw = static_cast<ImageHw<FamilyType> *>(image.get());
254 
255     for (auto &decompressInL3 : ::testing::Bool()) {
256         DebugManagerStateRestore restorer;
257         DebugManager.flags.DecompressInL3ForImage2dFromBuffer.set(decompressInL3);
258 
259         auto surfaceState = FamilyType::cmdInitRenderSurfaceState;
260         imageHw->setImageArg(&surfaceState, false, 0, context.getDevice(0)->getRootDeviceIndex(), false);
261         EXPECT_EQ(AUXILIARY_SURFACE_MODE::AUXILIARY_SURFACE_MODE_AUX_CCS_E, surfaceState.getAuxiliarySurfaceMode());
262         EXPECT_EQ(0u, surfaceState.getDecompressInL3());
263         EXPECT_EQ(0u, surfaceState.getMemoryCompressionEnable());
264         EXPECT_EQ(RENDER_SURFACE_STATE::MEMORY_COMPRESSION_TYPE::MEMORY_COMPRESSION_TYPE_MEDIA_COMPRESSION, surfaceState.getMemoryCompressionType());
265     }
266 
267     clReleaseMemObject(imageDesc.mem_object);
268 }
269 
XE_HPG_CORETEST_F(CmdsProgrammingTestsXeHpgCore,givenDecompressInL3ForImage2dFromBufferEnabledWhenProgrammingStateForImage2dFromNotCompressedBufferThenCorrectFlagsAreSet)270 XE_HPG_CORETEST_F(CmdsProgrammingTestsXeHpgCore, givenDecompressInL3ForImage2dFromBufferEnabledWhenProgrammingStateForImage2dFromNotCompressedBufferThenCorrectFlagsAreSet) {
271     using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE;
272     using AUXILIARY_SURFACE_MODE = typename RENDER_SURFACE_STATE::AUXILIARY_SURFACE_MODE;
273     MockContext context;
274     cl_int retVal = CL_SUCCESS;
275     cl_image_format imageFormat = {};
276     cl_image_desc imageDesc = {};
277 
278     imageFormat.image_channel_data_type = CL_UNORM_INT8;
279     imageFormat.image_channel_order = CL_R;
280 
281     imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
282     imageDesc.image_height = 128;
283     imageDesc.image_width = 256;
284 
285     imageDesc.mem_object = clCreateBuffer(&context, CL_MEM_READ_WRITE, imageDesc.image_height * imageDesc.image_width, nullptr, &retVal);
286 
287     auto gmm = new Gmm(context.getDevice(0)->getGmmHelper()->getClientContext(), nullptr, 1, 0, false);
288     gmm->isCompressionEnabled = false;
289 
290     auto buffer = castToObject<Buffer>(imageDesc.mem_object);
291     buffer->getGraphicsAllocation(0)->setGmm(gmm, 0);
292 
293     auto surfaceFormat = Image::getSurfaceFormatFromTable(CL_MEM_READ_WRITE, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);
294     auto image = std::unique_ptr<Image>(Image::create(&context, ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_READ_WRITE, 0, 0, &context.getDevice(0)->getDevice()),
295                                                       CL_MEM_READ_WRITE, 0, surfaceFormat, &imageDesc, NULL, retVal));
296     auto imageHw = static_cast<ImageHw<FamilyType> *>(image.get());
297 
298     for (auto &decompressInL3 : ::testing::Bool()) {
299         DebugManagerStateRestore restorer;
300         DebugManager.flags.DecompressInL3ForImage2dFromBuffer.set(decompressInL3);
301 
302         auto surfaceState = FamilyType::cmdInitRenderSurfaceState;
303         imageHw->setImageArg(&surfaceState, false, 0, context.getDevice(0)->getRootDeviceIndex(), false);
304         EXPECT_EQ(AUXILIARY_SURFACE_MODE::AUXILIARY_SURFACE_MODE_AUX_NONE, surfaceState.getAuxiliarySurfaceMode());
305         EXPECT_EQ(0u, surfaceState.getDecompressInL3());
306         EXPECT_EQ(0u, surfaceState.getMemoryCompressionEnable());
307         EXPECT_EQ(RENDER_SURFACE_STATE::MEMORY_COMPRESSION_TYPE::MEMORY_COMPRESSION_TYPE_MEDIA_COMPRESSION, surfaceState.getMemoryCompressionType());
308     }
309 
310     clReleaseMemObject(imageDesc.mem_object);
311 }
312 
XE_HPG_CORETEST_F(CmdsProgrammingTestsXeHpgCore,givenDecompressInL3ForImage2dFromBufferEnabledWhenProgrammingStateForImage2dFromMediaCompressedBufferThenCorrectFlagsAreSet)313 XE_HPG_CORETEST_F(CmdsProgrammingTestsXeHpgCore, givenDecompressInL3ForImage2dFromBufferEnabledWhenProgrammingStateForImage2dFromMediaCompressedBufferThenCorrectFlagsAreSet) {
314     using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE;
315     using AUXILIARY_SURFACE_MODE = typename RENDER_SURFACE_STATE::AUXILIARY_SURFACE_MODE;
316     MockContext context;
317     cl_int retVal = CL_SUCCESS;
318     cl_image_format imageFormat = {};
319     cl_image_desc imageDesc = {};
320 
321     imageFormat.image_channel_data_type = CL_UNORM_INT8;
322     imageFormat.image_channel_order = CL_R;
323 
324     imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
325     imageDesc.image_height = 128;
326     imageDesc.image_width = 256;
327 
328     imageDesc.mem_object = clCreateBuffer(&context, CL_MEM_READ_WRITE, imageDesc.image_height * imageDesc.image_width, nullptr, &retVal);
329 
330     auto gmm = new Gmm(context.getDevice(0)->getGmmHelper()->getClientContext(), nullptr, 1, 0, false);
331     gmm->isCompressionEnabled = true;
332     gmm->gmmResourceInfo->getResourceFlags()->Info.MediaCompressed = true;
333 
334     auto buffer = castToObject<Buffer>(imageDesc.mem_object);
335     buffer->getGraphicsAllocation(0)->setGmm(gmm, 0);
336 
337     auto surfaceFormat = Image::getSurfaceFormatFromTable(CL_MEM_READ_WRITE, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features);
338     auto image = std::unique_ptr<Image>(Image::create(&context, ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_READ_WRITE, 0, 0, &context.getDevice(0)->getDevice()),
339                                                       CL_MEM_READ_WRITE, 0, surfaceFormat, &imageDesc, NULL, retVal));
340     auto imageHw = static_cast<ImageHw<FamilyType> *>(image.get());
341 
342     for (auto &decompressInL3 : ::testing::Bool()) {
343         DebugManagerStateRestore restorer;
344         DebugManager.flags.DecompressInL3ForImage2dFromBuffer.set(decompressInL3);
345 
346         auto surfaceState = FamilyType::cmdInitRenderSurfaceState;
347         imageHw->setImageArg(&surfaceState, false, 0, context.getDevice(0)->getRootDeviceIndex(), false);
348         EXPECT_EQ(AUXILIARY_SURFACE_MODE::AUXILIARY_SURFACE_MODE_AUX_NONE, surfaceState.getAuxiliarySurfaceMode());
349         EXPECT_EQ(0u, surfaceState.getDecompressInL3());
350         EXPECT_EQ(1u, surfaceState.getMemoryCompressionEnable());
351         EXPECT_EQ(RENDER_SURFACE_STATE::MEMORY_COMPRESSION_TYPE::MEMORY_COMPRESSION_TYPE_MEDIA_COMPRESSION, surfaceState.getMemoryCompressionType());
352     }
353 
354     clReleaseMemObject(imageDesc.mem_object);
355 }
356 
357 using PreambleCfeState = PreambleFixture;
358 
HWTEST2_F(PreambleCfeState,givenXehpAndDisabledFusedEuWhenCfeStateProgrammedThenFusedEuDispatchSetToTrue,IsXeHpgCore)359 HWTEST2_F(PreambleCfeState, givenXehpAndDisabledFusedEuWhenCfeStateProgrammedThenFusedEuDispatchSetToTrue, IsXeHpgCore) {
360     using CFE_STATE = typename FamilyType::CFE_STATE;
361 
362     auto hwInfo = *defaultHwInfo;
363     hwInfo.capabilityTable.fusedEuEnabled = false;
364 
365     auto pVfeCmd = PreambleHelper<FamilyType>::getSpaceForVfeState(&linearStream, hwInfo, EngineGroupType::RenderCompute);
366     StreamProperties streamProperties{};
367     streamProperties.frontEndState.setProperties(false, false, false, hwInfo);
368     PreambleHelper<FamilyType>::programVfeState(pVfeCmd, hwInfo, 0u, 0, 0, streamProperties);
369     parseCommands<FamilyType>(linearStream);
370     auto cfeStateIt = find<CFE_STATE *>(cmdList.begin(), cmdList.end());
371     ASSERT_NE(cmdList.end(), cfeStateIt);
372     auto cfeState = reinterpret_cast<CFE_STATE *>(*cfeStateIt);
373 
374     EXPECT_TRUE(cfeState->getFusedEuDispatch());
375 }
376 
HWTEST2_F(PreambleCfeState,givenXehpAndEnabledFusedEuWhenCfeStateProgrammedThenFusedEuDispatchSetToFalse,IsXeHpgCore)377 HWTEST2_F(PreambleCfeState, givenXehpAndEnabledFusedEuWhenCfeStateProgrammedThenFusedEuDispatchSetToFalse, IsXeHpgCore) {
378     using CFE_STATE = typename FamilyType::CFE_STATE;
379 
380     auto hwInfo = *defaultHwInfo;
381     hwInfo.capabilityTable.fusedEuEnabled = true;
382 
383     auto pVfeCmd = PreambleHelper<FamilyType>::getSpaceForVfeState(&linearStream, hwInfo, EngineGroupType::RenderCompute);
384     StreamProperties streamProperties{};
385     streamProperties.frontEndState.setProperties(false, false, false, hwInfo);
386     PreambleHelper<FamilyType>::programVfeState(pVfeCmd, hwInfo, 0u, 0, 0, streamProperties);
387     parseCommands<FamilyType>(linearStream);
388     auto cfeStateIt = find<CFE_STATE *>(cmdList.begin(), cmdList.end());
389     ASSERT_NE(cmdList.end(), cfeStateIt);
390     auto cfeState = reinterpret_cast<CFE_STATE *>(*cfeStateIt);
391 
392     EXPECT_FALSE(cfeState->getFusedEuDispatch());
393 }