1 /*
2 * Copyright (C) 2021 Intel Corporation
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 */
7
8 #include "shared/source/helpers/hw_helper.h"
9 #include "shared/source/helpers/pipe_control_args.h"
10 #include "shared/source/os_interface/hw_info_config.h"
11 #include "shared/test/common/cmd_parse/gen_cmd_parse.h"
12 #include "shared/test/common/helpers/debug_manager_state_restore.h"
13 #include "shared/test/common/helpers/hw_helper_tests.h"
14 #include "shared/test/common/helpers/unit_test_helper.h"
15 #include "shared/test/common/test_macros/test.h"
16
17 #include "opencl/test/unit_test/fixtures/cl_device_fixture.h"
18
19 using PipeControlHelperTestsDg2AndLater = ::testing::Test;
20 using HwHelperTestsDg2AndLater = Test<ClDeviceFixture>;
21
HWTEST2_F(PipeControlHelperTestsDg2AndLater,WhenAddingPipeControlWAThenCorrectCommandsAreProgrammed,IsAtLeastXeHpgCore)22 HWTEST2_F(PipeControlHelperTestsDg2AndLater, WhenAddingPipeControlWAThenCorrectCommandsAreProgrammed, IsAtLeastXeHpgCore) {
23 using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
24 using MI_SEMAPHORE_WAIT = typename FamilyType::MI_SEMAPHORE_WAIT;
25 uint8_t buffer[128];
26 uint64_t address = 0x1234567887654321;
27 HardwareInfo hardwareInfo = *defaultHwInfo;
28 bool requiresMemorySynchronization = (MemorySynchronizationCommands<FamilyType>::getSizeForAdditonalSynchronization(hardwareInfo) > 0) ? true : false;
29
30 for (auto ftrLocalMemory : ::testing::Bool()) {
31 LinearStream stream(buffer, 128);
32 hardwareInfo.featureTable.flags.ftrLocalMemory = ftrLocalMemory;
33
34 MemorySynchronizationCommands<FamilyType>::addPipeControlWA(stream, address, hardwareInfo);
35
36 if (MemorySynchronizationCommands<FamilyType>::isPipeControlWArequired(hardwareInfo) == false) {
37 EXPECT_EQ(0u, stream.getUsed());
38 continue;
39 }
40
41 GenCmdList cmdList;
42 FamilyType::PARSE::parseCommandBuffer(cmdList, stream.getCpuBase(), stream.getUsed());
43 EXPECT_EQ(requiresMemorySynchronization ? 2u : 1u, cmdList.size());
44
45 PIPE_CONTROL expectedPipeControl = FamilyType::cmdInitPipeControl;
46 expectedPipeControl.setCommandStreamerStallEnable(true);
47 expectedPipeControl.setHdcPipelineFlush(true);
48 expectedPipeControl.setUnTypedDataPortCacheFlush(true);
49 auto it = cmdList.begin();
50 auto pPipeControl = genCmdCast<PIPE_CONTROL *>(*it);
51 ASSERT_NE(nullptr, pPipeControl);
52 EXPECT_TRUE(memcmp(&expectedPipeControl, pPipeControl, sizeof(PIPE_CONTROL)) == 0);
53
54 if (requiresMemorySynchronization) {
55 if (UnitTestHelper<FamilyType>::isAdditionalMiSemaphoreWaitRequired(hardwareInfo)) {
56 MI_SEMAPHORE_WAIT expectedMiSemaphoreWait;
57 EncodeSempahore<FamilyType>::programMiSemaphoreWait(&expectedMiSemaphoreWait, address,
58 EncodeSempahore<FamilyType>::invalidHardwareTag,
59 MI_SEMAPHORE_WAIT::COMPARE_OPERATION::COMPARE_OPERATION_SAD_NOT_EQUAL_SDD,
60 false);
61 auto pMiSemaphoreWait = genCmdCast<MI_SEMAPHORE_WAIT *>(*(++it));
62 ASSERT_NE(nullptr, pMiSemaphoreWait);
63 EXPECT_TRUE(memcmp(&expectedMiSemaphoreWait, pMiSemaphoreWait, sizeof(MI_SEMAPHORE_WAIT)) == 0);
64 }
65 }
66 }
67 }
68
HWTEST2_F(PipeControlHelperTestsDg2AndLater,WhenSettingExtraPipeControlPropertiesThenCorrectValuesAreSet,IsAtLeastXeHpgCore)69 HWTEST2_F(PipeControlHelperTestsDg2AndLater, WhenSettingExtraPipeControlPropertiesThenCorrectValuesAreSet, IsAtLeastXeHpgCore) {
70 using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
71
72 for (auto ftrLocalMemory : ::testing::Bool()) {
73 HardwareInfo hardwareInfo = *defaultHwInfo;
74 hardwareInfo.featureTable.flags.ftrLocalMemory = ftrLocalMemory;
75
76 PipeControlArgs args;
77 MemorySynchronizationCommands<FamilyType>::setPostSyncExtraProperties(args, hardwareInfo);
78
79 if (ftrLocalMemory) {
80 EXPECT_TRUE(args.hdcPipelineFlush);
81 EXPECT_TRUE(args.unTypedDataPortCacheFlush);
82 } else {
83 EXPECT_FALSE(args.hdcPipelineFlush);
84 EXPECT_FALSE(args.unTypedDataPortCacheFlush);
85 }
86 }
87 }
88
HWTEST2_F(PipeControlHelperTestsDg2AndLater,whenSettingCacheFlushExtraFieldsThenExpectHdcAndUnTypedDataPortFlushSet,IsAtLeastXeHpgCore)89 HWTEST2_F(PipeControlHelperTestsDg2AndLater, whenSettingCacheFlushExtraFieldsThenExpectHdcAndUnTypedDataPortFlushSet, IsAtLeastXeHpgCore) {
90 PipeControlArgs args;
91
92 MemorySynchronizationCommands<FamilyType>::setCacheFlushExtraProperties(args);
93 EXPECT_TRUE(args.hdcPipelineFlush);
94 EXPECT_TRUE(args.unTypedDataPortCacheFlush);
95 }
96
HWTEST2_F(PipeControlHelperTestsDg2AndLater,givenRequestedCacheFlushesWhenProgrammingPipeControlThenFlushHdcAndUnTypedDataPortCache,IsAtLeastXeHpgCore)97 HWTEST2_F(PipeControlHelperTestsDg2AndLater, givenRequestedCacheFlushesWhenProgrammingPipeControlThenFlushHdcAndUnTypedDataPortCache, IsAtLeastXeHpgCore) {
98 using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
99
100 uint32_t buffer[sizeof(PIPE_CONTROL) * 2] = {};
101 LinearStream stream(buffer, sizeof(buffer));
102
103 PipeControlArgs args;
104 args.hdcPipelineFlush = true;
105 args.unTypedDataPortCacheFlush = true;
106 args.compressionControlSurfaceCcsFlush = true;
107 MemorySynchronizationCommands<FamilyType>::addPipeControl(stream, args);
108
109 auto pipeControl = reinterpret_cast<PIPE_CONTROL *>(buffer);
110 EXPECT_TRUE(pipeControl->getHdcPipelineFlush());
111 EXPECT_TRUE(pipeControl->getUnTypedDataPortCacheFlush());
112 EXPECT_TRUE(pipeControl->getCompressionControlSurfaceCcsFlush());
113 }
114
HWTEST2_F(PipeControlHelperTestsDg2AndLater,givenDebugVariableSetWhenProgrammingPipeControlThenFlushHdcAndUnTypedDataPortCache,IsAtLeastXeHpgCore)115 HWTEST2_F(PipeControlHelperTestsDg2AndLater, givenDebugVariableSetWhenProgrammingPipeControlThenFlushHdcAndUnTypedDataPortCache, IsAtLeastXeHpgCore) {
116 using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
117 DebugManagerStateRestore restore;
118 DebugManager.flags.FlushAllCaches.set(true);
119
120 uint32_t buffer[sizeof(PIPE_CONTROL) * 2] = {};
121 LinearStream stream(buffer, sizeof(buffer));
122
123 PipeControlArgs args;
124 MemorySynchronizationCommands<FamilyType>::addPipeControl(stream, args);
125
126 auto pipeControl = reinterpret_cast<PIPE_CONTROL *>(buffer);
127 EXPECT_TRUE(pipeControl->getHdcPipelineFlush());
128 EXPECT_TRUE(pipeControl->getUnTypedDataPortCacheFlush());
129 EXPECT_TRUE(pipeControl->getCompressionControlSurfaceCcsFlush());
130 }
131
HWTEST2_F(PipeControlHelperTestsDg2AndLater,givenDebugDisableCacheFlushWhenProgrammingPipeControlWithCacheFlushThenExpectDebugOverrideFlushHdcAndUnTypedDataPortCache,IsAtLeastXeHpgCore)132 HWTEST2_F(PipeControlHelperTestsDg2AndLater, givenDebugDisableCacheFlushWhenProgrammingPipeControlWithCacheFlushThenExpectDebugOverrideFlushHdcAndUnTypedDataPortCache, IsAtLeastXeHpgCore) {
133 using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
134 DebugManagerStateRestore restore;
135 DebugManager.flags.DoNotFlushCaches.set(true);
136
137 uint32_t buffer[sizeof(PIPE_CONTROL) * 2] = {};
138 LinearStream stream(buffer, sizeof(buffer));
139
140 PipeControlArgs args;
141 args.hdcPipelineFlush = true;
142 args.unTypedDataPortCacheFlush = true;
143 args.compressionControlSurfaceCcsFlush = true;
144 MemorySynchronizationCommands<FamilyType>::addPipeControl(stream, args);
145
146 auto pipeControl = reinterpret_cast<PIPE_CONTROL *>(buffer);
147 EXPECT_FALSE(pipeControl->getHdcPipelineFlush());
148 EXPECT_FALSE(pipeControl->getUnTypedDataPortCacheFlush());
149 EXPECT_FALSE(pipeControl->getCompressionControlSurfaceCcsFlush());
150 }
151
HWTEST2_F(HwHelperTestsDg2AndLater,givenXeHPGAndLaterPlatformWhenCheckingIfUnTypedDataPortCacheFlushRequiredThenReturnTrue,IsAtLeastXeHpgCore)152 HWTEST2_F(HwHelperTestsDg2AndLater, givenXeHPGAndLaterPlatformWhenCheckingIfUnTypedDataPortCacheFlushRequiredThenReturnTrue, IsAtLeastXeHpgCore) {
153 auto &hwHelper = HwHelper::get(renderCoreFamily);
154 EXPECT_TRUE(hwHelper.unTypedDataPortCacheFlushRequired());
155 }
156
157 using HwInfoConfigTestDg2AndLater = ::testing::Test;
158
HWTEST2_F(HwInfoConfigTestDg2AndLater,givenDg2AndLaterPlatformWhenAskedIfHeapInLocalMemThenTrueIsReturned,IsAtLeastXeHpgCore)159 HWTEST2_F(HwInfoConfigTestDg2AndLater, givenDg2AndLaterPlatformWhenAskedIfHeapInLocalMemThenTrueIsReturned, IsAtLeastXeHpgCore) {
160 const auto &hwInfoConfig = *HwInfoConfig::get(defaultHwInfo->platform.eProductFamily);
161 EXPECT_TRUE(hwInfoConfig.heapInLocalMem(*defaultHwInfo));
162 }
163