Load GDI once

Resolves: NEO-4174

Change-Id: I465d6137deb1dac1146a5b28ff1c100823a1d6b6
Signed-off-by: Lukasz Jobczyk <lukasz.jobczyk@intel.com>
This commit is contained in:
Lukasz Jobczyk
2020-03-17 07:26:46 +01:00
committed by sys_ocldev
parent 03ce6681a0
commit 13e053f538
29 changed files with 187 additions and 65 deletions

View File

@ -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++) {

View File

@ -153,6 +153,7 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeMemoryManagerI
}
static_assert(sizeof(ExecutionEnvironment) == sizeof(std::unique_ptr<HardwareInfo>) +
sizeof(std::vector<RootDeviceEnvironment>) +
sizeof(std::unique_ptr<OsEnvironment>) +
(is64bit ? 16 : 12),
"New members detected in ExecutionEnvironment, please ensure that destruction sequence of objects is correct");

View File

@ -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<Gmm>(executionEnvironment.rootDeviceEnvironments[i]->getGmmClientContext(), nullptr, 0, false);
auto wddm = static_cast<WddmMock *>(executionEnvironment.rootDeviceEnvironments[i]->osInterface->get()->getWddm());
wddm->hwDeviceId = std::make_unique<HwDeviceId>(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) {}

View File

@ -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);
}

View File

@ -72,7 +72,8 @@ TEST(DrmTest, GivenTwoOpenableDevicesWhenDiscoverDevicesThenCreateTwoHwDeviceIds
VariableBackup<decltype(openFull)> 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<decltype(openFull)> 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<decltype(openFull)> 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<decltype(openFull)> backupOpenFull(&openFull);
openFull = testOpen;
openRetVal = 1024;
ExecutionEnvironment executionEnvironment;
auto hwDeviceIds = OSInterface::discoverDevices();
auto hwDeviceIds = OSInterface::discoverDevices(executionEnvironment);
EXPECT_TRUE(hwDeviceIds.empty());
}

View File

@ -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<HwDeviceId>(ADAPTER_HANDLE, LUID{}, std::make_unique<Gdi>()), rootDeviceEnvironment) {
struct mockHwDeviceId : public HwDeviceId {
using HwDeviceId::osEnvironment;
};
WddmMock::WddmMock(RootDeviceEnvironment &rootDeviceEnvironment) : Wddm(std::make_unique<HwDeviceId>(ADAPTER_HANDLE, LUID{}, rootDeviceEnvironment.executionEnvironment.osEnvironment.get()), rootDeviceEnvironment) {
if (!rootDeviceEnvironment.executionEnvironment.osEnvironment.get()) {
rootDeviceEnvironment.executionEnvironment.osEnvironment = std::make_unique<OsEnvironmentWin>();
}
static_cast<mockHwDeviceId *>(this->hwDeviceId.get())->osEnvironment = rootDeviceEnvironment.executionEnvironment.osEnvironment.get();
this->temporaryResources = std::make_unique<MockWddmResidentAllocationsContainer>(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<HwDeviceId>(ADAPTER_HANDLE, LUID{}, std::unique_ptr<Gdi>(gdi));
static_cast<OsEnvironmentWin *>(this->rootDeviceEnvironment.executionEnvironment.osEnvironment.get())->gdi.reset(gdi);
}
void WddmMock::setHeap32(uint64_t base, uint64_t size) {

View File

@ -94,6 +94,8 @@ TEST_F(DeviceFactoryTest, overrideKmdNotifySettings) {
DebugManager.flags.OverrideEnableQuickKmdSleepForSporadicWaits.set(!refEnableQuickKmdSleepForSporadicWaits);
DebugManager.flags.OverrideDelayQuickKmdSleepForSporadicWaitsMicroseconds.set(static_cast<int32_t>(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());
}

View File

@ -231,10 +231,10 @@ struct PerformanceCountersFixture {
std::unique_ptr<MockClDevice> device;
std::unique_ptr<MockContext> context;
std::unique_ptr<MockCommandQueue> queue;
std::unique_ptr<OSInterface> osInterface;
std::unique_ptr<PerformanceCounters> performanceCountersBase;
std::unique_ptr<MockExecutionEnvironment> executionEnvironment;
std::unique_ptr<RootDeviceEnvironment> rootDeviceEnvironment;
std::unique_ptr<OSInterface> osInterface;
};
//////////////////////////////////////////////////////

View File

@ -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<MockOSInterfaceImpl *>(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();

View File

@ -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<HwDeviceId> hwDeviceIdIn, RootDeviceEnvironment &rootDeviceEnvironment) : Wddm(std::move(hwDeviceIdIn), rootDeviceEnvironment) {}
@ -107,8 +109,9 @@ TEST(WddmDiscoverDevices, WhenAdapterDescriptionContainsDCHDAndgdrclPathDoesntCo
descriptionBackup = L"Intel DCH-D";
VariableBackup<const wchar_t *> 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<const wchar_t *> 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<uint32_t> 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<const wchar_t *> 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<const wchar_t *> 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<const wchar_t *> 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<HwDeviceId>(0, LUID{}, std::make_unique<Gdi>());
auto gdi = std::make_unique<Gdi>();
wddm->resetGdi(gdi.release());
EXPECT_CALL(*gmmMem,
configureDeviceAddressSpace(static_cast<D3DKMT_HANDLE>(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<GdiWithMockedCloseFunc>();
auto osEnv = std::make_unique<OsEnvironmentWin>();
osEnv->gdi.reset(gdi.release());
D3DKMT_HANDLE adapter = 0x1234;
{
HwDeviceId hwDeviceId{adapter, {}, std::make_unique<GdiWithMockedCloseFunc>()};
HwDeviceId hwDeviceId{adapter, {}, osEnv.get()};
}
EXPECT_EQ(1u, GdiWithMockedCloseFunc::closeAdapterCalled);
EXPECT_EQ(adapter, GdiWithMockedCloseFunc::closeAdapterCalledArgPassed);

View File

@ -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<WddmMock *>(Wddm::createWddm(nullptr, *rootDeviceEnvironemnt));
rootDeviceEnvironemnt->osInterface = std::make_unique<OSInterface>();
rootDeviceEnvironemnt->osInterface->get()->setWddm(wddm);
rootDeviceEnvironemnt->memoryOperationsInterface = std::make_unique<WddmMemoryOperationsHandler>(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<OsContextWin> osContext;
ExecutionEnvironment *executionEnvironment;
RootDeviceEnvironment *rootDeviceEnvironemnt = nullptr;
std::unique_ptr<OsContextWin> osContext;
MockGdi *gdi = nullptr;
MockWddmResidentAllocationsContainer *mockTemporaryResources;

View File

@ -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<HwDeviceId>(ADAPTER_HANDLE, LUID{}, std::unique_ptr<Gdi>(mockGdi)), rootDeviceEnvironment) {
WddmWithKmDafMock(RootDeviceEnvironment &rootDeviceEnvironment) : Wddm(std::make_unique<HwDeviceId>(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;
}

View File

@ -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<WddmMock *>(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<MockWddmMemoryManager> memoryManager;
ExecutionEnvironment *executionEnvironment;
HardwareInfo *hwInfo;
WddmMock *wddm;
};
TEST_F(WddmMemoryManagerWithAsyncDeleterTest, givenWddmWhenAsyncDeleterIsEnabledThenCanDeferDeletions) {

View File

@ -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<WddmMock *>(Wddm::createWddm(nullptr, *rootDeviceEnvironment));
wddm->resetGdi(gdi);
constexpr uint64_t heap32Base = (is32bit) ? 0x1000 : 0x800000000000;
wddm->setHeap32(heap32Base, 1000 * MemoryConstants::pageSize - 1);
wddm->init();

View File

@ -81,10 +81,10 @@ struct WddmResidencyControllerTest : ::testing::Test {
residencyController = &mockOsContextWin->mockResidencyController;
}
std::unique_ptr<WddmMock> wddm;
std::unique_ptr<MockOsContextWin> mockOsContextWin;
std::unique_ptr<MockExecutionEnvironment> executionEnvironment;
std::unique_ptr<RootDeviceEnvironment> rootDeviceEnvironment;
std::unique_ptr<WddmMock> wddm;
std::unique_ptr<MockOsContextWin> mockOsContextWin;
MockWddmResidencyController *residencyController = nullptr;
};
@ -106,10 +106,10 @@ struct WddmResidencyControllerWithGdiTest : ::testing::Test {
residencyController->registerCallback();
}
std::unique_ptr<WddmMock> wddm;
std::unique_ptr<MockOsContextWin> mockOsContextWin;
std::unique_ptr<MockExecutionEnvironment> executionEnvironment;
std::unique_ptr<RootDeviceEnvironment> rootDeviceEnvironment;
std::unique_ptr<WddmMock> wddm;
std::unique_ptr<MockOsContextWin> mockOsContextWin;
MockWddmResidencyController *residencyController = nullptr;
MockGdi *gdi;
};

View File

@ -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(Wddm::createWddm(std::move(hwDeviceIds[0]), rootDeviceEnvironment));
EXPECT_EQ(typeid(*wddm.get()), typeid(Wddm));
}

View File

@ -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"

View File

@ -12,6 +12,7 @@
namespace NEO {
class MemoryManager;
struct OsEnvironment;
struct RootDeviceEnvironment;
class ExecutionEnvironment : public ReferenceTrackedObject<ExecutionEnvironment> {
@ -25,6 +26,7 @@ class ExecutionEnvironment : public ReferenceTrackedObject<ExecutionEnvironment>
void prepareRootDeviceEnvironments(uint32_t numRootDevices);
std::unique_ptr<MemoryManager> memoryManager;
std::unique_ptr<OsEnvironment> osEnvironment;
std::vector<std::unique_ptr<RootDeviceEnvironment>> rootDeviceEnvironments;
};
} // namespace NEO

View File

@ -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

View File

@ -88,7 +88,7 @@ bool DeviceFactory::isHwModeSelected() {
bool DeviceFactory::getDevices(size_t &totalNumRootDevices, ExecutionEnvironment &executionEnvironment) {
using HwDeviceIds = std::vector<std::unique_ptr<HwDeviceId>>;
HwDeviceIds hwDeviceIds = OSInterface::discoverDevices();
HwDeviceIds hwDeviceIds = OSInterface::discoverDevices(executionEnvironment);
totalNumRootDevices = hwDeviceIds.size();
if (totalNumRootDevices == 0) {
return false;

View File

@ -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<std::unique_ptr<HwDeviceId>> OSInterface::discoverDevices() {
std::vector<std::unique_ptr<HwDeviceId>> OSInterface::discoverDevices(ExecutionEnvironment &executionEnvironment) {
std::vector<std::unique_ptr<HwDeviceId>> hwDeviceIds;
executionEnvironment.osEnvironment = std::make_unique<OsEnvironment>();
char fullPath[PATH_MAX];
size_t numRootDevices = 1u;
if (DebugManager.flags.CreateMultipleRootDevices.get()) {

View File

@ -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

View File

@ -11,6 +11,7 @@
#include <vector>
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<std::unique_ptr<HwDeviceId>> discoverDevices();
static std::vector<std::unique_ptr<HwDeviceId>> discoverDevices(ExecutionEnvironment &executionEnvironment);
protected:
OSInterfaceImpl *osInterfaceImpl = nullptr;

View File

@ -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

View File

@ -15,12 +15,11 @@
namespace NEO {
class Gdi;
struct OsEnvironment;
class HwDeviceId : NonCopyableClass {
public:
HwDeviceId(D3DKMT_HANDLE adapterIn, LUID adapterLuidIn, std::unique_ptr<Gdi> 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> gdi;
OsEnvironment *osEnvironment;
};
} // namespace NEO

View File

@ -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<OsEnvironmentWin *>(osEnvironment)->gdi->closeAdapter(&CloseAdapter);
DEBUG_BREAK_IF(status != STATUS_SUCCESS);
}
HwDeviceId::HwDeviceId(D3DKMT_HANDLE adapterIn, LUID adapterLuidIn, std::unique_ptr<Gdi> 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<OsEnvironmentWin *>(osEnvironment)->gdi.get();
};
} // namespace NEO

View File

@ -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<Gdi>()){};
OsEnvironmentWin::~OsEnvironmentWin() = default;
} // namespace NEO

View File

@ -0,0 +1,23 @@
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "shared/source/os_interface/os_environment.h"
#include <memory>
namespace NEO {
class Gdi;
struct OsEnvironmentWin : public OsEnvironment {
OsEnvironmentWin();
~OsEnvironmentWin() override;
std::unique_ptr<Gdi> gdi;
};
} // namespace NEO

View File

@ -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<HwDeviceId> createHwDeviceIdFromAdapterLuid(Gdi &gdi, LUID adapterLuid) {
std::unique_ptr<HwDeviceId> 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<HwDeviceId>(OpenAdapterData.hAdapter, adapterLuid, std::make_unique<Gdi>());
return std::make_unique<HwDeviceId>(OpenAdapterData.hAdapter, adapterLuid, &osEnvironment);
}
return nullptr;
}
std::vector<std::unique_ptr<HwDeviceId>> OSInterface::discoverDevices() {
std::vector<std::unique_ptr<HwDeviceId>> OSInterface::discoverDevices(ExecutionEnvironment &executionEnvironment) {
std::vector<std::unique_ptr<HwDeviceId>> hwDeviceIds;
auto gdi = std::make_unique<Gdi>();
auto osEnvironment = new OsEnvironmentWin();
auto gdi = osEnvironment->gdi.get();
executionEnvironment.osEnvironment.reset(osEnvironment);
if (!gdi->isInitialized()) {
return hwDeviceIds;
@ -286,7 +290,7 @@ std::vector<std::unique_ptr<HwDeviceId>> 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<std::unique_ptr<HwDeviceId>> OSInterface::discoverDevices() {
}
while (hwDeviceIds.size() < numRootDevices) {
hwDeviceIds.push_back(std::make_unique<HwDeviceId>(hwDeviceIds[0]->getAdapter(), hwDeviceIds[0]->getAdapterLuid(), std::make_unique<Gdi>()));
hwDeviceIds.push_back(std::make_unique<HwDeviceId>(hwDeviceIds[0]->getAdapter(), hwDeviceIds[0]->getAdapterLuid(), osEnvironment));
}
return hwDeviceIds;