| 1 |
/* |
| 2 |
* Copyright (C) 2020-2024 Intel Corporation |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: MIT |
| 5 |
* |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "shared/source/command_stream/submissions_aggregator.h" |
| 9 |
#include "shared/source/direct_submission/dispatchers/render_dispatcher.h" |
| 10 |
#include "shared/source/gmm_helper/gmm_helper.h" |
| 11 |
#include "shared/source/helpers/flush_stamp.h" |
| 12 |
#include "shared/source/memory_manager/allocation_properties.h" |
| 13 |
#include "shared/source/os_interface/windows/wddm/wddm_residency_logger.h" |
| 14 |
#include "shared/source/os_interface/windows/wddm_memory_manager.h" |
| 15 |
#include "shared/source/os_interface/windows/wddm_residency_controller.h" |
| 16 |
#include "shared/test/common/cmd_parse/hw_parse.h" |
| 17 |
#include "shared/test/common/helpers/debug_manager_state_restore.h" |
| 18 |
#include "shared/test/common/helpers/unit_test_helper.h" |
| 19 |
#include "shared/test/common/mocks/mock_io_functions.h" |
| 20 |
#include "shared/test/common/mocks/mock_os_context_win.h" |
| 21 |
#include "shared/test/common/os_interface/windows/wddm_fixture.h" |
| 22 |
#include "shared/test/common/test_macros/hw_test.h" |
| 23 |
#include "shared/test/unit_test/mocks/windows/mock_wddm_direct_submission.h" |
| 24 |
|
| 25 |
using namespace NEO; |
| 26 |
|
| 27 |
extern uint64_t cpuFence; |
| 28 |
|
| 29 |
template <PreemptionMode preemptionMode> |
| 30 |
struct WddmDirectSubmissionFixture : public WddmFixture { |
| 31 |
void SetUp() override { |
| 32 |
VariableBackup<HardwareInfo> backupHwInfo(defaultHwInfo.get()); |
| 33 |
defaultHwInfo->capabilityTable.blitterOperationsSupported = true; |
| 34 |
debugManager.flags.ForcePreemptionMode.set(preemptionMode); |
| 35 |
|
| 36 |
WddmFixture::SetUp(); |
| 37 |
|
| 38 |
wddm->wddmInterface.reset(new WddmMockInterface20(*wddm)); |
| 39 |
wddmMockInterface = static_cast<WddmMockInterface20 *>(wddm->wddmInterface.get()); |
| 40 |
|
| 41 |
executionEnvironment->memoryManager.reset(new WddmMemoryManager{*executionEnvironment}); |
| 42 |
device.reset(MockDevice::create<MockDevice>(executionEnvironment.get(), 0u)); |
| 43 |
|
| 44 |
osContext = static_cast<OsContextWin *>(device->getDefaultEngine().osContext); |
| 45 |
|
| 46 |
wddmMockInterface->createMonitoredFence(*osContext); |
| 47 |
} |
| 48 |
|
| 49 |
DebugManagerStateRestore restorer; |
| 50 |
|
| 51 |
WddmMockInterface20 *wddmMockInterface = nullptr; |
| 52 |
OsContextWin *osContext = nullptr; |
| 53 |
std::unique_ptr<MockDevice> device; |
| 54 |
}; |
| 55 |
|
| 56 |
using WddmDirectSubmissionTest = WddmDirectSubmissionFixture<PreemptionMode::ThreadGroup>; |
| 57 |
|
| 58 |
struct WddmDirectSubmissionWithMockGdiDllFixture : public WddmFixtureWithMockGdiDll { |
| 59 |
void setUp() { |
| 60 |
debugManager.flags.ForcePreemptionMode.set(PreemptionMode::ThreadGroup); |
| 61 |
|
| 62 |
WddmFixtureWithMockGdiDll::setUp(); |
| 63 |
init(); |
| 64 |
device.reset(MockDevice::create<MockDevice>(executionEnvironment.get(), 0u)); |
| 65 |
osContextWin = static_cast<NEO::OsContextWin *>(device->getDefaultEngine().osContext); |
| 66 |
osContextWin->ensureContextInitialized(false); |
| 67 |
} |
| 68 |
|
| 69 |
DebugManagerStateRestore restorer; |
| 70 |
std::unique_ptr<MockDevice> device; |
| 71 |
NEO::OsContextWin *osContextWin = nullptr; |
| 72 |
}; |
| 73 |
|
| 74 |
using WddmDirectSubmissionWithMockGdiDllTest = Test<WddmDirectSubmissionWithMockGdiDllFixture>; |
| 75 |
|
| 76 |
HWTEST_F(WddmDirectSubmissionTest, givenWddmWhenDirectIsInitializedAndStartedThenExpectProperCommandsDispatched) { |
| 77 |
std::unique_ptr<MockWddmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>>> wddmDirectSubmission = |
| 78 |
std::make_unique<MockWddmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>>>(*device->getDefaultEngine().commandStreamReceiver); |
| 79 |
|
| 80 |
EXPECT_EQ(1u, wddmDirectSubmission->commandBufferHeader->NeedsMidBatchPreEmptionSupport); |
| 81 |
|
| 82 |
bool ret = wddmDirectSubmission->initialize(true, false); |
| 83 |
EXPECT_TRUE(ret); |
| 84 |
EXPECT_TRUE(wddmDirectSubmission->ringStart); |
| 85 |
EXPECT_NE(nullptr, wddmDirectSubmission->ringBuffers[0].ringBuffer); |
| 86 |
EXPECT_NE(nullptr, wddmDirectSubmission->ringBuffers[1].ringBuffer); |
| 87 |
EXPECT_NE(nullptr, wddmDirectSubmission->semaphores); |
| 88 |
|
| 89 |
auto &gfxCoreHelper = device->getGfxCoreHelper(); |
| 90 |
size_t expectedAllocationsCnt = 4; |
| 91 |
if (gfxCoreHelper.isRelaxedOrderingSupported()) { |
| 92 |
expectedAllocationsCnt += 2; |
| 93 |
} |
| 94 |
EXPECT_EQ(expectedAllocationsCnt, wddm->makeResidentResult.handleCount); |
| 95 |
|
| 96 |
EXPECT_EQ(1u, wddmMockInterface->createMonitoredFenceCalled); |
| 97 |
|
| 98 |
EXPECT_EQ(1u, wddm->submitResult.called); |
| 99 |
|
| 100 |
EXPECT_NE(0u, wddmDirectSubmission->ringCommandStream.getUsed()); |
| 101 |
|
| 102 |
*wddmDirectSubmission->ringFence.cpuAddress = 1ull; |
| 103 |
wddmDirectSubmission->ringBuffers[wddmDirectSubmission->currentRingBuffer].completionFence = 2ull; |
| 104 |
|
| 105 |
wddmDirectSubmission.reset(nullptr); |
| 106 |
EXPECT_EQ(1u, wddm->waitFromCpuResult.called); |
| 107 |
EXPECT_EQ(1u, wddmMockInterface->destroyMonitorFenceCalled); |
| 108 |
} |
| 109 |
|
| 110 |
using WddmDirectSubmissionNoPreemptionTest = WddmDirectSubmissionFixture<PreemptionMode::Disabled>; |
| 111 |
HWTEST_F(WddmDirectSubmissionNoPreemptionTest, givenWddmWhenDirectIsInitializedAndNotStartedThenExpectNoCommandsDispatched) { |
| 112 |
std::unique_ptr<MockWddmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>>> wddmDirectSubmission = |
| 113 |
std::make_unique<MockWddmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>>>(*device->getDefaultEngine().commandStreamReceiver); |
| 114 |
|
| 115 |
EXPECT_EQ(0u, wddmDirectSubmission->commandBufferHeader->NeedsMidBatchPreEmptionSupport); |
| 116 |
|
| 117 |
bool ret = wddmDirectSubmission->initialize(false, false); |
| 118 |
EXPECT_TRUE(ret); |
| 119 |
EXPECT_FALSE(wddmDirectSubmission->ringStart); |
| 120 |
EXPECT_NE(nullptr, wddmDirectSubmission->ringBuffers[0].ringBuffer); |
| 121 |
EXPECT_NE(nullptr, wddmDirectSubmission->ringBuffers[1].ringBuffer); |
| 122 |
EXPECT_NE(nullptr, wddmDirectSubmission->semaphores); |
| 123 |
|
| 124 |
auto &gfxCoreHelper = device->getGfxCoreHelper(); |
| 125 |
size_t expectedAllocationsCnt = 4; |
| 126 |
if (gfxCoreHelper.isRelaxedOrderingSupported()) { |
| 127 |
expectedAllocationsCnt += 2; |
| 128 |
} |
| 129 |
EXPECT_EQ(expectedAllocationsCnt, wddm->makeResidentResult.handleCount); |
| 130 |
|
| 131 |
EXPECT_EQ(1u, wddmMockInterface->createMonitoredFenceCalled); |
| 132 |
|
| 133 |
EXPECT_EQ(0u, wddm->submitResult.called); |
| 134 |
|
| 135 |
EXPECT_EQ(0u, wddmDirectSubmission->ringCommandStream.getUsed()); |
| 136 |
|
| 137 |
wddmDirectSubmission.reset(nullptr); |
| 138 |
EXPECT_EQ(0u, wddm->waitFromCpuResult.called); |
| 139 |
EXPECT_EQ(1u, wddmMockInterface->destroyMonitorFenceCalled); |
| 140 |
} |
| 141 |
|
| 142 |
HWTEST_F(WddmDirectSubmissionTest, givenWddmWhenSubmitingCmdBufferThenExpectPassWddmContextAndProperHeader) { |
| 143 |
MockWddmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 144 |
|
| 145 |
bool ret = wddmDirectSubmission.initialize(false, false); |
| 146 |
EXPECT_TRUE(ret); |
| 147 |
|
| 148 |
uint64_t gpuAddress = 0xFF00FF000; |
| 149 |
size_t size = 0xF0; |
| 150 |
ret = wddmDirectSubmission.submit(gpuAddress, size); |
| 151 |
EXPECT_TRUE(ret); |
| 152 |
EXPECT_EQ(1u, wddm->submitResult.called); |
| 153 |
EXPECT_EQ(gpuAddress, wddm->submitResult.commandBufferSubmitted); |
| 154 |
EXPECT_EQ(size, wddm->submitResult.size); |
| 155 |
EXPECT_EQ(wddmDirectSubmission.commandBufferHeader.get(), wddm->submitResult.commandHeaderSubmitted); |
| 156 |
EXPECT_EQ(&wddmDirectSubmission.ringFence, wddm->submitResult.submitArgs.monitorFence); |
| 157 |
EXPECT_EQ(osContext->getWddmContextHandle(), wddm->submitResult.submitArgs.contextHandle); |
| 158 |
} |
| 159 |
|
| 160 |
HWTEST_F(WddmDirectSubmissionTest, givenWddmWhenAllocateOsResourcesThenExpectRingMonitorFenceCreatedAndAllocationsResident) { |
| 161 |
MockWddmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 162 |
|
| 163 |
bool ret = wddmDirectSubmission.allocateResources(); |
| 164 |
EXPECT_TRUE(ret); |
| 165 |
auto &gfxCoreHelper = device->getGfxCoreHelper(); |
| 166 |
size_t expectedAllocationsCnt = 4; |
| 167 |
if (gfxCoreHelper.isRelaxedOrderingSupported()) { |
| 168 |
expectedAllocationsCnt += 2; |
| 169 |
} |
| 170 |
|
| 171 |
EXPECT_EQ(1u, wddmMockInterface->createMonitoredFenceCalled); |
| 172 |
EXPECT_EQ(expectedAllocationsCnt, wddm->makeResidentResult.handleCount); |
| 173 |
} |
| 174 |
|
| 175 |
HWTEST_F(WddmDirectSubmissionTest, givenWddmWhenAllocateOsResourcesFenceCreationFailsThenExpectRingMonitorFenceNotCreatedAndAllocationsNotResident) { |
| 176 |
MemoryManager *memoryManager = device->getExecutionEnvironment()->memoryManager.get(); |
| 177 |
const auto allocationSize = MemoryConstants::pageSize; |
| 178 |
const AllocationProperties commandStreamAllocationProperties{device->getRootDeviceIndex(), allocationSize, |
| 179 |
AllocationType::ringBuffer, device->getDeviceBitfield()}; |
| 180 |
GraphicsAllocation *ringBuffer = memoryManager->allocateGraphicsMemoryWithProperties(commandStreamAllocationProperties); |
| 181 |
ASSERT_NE(nullptr, ringBuffer); |
| 182 |
|
| 183 |
MockWddmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 184 |
|
| 185 |
DirectSubmissionAllocations allocations; |
| 186 |
allocations.push_back(ringBuffer); |
| 187 |
|
| 188 |
wddmMockInterface->createMonitoredFenceCalledFail = true; |
| 189 |
|
| 190 |
bool ret = wddmDirectSubmission.allocateOsResources(); |
| 191 |
EXPECT_FALSE(ret); |
| 192 |
|
| 193 |
EXPECT_EQ(1u, wddmMockInterface->createMonitoredFenceCalled); |
| 194 |
|
| 195 |
memoryManager->freeGraphicsMemory(ringBuffer); |
| 196 |
} |
| 197 |
|
| 198 |
HWTEST_F(WddmDirectSubmissionTest, givenWddmWhenAllocateOsResourcesResidencyFailsThenExpectRingMonitorFenceCreatedAndAllocationsNotResident) { |
| 199 |
MockWddmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 200 |
|
| 201 |
wddm->callBaseMakeResident = false; |
| 202 |
wddm->makeResidentStatus = false; |
| 203 |
|
| 204 |
bool ret = wddmDirectSubmission.allocateResources(); |
| 205 |
EXPECT_FALSE(ret); |
| 206 |
auto &gfxCoreHelper = device->getGfxCoreHelper(); |
| 207 |
size_t expectedAllocationsCnt = 4; |
| 208 |
if (gfxCoreHelper.isRelaxedOrderingSupported()) { |
| 209 |
expectedAllocationsCnt += 2; |
| 210 |
} |
| 211 |
|
| 212 |
EXPECT_EQ(0u, wddmMockInterface->createMonitoredFenceCalled); |
| 213 |
EXPECT_EQ(expectedAllocationsCnt, wddm->makeResidentResult.handleCount); |
| 214 |
} |
| 215 |
|
| 216 |
HWTEST_F(WddmDirectSubmissionTest, givenWddmWhenGettingTagDataThenExpectContextMonitorFence) { |
| 217 |
uint64_t address = 0xFF00FF0000ull; |
| 218 |
uint64_t value = 0x12345678ull; |
| 219 |
MonitoredFence &contextFence = osContext->getResidencyController().getMonitoredFence(); |
| 220 |
contextFence.gpuAddress = address; |
| 221 |
contextFence.currentFenceValue = value; |
| 222 |
|
| 223 |
MockWddmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 224 |
|
| 225 |
TagData tagData; |
| 226 |
wddmDirectSubmission.getTagAddressValue(tagData); |
| 227 |
|
| 228 |
EXPECT_EQ(address, tagData.tagAddress); |
| 229 |
EXPECT_EQ(value, tagData.tagValue); |
| 230 |
} |
| 231 |
|
| 232 |
HWTEST_F(WddmDirectSubmissionTest, givenWddmWhenHandleResidencyThenExpectWddmWaitOnPaginfFenceFromCpuCalled) { |
| 233 |
MockWddmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 234 |
auto expectedMakeResidentCalled = wddm->makeResidentResult.called + 1; |
| 235 |
|
| 236 |
wddmDirectSubmission.handleResidency(); |
| 237 |
|
| 238 |
EXPECT_EQ(expectedMakeResidentCalled, wddm->waitOnPagingFenceFromCpuResult.called); |
| 239 |
} |
| 240 |
|
| 241 |
HWTEST_F(WddmDirectSubmissionTest, givenWddmWhenHandlingRingBufferCompletionThenExpectWaitFromCpuWithCorrectFenceValue) { |
| 242 |
uint64_t address = 0xFF00FF0000ull; |
| 243 |
uint64_t value = 0x12345678ull; |
| 244 |
MonitoredFence &contextFence = osContext->getResidencyController().getMonitoredFence(); |
| 245 |
contextFence.gpuAddress = address; |
| 246 |
contextFence.currentFenceValue = value; |
| 247 |
|
| 248 |
MockWddmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 249 |
|
| 250 |
uint64_t completionValue = 0x12345679ull; |
| 251 |
wddmDirectSubmission.handleCompletionFence(completionValue, contextFence); |
| 252 |
|
| 253 |
EXPECT_EQ(1u, wddm->waitFromCpuResult.called); |
| 254 |
EXPECT_EQ(completionValue, wddm->waitFromCpuResult.uint64ParamPassed); |
| 255 |
EXPECT_EQ(address, wddm->waitFromCpuResult.monitoredFence->gpuAddress); |
| 256 |
EXPECT_EQ(value, wddm->waitFromCpuResult.monitoredFence->currentFenceValue); |
| 257 |
} |
| 258 |
|
| 259 |
HWTEST_F(WddmDirectSubmissionTest, givenWddmWhenCallIsCompleteThenProperValueIsReturned) { |
| 260 |
MonitoredFence &contextFence = osContext->getResidencyController().getMonitoredFence(); |
| 261 |
|
| 262 |
MockWddmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 263 |
|
| 264 |
*contextFence.cpuAddress = 0u; |
| 265 |
wddmDirectSubmission.ringBuffers[0].completionFence = 1u; |
| 266 |
EXPECT_FALSE(wddmDirectSubmission.isCompleted(0u)); |
| 267 |
|
| 268 |
*contextFence.cpuAddress = 1u; |
| 269 |
EXPECT_TRUE(wddmDirectSubmission.isCompleted(0u)); |
| 270 |
|
| 271 |
wddmDirectSubmission.ringBuffers[0].completionFence = 0u; |
| 272 |
} |
| 273 |
|
| 274 |
HWTEST_F(WddmDirectSubmissionTest, givenWddmWhenSwitchingRingBufferStartedThenExpectDispatchSwitchCommandsLinearStreamUpdated) { |
| 275 |
using MI_BATCH_BUFFER_START = typename FamilyType::MI_BATCH_BUFFER_START; |
| 276 |
MockWddmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 277 |
|
| 278 |
bool ret = wddmDirectSubmission.initialize(true, false); |
| 279 |
EXPECT_TRUE(ret); |
| 280 |
size_t usedSpace = wddmDirectSubmission.ringCommandStream.getUsed(); |
| 281 |
uint64_t expectedGpuVa = wddmDirectSubmission.ringBuffers[0].ringBuffer->getGpuAddress() + usedSpace; |
| 282 |
|
| 283 |
uint64_t gpuVa = wddmDirectSubmission.switchRingBuffers(nullptr); |
| 284 |
EXPECT_EQ(expectedGpuVa, gpuVa); |
| 285 |
EXPECT_EQ(wddmDirectSubmission.ringBuffers[1].ringBuffer, wddmDirectSubmission.ringCommandStream.getGraphicsAllocation()); |
| 286 |
|
| 287 |
LinearStream tmpCmdBuffer; |
| 288 |
tmpCmdBuffer.replaceBuffer(wddmDirectSubmission.ringBuffers[0].ringBuffer->getUnderlyingBuffer(), |
| 289 |
wddmDirectSubmission.ringCommandStream.getMaxAvailableSpace()); |
| 290 |
tmpCmdBuffer.getSpace(usedSpace + wddmDirectSubmission.getSizeSwitchRingBufferSection()); |
| 291 |
HardwareParse hwParse; |
| 292 |
hwParse.parseCommands<FamilyType>(tmpCmdBuffer, usedSpace); |
| 293 |
MI_BATCH_BUFFER_START *bbStart = hwParse.getCommand<MI_BATCH_BUFFER_START>(); |
| 294 |
ASSERT_NE(nullptr, bbStart); |
| 295 |
auto gmmHelper = device->getGmmHelper(); |
| 296 |
uint64_t actualGpuVa = gmmHelper->canonize(bbStart->getBatchBufferStartAddress()); |
| 297 |
EXPECT_EQ(wddmDirectSubmission.ringBuffers[1].ringBuffer->getGpuAddress(), actualGpuVa); |
| 298 |
} |
| 299 |
|
| 300 |
HWTEST_F(WddmDirectSubmissionTest, givenWddmWhenSwitchingRingBufferNotStartedThenExpectNoSwitchCommandsLinearStreamUpdated) { |
| 301 |
using MI_BATCH_BUFFER_START = typename FamilyType::MI_BATCH_BUFFER_START; |
| 302 |
MockWddmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 303 |
|
| 304 |
bool ret = wddmDirectSubmission.initialize(false, false); |
| 305 |
EXPECT_TRUE(ret); |
| 306 |
|
| 307 |
size_t usedSpace = wddmDirectSubmission.ringCommandStream.getUsed(); |
| 308 |
EXPECT_EQ(0u, usedSpace); |
| 309 |
|
| 310 |
uint64_t expectedGpuVa = wddmDirectSubmission.ringBuffers[0].ringBuffer->getGpuAddress(); |
| 311 |
|
| 312 |
uint64_t gpuVa = wddmDirectSubmission.switchRingBuffers(nullptr); |
| 313 |
EXPECT_EQ(expectedGpuVa, gpuVa); |
| 314 |
EXPECT_EQ(wddmDirectSubmission.ringBuffers[1].ringBuffer, wddmDirectSubmission.ringCommandStream.getGraphicsAllocation()); |
| 315 |
|
| 316 |
LinearStream tmpCmdBuffer; |
| 317 |
tmpCmdBuffer.replaceBuffer(wddmDirectSubmission.ringBuffers[0].ringBuffer->getUnderlyingBuffer(), |
| 318 |
wddmDirectSubmission.ringCommandStream.getMaxAvailableSpace()); |
| 319 |
HardwareParse hwParse; |
| 320 |
hwParse.parseCommands<FamilyType>(tmpCmdBuffer, 0u); |
| 321 |
MI_BATCH_BUFFER_START *bbStart = hwParse.getCommand<MI_BATCH_BUFFER_START>(); |
| 322 |
EXPECT_EQ(nullptr, bbStart); |
| 323 |
} |
| 324 |
|
| 325 |
HWTEST_F(WddmDirectSubmissionTest, givenWddmDirectSubmissionWhenDispatchMonitorFenceThenProgramPipeControl) { |
| 326 |
using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL; |
| 327 |
MockWddmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 328 |
|
| 329 |
bool ret = wddmDirectSubmission.initialize(false, false); |
| 330 |
EXPECT_TRUE(ret); |
| 331 |
|
| 332 |
wddmDirectSubmission.flushMonitorFence(); |
| 333 |
|
| 334 |
HardwareParse hwParse; |
| 335 |
hwParse.parseCommands<FamilyType>(wddmDirectSubmission.ringCommandStream, 0u); |
| 336 |
auto pipeControl = hwParse.getCommand<PIPE_CONTROL>(); |
| 337 |
EXPECT_NE(nullptr, pipeControl); |
| 338 |
} |
| 339 |
|
| 340 |
HWTEST_F(WddmDirectSubmissionTest, givenDirectSubmissionNewResourceTlbFlushWhenHandleNewResourcesSubmissionThenDispatchProperCommands) { |
| 341 |
DebugManagerStateRestore restorer; |
| 342 |
debugManager.flags.DirectSubmissionNewResourceTlbFlush.set(1); |
| 343 |
MockWddmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 344 |
|
| 345 |
bool ret = wddmDirectSubmission.initialize(false, false); |
| 346 |
EXPECT_TRUE(ret); |
| 347 |
|
| 348 |
size_t usedSpace = wddmDirectSubmission.ringCommandStream.getUsed(); |
| 349 |
EXPECT_EQ(0u, usedSpace); |
| 350 |
|
| 351 |
EXPECT_TRUE(wddmDirectSubmission.isNewResourceHandleNeeded()); |
| 352 |
|
| 353 |
wddmDirectSubmission.handleNewResourcesSubmission(); |
| 354 |
|
| 355 |
EXPECT_EQ(wddmDirectSubmission.ringCommandStream.getUsed(), usedSpace + wddmDirectSubmission.getSizeNewResourceHandler()); |
| 356 |
} |
| 357 |
|
| 358 |
HWTEST_F(WddmDirectSubmissionTest, givenWddmWhenSwitchingRingBufferStartedAndWaitFenceUpdateThenExpectNewRingBufferAllocated) { |
| 359 |
using MI_BATCH_BUFFER_START = typename FamilyType::MI_BATCH_BUFFER_START; |
| 360 |
MockWddmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 361 |
|
| 362 |
VariableBackup<uint64_t> cpuFenceBackup(&cpuFence, 0); |
| 363 |
|
| 364 |
bool ret = wddmDirectSubmission.initialize(true, false); |
| 365 |
EXPECT_TRUE(ret); |
| 366 |
uint64_t expectedWaitFence = 0x10ull; |
| 367 |
wddmDirectSubmission.ringBuffers[1u].completionFence = expectedWaitFence; |
| 368 |
size_t usedSpace = wddmDirectSubmission.ringCommandStream.getUsed(); |
| 369 |
uint64_t expectedGpuVa = wddmDirectSubmission.ringBuffers[0].ringBuffer->getGpuAddress() + usedSpace; |
| 370 |
|
| 371 |
uint64_t gpuVa = wddmDirectSubmission.switchRingBuffers(nullptr); |
| 372 |
EXPECT_EQ(expectedGpuVa, gpuVa); |
| 373 |
EXPECT_EQ(wddmDirectSubmission.ringBuffers[2u].ringBuffer, wddmDirectSubmission.ringCommandStream.getGraphicsAllocation()); |
| 374 |
|
| 375 |
LinearStream tmpCmdBuffer; |
| 376 |
tmpCmdBuffer.replaceBuffer(wddmDirectSubmission.ringBuffers[0].ringBuffer->getUnderlyingBuffer(), |
| 377 |
wddmDirectSubmission.ringCommandStream.getMaxAvailableSpace()); |
| 378 |
tmpCmdBuffer.getSpace(usedSpace + wddmDirectSubmission.getSizeSwitchRingBufferSection()); |
| 379 |
HardwareParse hwParse; |
| 380 |
hwParse.parseCommands<FamilyType>(tmpCmdBuffer, usedSpace); |
| 381 |
MI_BATCH_BUFFER_START *bbStart = hwParse.getCommand<MI_BATCH_BUFFER_START>(); |
| 382 |
ASSERT_NE(nullptr, bbStart); |
| 383 |
auto gmmHelper = device->getGmmHelper(); |
| 384 |
uint64_t actualGpuVa = gmmHelper->canonize(bbStart->getBatchBufferStartAddress()); |
| 385 |
EXPECT_EQ(wddmDirectSubmission.ringBuffers[2u].ringBuffer->getGpuAddress(), actualGpuVa); |
| 386 |
|
| 387 |
EXPECT_EQ(0u, wddm->waitFromCpuResult.called); |
| 388 |
} |
| 389 |
|
| 390 |
HWTEST_F(WddmDirectSubmissionTest, givenWddmWhenSwitchingRingBufferStartedAndWaitFenceUpdateThenExpectWaitNotCalled) { |
| 391 |
using MI_BATCH_BUFFER_START = typename FamilyType::MI_BATCH_BUFFER_START; |
| 392 |
|
| 393 |
DebugManagerStateRestore restorer; |
| 394 |
debugManager.flags.DirectSubmissionMaxRingBuffers.set(2u); |
| 395 |
|
| 396 |
MockWddmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 397 |
|
| 398 |
bool ret = wddmDirectSubmission.initialize(true, false); |
| 399 |
EXPECT_TRUE(ret); |
| 400 |
uint64_t expectedWaitFence = 0x10ull; |
| 401 |
wddmDirectSubmission.ringBuffers[1u].completionFence = expectedWaitFence; |
| 402 |
size_t usedSpace = wddmDirectSubmission.ringCommandStream.getUsed(); |
| 403 |
uint64_t expectedGpuVa = wddmDirectSubmission.ringBuffers[0].ringBuffer->getGpuAddress() + usedSpace; |
| 404 |
|
| 405 |
uint64_t gpuVa = wddmDirectSubmission.switchRingBuffers(nullptr); |
| 406 |
EXPECT_EQ(expectedGpuVa, gpuVa); |
| 407 |
EXPECT_EQ(wddmDirectSubmission.ringBuffers.size(), 2u); |
| 408 |
EXPECT_EQ(wddmDirectSubmission.ringBuffers[1u].ringBuffer, wddmDirectSubmission.ringCommandStream.getGraphicsAllocation()); |
| 409 |
|
| 410 |
LinearStream tmpCmdBuffer; |
| 411 |
tmpCmdBuffer.replaceBuffer(wddmDirectSubmission.ringBuffers[0].ringBuffer->getUnderlyingBuffer(), |
| 412 |
wddmDirectSubmission.ringCommandStream.getMaxAvailableSpace()); |
| 413 |
tmpCmdBuffer.getSpace(usedSpace + wddmDirectSubmission.getSizeSwitchRingBufferSection()); |
| 414 |
HardwareParse hwParse; |
| 415 |
hwParse.parseCommands<FamilyType>(tmpCmdBuffer, usedSpace); |
| 416 |
MI_BATCH_BUFFER_START *bbStart = hwParse.getCommand<MI_BATCH_BUFFER_START>(); |
| 417 |
ASSERT_NE(nullptr, bbStart); |
| 418 |
auto gmmHelper = device->getGmmHelper(); |
| 419 |
uint64_t actualGpuVa = gmmHelper->canonize(bbStart->getBatchBufferStartAddress()); |
| 420 |
EXPECT_EQ(wddmDirectSubmission.ringBuffers[1u].ringBuffer->getGpuAddress(), actualGpuVa); |
| 421 |
|
| 422 |
EXPECT_EQ(0u, wddm->waitFromCpuResult.called); |
| 423 |
EXPECT_NE(expectedWaitFence, wddm->waitFromCpuResult.uint64ParamPassed); |
| 424 |
} |
| 425 |
|
| 426 |
HWTEST_F(WddmDirectSubmissionTest, whenCreateWddmDirectSubmissionThenDisableMonitorFence) { |
| 427 |
MockWddmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 428 |
EXPECT_TRUE(wddmDirectSubmission.disableMonitorFence); |
| 429 |
} |
| 430 |
|
| 431 |
HWTEST_F(WddmDirectSubmissionTest, givenWddmWhenUpdatingTagValueThenExpectcompletionFenceUpdated) { |
| 432 |
DebugManagerStateRestore restorer; |
| 433 |
debugManager.flags.DirectSubmissionDisableMonitorFence.set(0); |
| 434 |
|
| 435 |
uint64_t address = 0xFF00FF0000ull; |
| 436 |
uint64_t value = 0x12345678ull; |
| 437 |
MonitoredFence &contextFence = osContext->getResidencyController().getMonitoredFence(); |
| 438 |
contextFence.gpuAddress = address; |
| 439 |
contextFence.currentFenceValue = value; |
| 440 |
|
| 441 |
MockWddmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 442 |
EXPECT_TRUE(wddmDirectSubmission.allocateOsResources()); |
| 443 |
|
| 444 |
uint64_t actualTagValue = wddmDirectSubmission.updateTagValue(wddmDirectSubmission.dispatchMonitorFenceRequired(false)); |
| 445 |
EXPECT_EQ(value, actualTagValue); |
| 446 |
EXPECT_EQ(value + 1, contextFence.currentFenceValue); |
| 447 |
EXPECT_EQ(value, wddmDirectSubmission.ringBuffers[wddmDirectSubmission.currentRingBuffer].completionFence); |
| 448 |
} |
| 449 |
|
| 450 |
HWTEST_F(WddmDirectSubmissionTest, givenWddmDisableMonitorFenceAndStallingCmdsWhenUpdatingTagValueThenUpdateCompletionFence) { |
| 451 |
uint64_t address = 0xFF00FF0000ull; |
| 452 |
uint64_t value = 0x12345678ull; |
| 453 |
MonitoredFence &contextFence = osContext->getResidencyController().getMonitoredFence(); |
| 454 |
contextFence.gpuAddress = address; |
| 455 |
contextFence.currentFenceValue = value; |
| 456 |
|
| 457 |
MockWddmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 458 |
wddmDirectSubmission.disableMonitorFence = true; |
| 459 |
EXPECT_TRUE(wddmDirectSubmission.allocateOsResources()); |
| 460 |
|
| 461 |
uint64_t actualTagValue = wddmDirectSubmission.updateTagValue(wddmDirectSubmission.dispatchMonitorFenceRequired(true)); |
| 462 |
EXPECT_EQ(value, actualTagValue); |
| 463 |
EXPECT_EQ(value + 1, contextFence.currentFenceValue); |
| 464 |
EXPECT_EQ(value, wddmDirectSubmission.ringBuffers[wddmDirectSubmission.currentRingBuffer].completionFence); |
| 465 |
} |
| 466 |
|
| 467 |
HWTEST_F(WddmDirectSubmissionWithMockGdiDllTest, givenNoMonitorFenceHangDetectedWhenUpdatingTagValueThenReturnUpdatedFenceCounter) { |
| 468 |
DebugManagerStateRestore restorer; |
| 469 |
debugManager.flags.DirectSubmissionDetectGpuHang.set(1); |
| 470 |
|
| 471 |
VariableBackup<bool> backupMonitorFenceCreateSelector(getMonitorFenceCpuAddressSelectorFcn()); |
| 472 |
|
| 473 |
MonitoredFence &contextFence = osContextWin->getResidencyController().getMonitoredFence(); |
| 474 |
VariableBackup<volatile uint64_t> backupWddmMonitorFence(contextFence.cpuAddress); |
| 475 |
*contextFence.cpuAddress = 1; |
| 476 |
contextFence.currentFenceValue = 2u; |
| 477 |
|
| 478 |
*getMonitorFenceCpuAddressSelectorFcn() = true; |
| 479 |
MockWddmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 480 |
EXPECT_TRUE(wddmDirectSubmission.detectGpuHang); |
| 481 |
EXPECT_TRUE(wddmDirectSubmission.allocateOsResources()); |
| 482 |
|
| 483 |
VariableBackup<volatile uint64_t> backupRingMonitorFence(wddmDirectSubmission.ringFence.cpuAddress); |
| 484 |
*wddmDirectSubmission.ringFence.cpuAddress = 1; |
| 485 |
|
| 486 |
uint64_t actualTagValue = wddmDirectSubmission.updateTagValue(true); |
| 487 |
EXPECT_EQ(2u, actualTagValue); |
| 488 |
} |
| 489 |
|
| 490 |
HWTEST_F(WddmDirectSubmissionWithMockGdiDllTest, givenWddmMonitorFenceHangDetectedWhenUpdatingTagValueThenReturnFail) { |
| 491 |
DebugManagerStateRestore restorer; |
| 492 |
debugManager.flags.DirectSubmissionDetectGpuHang.set(1); |
| 493 |
|
| 494 |
VariableBackup<bool> backupMonitorFenceCreateSelector(getMonitorFenceCpuAddressSelectorFcn()); |
| 495 |
|
| 496 |
MonitoredFence &contextFence = osContextWin->getResidencyController().getMonitoredFence(); |
| 497 |
VariableBackup<volatile uint64_t> backupWddmMonitorFence(contextFence.cpuAddress); |
| 498 |
*contextFence.cpuAddress = std::numeric_limits<uint64_t>::max(); |
| 499 |
|
| 500 |
*getMonitorFenceCpuAddressSelectorFcn() = true; |
| 501 |
MockWddmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 502 |
EXPECT_TRUE(wddmDirectSubmission.detectGpuHang); |
| 503 |
EXPECT_TRUE(wddmDirectSubmission.allocateOsResources()); |
| 504 |
|
| 505 |
uint64_t actualTagValue = wddmDirectSubmission.updateTagValue(true); |
| 506 |
EXPECT_EQ(std::numeric_limits<uint64_t>::max(), actualTagValue); |
| 507 |
} |
| 508 |
|
| 509 |
HWTEST_F(WddmDirectSubmissionWithMockGdiDllTest, givenRingMonitorFenceHangDetectedWhenUpdatingTagValueThenReturnFail) { |
| 510 |
DebugManagerStateRestore restorer; |
| 511 |
debugManager.flags.DirectSubmissionDetectGpuHang.set(1); |
| 512 |
|
| 513 |
VariableBackup<bool> backupMonitorFenceCreateSelector(getMonitorFenceCpuAddressSelectorFcn()); |
| 514 |
|
| 515 |
*getMonitorFenceCpuAddressSelectorFcn() = true; |
| 516 |
MockWddmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 517 |
EXPECT_TRUE(wddmDirectSubmission.detectGpuHang); |
| 518 |
EXPECT_TRUE(wddmDirectSubmission.allocateOsResources()); |
| 519 |
|
| 520 |
VariableBackup<volatile uint64_t> backupRingMonitorFence(wddmDirectSubmission.ringFence.cpuAddress); |
| 521 |
*wddmDirectSubmission.ringFence.cpuAddress = std::numeric_limits<uint64_t>::max(); |
| 522 |
|
| 523 |
uint64_t actualTagValue = wddmDirectSubmission.updateTagValue(true); |
| 524 |
EXPECT_EQ(std::numeric_limits<uint64_t>::max(), actualTagValue); |
| 525 |
} |
| 526 |
|
| 527 |
HWTEST_F(WddmDirectSubmissionTest, givenDetectGpuFalseAndRequiredMonitorFenceWhenCallUpdateTagValueThenCurrentFenceValueIsReturned) { |
| 528 |
uint64_t value = 0x12345678ull; |
| 529 |
MonitoredFence &contextFence = osContext->getResidencyController().getMonitoredFence(); |
| 530 |
contextFence.currentFenceValue = value; |
| 531 |
|
| 532 |
MockWddmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 533 |
wddmDirectSubmission.detectGpuHang = false; |
| 534 |
|
| 535 |
uint64_t actualTagValue = wddmDirectSubmission.updateTagValue(false); |
| 536 |
EXPECT_EQ(value, actualTagValue); |
| 537 |
} |
| 538 |
|
| 539 |
HWTEST_F(WddmDirectSubmissionTest, givenWddmDisableMonitorFenceWhenHandleStopRingBufferThenExpectCompletionFenceUpdated) { |
| 540 |
uint64_t address = 0xFF00FF0000ull; |
| 541 |
uint64_t value = 0x12345678ull; |
| 542 |
MonitoredFence &contextFence = osContext->getResidencyController().getMonitoredFence(); |
| 543 |
contextFence.gpuAddress = address; |
| 544 |
contextFence.currentFenceValue = value; |
| 545 |
|
| 546 |
MockWddmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 547 |
wddmDirectSubmission.disableMonitorFence = true; |
| 548 |
|
| 549 |
wddmDirectSubmission.handleStopRingBuffer(); |
| 550 |
EXPECT_EQ(value + 1, contextFence.currentFenceValue); |
| 551 |
} |
| 552 |
|
| 553 |
HWTEST_F(WddmDirectSubmissionTest, givenWddmDisableMonitorFenceWhenHandleSwitchRingBufferThenExpectCompletionFenceUpdated) { |
| 554 |
uint64_t address = 0xFF00FF0000ull; |
| 555 |
uint64_t value = 0x12345678ull; |
| 556 |
MonitoredFence &contextFence = osContext->getResidencyController().getMonitoredFence(); |
| 557 |
contextFence.gpuAddress = address; |
| 558 |
contextFence.currentFenceValue = value; |
| 559 |
|
| 560 |
MockWddmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 561 |
wddmDirectSubmission.disableMonitorFence = true; |
| 562 |
|
| 563 |
wddmDirectSubmission.handleSwitchRingBuffers(nullptr); |
| 564 |
EXPECT_EQ(value + 1, contextFence.currentFenceValue); |
| 565 |
EXPECT_EQ(value, wddmDirectSubmission.ringBuffers[wddmDirectSubmission.currentRingBuffer].completionFence); |
| 566 |
} |
| 567 |
|
| 568 |
HWTEST_F(WddmDirectSubmissionTest, givenWddmResidencyEnabledWhenCreatingDestroyingThenSubmitterNotifiesResidencyLogger) { |
| 569 |
using Dispatcher = RenderDispatcher<FamilyType>; |
| 570 |
if (!NEO::wddmResidencyLoggingAvailable) { |
| 571 |
GTEST_SKIP(); |
| 572 |
} |
| 573 |
|
| 574 |
DebugManagerStateRestore restorer; |
| 575 |
debugManager.flags.WddmResidencyLogger.set(1); |
| 576 |
|
| 577 |
NEO::IoFunctions::mockFopenCalled = 0u; |
| 578 |
NEO::IoFunctions::mockVfptrinfCalled = 0u; |
| 579 |
NEO::IoFunctions::mockFcloseCalled = 0u; |
| 580 |
|
| 581 |
wddm->createPagingFenceLogger(); |
| 582 |
|
| 583 |
EXPECT_EQ(1u, NEO::IoFunctions::mockFopenCalled); |
| 584 |
EXPECT_EQ(1u, NEO::IoFunctions::mockVfptrinfCalled); |
| 585 |
EXPECT_EQ(0u, NEO::IoFunctions::mockFcloseCalled); |
| 586 |
|
| 587 |
std::unique_ptr<MockWddmDirectSubmission<FamilyType, Dispatcher>> wddmSubmission = |
| 588 |
std::make_unique<MockWddmDirectSubmission<FamilyType, Dispatcher>>(*device->getDefaultEngine().commandStreamReceiver); |
| 589 |
|
| 590 |
EXPECT_EQ(1u, NEO::IoFunctions::mockFopenCalled); |
| 591 |
EXPECT_EQ(2u, NEO::IoFunctions::mockVfptrinfCalled); |
| 592 |
EXPECT_EQ(0u, NEO::IoFunctions::mockFcloseCalled); |
| 593 |
|
| 594 |
wddmSubmission.reset(nullptr); |
| 595 |
|
| 596 |
EXPECT_EQ(1u, NEO::IoFunctions::mockFopenCalled); |
| 597 |
EXPECT_EQ(3u, NEO::IoFunctions::mockVfptrinfCalled); |
| 598 |
EXPECT_EQ(0u, NEO::IoFunctions::mockFcloseCalled); |
| 599 |
} |
| 600 |
|
| 601 |
HWTEST_F(WddmDirectSubmissionTest, givenWddmResidencyEnabledWhenAllocatingResourcesThenSubmitterNotifiesResidencyLogger) { |
| 602 |
using Dispatcher = RenderDispatcher<FamilyType>; |
| 603 |
if (!NEO::wddmResidencyLoggingAvailable) { |
| 604 |
GTEST_SKIP(); |
| 605 |
} |
| 606 |
|
| 607 |
DebugManagerStateRestore restorer; |
| 608 |
debugManager.flags.WddmResidencyLogger.set(1); |
| 609 |
|
| 610 |
NEO::IoFunctions::mockFopenCalled = 0u; |
| 611 |
NEO::IoFunctions::mockVfptrinfCalled = 0u; |
| 612 |
NEO::IoFunctions::mockFcloseCalled = 0u; |
| 613 |
|
| 614 |
MockWddmDirectSubmission<FamilyType, Dispatcher> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 615 |
|
| 616 |
wddm->callBaseMakeResident = true; |
| 617 |
wddm->createPagingFenceLogger(); |
| 618 |
|
| 619 |
EXPECT_EQ(1u, NEO::IoFunctions::mockFopenCalled); |
| 620 |
EXPECT_EQ(1u, NEO::IoFunctions::mockVfptrinfCalled); |
| 621 |
EXPECT_EQ(0u, NEO::IoFunctions::mockFcloseCalled); |
| 622 |
|
| 623 |
bool ret = wddmDirectSubmission.allocateResources(); |
| 624 |
EXPECT_TRUE(ret); |
| 625 |
|
| 626 |
EXPECT_EQ(1u, NEO::IoFunctions::mockFopenCalled); |
| 627 |
EXPECT_EQ(0u, NEO::IoFunctions::mockFcloseCalled); |
| 628 |
} |
| 629 |
|
| 630 |
HWTEST_F(WddmDirectSubmissionTest, givenWddmResidencyEnabledWhenHandleResidencyThenSubmitterNotifiesResidencyLogger) { |
| 631 |
using Dispatcher = RenderDispatcher<FamilyType>; |
| 632 |
if (!NEO::wddmResidencyLoggingAvailable) { |
| 633 |
GTEST_SKIP(); |
| 634 |
} |
| 635 |
|
| 636 |
DebugManagerStateRestore restorer; |
| 637 |
debugManager.flags.WddmResidencyLogger.set(1); |
| 638 |
|
| 639 |
NEO::IoFunctions::mockFopenCalled = 0u; |
| 640 |
NEO::IoFunctions::mockVfptrinfCalled = 0u; |
| 641 |
NEO::IoFunctions::mockFcloseCalled = 0u; |
| 642 |
|
| 643 |
MockWddmDirectSubmission<FamilyType, Dispatcher> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 644 |
wddm->createPagingFenceLogger(); |
| 645 |
|
| 646 |
EXPECT_EQ(1u, NEO::IoFunctions::mockFopenCalled); |
| 647 |
EXPECT_EQ(1u, NEO::IoFunctions::mockVfptrinfCalled); |
| 648 |
EXPECT_EQ(0u, NEO::IoFunctions::mockFcloseCalled); |
| 649 |
|
| 650 |
bool ret = wddmDirectSubmission.handleResidency(); |
| 651 |
EXPECT_TRUE(ret); |
| 652 |
|
| 653 |
EXPECT_EQ(1u, NEO::IoFunctions::mockFopenCalled); |
| 654 |
EXPECT_EQ(5u, NEO::IoFunctions::mockVfptrinfCalled); |
| 655 |
EXPECT_EQ(0u, NEO::IoFunctions::mockFcloseCalled); |
| 656 |
} |
| 657 |
|
| 658 |
HWTEST_F(WddmDirectSubmissionTest, givenWddmResidencyEnabledWhenSubmitToGpuThenSubmitterNotifiesResidencyLogger) { |
| 659 |
using Dispatcher = RenderDispatcher<FamilyType>; |
| 660 |
if (!NEO::wddmResidencyLoggingAvailable) { |
| 661 |
GTEST_SKIP(); |
| 662 |
} |
| 663 |
|
| 664 |
DebugManagerStateRestore restorer; |
| 665 |
debugManager.flags.WddmResidencyLogger.set(1); |
| 666 |
|
| 667 |
NEO::IoFunctions::mockFopenCalled = 0u; |
| 668 |
NEO::IoFunctions::mockVfptrinfCalled = 0u; |
| 669 |
NEO::IoFunctions::mockFcloseCalled = 0u; |
| 670 |
|
| 671 |
MockWddmDirectSubmission<FamilyType, Dispatcher> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 672 |
wddm->createPagingFenceLogger(); |
| 673 |
|
| 674 |
EXPECT_EQ(1u, NEO::IoFunctions::mockFopenCalled); |
| 675 |
EXPECT_EQ(1u, NEO::IoFunctions::mockVfptrinfCalled); |
| 676 |
EXPECT_EQ(0u, NEO::IoFunctions::mockFcloseCalled); |
| 677 |
|
| 678 |
uint64_t gpuAddress = 0xF000; |
| 679 |
size_t size = 0xFF000; |
| 680 |
|
| 681 |
bool ret = wddmDirectSubmission.submit(gpuAddress, size); |
| 682 |
EXPECT_TRUE(ret); |
| 683 |
|
| 684 |
EXPECT_EQ(1u, NEO::IoFunctions::mockFopenCalled); |
| 685 |
EXPECT_EQ(5u, NEO::IoFunctions::mockVfptrinfCalled); |
| 686 |
EXPECT_EQ(0u, NEO::IoFunctions::mockFcloseCalled); |
| 687 |
} |
| 688 |
|
| 689 |
HWTEST_F(WddmDirectSubmissionTest, givenMiMemFenceRequiredThenGpuVaForAdditionalSynchronizationWAIsSet) { |
| 690 |
MockWddmDirectSubmission<FamilyType, RenderDispatcher<FamilyType>> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 691 |
|
| 692 |
ASSERT_NE(nullptr, wddmDirectSubmission.completionFenceAllocation); |
| 693 |
if (wddmDirectSubmission.miMemFenceRequired) { |
| 694 |
EXPECT_EQ(wddmDirectSubmission.completionFenceAllocation->getGpuAddress() + 8u, wddmDirectSubmission.gpuVaForAdditionalSynchronizationWA); |
| 695 |
} else { |
| 696 |
EXPECT_EQ(0u, wddmDirectSubmission.gpuVaForAdditionalSynchronizationWA); |
| 697 |
} |
| 698 |
} |
| 699 |
|
| 700 |
HWTEST_F(WddmDirectSubmissionTest, |
| 701 |
givenRenderDirectSubmissionWithDisabledMonitorFenceWhenHasStallingCommandDispatchedThenDispatchNoPostSyncOperation) { |
| 702 |
using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL; |
| 703 |
using POST_SYNC_OPERATION = typename PIPE_CONTROL::POST_SYNC_OPERATION; |
| 704 |
using Dispatcher = RenderDispatcher<FamilyType>; |
| 705 |
|
| 706 |
BatchBuffer batchBuffer; |
| 707 |
GraphicsAllocation *clientCommandBuffer = nullptr; |
| 708 |
std::unique_ptr<LinearStream> clientStream; |
| 709 |
|
| 710 |
auto memoryManager = executionEnvironment->memoryManager.get(); |
| 711 |
const AllocationProperties commandBufferProperties{device->getRootDeviceIndex(), 0x1000, |
| 712 |
AllocationType::commandBuffer, device->getDeviceBitfield()}; |
| 713 |
clientCommandBuffer = memoryManager->allocateGraphicsMemoryWithProperties(commandBufferProperties); |
| 714 |
ASSERT_NE(nullptr, clientCommandBuffer); |
| 715 |
|
| 716 |
clientStream = std::make_unique<LinearStream>(clientCommandBuffer); |
| 717 |
clientStream->getSpace(0x40); |
| 718 |
|
| 719 |
memset(clientStream->getCpuBase(), 0, 0x20); |
| 720 |
|
| 721 |
batchBuffer.endCmdPtr = ptrOffset(clientStream->getCpuBase(), 0x20); |
| 722 |
batchBuffer.commandBufferAllocation = clientCommandBuffer; |
| 723 |
batchBuffer.usedSize = 0x40; |
| 724 |
batchBuffer.taskStartAddress = clientCommandBuffer->getGpuAddress(); |
| 725 |
batchBuffer.stream = clientStream.get(); |
| 726 |
batchBuffer.hasStallingCmds = true; |
| 727 |
|
| 728 |
FlushStampTracker flushStamp(true); |
| 729 |
|
| 730 |
MockWddmDirectSubmission<FamilyType, Dispatcher> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 731 |
EXPECT_TRUE(wddmDirectSubmission.inputMonitorFenceDispatchRequirement); |
| 732 |
wddmDirectSubmission.disableMonitorFence = true; |
| 733 |
|
| 734 |
bool ret = wddmDirectSubmission.initialize(true, true); |
| 735 |
EXPECT_TRUE(ret); |
| 736 |
EXPECT_TRUE(wddmDirectSubmission.useNotifyForPostSync); |
| 737 |
|
| 738 |
size_t sizeUsedBefore = wddmDirectSubmission.ringCommandStream.getUsed(); |
| 739 |
ret = wddmDirectSubmission.dispatchCommandBuffer(batchBuffer, flushStamp); |
| 740 |
EXPECT_TRUE(ret); |
| 741 |
|
| 742 |
HardwareParse hwParse; |
| 743 |
hwParse.parsePipeControl = true; |
| 744 |
hwParse.parseCommands<FamilyType>(wddmDirectSubmission.ringCommandStream, sizeUsedBefore); |
| 745 |
hwParse.findHardwareCommands<FamilyType>(); |
| 746 |
|
| 747 |
auto &monitorFence = osContext->getResidencyController().getMonitoredFence(); |
| 748 |
|
| 749 |
bool foundFenceUpdate = false; |
| 750 |
for (auto it = hwParse.pipeControlList.begin(); it != hwParse.pipeControlList.end(); it++) { |
| 751 |
auto pipeControl = genCmdCast<PIPE_CONTROL *>(*it); |
| 752 |
if (pipeControl->getPostSyncOperation() == POST_SYNC_OPERATION::POST_SYNC_OPERATION_WRITE_IMMEDIATE_DATA) { |
| 753 |
uint64_t pipeControlPostSyncAddress = UnitTestHelper<FamilyType>::getPipeControlPostSyncAddress(*pipeControl); |
| 754 |
if (pipeControlPostSyncAddress == monitorFence.gpuAddress) { |
| 755 |
foundFenceUpdate = true; |
| 756 |
EXPECT_TRUE(pipeControl->getNotifyEnable()); |
| 757 |
break; |
| 758 |
} |
| 759 |
} |
| 760 |
} |
| 761 |
EXPECT_FALSE(foundFenceUpdate); |
| 762 |
|
| 763 |
memoryManager->freeGraphicsMemory(clientCommandBuffer); |
| 764 |
} |
| 765 |
|
| 766 |
HWTEST_F(WddmDirectSubmissionTest, |
| 767 |
givenRenderDirectSubmissionWithDisabledMonitorFenceWhenMonitorFenceDispatchedThenDispatchPostSyncOperation) { |
| 768 |
using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL; |
| 769 |
using POST_SYNC_OPERATION = typename PIPE_CONTROL::POST_SYNC_OPERATION; |
| 770 |
using Dispatcher = RenderDispatcher<FamilyType>; |
| 771 |
|
| 772 |
BatchBuffer batchBuffer; |
| 773 |
GraphicsAllocation *clientCommandBuffer = nullptr; |
| 774 |
std::unique_ptr<LinearStream> clientStream; |
| 775 |
|
| 776 |
auto memoryManager = executionEnvironment->memoryManager.get(); |
| 777 |
const AllocationProperties commandBufferProperties{device->getRootDeviceIndex(), 0x1000, |
| 778 |
AllocationType::commandBuffer, device->getDeviceBitfield()}; |
| 779 |
clientCommandBuffer = memoryManager->allocateGraphicsMemoryWithProperties(commandBufferProperties); |
| 780 |
ASSERT_NE(nullptr, clientCommandBuffer); |
| 781 |
|
| 782 |
clientStream = std::make_unique<LinearStream>(clientCommandBuffer); |
| 783 |
clientStream->getSpace(0x40); |
| 784 |
|
| 785 |
memset(clientStream->getCpuBase(), 0, 0x20); |
| 786 |
|
| 787 |
batchBuffer.endCmdPtr = ptrOffset(clientStream->getCpuBase(), 0x20); |
| 788 |
batchBuffer.commandBufferAllocation = clientCommandBuffer; |
| 789 |
batchBuffer.usedSize = 0x40; |
| 790 |
batchBuffer.taskStartAddress = clientCommandBuffer->getGpuAddress(); |
| 791 |
batchBuffer.stream = clientStream.get(); |
| 792 |
batchBuffer.dispatchMonitorFence = true; |
| 793 |
|
| 794 |
FlushStampTracker flushStamp(true); |
| 795 |
|
| 796 |
MockWddmDirectSubmission<FamilyType, Dispatcher> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 797 |
EXPECT_TRUE(wddmDirectSubmission.inputMonitorFenceDispatchRequirement); |
| 798 |
wddmDirectSubmission.disableMonitorFence = true; |
| 799 |
|
| 800 |
bool ret = wddmDirectSubmission.initialize(true, true); |
| 801 |
EXPECT_TRUE(ret); |
| 802 |
EXPECT_TRUE(wddmDirectSubmission.useNotifyForPostSync); |
| 803 |
|
| 804 |
size_t sizeUsedBefore = wddmDirectSubmission.ringCommandStream.getUsed(); |
| 805 |
ret = wddmDirectSubmission.dispatchCommandBuffer(batchBuffer, flushStamp); |
| 806 |
EXPECT_TRUE(ret); |
| 807 |
|
| 808 |
HardwareParse hwParse; |
| 809 |
hwParse.parsePipeControl = true; |
| 810 |
hwParse.parseCommands<FamilyType>(wddmDirectSubmission.ringCommandStream, sizeUsedBefore); |
| 811 |
hwParse.findHardwareCommands<FamilyType>(); |
| 812 |
|
| 813 |
auto &monitorFence = osContext->getResidencyController().getMonitoredFence(); |
| 814 |
|
| 815 |
bool foundFenceUpdate = false; |
| 816 |
for (auto it = hwParse.pipeControlList.begin(); it != hwParse.pipeControlList.end(); it++) { |
| 817 |
auto pipeControl = genCmdCast<PIPE_CONTROL *>(*it); |
| 818 |
if (pipeControl->getPostSyncOperation() == POST_SYNC_OPERATION::POST_SYNC_OPERATION_WRITE_IMMEDIATE_DATA) { |
| 819 |
uint64_t pipeControlPostSyncAddress = UnitTestHelper<FamilyType>::getPipeControlPostSyncAddress(*pipeControl); |
| 820 |
if (pipeControlPostSyncAddress == monitorFence.gpuAddress) { |
| 821 |
foundFenceUpdate = true; |
| 822 |
EXPECT_TRUE(pipeControl->getNotifyEnable()); |
| 823 |
break; |
| 824 |
} |
| 825 |
} |
| 826 |
} |
| 827 |
EXPECT_TRUE(foundFenceUpdate); |
| 828 |
|
| 829 |
memoryManager->freeGraphicsMemory(clientCommandBuffer); |
| 830 |
} |
| 831 |
|
| 832 |
HWTEST_F(WddmDirectSubmissionTest, |
| 833 |
givenDisableMonitorFenceIsFalseWhenDispatchArgumentIsFalseThenDispatchMonitorFenceReturnsTrue) { |
| 834 |
using Dispatcher = RenderDispatcher<FamilyType>; |
| 835 |
|
| 836 |
MockWddmDirectSubmission<FamilyType, Dispatcher> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 837 |
wddmDirectSubmission.disableMonitorFence = false; |
| 838 |
|
| 839 |
EXPECT_TRUE(wddmDirectSubmission.dispatchMonitorFenceRequired(false)); |
| 840 |
} |
| 841 |
|
| 842 |
HWTEST_F(WddmDirectSubmissionTest, |
| 843 |
givenDisableMonitorFenceIsFalseWhenDispatchArgumentIsTrueThenDispatchMonitorFenceReturnsTrue) { |
| 844 |
using Dispatcher = RenderDispatcher<FamilyType>; |
| 845 |
|
| 846 |
MockWddmDirectSubmission<FamilyType, Dispatcher> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 847 |
wddmDirectSubmission.disableMonitorFence = false; |
| 848 |
|
| 849 |
EXPECT_TRUE(wddmDirectSubmission.dispatchMonitorFenceRequired(true)); |
| 850 |
} |
| 851 |
|
| 852 |
HWTEST_F(WddmDirectSubmissionTest, |
| 853 |
givenDisableMonitorFenceIsTrueWhenDispatchArgumentIsFalseThenDispatchMonitorFenceReturnsFalse) { |
| 854 |
using Dispatcher = RenderDispatcher<FamilyType>; |
| 855 |
|
| 856 |
MockWddmDirectSubmission<FamilyType, Dispatcher> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 857 |
wddmDirectSubmission.disableMonitorFence = true; |
| 858 |
|
| 859 |
EXPECT_FALSE(wddmDirectSubmission.dispatchMonitorFenceRequired(false)); |
| 860 |
} |
| 861 |
|
| 862 |
HWTEST_F(WddmDirectSubmissionTest, |
| 863 |
givenDisableMonitorFenceIsTrueWhenDispatchArgumentIsTrueThenDispatchMonitorFenceReturnsTrue) { |
| 864 |
using Dispatcher = RenderDispatcher<FamilyType>; |
| 865 |
|
| 866 |
MockWddmDirectSubmission<FamilyType, Dispatcher> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 867 |
wddmDirectSubmission.disableMonitorFence = true; |
| 868 |
|
| 869 |
EXPECT_TRUE(wddmDirectSubmission.dispatchMonitorFenceRequired(true)); |
| 870 |
} |
| 871 |
|
| 872 |
HWTEST_F(WddmDirectSubmissionTest, |
| 873 |
givenWddmDirectSubmissionWithDisabledMonitorFenceWhenInputPolicyIsStallingCommandAndBatchBufferDispatchedWithExplicitMonitorFenceFlagThenDispatchNoPostSyncOperation) { |
| 874 |
using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL; |
| 875 |
using POST_SYNC_OPERATION = typename PIPE_CONTROL::POST_SYNC_OPERATION; |
| 876 |
using Dispatcher = RenderDispatcher<FamilyType>; |
| 877 |
|
| 878 |
DebugManagerStateRestore dbgRestorer; |
| 879 |
debugManager.flags.DirectSubmissionMonitorFenceInputPolicy.set(0); |
| 880 |
|
| 881 |
BatchBuffer batchBuffer = {}; |
| 882 |
GraphicsAllocation *clientCommandBuffer = nullptr; |
| 883 |
std::unique_ptr<LinearStream> clientStream; |
| 884 |
|
| 885 |
auto memoryManager = executionEnvironment->memoryManager.get(); |
| 886 |
const AllocationProperties commandBufferProperties{device->getRootDeviceIndex(), 0x1000, |
| 887 |
AllocationType::commandBuffer, device->getDeviceBitfield()}; |
| 888 |
clientCommandBuffer = memoryManager->allocateGraphicsMemoryWithProperties(commandBufferProperties); |
| 889 |
ASSERT_NE(nullptr, clientCommandBuffer); |
| 890 |
|
| 891 |
clientStream = std::make_unique<LinearStream>(clientCommandBuffer); |
| 892 |
clientStream->getSpace(0x40); |
| 893 |
|
| 894 |
memset(clientStream->getCpuBase(), 0, 0x20); |
| 895 |
|
| 896 |
batchBuffer.endCmdPtr = ptrOffset(clientStream->getCpuBase(), 0x20); |
| 897 |
batchBuffer.commandBufferAllocation = clientCommandBuffer; |
| 898 |
batchBuffer.usedSize = 0x40; |
| 899 |
batchBuffer.taskStartAddress = clientCommandBuffer->getGpuAddress(); |
| 900 |
batchBuffer.stream = clientStream.get(); |
| 901 |
batchBuffer.dispatchMonitorFence = true; |
| 902 |
|
| 903 |
FlushStampTracker flushStamp(true); |
| 904 |
|
| 905 |
MockWddmDirectSubmission<FamilyType, Dispatcher> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 906 |
EXPECT_FALSE(wddmDirectSubmission.inputMonitorFenceDispatchRequirement); |
| 907 |
wddmDirectSubmission.disableMonitorFence = true; |
| 908 |
|
| 909 |
bool ret = wddmDirectSubmission.initialize(true, true); |
| 910 |
EXPECT_TRUE(ret); |
| 911 |
EXPECT_TRUE(wddmDirectSubmission.useNotifyForPostSync); |
| 912 |
|
| 913 |
size_t sizeUsedBefore = wddmDirectSubmission.ringCommandStream.getUsed(); |
| 914 |
ret = wddmDirectSubmission.dispatchCommandBuffer(batchBuffer, flushStamp); |
| 915 |
EXPECT_TRUE(ret); |
| 916 |
|
| 917 |
HardwareParse hwParse; |
| 918 |
hwParse.parsePipeControl = true; |
| 919 |
hwParse.parseCommands<FamilyType>(wddmDirectSubmission.ringCommandStream, sizeUsedBefore); |
| 920 |
hwParse.findHardwareCommands<FamilyType>(); |
| 921 |
|
| 922 |
bool foundFenceUpdate = false; |
| 923 |
for (auto it = hwParse.pipeControlList.begin(); it != hwParse.pipeControlList.end(); it++) { |
| 924 |
auto pipeControl = genCmdCast<PIPE_CONTROL *>(*it); |
| 925 |
if (pipeControl->getPostSyncOperation() == POST_SYNC_OPERATION::POST_SYNC_OPERATION_WRITE_IMMEDIATE_DATA) { |
| 926 |
foundFenceUpdate = true; |
| 927 |
break; |
| 928 |
} |
| 929 |
} |
| 930 |
EXPECT_FALSE(foundFenceUpdate); |
| 931 |
|
| 932 |
memoryManager->freeGraphicsMemory(clientCommandBuffer); |
| 933 |
} |
| 934 |
|
| 935 |
HWTEST_F(WddmDirectSubmissionTest, |
| 936 |
givenWddmDirectSubmissionWithDisabledMonitorFenceWhenInputPolicyIsExplicitMonitorFenceAndBatchBufferDispatchedWithStallingCommandFlagThenDispatchNoPostSyncOperation) { |
| 937 |
using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL; |
| 938 |
using POST_SYNC_OPERATION = typename PIPE_CONTROL::POST_SYNC_OPERATION; |
| 939 |
using Dispatcher = RenderDispatcher<FamilyType>; |
| 940 |
|
| 941 |
DebugManagerStateRestore dbgRestorer; |
| 942 |
debugManager.flags.DirectSubmissionMonitorFenceInputPolicy.set(1); |
| 943 |
|
| 944 |
BatchBuffer batchBuffer = {}; |
| 945 |
GraphicsAllocation *clientCommandBuffer = nullptr; |
| 946 |
std::unique_ptr<LinearStream> clientStream; |
| 947 |
|
| 948 |
auto memoryManager = executionEnvironment->memoryManager.get(); |
| 949 |
const AllocationProperties commandBufferProperties{device->getRootDeviceIndex(), 0x1000, |
| 950 |
AllocationType::commandBuffer, device->getDeviceBitfield()}; |
| 951 |
clientCommandBuffer = memoryManager->allocateGraphicsMemoryWithProperties(commandBufferProperties); |
| 952 |
ASSERT_NE(nullptr, clientCommandBuffer); |
| 953 |
|
| 954 |
clientStream = std::make_unique<LinearStream>(clientCommandBuffer); |
| 955 |
clientStream->getSpace(0x40); |
| 956 |
|
| 957 |
memset(clientStream->getCpuBase(), 0, 0x20); |
| 958 |
|
| 959 |
batchBuffer.endCmdPtr = ptrOffset(clientStream->getCpuBase(), 0x20); |
| 960 |
batchBuffer.commandBufferAllocation = clientCommandBuffer; |
| 961 |
batchBuffer.usedSize = 0x40; |
| 962 |
batchBuffer.taskStartAddress = clientCommandBuffer->getGpuAddress(); |
| 963 |
batchBuffer.stream = clientStream.get(); |
| 964 |
batchBuffer.hasStallingCmds = true; |
| 965 |
|
| 966 |
FlushStampTracker flushStamp(true); |
| 967 |
|
| 968 |
MockWddmDirectSubmission<FamilyType, Dispatcher> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 969 |
EXPECT_TRUE(wddmDirectSubmission.inputMonitorFenceDispatchRequirement); |
| 970 |
wddmDirectSubmission.disableMonitorFence = true; |
| 971 |
|
| 972 |
bool ret = wddmDirectSubmission.initialize(true, true); |
| 973 |
EXPECT_TRUE(ret); |
| 974 |
EXPECT_TRUE(wddmDirectSubmission.useNotifyForPostSync); |
| 975 |
|
| 976 |
size_t sizeUsedBefore = wddmDirectSubmission.ringCommandStream.getUsed(); |
| 977 |
ret = wddmDirectSubmission.dispatchCommandBuffer(batchBuffer, flushStamp); |
| 978 |
EXPECT_TRUE(ret); |
| 979 |
|
| 980 |
HardwareParse hwParse; |
| 981 |
hwParse.parsePipeControl = true; |
| 982 |
hwParse.parseCommands<FamilyType>(wddmDirectSubmission.ringCommandStream, sizeUsedBefore); |
| 983 |
hwParse.findHardwareCommands<FamilyType>(); |
| 984 |
|
| 985 |
bool foundFenceUpdate = false; |
| 986 |
for (auto it = hwParse.pipeControlList.begin(); it != hwParse.pipeControlList.end(); it++) { |
| 987 |
auto pipeControl = genCmdCast<PIPE_CONTROL *>(*it); |
| 988 |
if (pipeControl->getPostSyncOperation() == POST_SYNC_OPERATION::POST_SYNC_OPERATION_WRITE_IMMEDIATE_DATA) { |
| 989 |
foundFenceUpdate = true; |
| 990 |
break; |
| 991 |
} |
| 992 |
} |
| 993 |
EXPECT_FALSE(foundFenceUpdate); |
| 994 |
|
| 995 |
memoryManager->freeGraphicsMemory(clientCommandBuffer); |
| 996 |
} |
| 997 |
|
| 998 |
HWTEST_F(WddmDirectSubmissionTest, |
| 999 |
givenBatchBufferWithThrottleLowWhenCallDispatchCommandBufferThenStoreLastSubmitedThrottle) { |
| 1000 |
|
| 1001 |
using Dispatcher = RenderDispatcher<FamilyType>; |
| 1002 |
|
| 1003 |
BatchBuffer batchBuffer; |
| 1004 |
GraphicsAllocation *clientCommandBuffer = nullptr; |
| 1005 |
std::unique_ptr<LinearStream> clientStream; |
| 1006 |
|
| 1007 |
auto memoryManager = executionEnvironment->memoryManager.get(); |
| 1008 |
const AllocationProperties commandBufferProperties{device->getRootDeviceIndex(), 0x1000, |
| 1009 |
AllocationType::commandBuffer, device->getDeviceBitfield()}; |
| 1010 |
clientCommandBuffer = memoryManager->allocateGraphicsMemoryWithProperties(commandBufferProperties); |
| 1011 |
ASSERT_NE(nullptr, clientCommandBuffer); |
| 1012 |
|
| 1013 |
clientStream = std::make_unique<LinearStream>(clientCommandBuffer); |
| 1014 |
clientStream->getSpace(0x40); |
| 1015 |
|
| 1016 |
memset(clientStream->getCpuBase(), 0, 0x20); |
| 1017 |
|
| 1018 |
batchBuffer.endCmdPtr = ptrOffset(clientStream->getCpuBase(), 0x20); |
| 1019 |
batchBuffer.commandBufferAllocation = clientCommandBuffer; |
| 1020 |
batchBuffer.usedSize = 0x40; |
| 1021 |
batchBuffer.taskStartAddress = clientCommandBuffer->getGpuAddress(); |
| 1022 |
batchBuffer.stream = clientStream.get(); |
| 1023 |
batchBuffer.throttle = QueueThrottle::LOW; |
| 1024 |
|
| 1025 |
FlushStampTracker flushStamp(true); |
| 1026 |
|
| 1027 |
MockWddmDirectSubmission<FamilyType, Dispatcher> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 1028 |
|
| 1029 |
wddmDirectSubmission.initialize(true, true); |
| 1030 |
|
| 1031 |
bool ret = wddmDirectSubmission.dispatchCommandBuffer(batchBuffer, flushStamp); |
| 1032 |
EXPECT_TRUE(ret); |
| 1033 |
EXPECT_EQ(QueueThrottle::LOW, wddmDirectSubmission.lastSubmittedThrottle); |
| 1034 |
|
| 1035 |
memoryManager->freeGraphicsMemory(clientCommandBuffer); |
| 1036 |
} |
| 1037 |
|
| 1038 |
HWTEST_F(WddmDirectSubmissionTest, givenNullPtrResidencyControllerWhenUpdatingResidencyAfterSwitchRingThenReturnBeforeAccessingContextId) { |
| 1039 |
|
| 1040 |
using Dispatcher = RenderDispatcher<FamilyType>; |
| 1041 |
auto mockOsContextWin = std::make_unique<MockOsContextWin>(*wddm, 0, 0, EngineDescriptorHelper::getDefaultDescriptor()); |
| 1042 |
|
| 1043 |
MockWddmDirectSubmission<FamilyType, Dispatcher> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 1044 |
wddmDirectSubmission.osContextWin = mockOsContextWin.get(); |
| 1045 |
wddmDirectSubmission.updateMonitorFenceValueForResidencyList(nullptr); |
| 1046 |
EXPECT_EQ(mockOsContextWin->getResidencyControllerCalledTimes, 0u); |
| 1047 |
} |
| 1048 |
|
| 1049 |
HWTEST_F(WddmDirectSubmissionTest, givenEmptyResidencyControllerWhenUpdatingResidencyAfterSwitchRingThenReturnAfterAccessingContextId) { |
| 1050 |
|
| 1051 |
using Dispatcher = RenderDispatcher<FamilyType>; |
| 1052 |
auto mockOsContextWin = std::make_unique<MockOsContextWin>(*wddm, 0, 0, EngineDescriptorHelper::getDefaultDescriptor()); |
| 1053 |
|
| 1054 |
MockWddmDirectSubmission<FamilyType, Dispatcher> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 1055 |
wddmDirectSubmission.osContextWin = mockOsContextWin.get(); |
| 1056 |
ResidencyContainer container; |
| 1057 |
wddmDirectSubmission.updateMonitorFenceValueForResidencyList(&container); |
| 1058 |
EXPECT_EQ(mockOsContextWin->getResidencyControllerCalledTimes, 1u); |
| 1059 |
} |
| 1060 |
|
| 1061 |
HWTEST_F(WddmDirectSubmissionTest, givenResidencyControllerWhenUpdatingResidencyAfterSwitchRingThenAllocationCallUpdateResidency) { |
| 1062 |
|
| 1063 |
using Dispatcher = RenderDispatcher<FamilyType>; |
| 1064 |
auto mockOsContextWin = std::make_unique<MockOsContextWin>(*wddm, 0, 0, EngineDescriptorHelper::getDefaultDescriptor()); |
| 1065 |
|
| 1066 |
MockWddmDirectSubmission<FamilyType, Dispatcher> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 1067 |
wddmDirectSubmission.osContextWin = mockOsContextWin.get(); |
| 1068 |
ResidencyContainer container; |
| 1069 |
NEO::MockGraphicsAllocation mockGa; |
| 1070 |
container.push_back(&mockGa); |
| 1071 |
wddmDirectSubmission.updateMonitorFenceValueForResidencyList(&container); |
| 1072 |
EXPECT_EQ(mockGa.updateCompletionDataForAllocationAndFragmentsCalledtimes, 1u); |
| 1073 |
} |
| 1074 |
|
| 1075 |
HWTEST_F(WddmDirectSubmissionTest, givenDirectSubmissionWhenSwitchingRingBuffersThenUpdateResidencyCalled) { |
| 1076 |
using Dispatcher = RenderDispatcher<FamilyType>; |
| 1077 |
|
| 1078 |
MockWddmDirectSubmission<FamilyType, Dispatcher> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 1079 |
wddmDirectSubmission.handleSwitchRingBuffers(nullptr); |
| 1080 |
EXPECT_EQ(wddmDirectSubmission.updateMonitorFenceValueForResidencyListCalled, 1u); |
| 1081 |
} |
| 1082 |
|
| 1083 |
template <typename GfxFamily, typename Dispatcher> |
| 1084 |
struct MyMockWddmDirectSubmission : public MockWddmDirectSubmission<GfxFamily, Dispatcher> { |
| 1085 |
using BaseClass = MockWddmDirectSubmission<GfxFamily, Dispatcher>; |
| 1086 |
using BaseClass::MockWddmDirectSubmission; |
| 1087 |
void updateMonitorFenceValueForResidencyList(ResidencyContainer *allocationsForResidency) override { |
| 1088 |
lockInTesting = true; |
| 1089 |
while (lockInTesting) |
| 1090 |
; |
| 1091 |
BaseClass::updateMonitorFenceValueForResidencyList(allocationsForResidency); |
| 1092 |
} |
| 1093 |
std::atomic<bool> lockInTesting = false; |
| 1094 |
}; |
| 1095 |
|
| 1096 |
HWTEST_F(WddmDirectSubmissionTest, givenDirectSubmissionWhenSwitchingRingBuffersThenUpdateResidencyCalledWithinLock) { |
| 1097 |
using Dispatcher = RenderDispatcher<FamilyType>; |
| 1098 |
|
| 1099 |
MyMockWddmDirectSubmission<FamilyType, Dispatcher> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 1100 |
std::thread th([&]() { |
| 1101 |
wddmDirectSubmission.handleSwitchRingBuffers(nullptr); |
| 1102 |
}); |
| 1103 |
while (!wddmDirectSubmission.lockInTesting) |
| 1104 |
; |
| 1105 |
auto tryLock = reinterpret_cast<MockWddmResidencyController *>(&(wddmDirectSubmission.osContextWin->getResidencyController()))->lock.try_lock(); |
| 1106 |
EXPECT_FALSE(tryLock); |
| 1107 |
wddmDirectSubmission.lockInTesting = false; |
| 1108 |
th.join(); |
| 1109 |
} |
| 1110 |
|
| 1111 |
HWTEST_F(WddmDirectSubmissionTest, givenDirectSubmissionWhenSwitchingRingBuffersThenPrevRingIndexPassedForCompletionUpdate) { |
| 1112 |
using Dispatcher = RenderDispatcher<FamilyType>; |
| 1113 |
|
| 1114 |
MockWddmDirectSubmission<FamilyType, Dispatcher> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 1115 |
wddmDirectSubmission.currentRingBuffer = 0; |
| 1116 |
wddmDirectSubmission.previousRingBuffer = 1; |
| 1117 |
wddmDirectSubmission.handleSwitchRingBuffers(nullptr); |
| 1118 |
EXPECT_EQ(wddmDirectSubmission.ringBufferForCompletionFence, wddmDirectSubmission.previousRingBuffer); |
| 1119 |
} |
| 1120 |
|
| 1121 |
HWTEST_F(WddmDirectSubmissionTest, givenDirectSubmissionWhenUnblockPagingFenceSemaphoreThenCorrectValueAssigned) { |
| 1122 |
using Dispatcher = RenderDispatcher<FamilyType>; |
| 1123 |
auto pagingFenceValueToWait = 30u; |
| 1124 |
auto mockedPagingFence = 20u; |
| 1125 |
|
| 1126 |
MockWddmDirectSubmission<FamilyType, Dispatcher> wddmDirectSubmission(*device->getDefaultEngine().commandStreamReceiver); |
| 1127 |
wddmDirectSubmission.initialize(false, false); |
| 1128 |
EXPECT_EQ(0u, wddmDirectSubmission.semaphoreData->pagingFenceCounter); |
| 1129 |
wddm->mockPagingFence = mockedPagingFence; |
| 1130 |
|
| 1131 |
wddmDirectSubmission.unblockPagingFenceSemaphore(pagingFenceValueToWait); |
| 1132 |
EXPECT_GT(wddmDirectSubmission.semaphoreData->pagingFenceCounter, mockedPagingFence); |
| 1133 |
} |