Debian Codegraph @

shared/test/unit_test/direct_submission/linux/drm_direct_submission_tests.cpp

raw
1 /*
2 * Copyright (C) 2020-2024 Intel Corporation
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 */
7
8 #include "shared/source/command_container/implicit_scaling.h"
9 #include "shared/source/command_stream/tag_allocation_layout.h"
10 #include "shared/source/direct_submission/dispatchers/blitter_dispatcher.h"
11 #include "shared/source/direct_submission/dispatchers/render_dispatcher.h"
12 #include "shared/source/direct_submission/linux/drm_direct_submission.h"
13 #include "shared/source/helpers/flush_stamp.h"
14 #include "shared/source/os_interface/linux/drm_gem_close_worker.h"
15 #include "shared/source/os_interface/linux/os_context_linux.h"
16 #include "shared/source/os_interface/linux/sys_calls.h"
17 #include "shared/source/utilities/wait_util.h"
18 #include "shared/test/common/cmd_parse/hw_parse.h"
19 #include "shared/test/common/helpers/debug_manager_state_restore.h"
20 #include "shared/test/common/helpers/engine_descriptor_helper.h"
21 #include "shared/test/common/helpers/ult_hw_config.h"
22 #include "shared/test/common/helpers/variable_backup.h"
23 #include "shared/test/common/libult/linux/drm_mock.h"
24 #include "shared/test/common/libult/ult_command_stream_receiver.h"
25 #include "shared/test/common/mocks/linux/mock_drm_allocation.h"
26 #include "shared/test/common/mocks/mock_device.h"
27 #include "shared/test/common/mocks/mock_graphics_allocation.h"
28 #include "shared/test/common/os_interface/linux/drm_memory_manager_fixture.h"
29 #include "shared/test/common/test_macros/hw_test.h"
30
31 #include <memory>
32
33 namespace CpuIntrinsicsTests {
34 extern std::atomic<uint32_t> pauseCounter;
35 }
36
37 namespace NEO {
38 namespace SysCalls {
39 extern bool failMmap;
40 }
41 } // namespace NEO
42
43 struct DrmDirectSubmissionTest : public DrmMemoryManagerBasic {
44 void SetUp() override {
45 DrmMemoryManagerBasic::SetUp();
46 executionEnvironment.incRefInternal();
47
48 executionEnvironment.memoryManager = std::make_unique<DrmMemoryManager>(GemCloseWorkerMode::gemCloseWorkerInactive,
49 debugManager.flags.EnableForcePin.get(),
50 true,
51 executionEnvironment);
52 device.reset(MockDevice::create<MockDevice>(&executionEnvironment, 0u));
53 osContext = std::make_unique<OsContextLinux>(*executionEnvironment.rootDeviceEnvironments[0]->osInterface->getDriverModel()->as<Drm>(), device->getRootDeviceIndex(), 0u,
54 EngineDescriptorHelper::getDefaultDescriptor({aub_stream::ENGINE_RCS, EngineUsage::regular},
55 PreemptionMode::ThreadGroup, device->getDeviceBitfield()));
56 osContext->ensureContextInitialized(false);
57 device->getDefaultEngine().commandStreamReceiver->setupContext(*osContext);
58 }
59
60 void TearDown() override {
61 DrmMemoryManagerBasic::TearDown();
62 }
63
64 std::unique_ptr<OsContextLinux> osContext;
65 std::unique_ptr<MockDevice> device;
66 };
67
68 template <typename GfxFamily, typename Dispatcher>
69 struct MockDrmDirectSubmission : public DrmDirectSubmission<GfxFamily, Dispatcher> {
70 using BaseClass = DrmDirectSubmission<GfxFamily, Dispatcher>;
71 using BaseClass::activeTiles;
72 using BaseClass::allocateResources;
73 using BaseClass::completionFenceAllocation;
74 using BaseClass::completionFenceValue;
75 using BaseClass::currentRingBuffer;
76 using BaseClass::currentTagData;
77 using BaseClass::disableMonitorFence;
78 using BaseClass::dispatchMonitorFenceRequired;
79 using BaseClass::dispatchSwitchRingBufferSection;
80 using BaseClass::DrmDirectSubmission;
81 using BaseClass::getSizeNewResourceHandler;
82 using BaseClass::getSizeSwitchRingBufferSection;
83 using BaseClass::getTagAddressValue;
84 using BaseClass::handleNewResourcesSubmission;
85 using BaseClass::handleResidency;
86 using BaseClass::handleSwitchRingBuffers;
87 using BaseClass::immWritePostSyncOffset;
88 using BaseClass::inputMonitorFenceDispatchRequirement;
89 using BaseClass::isCompleted;
90 using BaseClass::isNewResourceHandleNeeded;
91 using BaseClass::miMemFenceRequired;
92 using BaseClass::partitionConfigSet;
93 using BaseClass::partitionedMode;
94 using BaseClass::pciBarrierPtr;
95 using BaseClass::ringBuffers;
96 using BaseClass::ringStart;
97 using BaseClass::sfenceMode;
98 using BaseClass::submit;
99 using BaseClass::switchRingBuffers;
100 using BaseClass::tagAddress;
101 using BaseClass::updateTagValue;
102 using BaseClass::useNotifyForPostSync;
103 using BaseClass::wait;
104 using BaseClass::workPartitionAllocation;
105 };
106
107 using namespace NEO;
108
109 HWTEST_F(DrmDirectSubmissionTest, givenDrmDirectSubmissionWhenCallingLinuxImplementationThenExpectInitialImplementationValues) {
110 MockDrmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> drmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver);
111
112 auto drm = static_cast<DrmMock *>(executionEnvironment.rootDeviceEnvironments[0]->osInterface->getDriverModel()->as<Drm>());
113 EXPECT_TRUE(drm->isDirectSubmissionActive());
114
115 EXPECT_TRUE(drmDirectSubmission.allocateResources());
116
117 uint64_t gpuAddress = 0x1000;
118 size_t size = 0x1000;
119 EXPECT_TRUE(drmDirectSubmission.submit(gpuAddress, size));
120
121 EXPECT_TRUE(drmDirectSubmission.handleResidency());
122
123 EXPECT_NE(0ull, drmDirectSubmission.switchRingBuffers(nullptr));
124
125 EXPECT_EQ(0ull, drmDirectSubmission.updateTagValue(drmDirectSubmission.dispatchMonitorFenceRequired(false)));
126
127 TagData tagData = {1ull, 1ull};
128 drmDirectSubmission.getTagAddressValue(tagData);
129 EXPECT_EQ(drmDirectSubmission.currentTagData.tagAddress, tagData.tagAddress);
130 EXPECT_EQ(drmDirectSubmission.currentTagData.tagValue + 1, tagData.tagValue);
131
132 *drmDirectSubmission.tagAddress = 1u;
133 }
134
135 HWTEST_F(DrmDirectSubmissionTest, givenDrmDirectSubmissionWhenCallingIsCompletedThenProperValueReturned) {
136 MockDrmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> drmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver);
137
138 auto drm = static_cast<DrmMock *>(executionEnvironment.rootDeviceEnvironments[0]->osInterface->getDriverModel()->as<Drm>());
139 EXPECT_TRUE(drm->isDirectSubmissionActive());
140 EXPECT_TRUE(drmDirectSubmission.allocateResources());
141
142 drmDirectSubmission.ringBuffers[0].completionFence = 1u;
143 EXPECT_FALSE(drmDirectSubmission.isCompleted(0u));
144
145 *drmDirectSubmission.tagAddress = 1u;
146 EXPECT_TRUE(drmDirectSubmission.isCompleted(0u));
147
148 drmDirectSubmission.ringBuffers[0].completionFence = 0u;
149 }
150
151 HWTEST_F(DrmDirectSubmissionTest, whenCreateDirectSubmissionThenValidObjectIsReturned) {
152 auto directSubmission = DirectSubmissionHw<FamilyType, RenderDispatcher<FamilyType>>::create(*device->getDefaultEngine().commandStreamReceiver);
153 EXPECT_NE(directSubmission.get(), nullptr);
154
155 bool ret = directSubmission->initialize(false, false);
156 EXPECT_TRUE(ret);
157 }
158
159 HWTEST_F(DrmDirectSubmissionTest, givenCompletionFenceSupportWhenCreateDrmDirectSubmissionThenTagAllocationIsSetAsCompletionFenceAllocation) {
160 DebugManagerStateRestore restorer;
161 debugManager.flags.EnableDrmCompletionFence.set(1);
162 auto &commandStreamReceiver = *device->getDefaultEngine().commandStreamReceiver;
163 auto drm = executionEnvironment.rootDeviceEnvironments[0]->osInterface->getDriverModel()->as<Drm>();
164
165 ASSERT_TRUE(drm->completionFenceSupport());
166
167 auto expectedCompletionFenceAllocation = commandStreamReceiver.getTagAllocation();
168 EXPECT_NE(nullptr, expectedCompletionFenceAllocation);
169 {
170 MockDrmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> directSubmission(commandStreamReceiver);
171 EXPECT_EQ(expectedCompletionFenceAllocation, directSubmission.completionFenceAllocation);
172 }
173 {
174 MockDrmDirectSubmission<FamilyType, BlitterDispatcher<FamilyType>> directSubmission(commandStreamReceiver);
175 EXPECT_EQ(expectedCompletionFenceAllocation, directSubmission.completionFenceAllocation);
176 }
177 }
178
179 HWTEST_F(DrmDirectSubmissionTest, givenCompletionFenceSupportWhenGettingCompletionFencePointerThenCompletionFenceValueAddressIsReturned) {
180 DebugManagerStateRestore restorer;
181 debugManager.flags.EnableDrmCompletionFence.set(1);
182 auto &commandStreamReceiver = *device->getDefaultEngine().commandStreamReceiver;
183 auto drm = executionEnvironment.rootDeviceEnvironments[0]->osInterface->getDriverModel()->as<Drm>();
184
185 ASSERT_TRUE(drm->completionFenceSupport());
186
187 MockDrmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> directSubmission(commandStreamReceiver);
188 EXPECT_EQ(&directSubmission.completionFenceValue, directSubmission.getCompletionValuePointer());
189 }
190
191 HWTEST_F(DrmDirectSubmissionTest, givenDebugFlagSetWhenInitializingThenOverrideFenceStartValue) {
192 DebugManagerStateRestore restorer;
193
194 TaskCountType fenceStartValue = 1234;
195
196 debugManager.flags.EnableDrmCompletionFence.set(1);
197 debugManager.flags.OverrideUserFenceStartValue.set(static_cast<int32_t>(fenceStartValue));
198 auto &commandStreamReceiver = *device->getDefaultEngine().commandStreamReceiver;
199 auto drm = executionEnvironment.rootDeviceEnvironments[0]->osInterface->getDriverModel()->as<Drm>();
200
201 ASSERT_TRUE(drm->completionFenceSupport());
202
203 MockDrmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> directSubmission(commandStreamReceiver);
204 EXPECT_EQ(fenceStartValue, directSubmission.completionFenceValue);
205 }
206
207 HWTEST_F(DrmDirectSubmissionTest, givenLatestSentTaskCountWhenInitializingThenSetStartValue) {
208 DebugManagerStateRestore restorer;
209
210 TaskCountType fenceStartValue = 1234;
211
212 debugManager.flags.EnableDrmCompletionFence.set(1);
213 auto &commandStreamReceiver = device->getUltCommandStreamReceiver<FamilyType>();
214
215 commandStreamReceiver.latestSentTaskCount = fenceStartValue;
216
217 auto drm = executionEnvironment.rootDeviceEnvironments[0]->osInterface->getDriverModel()->as<Drm>();
218
219 ASSERT_TRUE(drm->completionFenceSupport());
220
221 MockDrmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> directSubmission(commandStreamReceiver);
222 EXPECT_EQ(fenceStartValue, directSubmission.completionFenceValue);
223 }
224
225 HWTEST_F(DrmDirectSubmissionTest, givenNoCompletionFenceSupportWhenGettingCompletionFencePointerThenNullptrIsReturned) {
226 DebugManagerStateRestore restorer;
227 debugManager.flags.EnableDrmCompletionFence.set(0);
228 auto &commandStreamReceiver = *device->getDefaultEngine().commandStreamReceiver;
229 auto drm = executionEnvironment.rootDeviceEnvironments[0]->osInterface->getDriverModel()->as<Drm>();
230
231 ASSERT_FALSE(drm->completionFenceSupport());
232
233 MockDrmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> directSubmission(commandStreamReceiver);
234 EXPECT_EQ(nullptr, directSubmission.getCompletionValuePointer());
235 }
236
237 HWTEST_F(DrmDirectSubmissionTest, givenPciBarrierWhenCreateDirectSubmissionThenPtrMappedAndOtherSyncMethodsDisabled) {
238 auto drm = executionEnvironment.rootDeviceEnvironments[0]->osInterface->getDriverModel()->as<Drm>();
239 auto ptr = drm->getIoctlHelper()->pciBarrierMmap();
240 if (!ptr) {
241 GTEST_SKIP();
242 }
243
244 DebugManagerStateRestore restorer;
245 debugManager.flags.DirectSubmissionPCIBarrier.set(1);
246 auto &commandStreamReceiver = *device->getDefaultEngine().commandStreamReceiver;
247
248 MockDrmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> directSubmission(commandStreamReceiver);
249
250 EXPECT_NE(nullptr, directSubmission.pciBarrierPtr);
251 EXPECT_NE(DirectSubmissionSfenceMode::disabled, directSubmission.sfenceMode);
252 EXPECT_FALSE(directSubmission.miMemFenceRequired);
253
254 SysCalls::munmap(ptr, MemoryConstants::pageSize);
255 }
256
257 HWTEST_F(DrmDirectSubmissionTest, givenPciBarrierWhenCreateDirectSubmissionAndMmapFailsThenPtrNotMappedAndOtherSyncMethodsRemain) {
258 auto drm = executionEnvironment.rootDeviceEnvironments[0]->osInterface->getDriverModel()->as<Drm>();
259 auto ptr = drm->getIoctlHelper()->pciBarrierMmap();
260 if (!ptr) {
261 GTEST_SKIP();
262 }
263
264 DebugManagerStateRestore restorer;
265 debugManager.flags.DirectSubmissionPCIBarrier.set(1);
266 auto &commandStreamReceiver = *device->getDefaultEngine().commandStreamReceiver;
267 VariableBackup<bool> backup(&SysCalls::failMmap, true);
268
269 MockDrmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> directSubmission(commandStreamReceiver);
270
271 EXPECT_EQ(nullptr, directSubmission.pciBarrierPtr);
272 EXPECT_NE(DirectSubmissionSfenceMode::disabled, directSubmission.sfenceMode);
273 auto expectMiMemFence = device->getHardwareInfo().capabilityTable.isIntegratedDevice ? false : device->getRootDeviceEnvironment().getHelper<ProductHelper>().isGlobalFenceInDirectSubmissionRequired(device->getHardwareInfo());
274 EXPECT_EQ(directSubmission.miMemFenceRequired, expectMiMemFence);
275
276 SysCalls::munmap(ptr, MemoryConstants::pageSize);
277 }
278
279 HWTEST_F(DrmDirectSubmissionTest, givenPciBarrierDisabledWhenCreateDirectSubmissionThenPtrNotMappedAndOtherSyncMethodsRemain) {
280 auto drm = executionEnvironment.rootDeviceEnvironments[0]->osInterface->getDriverModel()->as<Drm>();
281 auto ptr = drm->getIoctlHelper()->pciBarrierMmap();
282 if (!ptr) {
283 GTEST_SKIP();
284 }
285
286 DebugManagerStateRestore restorer;
287 debugManager.flags.DirectSubmissionPCIBarrier.set(0);
288 auto &commandStreamReceiver = *device->getDefaultEngine().commandStreamReceiver;
289
290 MockDrmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> directSubmission(commandStreamReceiver);
291
292 EXPECT_EQ(nullptr, directSubmission.pciBarrierPtr);
293 EXPECT_NE(DirectSubmissionSfenceMode::disabled, directSubmission.sfenceMode);
294 auto expectMiMemFence = device->getHardwareInfo().capabilityTable.isIntegratedDevice ? false : device->getRootDeviceEnvironment().getHelper<ProductHelper>().isGlobalFenceInDirectSubmissionRequired(device->getHardwareInfo());
295 EXPECT_EQ(directSubmission.miMemFenceRequired, expectMiMemFence);
296
297 SysCalls::munmap(ptr, MemoryConstants::pageSize);
298 }
299
300 HWTEST_F(DrmDirectSubmissionTest, givenNoCompletionFenceSupportWhenCreateDrmDirectSubmissionThenCompletionFenceAllocationIsNotSet) {
301 DebugManagerStateRestore restorer;
302 debugManager.flags.EnableDrmCompletionFence.set(0);
303 auto &commandStreamReceiver = *device->getDefaultEngine().commandStreamReceiver;
304 auto drm = executionEnvironment.rootDeviceEnvironments[0]->osInterface->getDriverModel()->as<Drm>();
305
306 ASSERT_FALSE(drm->completionFenceSupport());
307 {
308 MockDrmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> directSubmission(commandStreamReceiver);
309 EXPECT_EQ(directSubmission.miMemFenceRequired, directSubmission.completionFenceAllocation != nullptr);
310 }
311 {
312 MockDrmDirectSubmission<FamilyType, BlitterDispatcher<FamilyType>> directSubmission(commandStreamReceiver);
313 EXPECT_EQ(directSubmission.miMemFenceRequired, directSubmission.completionFenceAllocation != nullptr);
314 }
315 }
316
317 HWTEST_F(DrmDirectSubmissionTest, givenDirectSubmissionWithoutCompletionFenceAllocationWhenDestroyingThenNoWaitForUserFenceIsCalled) {
318 DebugManagerStateRestore restorer;
319 debugManager.flags.EnableDrmCompletionFence.set(0);
320 auto &commandStreamReceiver = *device->getDefaultEngine().commandStreamReceiver;
321 auto drm = static_cast<DrmMock *>(executionEnvironment.rootDeviceEnvironments[0]->osInterface->getDriverModel()->as<Drm>());
322
323 ASSERT_FALSE(drm->completionFenceSupport());
324
325 drm->waitUserFenceParams.clear();
326 {
327 MockDrmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> directSubmission(commandStreamReceiver);
328 directSubmission.completionFenceValue = 10;
329 }
330
331 EXPECT_EQ(0u, drm->waitUserFenceParams.size());
332 }
333
334 HWTEST_F(DrmDirectSubmissionTest, givenCompletionFenceSupportAndFenceIsNotCompletedWhenDestroyingThenWaitForUserFenceIsCalled) {
335 DebugManagerStateRestore restorer;
336 debugManager.flags.EnableDrmCompletionFence.set(1);
337
338 auto &commandStreamReceiver = *device->getDefaultEngine().commandStreamReceiver;
339 auto drm = static_cast<DrmMock *>(executionEnvironment.rootDeviceEnvironments[0]->osInterface->getDriverModel()->as<Drm>());
340
341 ASSERT_TRUE(drm->completionFenceSupport());
342
343 drm->waitUserFenceParams.clear();
344 {
345 MockDrmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> directSubmission(commandStreamReceiver);
346 directSubmission.completionFenceValue = 10;
347 }
348
349 EXPECT_EQ(osContext->getDrmContextIds().size(), drm->waitUserFenceParams.size());
350 }
351
352 HWTEST_F(DrmDirectSubmissionTest, givenCompletionFenceSupportAndHangingContextWhenDestroyingThenWaitForUserFenceIsCalledWithSmallTimeout) {
353 DebugManagerStateRestore restorer;
354 debugManager.flags.EnableDrmCompletionFence.set(1);
355
356 auto &commandStreamReceiver = *device->getDefaultEngine().commandStreamReceiver;
357 auto drm = static_cast<DrmMock *>(executionEnvironment.rootDeviceEnvironments[0]->osInterface->getDriverModel()->as<Drm>());
358
359 ASSERT_TRUE(drm->completionFenceSupport());
360
361 drm->waitUserFenceParams.clear();
362
363 osContext->setHangDetected();
364 {
365 MockDrmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> directSubmission(commandStreamReceiver);
366 directSubmission.completionFenceValue = 10;
367 }
368
369 EXPECT_EQ(osContext->getDrmContextIds().size(), drm->waitUserFenceParams.size());
370 EXPECT_EQ(1, drm->waitUserFenceParams[0].timeout);
371 EXPECT_EQ(10u, drm->waitUserFenceParams[0].value);
372 EXPECT_EQ(Drm::ValueWidth::u64, drm->waitUserFenceParams[0].dataWidth);
373 }
374
375 HWTEST_F(DrmDirectSubmissionTest, givenCompletionFenceSupportAndFenceIsNotCompletedWhenWaitOnSpecificAddressesPerOsContext) {
376 DebugManagerStateRestore restorer;
377 debugManager.flags.EnableDrmCompletionFence.set(1);
378
379 auto &commandStreamReceiver = device->getUltCommandStreamReceiver<FamilyType>();
380 memset(commandStreamReceiver.getTagAllocation()->getUnderlyingBuffer(), 0, commandStreamReceiver.getTagAllocation()->getUnderlyingBufferSize());
381 auto drm = static_cast<DrmMock *>(executionEnvironment.rootDeviceEnvironments[0]->osInterface->getDriverModel()->as<Drm>());
382
383 ASSERT_TRUE(drm->completionFenceSupport());
384 auto completionFenceBaseCpuAddress = reinterpret_cast<uint64_t>(commandStreamReceiver.getTagAddress()) + TagAllocationLayout::completionFenceOffset;
385 uint32_t expectedCompletionValueToWait = 10u;
386
387 {
388 DeviceBitfield firstTileBitfield{0b01};
389 OsContextLinux osContext(*drm, 0, 0u,
390 EngineDescriptorHelper::getDefaultDescriptor({aub_stream::ENGINE_RCS, EngineUsage::regular},
391 PreemptionMode::ThreadGroup, firstTileBitfield));
392 osContext.ensureContextInitialized(false);
393 commandStreamReceiver.setupContext(osContext);
394 drm->waitUserFenceParams.clear();
395 {
396 MockDrmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> directSubmission(commandStreamReceiver);
397 directSubmission.completionFenceValue = expectedCompletionValueToWait;
398 }
399 EXPECT_EQ(1u, drm->waitUserFenceParams.size());
400 EXPECT_EQ(expectedCompletionValueToWait, drm->waitUserFenceParams[0].value);
401 EXPECT_EQ(completionFenceBaseCpuAddress, drm->waitUserFenceParams[0].address);
402 }
403 {
404 DeviceBitfield secondTileBitfield{0b10};
405 OsContextLinux osContext(*drm, 0, 0u,
406 EngineDescriptorHelper::getDefaultDescriptor({aub_stream::ENGINE_RCS, EngineUsage::regular},
407 PreemptionMode::ThreadGroup, secondTileBitfield));
408 osContext.ensureContextInitialized(false);
409 commandStreamReceiver.setupContext(osContext);
410 drm->waitUserFenceParams.clear();
411 {
412 MockDrmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> directSubmission(commandStreamReceiver);
413 directSubmission.completionFenceValue = expectedCompletionValueToWait;
414 }
415 EXPECT_EQ(1u, drm->waitUserFenceParams.size());
416 EXPECT_EQ(expectedCompletionValueToWait, drm->waitUserFenceParams[0].value);
417 EXPECT_EQ(completionFenceBaseCpuAddress, drm->waitUserFenceParams[0].address);
418 }
419
420 {
421 DeviceBitfield twoTilesBitfield{0b11};
422 OsContextLinux osContext(*drm, 0, 0u,
423 EngineDescriptorHelper::getDefaultDescriptor({aub_stream::ENGINE_RCS, EngineUsage::regular},
424 PreemptionMode::ThreadGroup, twoTilesBitfield));
425 osContext.ensureContextInitialized(false);
426 commandStreamReceiver.setupContext(osContext);
427 drm->waitUserFenceParams.clear();
428 MockGraphicsAllocation workPartitionAllocation{};
429 commandStreamReceiver.workPartitionAllocation = &workPartitionAllocation;
430 {
431 debugManager.flags.EnableImplicitScaling.set(1);
432 MockDrmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> directSubmission(commandStreamReceiver);
433 directSubmission.completionFenceValue = expectedCompletionValueToWait;
434 }
435 commandStreamReceiver.workPartitionAllocation = nullptr;
436
437 EXPECT_EQ(2u, drm->waitUserFenceParams.size());
438 EXPECT_EQ(expectedCompletionValueToWait, drm->waitUserFenceParams[0].value);
439 EXPECT_EQ(completionFenceBaseCpuAddress, drm->waitUserFenceParams[0].address);
440
441 EXPECT_EQ(expectedCompletionValueToWait, drm->waitUserFenceParams[1].value);
442 EXPECT_EQ(completionFenceBaseCpuAddress + commandStreamReceiver.getImmWritePostSyncWriteOffset(), drm->waitUserFenceParams[1].address);
443 }
444 commandStreamReceiver.setupContext(*osContext);
445 }
446
447 HWTEST_F(DrmDirectSubmissionTest, givenNoCompletionFenceSupportWhenSubmittingThenNoCompletionAddressIsPassedToExec) {
448 uint64_t gpuAddress = 0x1000;
449 size_t size = 0x1000;
450 DebugManagerStateRestore restorer;
451 debugManager.flags.EnableDrmCompletionFence.set(0);
452
453 MockDrmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> drmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver);
454 drmDirectSubmission.completionFenceAllocation = nullptr;
455 EXPECT_TRUE(drmDirectSubmission.allocateResources());
456 auto ringBuffer = static_cast<DrmAllocation *>(drmDirectSubmission.ringBuffers[drmDirectSubmission.currentRingBuffer].ringBuffer);
457 auto initialBO = ringBuffer->getBufferObjectToModify(0);
458
459 auto drm = executionEnvironment.rootDeviceEnvironments[0]->osInterface->getDriverModel()->as<Drm>();
460 MockBufferObject mockBO(0, drm);
461 ringBuffer->getBufferObjectToModify(0) = &mockBO;
462
463 for (auto i = 0; i < 2; i++) {
464 mockBO.passedExecParams.clear();
465 EXPECT_TRUE(drmDirectSubmission.submit(gpuAddress, size));
466
467 ASSERT_EQ(1u, mockBO.passedExecParams.size());
468 EXPECT_EQ(0u, mockBO.passedExecParams[0].completionGpuAddress);
469 EXPECT_EQ(0u, mockBO.passedExecParams[0].completionValue);
470 }
471 ringBuffer->getBufferObjectToModify(0) = initialBO;
472 }
473
474 HWTEST_F(DrmDirectSubmissionTest, givenNoCompletionFenceSupportAndExecFailureWhenSubmittingThenGetDispatchErrorCode) {
475 uint64_t gpuAddress = 0x1000;
476 size_t size = 0x1000;
477 DebugManagerStateRestore restorer;
478 debugManager.flags.EnableDrmCompletionFence.set(0);
479
480 MockDrmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> drmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver);
481 drmDirectSubmission.completionFenceAllocation = nullptr;
482 EXPECT_TRUE(drmDirectSubmission.allocateResources());
483 auto ringBuffer = static_cast<DrmAllocation *>(drmDirectSubmission.ringBuffers[drmDirectSubmission.currentRingBuffer].ringBuffer);
484 auto initialBO = ringBuffer->getBufferObjectToModify(0);
485
486 auto drm = executionEnvironment.rootDeviceEnvironments[0]->osInterface->getDriverModel()->as<Drm>();
487 MockBufferObject mockBO(0, drm);
488 ringBuffer->getBufferObjectToModify(0) = &mockBO;
489
490 mockBO.execReturnValue = ENXIO;
491 EXPECT_FALSE(drmDirectSubmission.submit(gpuAddress, size));
492 EXPECT_EQ((uint32_t)ENXIO, drmDirectSubmission.getDispatchErrorCode());
493
494 ringBuffer->getBufferObjectToModify(0) = initialBO;
495 }
496
497 HWTEST_F(DrmDirectSubmissionTest, givenCompletionFenceSupportAndExecFailureWhenSubmittingThenCompletionFenceValueIsNotIncreased) {
498 uint64_t gpuAddress = 0x1000;
499 size_t size = 0x1000;
500 DebugManagerStateRestore restorer;
501 debugManager.flags.EnableDrmCompletionFence.set(1);
502
503 auto &commandStreamReceiver = *device->getDefaultEngine().commandStreamReceiver;
504 auto drm = executionEnvironment.rootDeviceEnvironments[0]->osInterface->getDriverModel()->as<Drm>();
505
506 MockDrmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> drmDirectSubmission(commandStreamReceiver);
507 drmDirectSubmission.completionFenceAllocation = commandStreamReceiver.getTagAllocation();
508 EXPECT_TRUE(drmDirectSubmission.allocateResources());
509 auto ringBuffer = static_cast<DrmAllocation *>(drmDirectSubmission.ringBuffers[drmDirectSubmission.currentRingBuffer].ringBuffer);
510 auto initialBO = ringBuffer->getBufferObjectToModify(0);
511
512 MockBufferObject mockBO(0, drm);
513 ringBuffer->getBufferObjectToModify(0) = &mockBO;
514
515 mockBO.execReturnValue = 1;
516 drmDirectSubmission.completionFenceValue = 1u;
517 EXPECT_FALSE(drmDirectSubmission.submit(gpuAddress, size));
518 EXPECT_EQ(1u, drmDirectSubmission.completionFenceValue);
519
520 ringBuffer->getBufferObjectToModify(0) = initialBO;
521 }
522
523 HWTEST_F(DrmDirectSubmissionTest, givenTile0AndCompletionFenceSupportWhenSubmittingThenCompletionAddressAndValueArePassedToExec) {
524 uint64_t gpuAddress = 0x1000;
525 size_t size = 0x1000;
526 DebugManagerStateRestore restorer;
527 debugManager.flags.EnableDrmCompletionFence.set(1);
528
529 auto &commandStreamReceiver = *device->getDefaultEngine().commandStreamReceiver;
530 auto drm = executionEnvironment.rootDeviceEnvironments[0]->osInterface->getDriverModel()->as<Drm>();
531 auto completionFenceBaseGpuAddress = commandStreamReceiver.getTagAllocation()->getGpuAddress() + TagAllocationLayout::completionFenceOffset;
532
533 DeviceBitfield firstTileBitfield{0b01};
534 OsContextLinux osContextTile0(*drm, 0, 0u,
535 EngineDescriptorHelper::getDefaultDescriptor({aub_stream::ENGINE_RCS, EngineUsage::regular},
536 PreemptionMode::ThreadGroup, firstTileBitfield));
537 osContextTile0.ensureContextInitialized(false);
538 commandStreamReceiver.setupContext(osContextTile0);
539
540 MockDrmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> drmDirectSubmission(commandStreamReceiver);
541 drmDirectSubmission.completionFenceAllocation = commandStreamReceiver.getTagAllocation();
542 EXPECT_TRUE(drmDirectSubmission.allocateResources());
543 auto ringBuffer = static_cast<DrmAllocation *>(drmDirectSubmission.ringBuffers[drmDirectSubmission.currentRingBuffer].ringBuffer);
544 auto initialBO = ringBuffer->getBufferObjectToModify(0);
545
546 MockBufferObject mockBO(0, drm);
547 ringBuffer->getBufferObjectToModify(0) = &mockBO;
548
549 for (auto i = 0u; i < 2; i++) {
550 mockBO.passedExecParams.clear();
551 EXPECT_TRUE(drmDirectSubmission.submit(gpuAddress, size));
552
553 ASSERT_EQ(1u, mockBO.passedExecParams.size());
554 EXPECT_EQ(completionFenceBaseGpuAddress, mockBO.passedExecParams[0].completionGpuAddress);
555 EXPECT_EQ(i + 1, mockBO.passedExecParams[0].completionValue);
556 }
557 ringBuffer->getBufferObjectToModify(0) = initialBO;
558
559 commandStreamReceiver.setupContext(*osContext);
560 }
561
562 HWTEST_F(DrmDirectSubmissionTest, givenTile1AndCompletionFenceSupportWhenSubmittingThenCompletionAddressAndValueArePassedToExec) {
563 uint64_t gpuAddress = 0x1000;
564 size_t size = 0x1000;
565 DebugManagerStateRestore restorer;
566 debugManager.flags.EnableDrmCompletionFence.set(1);
567
568 auto &commandStreamReceiver = *device->getDefaultEngine().commandStreamReceiver;
569 auto drm = executionEnvironment.rootDeviceEnvironments[0]->osInterface->getDriverModel()->as<Drm>();
570 auto completionFenceBaseGpuAddress = commandStreamReceiver.getTagAllocation()->getGpuAddress() + TagAllocationLayout::completionFenceOffset;
571
572 DeviceBitfield secondTileBitfield{0b10};
573 OsContextLinux osContextTile1(*drm, 0, 0u,
574 EngineDescriptorHelper::getDefaultDescriptor({aub_stream::ENGINE_RCS, EngineUsage::regular},
575 PreemptionMode::ThreadGroup, secondTileBitfield));
576 osContextTile1.ensureContextInitialized(false);
577 commandStreamReceiver.setupContext(osContextTile1);
578
579 MockDrmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> drmDirectSubmission(commandStreamReceiver);
580 drmDirectSubmission.completionFenceAllocation = commandStreamReceiver.getTagAllocation();
581 EXPECT_TRUE(drmDirectSubmission.allocateResources());
582 auto ringBuffer = static_cast<DrmAllocation *>(drmDirectSubmission.ringBuffers[drmDirectSubmission.currentRingBuffer].ringBuffer);
583 auto initialBO = ringBuffer->getBufferObjectToModify(0);
584
585 MockBufferObject mockBO(0, drm);
586 ringBuffer->getBufferObjectToModify(0) = &mockBO;
587
588 for (auto i = 0u; i < 2; i++) {
589 mockBO.passedExecParams.clear();
590 EXPECT_TRUE(drmDirectSubmission.submit(gpuAddress, size));
591
592 ASSERT_EQ(1u, mockBO.passedExecParams.size());
593 EXPECT_EQ(completionFenceBaseGpuAddress, mockBO.passedExecParams[0].completionGpuAddress);
594 EXPECT_EQ(i + 1, mockBO.passedExecParams[0].completionValue);
595 }
596 ringBuffer->getBufferObjectToModify(0) = initialBO;
597
598 commandStreamReceiver.setupContext(*osContext);
599 }
600
601 HWTEST_F(DrmDirectSubmissionTest, givenTwoTilesAndCompletionFenceSupportWhenSubmittingThenCompletionAddressAndValueArePassedToExec) {
602 uint64_t gpuAddress = 0x1000;
603 size_t size = 0x1000;
604 DebugManagerStateRestore restorer;
605 debugManager.flags.EnableDrmCompletionFence.set(1);
606
607 auto &commandStreamReceiver = device->getUltCommandStreamReceiver<FamilyType>();
608 auto drm = executionEnvironment.rootDeviceEnvironments[0]->osInterface->getDriverModel()->as<Drm>();
609 auto completionFenceBaseGpuAddress = commandStreamReceiver.getTagAllocation()->getGpuAddress() + TagAllocationLayout::completionFenceOffset;
610
611 DeviceBitfield twoTilesBitfield{0b11};
612 OsContextLinux osContextBothTiles(*drm, 0, 0u,
613 EngineDescriptorHelper::getDefaultDescriptor({aub_stream::ENGINE_RCS, EngineUsage::regular},
614 PreemptionMode::ThreadGroup, twoTilesBitfield));
615 osContextBothTiles.ensureContextInitialized(false);
616 commandStreamReceiver.setupContext(osContextBothTiles);
617
618 MockGraphicsAllocation workPartitionAllocation{};
619 commandStreamReceiver.workPartitionAllocation = &workPartitionAllocation;
620
621 MockDrmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> drmDirectSubmission(commandStreamReceiver);
622
623 commandStreamReceiver.workPartitionAllocation = nullptr;
624
625 drmDirectSubmission.completionFenceAllocation = commandStreamReceiver.getTagAllocation();
626 EXPECT_TRUE(drmDirectSubmission.allocateResources());
627 auto ringBuffer = static_cast<DrmAllocation *>(drmDirectSubmission.ringBuffers[drmDirectSubmission.currentRingBuffer].ringBuffer);
628 auto initialBO = ringBuffer->getBufferObjectToModify(0);
629
630 MockBufferObject mockBO(0, drm);
631 ringBuffer->getBufferObjectToModify(0) = &mockBO;
632
633 for (auto i = 0u; i < 2; i++) {
634 mockBO.passedExecParams.clear();
635 EXPECT_TRUE(drmDirectSubmission.submit(gpuAddress, size));
636
637 ASSERT_EQ(2u, mockBO.passedExecParams.size());
638 EXPECT_EQ(completionFenceBaseGpuAddress, mockBO.passedExecParams[0].completionGpuAddress);
639 EXPECT_EQ(i + 1, mockBO.passedExecParams[0].completionValue);
640
641 EXPECT_EQ(completionFenceBaseGpuAddress + commandStreamReceiver.getImmWritePostSyncWriteOffset(), mockBO.passedExecParams[1].completionGpuAddress);
642 EXPECT_EQ(i + 1, mockBO.passedExecParams[1].completionValue);
643 }
644 ringBuffer->getBufferObjectToModify(0) = initialBO;
645
646 commandStreamReceiver.setupContext(*osContext);
647 }
648
649 HWTEST_F(DrmDirectSubmissionTest, givenDisabledMonitorFenceWhenDispatchSwitchRingBufferThenDispatchPipeControl) {
650 using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
651 using Dispatcher = RenderDispatcher<FamilyType>;
652
653 MockDrmDirectSubmission<FamilyType, Dispatcher> directSubmission(*device->getDefaultEngine().commandStreamReceiver);
654 directSubmission.disableMonitorFence = true;
655 directSubmission.ringStart = true;
656
657 bool ret = directSubmission.allocateResources();
658 EXPECT_TRUE(ret);
659
660 uint64_t newAddress = 0x1234;
661 directSubmission.dispatchSwitchRingBufferSection(newAddress);
662
663 HardwareParse hwParse;
664 hwParse.parsePipeControl = true;
665 hwParse.parseCommands<FamilyType>(directSubmission.ringCommandStream, 0);
666 hwParse.findHardwareCommands<FamilyType>();
667 auto *pipeControl = hwParse.getCommand<PIPE_CONTROL>();
668
669 EXPECT_NE(pipeControl, nullptr);
670 EXPECT_EQ(directSubmission.getSizeSwitchRingBufferSection(), Dispatcher::getSizeStartCommandBuffer() + Dispatcher::getSizeMonitorFence(device->getRootDeviceEnvironment()));
671
672 directSubmission.currentTagData.tagValue--;
673 }
674
675 HWTEST_F(DrmDirectSubmissionTest, givenDisabledMonitorFenceWhenUpdateTagValueThenTagIsNotUpdated) {
676 using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
677 using Dispatcher = RenderDispatcher<FamilyType>;
678
679 MockDrmDirectSubmission<FamilyType, Dispatcher> directSubmission(*device->getDefaultEngine().commandStreamReceiver);
680 directSubmission.disableMonitorFence = true;
681 directSubmission.ringStart = true;
682
683 bool ret = directSubmission.allocateResources();
684 EXPECT_TRUE(ret);
685
686 auto currentTag = directSubmission.currentTagData.tagValue;
687 directSubmission.updateTagValue(directSubmission.dispatchMonitorFenceRequired(false));
688
689 auto updatedTag = directSubmission.currentTagData.tagValue;
690
691 EXPECT_EQ(currentTag, updatedTag);
692
693 directSubmission.currentTagData.tagValue--;
694 }
695
696 HWTEST_F(DrmDirectSubmissionTest, whenCheckForDirectSubmissionSupportThenProperValueIsReturned) {
697 auto directSubmissionSupported = osContext->isDirectSubmissionSupported();
698
699 auto &productHelper = device->getProductHelper();
700 EXPECT_EQ(directSubmissionSupported, productHelper.isDirectSubmissionSupported(device->getReleaseHelper()) && executionEnvironment.rootDeviceEnvironments[0]->osInterface->getDriverModel()->as<Drm>()->isVmBindAvailable());
701 }
702
703 HWTEST_F(DrmDirectSubmissionTest, givenDirectSubmissionNewResourceTlbFlushWhenDispatchCommandBufferThenTlbIsFlushed) {
704 using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
705 using Dispatcher = RenderDispatcher<FamilyType>;
706
707 DebugManagerStateRestore restorer;
708 debugManager.flags.DirectSubmissionNewResourceTlbFlush.set(1);
709
710 MockDrmDirectSubmission<FamilyType, Dispatcher> directSubmission(*device->getDefaultEngine().commandStreamReceiver);
711
712 bool ret = directSubmission.allocateResources();
713 EXPECT_TRUE(ret);
714
715 EXPECT_EQ(directSubmission.getSizeNewResourceHandler(), sizeof(PIPE_CONTROL));
716
717 directSubmission.handleNewResourcesSubmission();
718
719 HardwareParse hwParse;
720 hwParse.parsePipeControl = true;
721 hwParse.parseCommands<FamilyType>(directSubmission.ringCommandStream, 0);
722 hwParse.findHardwareCommands<FamilyType>();
723 auto *pipeControl = hwParse.getCommand<PIPE_CONTROL>();
724 EXPECT_TRUE(pipeControl->getTlbInvalidate());
725 EXPECT_TRUE(pipeControl->getTextureCacheInvalidationEnable());
726
727 EXPECT_EQ(directSubmission.getSizeNewResourceHandler(), sizeof(PIPE_CONTROL));
728 }
729
730 HWTEST_F(DrmDirectSubmissionTest, givenNewResourceBoundWhenDispatchCommandBufferThenTlbIsFlushed) {
731 using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
732 using Dispatcher = RenderDispatcher<FamilyType>;
733
734 DebugManagerStateRestore restorer;
735 debugManager.flags.DirectSubmissionNewResourceTlbFlush.set(-1);
736
737 MockDrmDirectSubmission<FamilyType, Dispatcher> directSubmission(*device->getDefaultEngine().commandStreamReceiver);
738
739 bool ret = directSubmission.allocateResources();
740 EXPECT_TRUE(ret);
741
742 osContext->setNewResourceBound();
743
744 EXPECT_EQ(directSubmission.getSizeNewResourceHandler(), sizeof(PIPE_CONTROL));
745 EXPECT_TRUE(osContext->isTlbFlushRequired());
746
747 directSubmission.handleNewResourcesSubmission();
748
749 HardwareParse hwParse;
750 hwParse.parsePipeControl = true;
751 hwParse.parseCommands<FamilyType>(directSubmission.ringCommandStream, 0);
752 hwParse.findHardwareCommands<FamilyType>();
753 auto *pipeControl = hwParse.getCommand<PIPE_CONTROL>();
754 EXPECT_TRUE(pipeControl->getTlbInvalidate());
755
756 EXPECT_EQ(directSubmission.getSizeNewResourceHandler(), sizeof(PIPE_CONTROL));
757 }
758
759 HWTEST_F(DrmDirectSubmissionTest, givenNoNewResourceBoundWhenDispatchCommandBufferThenTlbIsNotFlushed) {
760 using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
761 using Dispatcher = RenderDispatcher<FamilyType>;
762
763 DebugManagerStateRestore restorer;
764 debugManager.flags.DirectSubmissionNewResourceTlbFlush.set(-1);
765
766 MockDrmDirectSubmission<FamilyType, Dispatcher> directSubmission(*device->getDefaultEngine().commandStreamReceiver);
767
768 bool ret = directSubmission.allocateResources();
769 EXPECT_TRUE(ret);
770
771 EXPECT_EQ(directSubmission.getSizeNewResourceHandler(), sizeof(PIPE_CONTROL));
772
773 directSubmission.handleNewResourcesSubmission();
774
775 HardwareParse hwParse;
776 hwParse.parsePipeControl = true;
777 hwParse.parseCommands<FamilyType>(directSubmission.ringCommandStream, 0);
778 hwParse.findHardwareCommands<FamilyType>();
779 auto *pipeControl = hwParse.getCommand<PIPE_CONTROL>();
780 EXPECT_EQ(pipeControl, nullptr);
781 EXPECT_FALSE(osContext->isTlbFlushRequired());
782
783 EXPECT_EQ(directSubmission.getSizeNewResourceHandler(), sizeof(PIPE_CONTROL));
784 }
785
786 HWTEST_F(DrmDirectSubmissionTest, givenDirectSubmissionNewResourceTlbFlushZeroAndNewResourceBoundWhenDispatchCommandBufferThenTlbIsNotFlushed) {
787 using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
788 using Dispatcher = RenderDispatcher<FamilyType>;
789
790 DebugManagerStateRestore restorer;
791 debugManager.flags.DirectSubmissionNewResourceTlbFlush.set(0);
792
793 MockDrmDirectSubmission<FamilyType, Dispatcher> directSubmission(*device->getDefaultEngine().commandStreamReceiver);
794
795 bool ret = directSubmission.allocateResources();
796 EXPECT_TRUE(ret);
797
798 EXPECT_EQ(directSubmission.getSizeNewResourceHandler(), sizeof(PIPE_CONTROL));
799
800 directSubmission.handleNewResourcesSubmission();
801
802 HardwareParse hwParse;
803 hwParse.parsePipeControl = true;
804 hwParse.parseCommands<FamilyType>(directSubmission.ringCommandStream, 0);
805 hwParse.findHardwareCommands<FamilyType>();
806 auto *pipeControl = hwParse.getCommand<PIPE_CONTROL>();
807 EXPECT_EQ(pipeControl, nullptr);
808 EXPECT_FALSE(osContext->isTlbFlushRequired());
809
810 EXPECT_EQ(directSubmission.getSizeNewResourceHandler(), sizeof(PIPE_CONTROL));
811 }
812
813 HWCMDTEST_F(IGFX_XE_HP_CORE, DrmDirectSubmissionTest, givenMultipleActiveTilesWhenWaitingForTagUpdateThenQueryAllActiveTiles) {
814 using Dispatcher = RenderDispatcher<FamilyType>;
815
816 VariableBackup<bool> backupWaitpkgUse(&WaitUtils::waitpkgUse, false);
817 VariableBackup<uint32_t> backupWaitCount(&WaitUtils::waitCount, 1);
818
819 MockDrmDirectSubmission<FamilyType, Dispatcher> directSubmission(*device->getDefaultEngine().commandStreamReceiver);
820
821 uint32_t offset = directSubmission.immWritePostSyncOffset;
822 EXPECT_NE(0u, offset);
823 bool ret = directSubmission.allocateResources();
824 EXPECT_TRUE(ret);
825 directSubmission.activeTiles = 2;
826
827 auto pollAddress = directSubmission.tagAddress;
828 *pollAddress = 10;
829 pollAddress = ptrOffset(pollAddress, offset);
830 *pollAddress = 10;
831
832 CpuIntrinsicsTests::pauseCounter = 0;
833 directSubmission.wait(9);
834 EXPECT_EQ(2u, CpuIntrinsicsTests::pauseCounter);
835 }
836
837 HWTEST_F(DrmDirectSubmissionTest,
838 givenRenderDispatcherAndMultiTileDeviceWhenCreatingDirectSubmissionUsingMultiTileContextThenExpectActiveTilesMatchSubDeviceCount) {
839 using Dispatcher = RenderDispatcher<FamilyType>;
840
841 VariableBackup<bool> backup(&ImplicitScaling::apiSupport, true);
842 device->deviceBitfield.set(0b11);
843 device->rootCsrCreated = true;
844 device->numSubDevices = 2;
845
846 osContext = std::make_unique<OsContextLinux>(*executionEnvironment.rootDeviceEnvironments[0]->osInterface->getDriverModel()->as<Drm>(), device->getRootDeviceIndex(), 0u,
847 EngineDescriptorHelper::getDefaultDescriptor({aub_stream::ENGINE_RCS, EngineUsage::regular},
848 PreemptionMode::ThreadGroup, device->getDeviceBitfield()));
849 osContext->ensureContextInitialized(false);
850 EXPECT_EQ(2u, osContext->getDeviceBitfield().count());
851
852 auto ultCsr = reinterpret_cast<UltCommandStreamReceiver<FamilyType> *>(device->getDefaultEngine().commandStreamReceiver);
853 ultCsr->staticWorkPartitioningEnabled = true;
854 ultCsr->createWorkPartitionAllocation(*device);
855
856 device->getDefaultEngine().commandStreamReceiver->setupContext(*osContext);
857 MockDrmDirectSubmission<FamilyType, Dispatcher> directSubmission(*device->getDefaultEngine().commandStreamReceiver);
858
859 EXPECT_EQ(2u, directSubmission.activeTiles);
860 EXPECT_TRUE(directSubmission.partitionedMode);
861 EXPECT_FALSE(directSubmission.partitionConfigSet);
862
863 bool ret = directSubmission.allocateResources();
864 EXPECT_TRUE(ret);
865 }
866
867 HWTEST_F(DrmDirectSubmissionTest, givenRenderDispatcherAndMultiTileDeviceWhenCreatingDirectSubmissionSingleTileContextThenExpectActiveTilesEqualsSingleTile) {
868 using Dispatcher = RenderDispatcher<FamilyType>;
869
870 VariableBackup<bool> backup(&ImplicitScaling::apiSupport, true);
871 device->deviceBitfield.set(0b11);
872 device->rootCsrCreated = true;
873 device->numSubDevices = 2;
874
875 EXPECT_EQ(1u, osContext->getDeviceBitfield().count());
876
877 auto ultCsr = reinterpret_cast<UltCommandStreamReceiver<FamilyType> *>(device->getDefaultEngine().commandStreamReceiver);
878 ultCsr->staticWorkPartitioningEnabled = true;
879 ultCsr->createWorkPartitionAllocation(*device);
880
881 MockDrmDirectSubmission<FamilyType, Dispatcher> directSubmission(*device->getDefaultEngine().commandStreamReceiver);
882
883 EXPECT_EQ(1u, directSubmission.activeTiles);
884 EXPECT_FALSE(directSubmission.partitionedMode);
885 EXPECT_TRUE(directSubmission.partitionConfigSet);
886
887 bool ret = directSubmission.allocateResources();
888 EXPECT_TRUE(ret);
889 }
890
891 HWTEST_F(DrmDirectSubmissionTest, givenBlitterDispatcherAndMultiTileDeviceWhenCreatingDirectSubmissionThenExpectActiveTilesEqualsOne) {
892 using Dispatcher = BlitterDispatcher<FamilyType>;
893
894 VariableBackup<bool> backup(&ImplicitScaling::apiSupport, true);
895 device->deviceBitfield.set(0b11);
896
897 osContext = std::make_unique<OsContextLinux>(*executionEnvironment.rootDeviceEnvironments[0]->osInterface->getDriverModel()->as<Drm>(), device->getRootDeviceIndex(), 0u,
898 EngineDescriptorHelper::getDefaultDescriptor({aub_stream::ENGINE_RCS, EngineUsage::regular},
899 PreemptionMode::ThreadGroup, device->getDeviceBitfield()));
900 osContext->ensureContextInitialized(false);
901 EXPECT_EQ(2u, osContext->getDeviceBitfield().count());
902
903 device->getDefaultEngine().commandStreamReceiver->setupContext(*osContext);
904 MockDrmDirectSubmission<FamilyType, Dispatcher> directSubmission(*device->getDefaultEngine().commandStreamReceiver);
905
906 EXPECT_EQ(1u, directSubmission.activeTiles);
907 EXPECT_FALSE(directSubmission.partitionedMode);
908 EXPECT_TRUE(directSubmission.partitionConfigSet);
909
910 bool ret = directSubmission.allocateResources();
911 EXPECT_TRUE(ret);
912 }
913 HWTEST_F(DrmDirectSubmissionTest, givenDrmDirectSubmissionWhenHandleSwitchRingBufferCalledThenPrevRingBufferHasUpdatedFenceValue) {
914 MockDrmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> drmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver);
915 auto prevCompletionFenceVal = 1u;
916 auto prevRingBufferIndex = 0u;
917 auto newCompletionFenceValue = 10u;
918 drmDirectSubmission.currentTagData.tagValue = newCompletionFenceValue;
919 drmDirectSubmission.ringBuffers[prevRingBufferIndex].completionFence = prevCompletionFenceVal;
920 drmDirectSubmission.handleSwitchRingBuffers(nullptr);
921 EXPECT_EQ(drmDirectSubmission.ringBuffers[prevRingBufferIndex].completionFence, newCompletionFenceValue + 1);
922 }
923 HWTEST_F(DrmDirectSubmissionTest, givenDrmDirectSubmissionWhenEnableRingSwitchTagUpdateWaEnabledAndRingNotStartedThenCompletionFenceIsNotUpdated) {
924 DebugManagerStateRestore dbgRestorer;
925 debugManager.flags.EnableRingSwitchTagUpdateWa.set(1);
926 MockDrmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> drmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver);
927 auto prevCompletionFenceVal = 1u;
928 auto prevRingBufferIndex = 0u;
929 auto newCompletionFenceValue = 10u;
930
931 drmDirectSubmission.ringStart = false;
932
933 drmDirectSubmission.currentTagData.tagValue = newCompletionFenceValue;
934 drmDirectSubmission.ringBuffers[prevRingBufferIndex].completionFence = prevCompletionFenceVal;
935 drmDirectSubmission.handleSwitchRingBuffers(nullptr);
936 EXPECT_EQ(drmDirectSubmission.ringBuffers[prevRingBufferIndex].completionFence, prevCompletionFenceVal);
937 }
938 HWTEST_F(DrmDirectSubmissionTest, givenDrmDirectSubmissionWhenEnableRingSwitchTagUpdateWaEnabledAndRingStartedThenCompletionFenceIsUpdated) {
939 DebugManagerStateRestore dbgRestorer;
940 debugManager.flags.EnableRingSwitchTagUpdateWa.set(1);
941 MockDrmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> drmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver);
942 auto prevCompletionFenceVal = 1u;
943 auto prevRingBufferIndex = 0u;
944 auto newCompletionFenceValue = 10u;
945
946 drmDirectSubmission.ringStart = true;
947
948 drmDirectSubmission.currentTagData.tagValue = newCompletionFenceValue;
949 drmDirectSubmission.ringBuffers[prevRingBufferIndex].completionFence = prevCompletionFenceVal;
950 drmDirectSubmission.handleSwitchRingBuffers(nullptr);
951 EXPECT_EQ(drmDirectSubmission.ringBuffers[prevRingBufferIndex].completionFence, newCompletionFenceValue + 1);
952 drmDirectSubmission.ringStart = false;
953 }
954 HWTEST_F(DrmDirectSubmissionTest, givenDrmDirectSubmissionWhenEnableRingSwitchTagUpdateWaDisabledThenCompletionFenceIsUpdated) {
955 DebugManagerStateRestore dbgRestorer;
956 debugManager.flags.EnableRingSwitchTagUpdateWa.set(0);
957 MockDrmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> drmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver);
958 auto prevCompletionFenceVal = 1u;
959 auto prevRingBufferIndex = 0u;
960 auto newCompletionFenceValue = 10u;
961
962 drmDirectSubmission.currentTagData.tagValue = newCompletionFenceValue;
963 drmDirectSubmission.ringBuffers[prevRingBufferIndex].completionFence = prevCompletionFenceVal;
964 drmDirectSubmission.handleSwitchRingBuffers(nullptr);
965 EXPECT_EQ(drmDirectSubmission.ringBuffers[prevRingBufferIndex].completionFence, newCompletionFenceValue + 1);
966 }
967
968 HWTEST_F(DrmDirectSubmissionTest, givenDrmDirectSubmissionWhenGettingDefaultInputMonitorFencePolicyThenDefaultIsTrue) {
969 MockDrmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> drmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver);
970 EXPECT_TRUE(drmDirectSubmission.inputMonitorFenceDispatchRequirement);
971 }
972
973 HWTEST_F(DrmDirectSubmissionTest,
974 givenDrmDirectSubmissionWithStallingCommandInputMonitorFencePolicyWhenDispatchingWorkloadWithDisabledMonitorFenceThenDrmIgnoresInputFlag) {
975 using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
976 using POST_SYNC_OPERATION = typename FamilyType::PIPE_CONTROL::POST_SYNC_OPERATION;
977
978 DebugManagerStateRestore dbgRestorer;
979 debugManager.flags.DirectSubmissionMonitorFenceInputPolicy.set(0);
980
981 MockDrmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> drmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver);
982 EXPECT_FALSE(drmDirectSubmission.inputMonitorFenceDispatchRequirement);
983 drmDirectSubmission.disableMonitorFence = true;
984
985 FlushStampTracker flushStamp(true);
986
987 EXPECT_TRUE(drmDirectSubmission.initialize(false, false));
988
989 BatchBuffer batchBuffer = {};
990 GraphicsAllocation *commandBuffer = nullptr;
991 LinearStream stream;
992
993 const AllocationProperties commandBufferProperties{device->getRootDeviceIndex(), 0x1000,
994 AllocationType::commandBuffer, device->getDeviceBitfield()};
995 commandBuffer = executionEnvironment.memoryManager->allocateGraphicsMemoryWithProperties(commandBufferProperties);
996
997 stream.replaceGraphicsAllocation(commandBuffer);
998 stream.replaceBuffer(commandBuffer->getUnderlyingBuffer(), commandBuffer->getUnderlyingBufferSize());
999 stream.getSpace(0x20);
1000
1001 memset(stream.getCpuBase(), 0, 0x20);
1002
1003 batchBuffer.endCmdPtr = ptrOffset(stream.getCpuBase(), 0x20);
1004 batchBuffer.commandBufferAllocation = commandBuffer;
1005 batchBuffer.usedSize = 0x40;
1006 batchBuffer.taskStartAddress = 0x881112340000;
1007 batchBuffer.stream = &stream;
1008 batchBuffer.hasStallingCmds = true;
1009
1010 EXPECT_TRUE(drmDirectSubmission.dispatchCommandBuffer(batchBuffer, flushStamp));
1011
1012 HardwareParse hwParse;
1013 hwParse.parsePipeControl = true;
1014 hwParse.parseCommands<FamilyType>(drmDirectSubmission.ringCommandStream, 0);
1015 hwParse.findHardwareCommands<FamilyType>();
1016
1017 bool foundFenceUpdate = false;
1018 for (auto &it : hwParse.pipeControlList) {
1019 PIPE_CONTROL *pipeControl = reinterpret_cast<PIPE_CONTROL *>(it);
1020 if (pipeControl->getPostSyncOperation() == POST_SYNC_OPERATION::POST_SYNC_OPERATION_WRITE_IMMEDIATE_DATA) {
1021 foundFenceUpdate = true;
1022 break;
1023 }
1024 }
1025 EXPECT_FALSE(foundFenceUpdate);
1026
1027 executionEnvironment.memoryManager->freeGraphicsMemory(commandBuffer);
1028 *drmDirectSubmission.tagAddress = 1;
1029 }
1030
1031 HWTEST_F(DrmDirectSubmissionTest,
1032 givenDrmDirectSubmissionWithExplicitFlagInputMonitorFencePolicyWhenDispatchingWorkloadWithDisabledMonitorFenceThenDrmIgnoresInputFlag) {
1033 using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
1034 using POST_SYNC_OPERATION = typename FamilyType::PIPE_CONTROL::POST_SYNC_OPERATION;
1035
1036 DebugManagerStateRestore dbgRestorer;
1037 debugManager.flags.DirectSubmissionMonitorFenceInputPolicy.set(1);
1038
1039 MockDrmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> drmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver);
1040 EXPECT_TRUE(drmDirectSubmission.inputMonitorFenceDispatchRequirement);
1041 drmDirectSubmission.disableMonitorFence = true;
1042
1043 FlushStampTracker flushStamp(true);
1044
1045 EXPECT_TRUE(drmDirectSubmission.initialize(false, false));
1046
1047 BatchBuffer batchBuffer = {};
1048 GraphicsAllocation *commandBuffer = nullptr;
1049 LinearStream stream;
1050
1051 const AllocationProperties commandBufferProperties{device->getRootDeviceIndex(), 0x1000,
1052 AllocationType::commandBuffer, device->getDeviceBitfield()};
1053 commandBuffer = executionEnvironment.memoryManager->allocateGraphicsMemoryWithProperties(commandBufferProperties);
1054
1055 stream.replaceGraphicsAllocation(commandBuffer);
1056 stream.replaceBuffer(commandBuffer->getUnderlyingBuffer(), commandBuffer->getUnderlyingBufferSize());
1057 stream.getSpace(0x20);
1058
1059 memset(stream.getCpuBase(), 0, 0x20);
1060
1061 batchBuffer.endCmdPtr = ptrOffset(stream.getCpuBase(), 0x20);
1062 batchBuffer.commandBufferAllocation = commandBuffer;
1063 batchBuffer.usedSize = 0x40;
1064 batchBuffer.taskStartAddress = 0x881112340000;
1065 batchBuffer.stream = &stream;
1066 batchBuffer.dispatchMonitorFence = true;
1067
1068 EXPECT_TRUE(drmDirectSubmission.dispatchCommandBuffer(batchBuffer, flushStamp));
1069
1070 HardwareParse hwParse;
1071 hwParse.parsePipeControl = true;
1072 hwParse.parseCommands<FamilyType>(drmDirectSubmission.ringCommandStream, 0);
1073 hwParse.findHardwareCommands<FamilyType>();
1074
1075 bool foundFenceUpdate = false;
1076 for (auto &it : hwParse.pipeControlList) {
1077 PIPE_CONTROL *pipeControl = reinterpret_cast<PIPE_CONTROL *>(it);
1078 if (pipeControl->getPostSyncOperation() == POST_SYNC_OPERATION::POST_SYNC_OPERATION_WRITE_IMMEDIATE_DATA) {
1079 foundFenceUpdate = true;
1080 break;
1081 }
1082 }
1083 EXPECT_FALSE(foundFenceUpdate);
1084
1085 executionEnvironment.memoryManager->freeGraphicsMemory(commandBuffer);
1086 *drmDirectSubmission.tagAddress = 1;
1087 }