From 13e053f53892d6be065fe8204837df86efb38f08 Mon Sep 17 00:00:00 2001 From: Lukasz Jobczyk Date: Tue, 17 Mar 2020 07:26:46 +0100 Subject: [PATCH] Load GDI once Resolves: NEO-4174 Change-Id: I465d6137deb1dac1146a5b28ff1c100823a1d6b6 Signed-off-by: Lukasz Jobczyk --- .../command_stream/get_devices_tests.cpp | 6 ++- .../execution_environment_tests.cpp | 1 + ...allocator_multi_device_fixture_windows.cpp | 13 ++++--- opencl/test/unit_test/linux/drm_wrap.h | 3 +- .../test/unit_test/linux/main_linux_dll.cpp | 12 ++++-- opencl/test/unit_test/mocks/mock_wddm.cpp | 15 ++++++-- .../os_interface/device_factory_tests.cpp | 5 ++- .../os_interface/mock_performance_counters.h | 2 +- .../windows/gl/gl_os_sharing_tests.cpp | 9 +++-- .../os_interface/windows/wddm20_tests.cpp | 37 +++++++++++++------ .../os_interface/windows/wddm_fixture.h | 9 +++-- .../windows/wddm_kmdaf_listener_tests.cpp | 8 +++- .../windows/wddm_memory_manager_tests.cpp | 8 +++- .../windows/wddm_memory_manager_tests.h | 6 ++- .../wddm_residency_controller_tests.cpp | 8 ++-- .../unit_test/windows/wddm_create_tests.cpp | 2 +- .../execution_environment.cpp | 1 + .../execution_environment.h | 2 + shared/source/os_interface/CMakeLists.txt | 1 + shared/source/os_interface/device_factory.cpp | 2 +- shared/source/os_interface/linux/drm_neo.cpp | 5 ++- shared/source/os_interface/os_environment.h | 15 ++++++++ shared/source/os_interface/os_interface.h | 3 +- .../os_interface/windows/CMakeLists.txt | 2 + .../os_interface/windows/hw_device_id.h | 9 ++--- .../os_interface/windows/hw_device_id_win.cpp | 12 ++++-- .../windows/os_environment_win.cpp | 15 ++++++++ .../os_interface/windows/os_environment_win.h | 23 ++++++++++++ .../source/os_interface/windows/wddm/wddm.cpp | 18 +++++---- 29 files changed, 187 insertions(+), 65 deletions(-) create mode 100644 shared/source/os_interface/os_environment.h create mode 100644 shared/source/os_interface/windows/os_environment_win.cpp create mode 100644 shared/source/os_interface/windows/os_environment_win.h diff --git a/opencl/test/unit_test/command_stream/get_devices_tests.cpp b/opencl/test/unit_test/command_stream/get_devices_tests.cpp index 6b33a011e2..f6b28aa667 100644 --- a/opencl/test/unit_test/command_stream/get_devices_tests.cpp +++ b/opencl/test/unit_test/command_stream/get_devices_tests.cpp @@ -62,7 +62,8 @@ HWTEST_F(GetDevicesTest, givenGetDevicesWhenCsrIsSetToVariousTypesThenTheFunctio } DebugManager.flags.ProductFamilyOverride.set(productFamily); - ExecutionEnvironment *exeEnv = platform()->peekExecutionEnvironment(); + platformsImpl.clear(); + ExecutionEnvironment *exeEnv = constructPlatform()->peekExecutionEnvironment(); const auto ret = getDevices(numDevices, *exeEnv); for (auto i = 0u; i < expectedDevices; i++) { @@ -149,7 +150,8 @@ HWTEST_F(GetDevicesTest, givenGetDevicesAndUnknownProductFamilyWhenCsrIsSetToVal DebugManager.flags.SetCommandStreamReceiver.set(csrType); DebugManager.flags.ProductFamilyOverride.set(productFamily); - ExecutionEnvironment *exeEnv = platform()->peekExecutionEnvironment(); + platformsImpl.clear(); + ExecutionEnvironment *exeEnv = constructPlatform()->peekExecutionEnvironment(); auto ret = getDevices(numDevices, *exeEnv); for (auto i = 0u; i < expectedDevices; i++) { diff --git a/opencl/test/unit_test/execution_environment/execution_environment_tests.cpp b/opencl/test/unit_test/execution_environment/execution_environment_tests.cpp index 7afb0d5042..a496fb3f9d 100644 --- a/opencl/test/unit_test/execution_environment/execution_environment_tests.cpp +++ b/opencl/test/unit_test/execution_environment/execution_environment_tests.cpp @@ -153,6 +153,7 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeMemoryManagerI } static_assert(sizeof(ExecutionEnvironment) == sizeof(std::unique_ptr) + sizeof(std::vector) + + sizeof(std::unique_ptr) + (is64bit ? 16 : 12), "New members detected in ExecutionEnvironment, please ensure that destruction sequence of objects is correct"); diff --git a/opencl/test/unit_test/fixtures/windows/memory_allocator_multi_device_fixture_windows.cpp b/opencl/test/unit_test/fixtures/windows/memory_allocator_multi_device_fixture_windows.cpp index 65c2046f2d..a4f5ff031c 100644 --- a/opencl/test/unit_test/fixtures/windows/memory_allocator_multi_device_fixture_windows.cpp +++ b/opencl/test/unit_test/fixtures/windows/memory_allocator_multi_device_fixture_windows.cpp @@ -7,6 +7,7 @@ #include "shared/source/execution_environment/root_device_environment.h" #include "shared/source/gmm_helper/resource_info.h" +#include "shared/source/os_interface/windows/os_environment_win.h" #include "shared/source/os_interface/windows/os_interface.h" #include "shared/test/unit_test/os_interface/windows/mock_gdi_interface.h" @@ -18,20 +19,22 @@ using namespace NEO; void MemoryAllocatorMultiDeviceSystemSpecificFixture::SetUp(ExecutionEnvironment &executionEnvironment) { static D3DDDI_OPENALLOCATIONINFO allocationInfo; + auto gdi = new MockGdi(); + gdi->getQueryResourceInfoArgOut().NumAllocations = 1; + gdi->getOpenResourceArgOut().pOpenAllocationInfo = &allocationInfo; + auto osEnvironment = new OsEnvironmentWin(); + osEnvironment->gdi.reset(gdi); for (auto i = 0u; i < executionEnvironment.rootDeviceEnvironments.size(); i++) { gmm = std::make_unique(executionEnvironment.rootDeviceEnvironments[i]->getGmmClientContext(), nullptr, 0, false); auto wddm = static_cast(executionEnvironment.rootDeviceEnvironments[i]->osInterface->get()->getWddm()); + wddm->hwDeviceId = std::make_unique(ADAPTER_HANDLE, LUID{}, osEnvironment); wddm->callBaseMapGpuVa = false; - auto gdi = new MockGdi(); - wddm->resetGdi(gdi); - gdi->getQueryResourceInfoArgOut().NumAllocations = 1; allocationInfo.pPrivateDriverData = gmm->gmmResourceInfo->peekHandle(); allocationInfo.hAllocation = ALLOCATION_HANDLE; allocationInfo.PrivateDriverDataSize = sizeof(GMM_RESOURCE_INFO); - - gdi->getOpenResourceArgOut().pOpenAllocationInfo = &allocationInfo; } + executionEnvironment.osEnvironment.reset(osEnvironment); } void MemoryAllocatorMultiDeviceSystemSpecificFixture::TearDown(ExecutionEnvironment &executionEnvironment) {} diff --git a/opencl/test/unit_test/linux/drm_wrap.h b/opencl/test/unit_test/linux/drm_wrap.h index eb72aa081a..915eb0ed09 100644 --- a/opencl/test/unit_test/linux/drm_wrap.h +++ b/opencl/test/unit_test/linux/drm_wrap.h @@ -7,6 +7,7 @@ #pragma once +#include "shared/source/execution_environment/root_device_environment.h" #include "shared/source/os_interface/linux/drm_neo.h" #include "shared/source/os_interface/os_interface.h" @@ -15,7 +16,7 @@ class DrmWrap : public NEO::Drm { public: static NEO::Drm *createDrm(RootDeviceEnvironment &rootDeviceEnvironment) { - auto hwDeviceIds = OSInterface::discoverDevices(); + auto hwDeviceIds = OSInterface::discoverDevices(rootDeviceEnvironment.executionEnvironment); if (!hwDeviceIds.empty()) { return NEO::Drm::create(std::move(hwDeviceIds[0]), rootDeviceEnvironment); } diff --git a/opencl/test/unit_test/linux/main_linux_dll.cpp b/opencl/test/unit_test/linux/main_linux_dll.cpp index 9ed1d289b4..231df42380 100644 --- a/opencl/test/unit_test/linux/main_linux_dll.cpp +++ b/opencl/test/unit_test/linux/main_linux_dll.cpp @@ -72,7 +72,8 @@ TEST(DrmTest, GivenTwoOpenableDevicesWhenDiscoverDevicesThenCreateTwoHwDeviceIds VariableBackup backupOpenFull(&openFull); openFull = openWithCounter; openCounter = 2; - auto hwDeviceIds = OSInterface::discoverDevices(); + ExecutionEnvironment executionEnvironment; + auto hwDeviceIds = OSInterface::discoverDevices(executionEnvironment); EXPECT_EQ(2u, hwDeviceIds.size()); } @@ -82,7 +83,8 @@ TEST(DrmTest, GivenSelectedNotExistingDeviceWhenGetDeviceFdThenFail) { VariableBackup backupOpenFull(&openFull); openFull = testOpen; openRetVal = -1; - auto hwDeviceIds = OSInterface::discoverDevices(); + ExecutionEnvironment executionEnvironment; + auto hwDeviceIds = OSInterface::discoverDevices(executionEnvironment); EXPECT_TRUE(hwDeviceIds.empty()); } @@ -92,7 +94,8 @@ TEST(DrmTest, GivenSelectedExistingDeviceWhenGetDeviceFdThenReturnFd) { VariableBackup backupOpenFull(&openFull); openRetVal = 1023; // fakeFd openFull = testOpen; - auto hwDeviceIds = OSInterface::discoverDevices(); + ExecutionEnvironment executionEnvironment; + auto hwDeviceIds = OSInterface::discoverDevices(executionEnvironment); EXPECT_EQ(1u, hwDeviceIds.size()); EXPECT_NE(nullptr, hwDeviceIds[0].get()); } @@ -103,8 +106,9 @@ TEST(DrmTest, GivenSelectedIncorectDeviceWhenGetDeviceFdThenFail) { VariableBackup backupOpenFull(&openFull); openFull = testOpen; openRetVal = 1024; + ExecutionEnvironment executionEnvironment; - auto hwDeviceIds = OSInterface::discoverDevices(); + auto hwDeviceIds = OSInterface::discoverDevices(executionEnvironment); EXPECT_TRUE(hwDeviceIds.empty()); } diff --git a/opencl/test/unit_test/mocks/mock_wddm.cpp b/opencl/test/unit_test/mocks/mock_wddm.cpp index 89093597aa..94c231fb0e 100644 --- a/opencl/test/unit_test/mocks/mock_wddm.cpp +++ b/opencl/test/unit_test/mocks/mock_wddm.cpp @@ -10,6 +10,7 @@ #include "shared/source/execution_environment/root_device_environment.h" #include "shared/source/helpers/aligned_memory.h" #include "shared/source/os_interface/windows/gdi_interface.h" +#include "shared/source/os_interface/windows/os_environment_win.h" #include "shared/source/os_interface/windows/wddm_allocation.h" #include "opencl/test/unit_test/mock_gdi/mock_gdi.h" @@ -20,9 +21,17 @@ using namespace NEO; -WddmMock::WddmMock(RootDeviceEnvironment &rootDeviceEnvironment) : Wddm(std::make_unique(ADAPTER_HANDLE, LUID{}, std::make_unique()), rootDeviceEnvironment) { +struct mockHwDeviceId : public HwDeviceId { + using HwDeviceId::osEnvironment; +}; + +WddmMock::WddmMock(RootDeviceEnvironment &rootDeviceEnvironment) : Wddm(std::make_unique(ADAPTER_HANDLE, LUID{}, rootDeviceEnvironment.executionEnvironment.osEnvironment.get()), rootDeviceEnvironment) { + if (!rootDeviceEnvironment.executionEnvironment.osEnvironment.get()) { + rootDeviceEnvironment.executionEnvironment.osEnvironment = std::make_unique(); + } + static_cast(this->hwDeviceId.get())->osEnvironment = rootDeviceEnvironment.executionEnvironment.osEnvironment.get(); this->temporaryResources = std::make_unique(this); -} +}; WddmMock::~WddmMock() { EXPECT_EQ(0, reservedAddresses.size()); @@ -206,7 +215,7 @@ void WddmMock::setHwContextId(unsigned long hwContextId) { } void WddmMock::resetGdi(Gdi *gdi) { - this->hwDeviceId = std::make_unique(ADAPTER_HANDLE, LUID{}, std::unique_ptr(gdi)); + static_cast(this->rootDeviceEnvironment.executionEnvironment.osEnvironment.get())->gdi.reset(gdi); } void WddmMock::setHeap32(uint64_t base, uint64_t size) { diff --git a/opencl/test/unit_test/os_interface/device_factory_tests.cpp b/opencl/test/unit_test/os_interface/device_factory_tests.cpp index 6c9f0ed760..54364922b7 100644 --- a/opencl/test/unit_test/os_interface/device_factory_tests.cpp +++ b/opencl/test/unit_test/os_interface/device_factory_tests.cpp @@ -94,6 +94,8 @@ TEST_F(DeviceFactoryTest, overrideKmdNotifySettings) { DebugManager.flags.OverrideEnableQuickKmdSleepForSporadicWaits.set(!refEnableQuickKmdSleepForSporadicWaits); DebugManager.flags.OverrideDelayQuickKmdSleepForSporadicWaitsMicroseconds.set(static_cast(refDelayQuickKmdSleepForSporadicWaitsMicroseconds) + 12); + platformsImpl.clear(); + executionEnvironment = constructPlatform()->peekExecutionEnvironment(); success = DeviceFactory::getDevices(numDevices, *executionEnvironment); ASSERT_TRUE(success); hwInfo = executionEnvironment->rootDeviceEnvironments[0]->getHardwareInfo(); @@ -259,7 +261,8 @@ TEST(DeviceFactory, givenNonHwModeSelectedWhenIsHwModeSelectedIsCalledThenFalseI TEST(DiscoverDevices, whenDiscoverDevicesAndForceDeviceIdIsDifferentFromTheExistingDeviceThenReturnNullptr) { DebugManagerStateRestore stateRestore; DebugManager.flags.ForceDeviceId.set("invalid"); - auto hwDeviceIds = OSInterface::discoverDevices(); + ExecutionEnvironment executionEnviornment; + auto hwDeviceIds = OSInterface::discoverDevices(executionEnviornment); EXPECT_TRUE(hwDeviceIds.empty()); } diff --git a/opencl/test/unit_test/os_interface/mock_performance_counters.h b/opencl/test/unit_test/os_interface/mock_performance_counters.h index eabe9cf59d..0b89d16f4d 100644 --- a/opencl/test/unit_test/os_interface/mock_performance_counters.h +++ b/opencl/test/unit_test/os_interface/mock_performance_counters.h @@ -231,10 +231,10 @@ struct PerformanceCountersFixture { std::unique_ptr device; std::unique_ptr context; std::unique_ptr queue; - std::unique_ptr osInterface; std::unique_ptr performanceCountersBase; std::unique_ptr executionEnvironment; std::unique_ptr rootDeviceEnvironment; + std::unique_ptr osInterface; }; ////////////////////////////////////////////////////// diff --git a/opencl/test/unit_test/os_interface/windows/gl/gl_os_sharing_tests.cpp b/opencl/test/unit_test/os_interface/windows/gl/gl_os_sharing_tests.cpp index b7186c3751..c05fbe2086 100644 --- a/opencl/test/unit_test/os_interface/windows/gl/gl_os_sharing_tests.cpp +++ b/opencl/test/unit_test/os_interface/windows/gl/gl_os_sharing_tests.cpp @@ -209,10 +209,11 @@ TEST_F(GlArbSyncEventOsTest, GivenNewGlSyncInfoWhenCreateSynchronizationObjectFa } TEST_F(GlArbSyncEventOsTest, GivenNewGlSyncInfoWhenCreateEventFailsThenSetupArbSyncObjectFails) { + auto rootDeviceEnvironment = platform()->peekExecutionEnvironment()->rootDeviceEnvironments[0].get(); MockOSInterface mockOsInterface; MockOSInterfaceImpl *mockOsInterfaceImpl = static_cast(mockOsInterface.get()); - auto wddm = new WddmMock(*rootDeviceEnvironment.get()); + auto wddm = new WddmMock(*rootDeviceEnvironment); auto gdi = new MockGdi(); wddm->resetGdi(gdi); wddm->init(); @@ -239,8 +240,9 @@ TEST_F(GlArbSyncEventOsTest, GivenInvalidGlSyncInfoWhenCleanupArbSyncObjectIsCal return STATUS_INVALID_PARAMETER; } }; + auto rootDeviceEnvironment = platform()->peekExecutionEnvironment()->rootDeviceEnvironments[0].get(); - auto wddm = new WddmMock(*rootDeviceEnvironment.get()); + auto wddm = new WddmMock(*rootDeviceEnvironment); auto gdi = new MockGdi(); wddm->resetGdi(gdi); wddm->init(); @@ -268,8 +270,9 @@ TEST_F(GlArbSyncEventOsTest, GivenValidGlSyncInfoWhenCleanupArbSyncObjectIsCalle getDestroyCounter() = 0; } }; + auto rootDeviceEnvironment = platform()->peekExecutionEnvironment()->rootDeviceEnvironments[0].get(); - auto wddm = new WddmMock(*rootDeviceEnvironment.get()); + auto wddm = new WddmMock(*rootDeviceEnvironment); auto gdi = new MockGdi(); wddm->resetGdi(gdi); wddm->init(); diff --git a/opencl/test/unit_test/os_interface/windows/wddm20_tests.cpp b/opencl/test/unit_test/os_interface/windows/wddm20_tests.cpp index 2652a03b9b..8049400f7d 100644 --- a/opencl/test/unit_test/os_interface/windows/wddm20_tests.cpp +++ b/opencl/test/unit_test/os_interface/windows/wddm20_tests.cpp @@ -13,6 +13,7 @@ #include "shared/source/os_interface/os_library.h" #include "shared/source/os_interface/os_time.h" #include "shared/source/os_interface/windows/os_context_win.h" +#include "shared/source/os_interface/windows/os_environment_win.h" #include "shared/source/os_interface/windows/os_interface.h" #include "shared/source/os_interface/windows/wddm/wddm_interface.h" #include "shared/source/os_interface/windows/wddm_allocation.h" @@ -92,6 +93,7 @@ TEST_F(Wddm20Tests, givenNullPageTableManagerAndRenderCompressedResourceWhenMapp EXPECT_TRUE(wddm->mapGpuVirtualAddress(&allocation)); } + TEST(WddmDiscoverDevices, WhenNoHwDeviceIdIsProvidedToWddmThenWddmIsNotCreated) { struct MockWddm : public Wddm { MockWddm(std::unique_ptr hwDeviceIdIn, RootDeviceEnvironment &rootDeviceEnvironment) : Wddm(std::move(hwDeviceIdIn), rootDeviceEnvironment) {} @@ -107,8 +109,9 @@ TEST(WddmDiscoverDevices, WhenAdapterDescriptionContainsDCHDAndgdrclPathDoesntCo descriptionBackup = L"Intel DCH-D"; VariableBackup igdrclPathBackup(&SysCalls::igdrclFilePath); igdrclPathBackup = L"intel_dch.inf"; + ExecutionEnvironment executionEnvironment; - auto hwDeviceIds = OSInterface::discoverDevices(); + auto hwDeviceIds = OSInterface::discoverDevices(executionEnvironment); EXPECT_TRUE(hwDeviceIds.empty()); } @@ -117,15 +120,17 @@ TEST(WddmDiscoverDevices, WhenAdapterDescriptionContainsDCHIAndgdrclPathDoesntCo descriptionBackup = L"Intel DCH-I"; VariableBackup igdrclPathBackup(&SysCalls::igdrclFilePath); igdrclPathBackup = L"intel_dch.inf"; + ExecutionEnvironment executionEnvironment; - auto hwDeviceIds = OSInterface::discoverDevices(); + auto hwDeviceIds = OSInterface::discoverDevices(executionEnvironment); EXPECT_TRUE(hwDeviceIds.empty()); } TEST(WddmDiscoverDevices, WhenMultipleRootDevicesAreAvailableThenAllAreDiscovered) { VariableBackup backup{&numRootDevicesToEnum}; numRootDevicesToEnum = 3u; - auto hwDeviceIds = OSInterface::discoverDevices(); + ExecutionEnvironment executionEnvironment; + auto hwDeviceIds = OSInterface::discoverDevices(executionEnvironment); EXPECT_EQ(numRootDevicesToEnum, hwDeviceIds.size()); } @@ -134,8 +139,9 @@ TEST(WddmDiscoverDevices, WhenAdapterDescriptionContainsDCHDAndgdrclPathContains descriptionBackup = L"Intel DCH-D"; VariableBackup igdrclPathBackup(&SysCalls::igdrclFilePath); igdrclPathBackup = L"intel_dch_d.inf"; + ExecutionEnvironment executionEnvironment; - auto hwDeviceIds = OSInterface::discoverDevices(); + auto hwDeviceIds = OSInterface::discoverDevices(executionEnvironment); EXPECT_EQ(1u, hwDeviceIds.size()); EXPECT_NE(nullptr, hwDeviceIds[0].get()); } @@ -145,8 +151,9 @@ TEST(Wddm20EnumAdaptersTest, WhenAdapterDescriptionContainsDCHIAndgdrclPathConta descriptionBackup = L"Intel DCH-I"; VariableBackup igdrclPathBackup(&SysCalls::igdrclFilePath); igdrclPathBackup = L"intel_dch_i.inf"; + ExecutionEnvironment executionEnvironment; - auto hwDeviceIds = OSInterface::discoverDevices(); + auto hwDeviceIds = OSInterface::discoverDevices(executionEnvironment); EXPECT_EQ(1u, hwDeviceIds.size()); EXPECT_NE(nullptr, hwDeviceIds[0].get()); } @@ -154,8 +161,9 @@ TEST(Wddm20EnumAdaptersTest, WhenAdapterDescriptionContainsDCHIAndgdrclPathConta TEST(WddmDiscoverDevices, WhenAdapterDescriptionContainsVirtualRenderThenAdapterIsDiscovered) { VariableBackup descriptionBackup(&UltIDXGIAdapter1::description); descriptionBackup = L"Virtual Render"; + ExecutionEnvironment executionEnvironment; - auto hwDeviceIds = OSInterface::discoverDevices(); + auto hwDeviceIds = OSInterface::discoverDevices(executionEnvironment); EXPECT_EQ(1u, hwDeviceIds.size()); EXPECT_NE(nullptr, hwDeviceIds[0].get()); } @@ -566,7 +574,8 @@ HWTEST_F(Wddm20InstrumentationTest, configureDeviceAddressSpaceOnInit) { } TEST_F(Wddm20InstrumentationTest, configureDeviceAddressSpaceNoAdapter) { - wddm->hwDeviceId = std::make_unique(0, LUID{}, std::make_unique()); + auto gdi = std::make_unique(); + wddm->resetGdi(gdi.release()); EXPECT_CALL(*gmmMem, configureDeviceAddressSpace(static_cast(0), ::testing::_, ::testing::_, ::testing::_, ::testing::_)) .Times(0); @@ -1097,14 +1106,14 @@ TEST_F(WddmGfxPartitionTest, initGfxPartition) { } } -TEST_F(WddmGfxPartitionTest, initGfxPartitionHeapStandard64KBSplit) { +TEST(WddmGfxPartitionTests, initGfxPartitionHeapStandard64KBSplit) { struct MockWddm : public Wddm { using Wddm::gfxPartition; - MockWddm(RootDeviceEnvironment &rootDeviceEnvironment) : Wddm(std::move(OSInterface::discoverDevices()[0]), rootDeviceEnvironment) {} + MockWddm(RootDeviceEnvironment &rootDeviceEnvironment) : Wddm(std::move(OSInterface::discoverDevices(rootDeviceEnvironment.executionEnvironment)[0]), rootDeviceEnvironment) {} }; - MockWddm wddm(*executionEnvironment->rootDeviceEnvironments[0].get()); + MockWddm wddm(*platform()->peekExecutionEnvironment()->rootDeviceEnvironments[0].get()); uint32_t rootDeviceIndex = 3; size_t numRootDevices = 5; @@ -1121,7 +1130,8 @@ TEST_F(WddmGfxPartitionTest, initGfxPartitionHeapStandard64KBSplit) { TEST_F(Wddm20Tests, givenWddmWhenDiscoverDevicesAndForceDeviceIdIsTheSameAsTheExistingDeviceThenReturnTheAdapter) { DebugManagerStateRestore stateRestore; DebugManager.flags.ForceDeviceId.set("1234"); // Existing device Id - auto hwDeviceIds = OSInterface::discoverDevices(); + ExecutionEnvironment executionEnvironment; + auto hwDeviceIds = OSInterface::discoverDevices(executionEnvironment); EXPECT_EQ(1u, hwDeviceIds.size()); EXPECT_NE(nullptr, hwDeviceIds[0].get()); } @@ -1259,10 +1269,13 @@ struct GdiWithMockedCloseFunc : public Gdi { uint32_t GdiWithMockedCloseFunc::closeAdapterCalled; D3DKMT_HANDLE GdiWithMockedCloseFunc::closeAdapterCalledArgPassed; TEST(HwDeviceId, whenHwDeviceIdIsDestroyedThenAdapterIsClosed) { + auto gdi = std::make_unique(); + auto osEnv = std::make_unique(); + osEnv->gdi.reset(gdi.release()); D3DKMT_HANDLE adapter = 0x1234; { - HwDeviceId hwDeviceId{adapter, {}, std::make_unique()}; + HwDeviceId hwDeviceId{adapter, {}, osEnv.get()}; } EXPECT_EQ(1u, GdiWithMockedCloseFunc::closeAdapterCalled); EXPECT_EQ(adapter, GdiWithMockedCloseFunc::closeAdapterCalledArgPassed); diff --git a/opencl/test/unit_test/os_interface/windows/wddm_fixture.h b/opencl/test/unit_test/os_interface/windows/wddm_fixture.h index fba6f152b2..301388136f 100644 --- a/opencl/test/unit_test/os_interface/windows/wddm_fixture.h +++ b/opencl/test/unit_test/os_interface/windows/wddm_fixture.h @@ -13,6 +13,7 @@ #include "shared/source/helpers/hw_helper.h" #include "shared/source/os_interface/windows/gdi_interface.h" #include "shared/source/os_interface/windows/os_context_win.h" +#include "shared/source/os_interface/windows/os_environment_win.h" #include "shared/source/os_interface/windows/os_interface.h" #include "shared/source/os_interface/windows/wddm_memory_operations_handler.h" #include "shared/test/unit_test/helpers/default_hw_info.h" @@ -32,13 +33,15 @@ struct WddmFixture : ::testing::Test { void SetUp() override { executionEnvironment = platform()->peekExecutionEnvironment(); rootDeviceEnvironemnt = executionEnvironment->rootDeviceEnvironments[0].get(); + auto osEnvironment = new OsEnvironmentWin(); + gdi = new MockGdi(); + osEnvironment->gdi.reset(gdi); + executionEnvironment->osEnvironment.reset(osEnvironment); wddm = static_cast(Wddm::createWddm(nullptr, *rootDeviceEnvironemnt)); rootDeviceEnvironemnt->osInterface = std::make_unique(); rootDeviceEnvironemnt->osInterface->get()->setWddm(wddm); rootDeviceEnvironemnt->memoryOperationsInterface = std::make_unique(wddm); osInterface = rootDeviceEnvironemnt->osInterface.get(); - gdi = new MockGdi(); - wddm->resetGdi(gdi); auto preemptionMode = PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]); wddm->init(); auto hwInfo = rootDeviceEnvironemnt->getHardwareInfo(); @@ -50,9 +53,9 @@ struct WddmFixture : ::testing::Test { WddmMock *wddm = nullptr; OSInterface *osInterface; - std::unique_ptr osContext; ExecutionEnvironment *executionEnvironment; RootDeviceEnvironment *rootDeviceEnvironemnt = nullptr; + std::unique_ptr osContext; MockGdi *gdi = nullptr; MockWddmResidentAllocationsContainer *mockTemporaryResources; diff --git a/opencl/test/unit_test/os_interface/windows/wddm_kmdaf_listener_tests.cpp b/opencl/test/unit_test/os_interface/windows/wddm_kmdaf_listener_tests.cpp index 42fb952aac..ac84f99184 100644 --- a/opencl/test/unit_test/os_interface/windows/wddm_kmdaf_listener_tests.cpp +++ b/opencl/test/unit_test/os_interface/windows/wddm_kmdaf_listener_tests.cpp @@ -10,6 +10,7 @@ #include "shared/source/gmm_helper/gmm.h" #include "shared/source/gmm_helper/gmm_helper.h" #include "shared/source/memory_manager/memory_manager.h" +#include "shared/source/os_interface/windows/os_environment_win.h" #include "shared/source/os_interface/windows/wddm/wddm.h" #include "shared/source/os_interface/windows/wddm_allocation.h" #include "shared/test/unit_test/os_interface/windows/mock_gdi_interface.h" @@ -27,7 +28,7 @@ class WddmWithKmDafMock : public Wddm { using Wddm::featureTable; using Wddm::mapGpuVirtualAddress; - WddmWithKmDafMock(RootDeviceEnvironment &rootDeviceEnvironment, Gdi *mockGdi) : Wddm(std::make_unique(ADAPTER_HANDLE, LUID{}, std::unique_ptr(mockGdi)), rootDeviceEnvironment) { + WddmWithKmDafMock(RootDeviceEnvironment &rootDeviceEnvironment) : Wddm(std::make_unique(ADAPTER_HANDLE, LUID{}, rootDeviceEnvironment.executionEnvironment.osEnvironment.get()), rootDeviceEnvironment) { kmDafListener.reset(new KmDafListenerMock); } @@ -41,7 +42,10 @@ class WddmKmDafListenerTest : public ::testing::Test { void SetUp() { executionEnvironment = platform()->peekExecutionEnvironment(); rootDeviceEnvironment = executionEnvironment->rootDeviceEnvironments[0].get(); - wddmWithKmDafMock.reset(new WddmWithKmDafMock(*rootDeviceEnvironment, new MockGdi())); + auto osEnvironment = new OsEnvironmentWin(); + osEnvironment->gdi.reset(new MockGdi()); + executionEnvironment->osEnvironment.reset(osEnvironment); + wddmWithKmDafMock.reset(new WddmWithKmDafMock(*rootDeviceEnvironment)); wddmWithKmDafMock->init(); wddmWithKmDafMock->featureTable->ftrKmdDaf = true; } diff --git a/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp b/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp index e0835b5258..09087bdced 100644 --- a/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp +++ b/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.cpp @@ -1268,9 +1268,10 @@ TEST_F(BufferWithWddmMemory, givenFragmentsThatAreNotInOrderWhenGraphicsAllocati memoryManager->freeGraphicsMemory(allocation); } -struct WddmMemoryManagerWithAsyncDeleterTest : public MockWddmMemoryManagerTest { +struct WddmMemoryManagerWithAsyncDeleterTest : public ::testing::Test { void SetUp() { - MockWddmMemoryManagerTest::SetUp(); + executionEnvironment = getExecutionEnvironmentImpl(hwInfo, 1); + wddm = static_cast(executionEnvironment->rootDeviceEnvironments[0]->osInterface->get()->getWddm()); wddm->resetGdi(new MockGdi()); wddm->callBaseDestroyAllocations = false; wddm->init(); @@ -1280,6 +1281,9 @@ struct WddmMemoryManagerWithAsyncDeleterTest : public MockWddmMemoryManagerTest } MockDeferredDeleter *deleter = nullptr; std::unique_ptr memoryManager; + ExecutionEnvironment *executionEnvironment; + HardwareInfo *hwInfo; + WddmMock *wddm; }; TEST_F(WddmMemoryManagerWithAsyncDeleterTest, givenWddmWhenAsyncDeleterIsEnabledThenCanDeferDeletions) { diff --git a/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.h b/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.h index 0793c137dd..2d640fa3de 100644 --- a/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.h +++ b/opencl/test/unit_test/os_interface/windows/wddm_memory_manager_tests.h @@ -7,6 +7,7 @@ #pragma once +#include "shared/source/os_interface/windows/os_environment_win.h" #include "shared/source/os_interface/windows/os_interface.h" #include "shared/source/os_interface/windows/wddm_memory_operations_handler.h" #include "shared/test/unit_test/os_interface/windows/mock_gdi_interface.h" @@ -49,10 +50,11 @@ class MockWddmMemoryManagerFixture { void SetUp() { executionEnvironment = platform()->peekExecutionEnvironment(); rootDeviceEnvironment = executionEnvironment->rootDeviceEnvironments[0].get(); + auto osEnvironment = new OsEnvironmentWin(); gdi = new MockGdi(); - + osEnvironment->gdi.reset(gdi); + executionEnvironment->osEnvironment.reset(osEnvironment); wddm = static_cast(Wddm::createWddm(nullptr, *rootDeviceEnvironment)); - wddm->resetGdi(gdi); constexpr uint64_t heap32Base = (is32bit) ? 0x1000 : 0x800000000000; wddm->setHeap32(heap32Base, 1000 * MemoryConstants::pageSize - 1); wddm->init(); diff --git a/opencl/test/unit_test/os_interface/windows/wddm_residency_controller_tests.cpp b/opencl/test/unit_test/os_interface/windows/wddm_residency_controller_tests.cpp index 287e0551c6..f257673d90 100644 --- a/opencl/test/unit_test/os_interface/windows/wddm_residency_controller_tests.cpp +++ b/opencl/test/unit_test/os_interface/windows/wddm_residency_controller_tests.cpp @@ -81,10 +81,10 @@ struct WddmResidencyControllerTest : ::testing::Test { residencyController = &mockOsContextWin->mockResidencyController; } - std::unique_ptr wddm; - std::unique_ptr mockOsContextWin; std::unique_ptr executionEnvironment; std::unique_ptr rootDeviceEnvironment; + std::unique_ptr wddm; + std::unique_ptr mockOsContextWin; MockWddmResidencyController *residencyController = nullptr; }; @@ -106,10 +106,10 @@ struct WddmResidencyControllerWithGdiTest : ::testing::Test { residencyController->registerCallback(); } - std::unique_ptr wddm; - std::unique_ptr mockOsContextWin; std::unique_ptr executionEnvironment; std::unique_ptr rootDeviceEnvironment; + std::unique_ptr wddm; + std::unique_ptr mockOsContextWin; MockWddmResidencyController *residencyController = nullptr; MockGdi *gdi; }; diff --git a/opencl/test/unit_test/windows/wddm_create_tests.cpp b/opencl/test/unit_test/windows/wddm_create_tests.cpp index 9a322fb792..c2e65be56d 100644 --- a/opencl/test/unit_test/windows/wddm_create_tests.cpp +++ b/opencl/test/unit_test/windows/wddm_create_tests.cpp @@ -21,7 +21,7 @@ using namespace NEO; TEST(wddmCreateTests, givenInputVersionWhenCreatingThenCreateRequestedObject) { MockExecutionEnvironment executionEnvironment; RootDeviceEnvironment rootDeviceEnvironment(executionEnvironment); - auto hwDeviceIds = OSInterface::discoverDevices(); + auto hwDeviceIds = OSInterface::discoverDevices(executionEnvironment); std::unique_ptr wddm(Wddm::createWddm(std::move(hwDeviceIds[0]), rootDeviceEnvironment)); EXPECT_EQ(typeid(*wddm.get()), typeid(Wddm)); } diff --git a/shared/source/execution_environment/execution_environment.cpp b/shared/source/execution_environment/execution_environment.cpp index 850754b928..9f35a89bc2 100644 --- a/shared/source/execution_environment/execution_environment.cpp +++ b/shared/source/execution_environment/execution_environment.cpp @@ -9,6 +9,7 @@ #include "shared/source/execution_environment/root_device_environment.h" #include "shared/source/helpers/hw_helper.h" +#include "shared/source/os_interface/os_environment.h" #include "opencl/source/memory_manager/os_agnostic_memory_manager.h" diff --git a/shared/source/execution_environment/execution_environment.h b/shared/source/execution_environment/execution_environment.h index 37655ae1e8..ddf3a79dd5 100644 --- a/shared/source/execution_environment/execution_environment.h +++ b/shared/source/execution_environment/execution_environment.h @@ -12,6 +12,7 @@ namespace NEO { class MemoryManager; +struct OsEnvironment; struct RootDeviceEnvironment; class ExecutionEnvironment : public ReferenceTrackedObject { @@ -25,6 +26,7 @@ class ExecutionEnvironment : public ReferenceTrackedObject void prepareRootDeviceEnvironments(uint32_t numRootDevices); std::unique_ptr memoryManager; + std::unique_ptr osEnvironment; std::vector> rootDeviceEnvironments; }; } // namespace NEO diff --git a/shared/source/os_interface/CMakeLists.txt b/shared/source/os_interface/CMakeLists.txt index b91b3d8584..0576412acc 100644 --- a/shared/source/os_interface/CMakeLists.txt +++ b/shared/source/os_interface/CMakeLists.txt @@ -15,6 +15,7 @@ set(NEO_CORE_OS_INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/hw_info_config.inl ${CMAKE_CURRENT_SOURCE_DIR}/hw_info_config_bdw_plus.inl ${CMAKE_CURRENT_SOURCE_DIR}/os_context.h + ${CMAKE_CURRENT_SOURCE_DIR}/os_environment.h ${CMAKE_CURRENT_SOURCE_DIR}/os_interface.h ${CMAKE_CURRENT_SOURCE_DIR}/os_library.h ${CMAKE_CURRENT_SOURCE_DIR}/os_memory.h diff --git a/shared/source/os_interface/device_factory.cpp b/shared/source/os_interface/device_factory.cpp index 5b8e51b42e..d9d062d958 100644 --- a/shared/source/os_interface/device_factory.cpp +++ b/shared/source/os_interface/device_factory.cpp @@ -88,7 +88,7 @@ bool DeviceFactory::isHwModeSelected() { bool DeviceFactory::getDevices(size_t &totalNumRootDevices, ExecutionEnvironment &executionEnvironment) { using HwDeviceIds = std::vector>; - HwDeviceIds hwDeviceIds = OSInterface::discoverDevices(); + HwDeviceIds hwDeviceIds = OSInterface::discoverDevices(executionEnvironment); totalNumRootDevices = hwDeviceIds.size(); if (totalNumRootDevices == 0) { return false; diff --git a/shared/source/os_interface/linux/drm_neo.cpp b/shared/source/os_interface/linux/drm_neo.cpp index 0859465518..f383919ce0 100644 --- a/shared/source/os_interface/linux/drm_neo.cpp +++ b/shared/source/os_interface/linux/drm_neo.cpp @@ -8,12 +8,14 @@ #include "drm_neo.h" #include "shared/source/debug_settings/debug_settings_manager.h" +#include "shared/source/execution_environment/execution_environment.h" #include "shared/source/helpers/debug_helpers.h" #include "shared/source/helpers/hw_info.h" #include "shared/source/memory_manager/memory_constants.h" #include "shared/source/os_interface/linux/hw_device_id.h" #include "shared/source/os_interface/linux/os_inc.h" #include "shared/source/os_interface/linux/sys_calls.h" +#include "shared/source/os_interface/os_environment.h" #include "shared/source/os_interface/os_interface.h" #include "shared/source/utilities/directory.h" @@ -291,8 +293,9 @@ int Drm::setupHardwareInfo(DeviceDescriptor *device, bool setupFeatureTableAndWo return 0; } -std::vector> OSInterface::discoverDevices() { +std::vector> OSInterface::discoverDevices(ExecutionEnvironment &executionEnvironment) { std::vector> hwDeviceIds; + executionEnvironment.osEnvironment = std::make_unique(); char fullPath[PATH_MAX]; size_t numRootDevices = 1u; if (DebugManager.flags.CreateMultipleRootDevices.get()) { diff --git a/shared/source/os_interface/os_environment.h b/shared/source/os_interface/os_environment.h new file mode 100644 index 0000000000..7042ac0aca --- /dev/null +++ b/shared/source/os_interface/os_environment.h @@ -0,0 +1,15 @@ +/* + * Copyright (C) 2020 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once + +namespace NEO { +struct OsEnvironment { + OsEnvironment() = default; + virtual ~OsEnvironment() = default; +}; +} // namespace NEO \ No newline at end of file diff --git a/shared/source/os_interface/os_interface.h b/shared/source/os_interface/os_interface.h index 71743d245f..36387f639a 100644 --- a/shared/source/os_interface/os_interface.h +++ b/shared/source/os_interface/os_interface.h @@ -11,6 +11,7 @@ #include namespace NEO { +class ExecutionEnvironment; class HwDeviceId; class OSInterface { @@ -30,7 +31,7 @@ class OSInterface { static bool are64kbPagesEnabled(); uint32_t getDeviceHandle() const; void setGmmInputArgs(void *args); - static std::vector> discoverDevices(); + static std::vector> discoverDevices(ExecutionEnvironment &executionEnvironment); protected: OSInterfaceImpl *osInterfaceImpl = nullptr; diff --git a/shared/source/os_interface/windows/CMakeLists.txt b/shared/source/os_interface/windows/CMakeLists.txt index 8597cb6d12..66041a728b 100644 --- a/shared/source/os_interface/windows/CMakeLists.txt +++ b/shared/source/os_interface/windows/CMakeLists.txt @@ -31,6 +31,8 @@ set(NEO_CORE_OS_INTERFACE_WINDOWS ${CMAKE_CURRENT_SOURCE_DIR}/kmdaf_listener.h ${CMAKE_CURRENT_SOURCE_DIR}/os_context_win.cpp ${CMAKE_CURRENT_SOURCE_DIR}/os_context_win.h + ${CMAKE_CURRENT_SOURCE_DIR}/os_environment_win.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/os_environment_win.h ${CMAKE_CURRENT_SOURCE_DIR}/os_inc.h ${CMAKE_CURRENT_SOURCE_DIR}/os_interface.cpp ${CMAKE_CURRENT_SOURCE_DIR}/os_interface.h diff --git a/shared/source/os_interface/windows/hw_device_id.h b/shared/source/os_interface/windows/hw_device_id.h index 85fd0d22ec..cd393eef3c 100644 --- a/shared/source/os_interface/windows/hw_device_id.h +++ b/shared/source/os_interface/windows/hw_device_id.h @@ -15,12 +15,11 @@ namespace NEO { class Gdi; +struct OsEnvironment; class HwDeviceId : NonCopyableClass { public: - HwDeviceId(D3DKMT_HANDLE adapterIn, LUID adapterLuidIn, std::unique_ptr gdiIn); - inline Gdi *getGdi() const { - return gdi.get(); - } + HwDeviceId(D3DKMT_HANDLE adapterIn, LUID adapterLuidIn, OsEnvironment *osEnvironmentIn); + Gdi *getGdi() const; constexpr D3DKMT_HANDLE getAdapter() const { return adapter; } @@ -32,6 +31,6 @@ class HwDeviceId : NonCopyableClass { protected: const D3DKMT_HANDLE adapter; const LUID adapterLuid; - const std::unique_ptr gdi; + OsEnvironment *osEnvironment; }; } // namespace NEO diff --git a/shared/source/os_interface/windows/hw_device_id_win.cpp b/shared/source/os_interface/windows/hw_device_id_win.cpp index b2d4fcc4cd..8e356d2071 100644 --- a/shared/source/os_interface/windows/hw_device_id_win.cpp +++ b/shared/source/os_interface/windows/hw_device_id_win.cpp @@ -8,16 +8,20 @@ #include "shared/source/helpers/debug_helpers.h" #include "shared/source/os_interface/windows/gdi_interface.h" #include "shared/source/os_interface/windows/hw_device_id.h" +#include "shared/source/os_interface/windows/os_environment_win.h" namespace NEO { HwDeviceId::~HwDeviceId() { NTSTATUS status = STATUS_UNSUCCESSFUL; D3DKMT_CLOSEADAPTER CloseAdapter = {0}; CloseAdapter.hAdapter = adapter; - status = gdi->closeAdapter(&CloseAdapter); + status = static_cast(osEnvironment)->gdi->closeAdapter(&CloseAdapter); DEBUG_BREAK_IF(status != STATUS_SUCCESS); } -HwDeviceId::HwDeviceId(D3DKMT_HANDLE adapterIn, LUID adapterLuidIn, std::unique_ptr gdiIn) : adapter(adapterIn), - adapterLuid(adapterLuidIn), - gdi(std::move(gdiIn)){}; +HwDeviceId::HwDeviceId(D3DKMT_HANDLE adapterIn, LUID adapterLuidIn, OsEnvironment *osEnvironmentIn) : adapter(adapterIn), + adapterLuid(adapterLuidIn), + osEnvironment(osEnvironmentIn) {} +Gdi *HwDeviceId::getGdi() const { + return static_cast(osEnvironment)->gdi.get(); +}; } // namespace NEO diff --git a/shared/source/os_interface/windows/os_environment_win.cpp b/shared/source/os_interface/windows/os_environment_win.cpp new file mode 100644 index 0000000000..a6e74ce8ea --- /dev/null +++ b/shared/source/os_interface/windows/os_environment_win.cpp @@ -0,0 +1,15 @@ +/* + * Copyright (C) 2020 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/os_interface/windows/os_environment_win.h" + +#include "shared/source/os_interface/windows/gdi_interface.h" + +namespace NEO { +OsEnvironmentWin::OsEnvironmentWin() : gdi(std::make_unique()){}; +OsEnvironmentWin::~OsEnvironmentWin() = default; +} // namespace NEO \ No newline at end of file diff --git a/shared/source/os_interface/windows/os_environment_win.h b/shared/source/os_interface/windows/os_environment_win.h new file mode 100644 index 0000000000..d6766d42f4 --- /dev/null +++ b/shared/source/os_interface/windows/os_environment_win.h @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2020 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once + +#include "shared/source/os_interface/os_environment.h" + +#include + +namespace NEO { +class Gdi; + +struct OsEnvironmentWin : public OsEnvironment { + OsEnvironmentWin(); + ~OsEnvironmentWin() override; + + std::unique_ptr gdi; +}; +} // namespace NEO \ No newline at end of file diff --git a/shared/source/os_interface/windows/wddm/wddm.cpp b/shared/source/os_interface/windows/wddm/wddm.cpp index 09c359eccb..4a442a1d84 100644 --- a/shared/source/os_interface/windows/wddm/wddm.cpp +++ b/shared/source/os_interface/windows/wddm/wddm.cpp @@ -20,6 +20,7 @@ #include "shared/source/os_interface/windows/gdi_interface.h" #include "shared/source/os_interface/windows/kmdaf_listener.h" #include "shared/source/os_interface/windows/os_context_win.h" +#include "shared/source/os_interface/windows/os_environment_win.h" #include "shared/source/os_interface/windows/os_interface.h" #include "shared/source/os_interface/windows/sys_calls.h" #include "shared/source/os_interface/windows/wddm/wddm_interface.h" @@ -227,20 +228,23 @@ bool Wddm::destroyDevice() { return true; } -std::unique_ptr createHwDeviceIdFromAdapterLuid(Gdi &gdi, LUID adapterLuid) { +std::unique_ptr createHwDeviceIdFromAdapterLuid(OsEnvironmentWin &osEnvironment, LUID adapterLuid) { D3DKMT_OPENADAPTERFROMLUID OpenAdapterData = {{0}}; OpenAdapterData.AdapterLuid = adapterLuid; - auto status = gdi.openAdapterFromLuid(&OpenAdapterData); + auto status = osEnvironment.gdi->openAdapterFromLuid(&OpenAdapterData); if (status == STATUS_SUCCESS) { - return std::make_unique(OpenAdapterData.hAdapter, adapterLuid, std::make_unique()); + return std::make_unique(OpenAdapterData.hAdapter, adapterLuid, &osEnvironment); } return nullptr; } -std::vector> OSInterface::discoverDevices() { +std::vector> OSInterface::discoverDevices(ExecutionEnvironment &executionEnvironment) { std::vector> hwDeviceIds; - auto gdi = std::make_unique(); + + auto osEnvironment = new OsEnvironmentWin(); + auto gdi = osEnvironment->gdi.get(); + executionEnvironment.osEnvironment.reset(osEnvironment); if (!gdi->isInitialized()) { return hwDeviceIds; @@ -286,7 +290,7 @@ std::vector> OSInterface::discoverDevices() { } } if (createHwDeviceId) { - auto hwDeviceId = createHwDeviceIdFromAdapterLuid(*gdi, OpenAdapterDesc.AdapterLuid); + auto hwDeviceId = createHwDeviceIdFromAdapterLuid(*osEnvironment, OpenAdapterDesc.AdapterLuid); if (hwDeviceId) { hwDeviceIds.push_back(std::move(hwDeviceId)); } @@ -314,7 +318,7 @@ std::vector> OSInterface::discoverDevices() { } while (hwDeviceIds.size() < numRootDevices) { - hwDeviceIds.push_back(std::make_unique(hwDeviceIds[0]->getAdapter(), hwDeviceIds[0]->getAdapterLuid(), std::make_unique())); + hwDeviceIds.push_back(std::make_unique(hwDeviceIds[0]->getAdapter(), hwDeviceIds[0]->getAdapterLuid(), osEnvironment)); } return hwDeviceIds;