diff --git a/runtime/command_stream/command_stream_receiver_with_aub_dump.inl b/runtime/command_stream/command_stream_receiver_with_aub_dump.inl index 1ff30c955b..84a38e15ad 100644 --- a/runtime/command_stream/command_stream_receiver_with_aub_dump.inl +++ b/runtime/command_stream/command_stream_receiver_with_aub_dump.inl @@ -29,7 +29,7 @@ extern CommandStreamReceiverCreateFunc commandStreamReceiverFactory[2 * IGFX_MAX template CommandStreamReceiverWithAUBDump::CommandStreamReceiverWithAUBDump(const HardwareInfo &hwInfoIn, ExecutionEnvironment &executionEnvironment) - : BaseCSR(hwInfoIn, nullptr, executionEnvironment) { + : BaseCSR(hwInfoIn, executionEnvironment) { aubCSR = AUBCommandStreamReceiver::create(hwInfoIn, "aubfile", false, executionEnvironment); } diff --git a/runtime/command_stream/tbx_command_stream_receiver_hw.h b/runtime/command_stream/tbx_command_stream_receiver_hw.h index 4e4196399f..9dca3cdff0 100644 --- a/runtime/command_stream/tbx_command_stream_receiver_hw.h +++ b/runtime/command_stream/tbx_command_stream_receiver_hw.h @@ -60,7 +60,7 @@ class TbxCommandStreamReceiverHw : public CommandStreamReceiverHw { static CommandStreamReceiver *create(const HardwareInfo &hwInfoIn, bool withAubDump, ExecutionEnvironment &executionEnvironment); - TbxCommandStreamReceiverHw(const HardwareInfo &hwInfoIn, void *ptr, ExecutionEnvironment &executionEnvironment); + TbxCommandStreamReceiverHw(const HardwareInfo &hwInfoIn, ExecutionEnvironment &executionEnvironment); ~TbxCommandStreamReceiverHw() override; void initializeEngine(EngineType engineType); diff --git a/runtime/command_stream/tbx_command_stream_receiver_hw.inl b/runtime/command_stream/tbx_command_stream_receiver_hw.inl index 9b025c731e..845394bf12 100644 --- a/runtime/command_stream/tbx_command_stream_receiver_hw.inl +++ b/runtime/command_stream/tbx_command_stream_receiver_hw.inl @@ -32,7 +32,8 @@ namespace OCLRT { template -TbxCommandStreamReceiverHw::TbxCommandStreamReceiverHw(const HardwareInfo &hwInfoIn, void *ptr, ExecutionEnvironment &executionEnvironment) +TbxCommandStreamReceiverHw::TbxCommandStreamReceiverHw(const HardwareInfo &hwInfoIn, + ExecutionEnvironment &executionEnvironment) : BaseClass(hwInfoIn, executionEnvironment) { for (auto &engineInfo : engineInfoTable) { engineInfo.pLRCA = nullptr; @@ -175,7 +176,7 @@ CommandStreamReceiver *TbxCommandStreamReceiverHw::create(const Hardw if (withAubDump) { csr = new CommandStreamReceiverWithAUBDump>(hwInfoIn, executionEnvironment); } else { - csr = new TbxCommandStreamReceiverHw(hwInfoIn, nullptr, executionEnvironment); + csr = new TbxCommandStreamReceiverHw(hwInfoIn, executionEnvironment); } // Open our stream diff --git a/runtime/os_interface/linux/device_command_stream.inl b/runtime/os_interface/linux/device_command_stream.inl index 7169c0bca7..553019bb91 100644 --- a/runtime/os_interface/linux/device_command_stream.inl +++ b/runtime/os_interface/linux/device_command_stream.inl @@ -33,7 +33,7 @@ CommandStreamReceiver *DeviceCommandStreamReceiver::create(const Hard if (withAubDump) { return new CommandStreamReceiverWithAUBDump>(hwInfo, executionEnvironment); } else { - return new DrmCommandStreamReceiver(hwInfo, nullptr, executionEnvironment); + return new DrmCommandStreamReceiver(hwInfo, executionEnvironment); } }; } // namespace OCLRT diff --git a/runtime/os_interface/linux/drm_command_stream.h b/runtime/os_interface/linux/drm_command_stream.h index c0c771a916..f049fb034c 100644 --- a/runtime/os_interface/linux/drm_command_stream.h +++ b/runtime/os_interface/linux/drm_command_stream.h @@ -48,7 +48,8 @@ class DrmCommandStreamReceiver : public DeviceCommandStreamReceiver { public: // When drm is null default implementation is used. In this case DrmCommandStreamReceiver is responsible to free drm. // When drm is passed, DCSR will not free it at destruction - DrmCommandStreamReceiver(const HardwareInfo &hwInfoIn, Drm *drm, ExecutionEnvironment &executionEnvironment, gemCloseWorkerMode mode = gemCloseWorkerMode::gemCloseWorkerActive); + DrmCommandStreamReceiver(const HardwareInfo &hwInfoIn, ExecutionEnvironment &executionEnvironment, + gemCloseWorkerMode mode = gemCloseWorkerMode::gemCloseWorkerActive); FlushStamp flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer *allocationsForResidency, OsContext &osContext) override; void makeResident(GraphicsAllocation &gfxAllocation) override; diff --git a/runtime/os_interface/linux/drm_command_stream.inl b/runtime/os_interface/linux/drm_command_stream.inl index 3596155afb..e85f62c968 100644 --- a/runtime/os_interface/linux/drm_command_stream.inl +++ b/runtime/os_interface/linux/drm_command_stream.inl @@ -41,14 +41,19 @@ namespace OCLRT { template DrmCommandStreamReceiver::DrmCommandStreamReceiver(const HardwareInfo &hwInfoIn, - Drm *drm, ExecutionEnvironment &executionEnvironment, gemCloseWorkerMode mode) + ExecutionEnvironment &executionEnvironment, gemCloseWorkerMode mode) : BaseClass(hwInfoIn, executionEnvironment), gemCloseWorkerOperationMode(mode) { - this->drm = drm ? drm : Drm::get(0); - residency.reserve(512); - execObjectsStorage.reserve(512); if (!executionEnvironment.osInterface) { executionEnvironment.osInterface = std::make_unique(); + this->drm = Drm::get(0); + } else { + this->drm = executionEnvironment.osInterface->get()->getDrm() + ? executionEnvironment.osInterface->get()->getDrm() + : Drm::get(0); } + residency.reserve(512); + execObjectsStorage.reserve(512); + executionEnvironment.osInterface->get()->setDrm(this->drm); CommandStreamReceiver::osInterface = executionEnvironment.osInterface.get(); auto gmmHelper = platform()->peekExecutionEnvironment()->getGmmHelper(); diff --git a/runtime/os_interface/windows/device_command_stream.inl b/runtime/os_interface/windows/device_command_stream.inl index b8dd993131..ca37bf38a8 100644 --- a/runtime/os_interface/windows/device_command_stream.inl +++ b/runtime/os_interface/windows/device_command_stream.inl @@ -37,7 +37,7 @@ CommandStreamReceiver *DeviceCommandStreamReceiver::create(const Hard if (withAubDump) { return new CommandStreamReceiverWithAUBDump>(hwInfo, executionEnvironment); } else { - return new WddmCommandStreamReceiver(hwInfo, nullptr, executionEnvironment); + return new WddmCommandStreamReceiver(hwInfo, executionEnvironment); } } } // namespace OCLRT diff --git a/runtime/os_interface/windows/wddm_device_command_stream.h b/runtime/os_interface/windows/wddm_device_command_stream.h index 4562e84e41..d910601d64 100644 --- a/runtime/os_interface/windows/wddm_device_command_stream.h +++ b/runtime/os_interface/windows/wddm_device_command_stream.h @@ -37,7 +37,7 @@ class WddmCommandStreamReceiver : public DeviceCommandStreamReceiver using CommandStreamReceiverHw::CommandStreamReceiver::memoryManager; public: - WddmCommandStreamReceiver(const HardwareInfo &hwInfoIn, Wddm *wddm, ExecutionEnvironment &executionEnvironment); + WddmCommandStreamReceiver(const HardwareInfo &hwInfoIn, ExecutionEnvironment &executionEnvironment); virtual ~WddmCommandStreamReceiver(); FlushStamp flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer *allocationsForResidency, OsContext &osContext) override; diff --git a/runtime/os_interface/windows/wddm_device_command_stream.inl b/runtime/os_interface/windows/wddm_device_command_stream.inl index cb248a1b0b..890c889c0b 100644 --- a/runtime/os_interface/windows/wddm_device_command_stream.inl +++ b/runtime/os_interface/windows/wddm_device_command_stream.inl @@ -49,21 +49,26 @@ namespace OCLRT { DECLARE_COMMAND_BUFFER(CommandBufferHeader, UMD_OCL, FALSE, FALSE, PERFTAG_OCL); template -WddmCommandStreamReceiver::WddmCommandStreamReceiver(const HardwareInfo &hwInfoIn, Wddm *wddm, ExecutionEnvironment &executionEnvironment) +WddmCommandStreamReceiver::WddmCommandStreamReceiver(const HardwareInfo &hwInfoIn, + ExecutionEnvironment &executionEnvironment) : BaseClass(hwInfoIn, executionEnvironment) { - this->wddm = wddm; - if (this->wddm == nullptr) { + + if (!executionEnvironment.osInterface) { + executionEnvironment.osInterface = std::make_unique(); this->wddm = Wddm::createWddm(); + this->osInterface = executionEnvironment.osInterface.get(); + this->osInterface->get()->setWddm(this->wddm); + } else { + this->wddm = executionEnvironment.osInterface->get()->getWddm(); + this->osInterface = executionEnvironment.osInterface.get(); } + GPUNODE_ORDINAL nodeOrdinal = GPUNODE_3D; UNRECOVERABLE_IF(!WddmEngineMapper::engineNodeMap(hwInfoIn.capabilityTable.defaultEngineType, nodeOrdinal)); this->wddm->setNode(nodeOrdinal); PreemptionMode preemptionMode = PreemptionHelper::getDefaultPreemptionMode(hwInfoIn); this->wddm->setPreemptionMode(preemptionMode); - executionEnvironment.osInterface.reset(new OSInterface()); - this->osInterface = executionEnvironment.osInterface.get(); - this->osInterface->get()->setWddm(this->wddm); commandBufferHeader = new COMMAND_BUFFER_HEADER; *commandBufferHeader = CommandBufferHeader; diff --git a/unit_tests/command_stream/command_stream_receiver_with_aub_dump_tests.cpp b/unit_tests/command_stream/command_stream_receiver_with_aub_dump_tests.cpp index ac96772185..43443d8021 100644 --- a/unit_tests/command_stream/command_stream_receiver_with_aub_dump_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_with_aub_dump_tests.cpp @@ -32,7 +32,8 @@ using namespace OCLRT; struct MyMockCsr : UltCommandStreamReceiver { - MyMockCsr(const HardwareInfo &hwInfoIn, void *ptr, ExecutionEnvironment &executionEnvironment) : UltCommandStreamReceiver(hwInfoIn, executionEnvironment) { + MyMockCsr(const HardwareInfo &hwInfoIn, ExecutionEnvironment &executionEnvironment) + : UltCommandStreamReceiver(hwInfoIn, executionEnvironment) { } FlushStamp flush(BatchBuffer &batchBuffer, EngineType engineOrdinal, ResidencyContainer *allocationsForResidency, OsContext &osContext) override { @@ -101,7 +102,7 @@ struct MyMockCsrWithAubDump : CommandStreamReceiverWithAUBDump { } if (createAubCSR) { // overwrite with mock - this->aubCSR = new MyMockCsr(hwInfoIn, nullptr, executionEnvironment); + this->aubCSR = new MyMockCsr(hwInfoIn, executionEnvironment); } } diff --git a/unit_tests/command_stream/tbx_command_stream_tests.cpp b/unit_tests/command_stream/tbx_command_stream_tests.cpp index 829f328b01..3e97379b28 100644 --- a/unit_tests/command_stream/tbx_command_stream_tests.cpp +++ b/unit_tests/command_stream/tbx_command_stream_tests.cpp @@ -58,7 +58,8 @@ template class MockTbxCsr : public TbxCommandStreamReceiverHw { public: using CommandStreamReceiver::latestFlushedTaskCount; - MockTbxCsr(const HardwareInfo &hwInfoIn, void *ptr, ExecutionEnvironment &executionEnvironment) : TbxCommandStreamReceiverHw(hwInfoIn, ptr, executionEnvironment) {} + MockTbxCsr(const HardwareInfo &hwInfoIn, ExecutionEnvironment &executionEnvironment) + : TbxCommandStreamReceiverHw(hwInfoIn, executionEnvironment) {} void makeCoherent(GraphicsAllocation &gfxAllocation) override { auto tagAddress = reinterpret_cast(gfxAllocation.getUnderlyingBuffer()); @@ -318,7 +319,7 @@ HWTEST_F(TbxCommandStreamTests, givenDbgDeviceIdFlagIsSetWhenTbxCsrIsCreatedThen HWTEST_F(TbxCommandSteamSimpleTest, givenTbxCsrWhenWaitBeforeMakeNonResidentWhenRequiredIsCalledWithBlockingFlagTrueThenFunctionStallsUntilMakeCoherentUpdatesTagAddress) { uint32_t tag = 0; - MockTbxCsr tbxCsr(*platformDevices[0], &tag, *pDevice->executionEnvironment); + MockTbxCsr tbxCsr(*platformDevices[0], *pDevice->executionEnvironment); GraphicsAllocation graphicsAllocation(&tag, sizeof(tag)); tbxCsr.setTagAllocation(&graphicsAllocation); diff --git a/unit_tests/os_interface/linux/device_command_stream_tests.cpp b/unit_tests/os_interface/linux/device_command_stream_tests.cpp index b80a382b58..f995d46fb5 100644 --- a/unit_tests/os_interface/linux/device_command_stream_tests.cpp +++ b/unit_tests/os_interface/linux/device_command_stream_tests.cpp @@ -28,6 +28,7 @@ #include "runtime/command_stream/linear_stream.h" #include "runtime/os_interface/linux/device_command_stream.inl" #include "runtime/os_interface/linux/drm_command_stream.h" +#include "runtime/os_interface/linux/os_interface.h" #include "hw_cmds.h" #include "unit_tests/fixtures/device_fixture.h" #include "test.h" @@ -39,21 +40,32 @@ using namespace OCLRT; typedef Test DeviceCommandStreamLeaksTest; HWTEST_F(DeviceCommandStreamLeaksTest, Create) { + this->executionEnvironment.osInterface = std::make_unique(); std::unique_ptr ptr(DeviceCommandStreamReceiver::create(*platformDevices[0], false, this->executionEnvironment)); DrmMockSuccess mockDrm; EXPECT_NE(nullptr, ptr); } HWTEST_F(DeviceCommandStreamLeaksTest, givenDefaultDrmCsrWhenItIsCreatedThenGemCloseWorkerInactiveModeIsSelected) { + this->executionEnvironment.osInterface = std::make_unique(); std::unique_ptr ptr(DeviceCommandStreamReceiver::create(*platformDevices[0], false, this->executionEnvironment)); auto drmCsr = (DrmCommandStreamReceiver *)ptr.get(); EXPECT_EQ(drmCsr->peekGemCloseWorkerOperationMode(), gemCloseWorkerMode::gemCloseWorkerActive); } HWTEST_F(DeviceCommandStreamLeaksTest, givenDefaultDrmCsrWithAubDumWhenItIsCreatedThenGemCloseWorkerInactiveModeIsSelected) { + this->executionEnvironment.osInterface = std::make_unique(); std::unique_ptr ptr(DeviceCommandStreamReceiver::create(*platformDevices[0], true, this->executionEnvironment)); auto drmCsrWithAubDump = (CommandStreamReceiverWithAUBDump> *)ptr.get(); EXPECT_EQ(drmCsrWithAubDump->peekGemCloseWorkerOperationMode(), gemCloseWorkerMode::gemCloseWorkerActive); auto aubCSR = static_cast> *>(ptr.get())->aubCSR; EXPECT_NE(nullptr, aubCSR); } + +HWTEST_F(DeviceCommandStreamLeaksTest, givenDefaultDrmCsrWhenOsInterfaceIsNullptrThenValidateDrm) { + std::unique_ptr ptr(DeviceCommandStreamReceiver::create(*platformDevices[0], false, + this->executionEnvironment)); + auto drmCsr = (DrmCommandStreamReceiver *)ptr.get(); + EXPECT_NE(nullptr, executionEnvironment.osInterface); + EXPECT_EQ(drmCsr->getOSInterface()->get()->getDrm(), executionEnvironment.osInterface->get()->getDrm()); +} \ No newline at end of file diff --git a/unit_tests/os_interface/linux/drm_command_stream_mm_tests.cpp b/unit_tests/os_interface/linux/drm_command_stream_mm_tests.cpp index be54a0d216..0640398ac0 100644 --- a/unit_tests/os_interface/linux/drm_command_stream_mm_tests.cpp +++ b/unit_tests/os_interface/linux/drm_command_stream_mm_tests.cpp @@ -23,6 +23,7 @@ #include "runtime/execution_environment/execution_environment.h" #include "runtime/os_interface/linux/drm_command_stream.h" #include "runtime/os_interface/linux/drm_memory_manager.h" +#include "runtime/os_interface/linux/os_interface.h" #include "unit_tests/helpers/debug_manager_state_restore.h" #include "unit_tests/os_interface/linux/device_command_stream_fixture.h" #include "test.h" @@ -41,7 +42,11 @@ HWTEST_F(DrmCommandStreamMMTest, MMwithPinBB) { std::unique_ptr mock(new DrmMockCustom()); ASSERT_NE(nullptr, mock); - DrmCommandStreamReceiver csr(*platformDevices[0], mock.get(), executionEnvironment, gemCloseWorkerMode::gemCloseWorkerInactive); + executionEnvironment.osInterface = std::make_unique(); + executionEnvironment.osInterface->get()->setDrm(mock.get()); + + DrmCommandStreamReceiver csr(*platformDevices[0], executionEnvironment, + gemCloseWorkerMode::gemCloseWorkerInactive); auto mm = (DrmMemoryManager *)csr.createMemoryManager(false); ASSERT_NE(nullptr, mm); @@ -61,7 +66,11 @@ HWTEST_F(DrmCommandStreamMMTest, givenForcePinDisabledWhenMemoryManagerIsCreated std::unique_ptr mock(new DrmMockCustom()); ASSERT_NE(nullptr, mock); - DrmCommandStreamReceiver csr(*platformDevices[0], mock.get(), executionEnvironment, gemCloseWorkerMode::gemCloseWorkerInactive); + executionEnvironment.osInterface = std::make_unique(); + executionEnvironment.osInterface->get()->setDrm(mock.get()); + + DrmCommandStreamReceiver csr(*platformDevices[0], executionEnvironment, + gemCloseWorkerMode::gemCloseWorkerInactive); auto mm = (DrmMemoryManager *)csr.createMemoryManager(false); csr.setMemoryManager(nullptr); diff --git a/unit_tests/os_interface/linux/drm_command_stream_tests.cpp b/unit_tests/os_interface/linux/drm_command_stream_tests.cpp index 7623d6f730..51efe02b15 100644 --- a/unit_tests/os_interface/linux/drm_command_stream_tests.cpp +++ b/unit_tests/os_interface/linux/drm_command_stream_tests.cpp @@ -64,7 +64,11 @@ class DrmCommandStreamFixture { this->mock = new DrmMockImpl(mockFd); - csr = new DrmCommandStreamReceiver(*platformDevices[0], mock, executionEnvironment, gemCloseWorkerMode::gemCloseWorkerActive); + executionEnvironment.osInterface = std::make_unique(); + executionEnvironment.osInterface->get()->setDrm(mock); + + csr = new DrmCommandStreamReceiver(*platformDevices[0], executionEnvironment, + gemCloseWorkerMode::gemCloseWorkerActive); ASSERT_NE(nullptr, csr); // Memory manager creates pinBB with ioctl, expect one call @@ -511,7 +515,9 @@ struct DrmCsrVfeTests : ::testing::Test { using DrmCommandStreamReceiver::mediaVfeStateLowPriorityDirty; using CommandStreamReceiver::commandStream; - MyCsr(ExecutionEnvironment &executionEnvironment) : DrmCommandStreamReceiver(*platformDevices[0], nullptr, executionEnvironment, gemCloseWorkerMode::gemCloseWorkerInactive) {} + MyCsr(ExecutionEnvironment &executionEnvironment) + : DrmCommandStreamReceiver(*platformDevices[0], executionEnvironment, + gemCloseWorkerMode::gemCloseWorkerInactive) {} FlushStamp flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer *allocationsForResidency, OsContext &osContext) override { return (FlushStamp)0; } @@ -535,6 +541,7 @@ struct DrmCsrVfeTests : ::testing::Test { HWCMDTEST_F(IGFX_GEN8_CORE, DrmCsrVfeTests, givenNonDirtyVfeForDefaultContextWhenLowPriorityIsFlushedThenReprogram) { std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); + device->executionEnvironment->osInterface = std::make_unique(); auto mockCsr = new MyCsr(*device->executionEnvironment); device->resetCommandStreamReceiver(mockCsr); @@ -563,6 +570,7 @@ HWCMDTEST_F(IGFX_GEN8_CORE, DrmCsrVfeTests, givenNonDirtyVfeForDefaultContextWhe HWCMDTEST_F(IGFX_GEN8_CORE, DrmCsrVfeTests, givenNonDirtyVfeForLowPriorityContextWhenDefaultPriorityIsFlushedThenReprogram) { std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); + device->executionEnvironment->osInterface = std::make_unique(); auto mockCsr = new MyCsr(*device->executionEnvironment); device->resetCommandStreamReceiver(mockCsr); @@ -591,6 +599,7 @@ HWCMDTEST_F(IGFX_GEN8_CORE, DrmCsrVfeTests, givenNonDirtyVfeForLowPriorityContex HWCMDTEST_F(IGFX_GEN8_CORE, DrmCsrVfeTests, givenNonDirtyVfeForLowPriorityContextWhenLowPriorityIsFlushedThenDontReprogram) { std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); + device->executionEnvironment->osInterface = std::make_unique(); auto mockCsr = new MyCsr(*device->executionEnvironment); device->resetCommandStreamReceiver(mockCsr); @@ -619,6 +628,7 @@ HWCMDTEST_F(IGFX_GEN8_CORE, DrmCsrVfeTests, givenNonDirtyVfeForLowPriorityContex HWTEST_F(DrmCsrVfeTests, givenNonDirtyVfeForBothPriorityContextWhenFlushedLowWithScratchRequirementThenMakeDefaultDirty) { std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); + device->executionEnvironment->osInterface = std::make_unique(); auto mockCsr = new MyCsr(*device->executionEnvironment); device->resetCommandStreamReceiver(mockCsr); @@ -640,6 +650,7 @@ HWTEST_F(DrmCsrVfeTests, givenNonDirtyVfeForBothPriorityContextWhenFlushedLowWit HWTEST_F(DrmCsrVfeTests, givenNonDirtyVfeForBothPriorityContextWhenFlushedDefaultWithScratchRequirementThenMakeLowDirty) { std::unique_ptr device(MockDevice::createWithNewExecutionEnvironment(nullptr)); + device->executionEnvironment->osInterface = std::make_unique(); auto mockCsr = new MyCsr(*device->executionEnvironment); device->resetCommandStreamReceiver(mockCsr); @@ -682,7 +693,10 @@ class DrmCommandStreamEnhancedFixture DebugManager.flags.EnableForcePin.set(false); mock = new DrmMockCustom(); - tCsr = new TestedDrmCommandStreamReceiver(mock, *executionEnvironment); + executionEnvironment->osInterface = std::make_unique(); + executionEnvironment->osInterface->get()->setDrm(mock); + + tCsr = new TestedDrmCommandStreamReceiver(*executionEnvironment); csr = tCsr; ASSERT_NE(nullptr, csr); mm = reinterpret_cast(csr->createMemoryManager(false)); @@ -715,9 +729,12 @@ class DrmCommandStreamEnhancedFixture public: using CommandStreamReceiver::commandStream; - TestedDrmCommandStreamReceiver(Drm *drm, gemCloseWorkerMode mode, ExecutionEnvironment &executionEnvironment) : DrmCommandStreamReceiver(*platformDevices[0], drm, executionEnvironment, mode) { + TestedDrmCommandStreamReceiver(gemCloseWorkerMode mode, ExecutionEnvironment &executionEnvironment) + : DrmCommandStreamReceiver(*platformDevices[0], executionEnvironment, mode) { } - TestedDrmCommandStreamReceiver(Drm *drm, ExecutionEnvironment &executionEnvironment) : DrmCommandStreamReceiver(*platformDevices[0], drm, executionEnvironment, gemCloseWorkerMode::gemCloseWorkerInactive) { + TestedDrmCommandStreamReceiver(ExecutionEnvironment &executionEnvironment) + : DrmCommandStreamReceiver(*platformDevices[0], executionEnvironment, + gemCloseWorkerMode::gemCloseWorkerInactive) { } void overrideGemCloseWorkerOperationMode(gemCloseWorkerMode overrideValue) { @@ -928,7 +945,10 @@ TEST_F(DrmCommandStreamGemWorkerTests, givenCommandStreamWithDuplicatesWhenItIsF } TEST_F(DrmCommandStreamGemWorkerTests, givenDrmCsrCreatedWithInactiveGemCloseWorkerPolicyThenThreadIsNotCreated) { - TestedDrmCommandStreamReceiver testedCsr(mock, gemCloseWorkerMode::gemCloseWorkerInactive, *this->executionEnvironment); + this->executionEnvironment->osInterface = std::make_unique(); + this->executionEnvironment->osInterface->get()->setDrm(mock); + TestedDrmCommandStreamReceiver testedCsr(gemCloseWorkerMode::gemCloseWorkerInactive, + *this->executionEnvironment); EXPECT_EQ(gemCloseWorkerMode::gemCloseWorkerInactive, testedCsr.peekGemCloseWorkerOperationMode()); } diff --git a/unit_tests/os_interface/windows/device_command_stream_tests.cpp b/unit_tests/os_interface/windows/device_command_stream_tests.cpp index 9bd04e6d57..c69816241d 100644 --- a/unit_tests/os_interface/windows/device_command_stream_tests.cpp +++ b/unit_tests/os_interface/windows/device_command_stream_tests.cpp @@ -33,6 +33,7 @@ #include "runtime/mem_obj/buffer.h" #include "runtime/memory_manager/memory_manager.h" #include "runtime/os_interface/windows/os_context_win.h" +#include "runtime/os_interface/windows/os_interface.h" #include "runtime/os_interface/windows/wddm_device_command_stream.h" #include "runtime/os_interface/windows/wddm_memory_manager.h" @@ -73,7 +74,10 @@ class WddmCommandStreamFixture { DebugManager.flags.CsrDispatchMode.set(static_cast(DispatchMode::ImmediateDispatch)); - csr.reset(new WddmCommandStreamReceiver(*platformDevices[0], wddm, *executionEnvironment)); + executionEnvironment->osInterface = std::make_unique(); + executionEnvironment->osInterface->get()->setWddm(wddm); + csr = std::make_unique>(*platformDevices[0], *executionEnvironment); + ASSERT_NE(nullptr, csr); mockWddmMM = new MockWddmMemoryManager(wddm); @@ -93,7 +97,8 @@ class WddmCommandStreamFixture { template struct MockWddmCsr : public WddmCommandStreamReceiver { - MockWddmCsr(const HardwareInfo &hwInfoIn, Wddm *wddm, ExecutionEnvironment &executionEnvironment) : WddmCommandStreamReceiver(hwInfoIn, wddm, executionEnvironment){}; + MockWddmCsr(const HardwareInfo &hwInfoIn, ExecutionEnvironment &executionEnvironment) + : WddmCommandStreamReceiver(hwInfoIn, executionEnvironment){}; using CommandStreamReceiver::commandStream; using CommandStreamReceiver::dispatchMode; @@ -138,8 +143,11 @@ class WddmCommandStreamWithMockGdiFixture { gdi = new MockGdi(); wddm->gdi.reset(gdi); ASSERT_NE(wddm, nullptr); + executionEnvironment->osInterface = std::make_unique(); + executionEnvironment->osInterface->get()->setWddm(wddm); DebugManager.flags.CsrDispatchMode.set(static_cast(DispatchMode::ImmediateDispatch)); - executionEnvironment->commandStreamReceiver = std::make_unique>(*platformDevices[0], wddm, *executionEnvironment); + executionEnvironment->commandStreamReceiver = std::make_unique>(*platformDevices[0], + *executionEnvironment); this->csr = static_cast *>(executionEnvironment->commandStreamReceiver.get()); memManager = csr->createMemoryManager(false); ASSERT_NE(nullptr, memManager); @@ -167,17 +175,23 @@ using WddmDefaultTest = ::Test; using DeviceCommandStreamTest = ::Test; TEST_F(DeviceCommandStreamTest, CreateWddmCSR) { + auto wddm = Wddm::createWddm(); + this->executionEnvironment.osInterface = std::make_unique(); + this->executionEnvironment.osInterface->get()->setWddm(static_cast(wddm)); std::unique_ptr> csr(static_cast *>(WddmCommandStreamReceiver::create(DEFAULT_TEST_PLATFORM::hwInfo, false, this->executionEnvironment))); EXPECT_NE(nullptr, csr); - auto wddm = csr->peekWddm(); - EXPECT_NE(nullptr, wddm); + auto wddmFromCsr = csr->peekWddm(); + EXPECT_NE(nullptr, wddmFromCsr); } TEST_F(DeviceCommandStreamTest, CreateWddmCSRWithAubDump) { + auto wddm = Wddm::createWddm(); + this->executionEnvironment.osInterface = std::make_unique(); + this->executionEnvironment.osInterface->get()->setWddm(static_cast(wddm)); std::unique_ptr> csr(static_cast *>(WddmCommandStreamReceiver::create(DEFAULT_TEST_PLATFORM::hwInfo, true, this->executionEnvironment))); EXPECT_NE(nullptr, csr); - auto wddm = csr->peekWddm(); - EXPECT_NE(nullptr, wddm); + auto wddmFromCsr = csr->peekWddm(); + EXPECT_NE(nullptr, wddmFromCsr); auto aubCSR = static_cast> *>(csr.get())->aubCSR; EXPECT_NE(nullptr, aubCSR); } @@ -253,7 +267,10 @@ TEST(WddmPreemptionHeaderTests, givenWddmCommandStreamReceiverWhenPreemptionIsOf auto localHwInfo = *platformDevices[0]; localHwInfo.capabilityTable.defaultPreemptionMode = PreemptionMode::Disabled; ExecutionEnvironment executionEnvironment; - executionEnvironment.commandStreamReceiver = std::make_unique>(localHwInfo, wddm, executionEnvironment); + executionEnvironment.osInterface = std::make_unique(); + executionEnvironment.osInterface->get()->setWddm(wddm); + executionEnvironment.commandStreamReceiver = std::make_unique>(localHwInfo, + executionEnvironment); executionEnvironment.memoryManager.reset(executionEnvironment.commandStreamReceiver->createMemoryManager(false)); executionEnvironment.commandStreamReceiver->overrideDispatchPolicy(DispatchMode::ImmediateDispatch); @@ -278,7 +295,10 @@ TEST(WddmPreemptionHeaderTests, givenWddmCommandStreamReceiverWhenPreemptionIsOn auto localHwInfo = *platformDevices[0]; localHwInfo.capabilityTable.defaultPreemptionMode = PreemptionMode::MidThread; ExecutionEnvironment executionEnvironment; - executionEnvironment.commandStreamReceiver = std::make_unique>(localHwInfo, wddm, executionEnvironment); + executionEnvironment.osInterface = std::make_unique(); + executionEnvironment.osInterface->get()->setWddm(wddm); + executionEnvironment.commandStreamReceiver = std::make_unique>(localHwInfo, + executionEnvironment); executionEnvironment.memoryManager.reset(executionEnvironment.commandStreamReceiver->createMemoryManager(false)); executionEnvironment.commandStreamReceiver->overrideDispatchPolicy(DispatchMode::ImmediateDispatch); @@ -302,7 +322,9 @@ TEST(WddmPreemptionHeaderTests, givenDeviceSupportingPreemptionWhenCommandStream auto localHwInfo = *platformDevices[0]; localHwInfo.capabilityTable.defaultPreemptionMode = PreemptionMode::MidThread; ExecutionEnvironment executionEnvironment; - auto commandStreamReceiver = std::make_unique>(localHwInfo, wddm, executionEnvironment); + executionEnvironment.osInterface = std::make_unique(); + executionEnvironment.osInterface->get()->setWddm(wddm); + auto commandStreamReceiver = std::make_unique>(localHwInfo, executionEnvironment); auto commandHeader = commandStreamReceiver->commandBufferHeader; auto header = reinterpret_cast(commandHeader); EXPECT_TRUE(header->NeedsMidBatchPreEmptionSupport); @@ -313,7 +335,9 @@ TEST(WddmPreemptionHeaderTests, givenDevicenotSupportingPreemptionWhenCommandStr auto localHwInfo = *platformDevices[0]; localHwInfo.capabilityTable.defaultPreemptionMode = PreemptionMode::Disabled; ExecutionEnvironment executionEnvironment; - auto commandStreamReceiver = std::make_unique>(localHwInfo, wddm, executionEnvironment); + executionEnvironment.osInterface = std::make_unique(); + executionEnvironment.osInterface->get()->setWddm(wddm); + auto commandStreamReceiver = std::make_unique>(localHwInfo, executionEnvironment); auto commandHeader = commandStreamReceiver->commandBufferHeader; auto header = reinterpret_cast(commandHeader); EXPECT_FALSE(header->NeedsMidBatchPreEmptionSupport); @@ -794,7 +818,9 @@ HWTEST_F(WddmSimpleTest, givenDefaultWddmCsrWhenItIsCreatedThenBatchingIsTurnedO ExecutionEnvironment *executionEnvironment = new ExecutionEnvironment; std::unique_ptr device(Device::create(platformDevices[0], executionEnvironment)); auto wddm = Wddm::createWddm(); - std::unique_ptr> mockCsr(new MockWddmCsr(*platformDevices[0], wddm, *executionEnvironment)); + executionEnvironment->osInterface = std::make_unique(); + executionEnvironment->osInterface->get()->setWddm(wddm); + std::unique_ptr> mockCsr(new MockWddmCsr(*platformDevices[0], *executionEnvironment)); EXPECT_EQ(DispatchMode::BatchedDispatch, mockCsr->dispatchMode); } @@ -802,10 +828,13 @@ HWTEST_F(WddmDefaultTest, givenFtrWddmHwQueuesFlagWhenCreatingCsrThenPickWddmVer HardwareInfo myHwInfo = *platformDevices[0]; FeatureTable myFtrTable = *myHwInfo.pSkuTable; myHwInfo.pSkuTable = &myFtrTable; + auto wddm = Wddm::createWddm(); + pDevice->executionEnvironment->osInterface = std::make_unique(); + pDevice->executionEnvironment->osInterface->get()->setWddm(wddm); + WddmCommandStreamReceiver wddmCsr(myHwInfo, *pDevice->executionEnvironment); - WddmCommandStreamReceiver wddmCsr(myHwInfo, nullptr, *pDevice->executionEnvironment); - auto wddm = wddmCsr.peekWddm(); - EXPECT_EQ(typeid(*wddm), typeid(WddmMock)); + auto wddmFromCsr = wddmCsr.peekWddm(); + EXPECT_EQ(typeid(*wddmFromCsr), typeid(WddmMock)); } struct WddmCsrCompressionTests : ::testing::Test { @@ -837,7 +866,10 @@ HWTEST_F(WddmCsrCompressionTests, givenEnabledCompressionWhenInitializedThenCrea setCompressionEnabled(compressionEnabled[i][0], compressionEnabled[i][1]); createMockWddm(); EXPECT_EQ(nullptr, myMockWddm->getPageTableManager()); - MockWddmCsr mockWddmCsr(hwInfo, myMockWddm, *executionEnvironment); + + executionEnvironment->osInterface = std::make_unique(); + executionEnvironment->osInterface->get()->setWddm(myMockWddm); + MockWddmCsr mockWddmCsr(hwInfo, *executionEnvironment); mockWddmCsr.createPageTableManager(); ASSERT_NE(nullptr, myMockWddm->getPageTableManager()); @@ -884,7 +916,9 @@ HWTEST_F(WddmCsrCompressionTests, givenDisabledCompressionWhenInitializedThenDon std::unique_ptr device(Device::create(platformDevices[0], executionEnvironment)); setCompressionEnabled(false, false); createMockWddm(); - MockWddmCsr mockWddmCsr(hwInfo, myMockWddm, *executionEnvironment); + executionEnvironment->osInterface = std::make_unique(); + executionEnvironment->osInterface->get()->setWddm(myMockWddm); + MockWddmCsr mockWddmCsr(hwInfo, *executionEnvironment); EXPECT_EQ(nullptr, myMockWddm->getPageTableManager()); } @@ -894,7 +928,9 @@ HWTEST_F(WddmCsrCompressionTests, givenEnabledCompressionWhenFlushingThenInitTra ExecutionEnvironment *executionEnvironment = new ExecutionEnvironment; setCompressionEnabled(compressionEnabled[i][0], compressionEnabled[i][1]); createMockWddm(); - auto mockWddmCsr = new MockWddmCsr(hwInfo, myMockWddm, *executionEnvironment); + executionEnvironment->osInterface = std::make_unique(); + executionEnvironment->osInterface->get()->setWddm(myMockWddm); + auto mockWddmCsr = new MockWddmCsr(hwInfo, *executionEnvironment); mockWddmCsr->createPageTableManager(); mockWddmCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch); @@ -936,7 +972,9 @@ HWTEST_F(WddmCsrCompressionTests, givenDisabledCompressionWhenFlushingThenDontIn ExecutionEnvironment *executionEnvironment = new ExecutionEnvironment; setCompressionEnabled(false, false); createMockWddm(); - auto mockWddmCsr = new MockWddmCsr(hwInfo, myMockWddm, *executionEnvironment); + executionEnvironment->osInterface = std::make_unique(); + executionEnvironment->osInterface->get()->setWddm(myMockWddm); + auto mockWddmCsr = new MockWddmCsr(hwInfo, *executionEnvironment); executionEnvironment->commandStreamReceiver.reset(mockWddmCsr); mockWddmCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch);