mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-08 22:12:59 +08:00
Refactoring HwDeviceId
Signed-off-by: Jaroslaw Chodor <jaroslaw.chodor@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
b2fae343ec
commit
67aa1ad7ec
@@ -17,15 +17,18 @@ struct HardwareInfo;
|
||||
class OSInterface;
|
||||
|
||||
struct PhysicalDevicePciBusInfo {
|
||||
PhysicalDevicePciBusInfo() = default;
|
||||
|
||||
PhysicalDevicePciBusInfo(uint32_t domain, uint32_t bus, uint32_t device, uint32_t function)
|
||||
: pciDomain(domain), pciBus(bus), pciDevice(device), pciFunction(function) {}
|
||||
|
||||
uint32_t pciDomain;
|
||||
uint32_t pciBus;
|
||||
uint32_t pciDevice;
|
||||
uint32_t pciFunction;
|
||||
static constexpr uint32_t InvalidValue = std::numeric_limits<uint32_t>::max();
|
||||
static constexpr PhysicalDevicePciBusInfo invalid() { return {}; }
|
||||
|
||||
static const uint32_t InvalidValue = std::numeric_limits<uint32_t>::max();
|
||||
uint32_t pciDomain = InvalidValue;
|
||||
uint32_t pciBus = InvalidValue;
|
||||
uint32_t pciDevice = InvalidValue;
|
||||
uint32_t pciFunction = InvalidValue;
|
||||
};
|
||||
|
||||
class DriverInfo {
|
||||
|
||||
@@ -63,7 +63,7 @@ constexpr const char *getIoctlParamString(int param) {
|
||||
|
||||
} // namespace IoctlHelper
|
||||
|
||||
Drm::Drm(std::unique_ptr<HwDeviceId> hwDeviceIdIn, RootDeviceEnvironment &rootDeviceEnvironment)
|
||||
Drm::Drm(std::unique_ptr<HwDeviceIdDrm> hwDeviceIdIn, RootDeviceEnvironment &rootDeviceEnvironment)
|
||||
: DriverModel(DriverModelType::DRM),
|
||||
hwDeviceId(std::move(hwDeviceIdIn)), rootDeviceEnvironment(rootDeviceEnvironment) {
|
||||
pagingFence.fill(0u);
|
||||
@@ -375,7 +375,7 @@ void Drm::setupSystemInfo(HardwareInfo *hwInfo, SystemInfo &sysInfo) {
|
||||
void appendHwDeviceId(std::vector<std::unique_ptr<HwDeviceId>> &hwDeviceIds, int fileDescriptor, const char *pciPath) {
|
||||
if (fileDescriptor >= 0) {
|
||||
if (Drm::isi915Version(fileDescriptor)) {
|
||||
hwDeviceIds.push_back(std::make_unique<HwDeviceId>(fileDescriptor, pciPath));
|
||||
hwDeviceIds.push_back(std::make_unique<HwDeviceIdDrm>(fileDescriptor, pciPath));
|
||||
} else {
|
||||
SysCalls::close(fileDescriptor);
|
||||
}
|
||||
|
||||
@@ -191,7 +191,7 @@ class Drm : public DriverModel {
|
||||
|
||||
static bool isi915Version(int fd);
|
||||
|
||||
static Drm *create(std::unique_ptr<HwDeviceId> hwDeviceId, RootDeviceEnvironment &rootDeviceEnvironment);
|
||||
static Drm *create(std::unique_ptr<HwDeviceIdDrm> hwDeviceId, RootDeviceEnvironment &rootDeviceEnvironment);
|
||||
static void overrideBindSupport(bool &useVmBind);
|
||||
std::string getPciPath() {
|
||||
return hwDeviceId->getPciPath();
|
||||
@@ -224,14 +224,14 @@ class Drm : public DriverModel {
|
||||
bool contextDebugSupported = false;
|
||||
bool newResourceBound = false;
|
||||
std::once_flag checkBindOnce;
|
||||
std::unique_ptr<HwDeviceId> hwDeviceId;
|
||||
std::unique_ptr<HwDeviceIdDrm> hwDeviceId;
|
||||
int deviceId = 0;
|
||||
int revisionId = 0;
|
||||
GTTYPE eGtType = GTTYPE_UNDEFINED;
|
||||
RootDeviceEnvironment &rootDeviceEnvironment;
|
||||
uint64_t uuid = 0;
|
||||
|
||||
Drm(std::unique_ptr<HwDeviceId> hwDeviceIdIn, RootDeviceEnvironment &rootDeviceEnvironment);
|
||||
Drm(std::unique_ptr<HwDeviceIdDrm> hwDeviceIdIn, RootDeviceEnvironment &rootDeviceEnvironment);
|
||||
std::unique_ptr<SystemInfo> systemInfo;
|
||||
std::unique_ptr<CacheInfo> cacheInfo;
|
||||
std::unique_ptr<EngineInfo> engineInfo;
|
||||
|
||||
@@ -38,7 +38,7 @@ class DrmNullDevice : public Drm {
|
||||
}
|
||||
}
|
||||
|
||||
DrmNullDevice(std::unique_ptr<HwDeviceId> hwDeviceId, RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::move(hwDeviceId), rootDeviceEnvironment), gpuTimestamp(0){};
|
||||
DrmNullDevice(std::unique_ptr<HwDeviceIdDrm> hwDeviceId, RootDeviceEnvironment &rootDeviceEnvironment) : Drm(std::move(hwDeviceId), rootDeviceEnvironment), gpuTimestamp(0){};
|
||||
|
||||
protected:
|
||||
uint64_t gpuTimestamp;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Intel Corporation
|
||||
* Copyright (C) 2020-2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -7,14 +7,19 @@
|
||||
|
||||
#pragma once
|
||||
#include "shared/source/helpers/non_copyable_or_moveable.h"
|
||||
#include "shared/source/os_interface/os_interface.h"
|
||||
|
||||
#include <string>
|
||||
namespace NEO {
|
||||
|
||||
class HwDeviceId : NonCopyableClass {
|
||||
class HwDeviceIdDrm : public HwDeviceId {
|
||||
public:
|
||||
HwDeviceId(int fileDescriptorIn, const char *pciPathIn) : fileDescriptor(fileDescriptorIn), pciPath(pciPathIn) {}
|
||||
~HwDeviceId();
|
||||
static constexpr DriverModelType driverModelType = DriverModelType::DRM;
|
||||
|
||||
HwDeviceIdDrm(int fileDescriptorIn, const char *pciPathIn)
|
||||
: HwDeviceId(DriverModelType::DRM),
|
||||
fileDescriptor(fileDescriptorIn), pciPath(pciPathIn) {}
|
||||
~HwDeviceIdDrm() override;
|
||||
int getFileDescriptor() const { return fileDescriptor; }
|
||||
const char *getPciPath() const { return pciPath.c_str(); }
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Intel Corporation
|
||||
* Copyright (C) 2020-2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
namespace NEO {
|
||||
|
||||
HwDeviceId::~HwDeviceId() {
|
||||
HwDeviceIdDrm::~HwDeviceIdDrm() {
|
||||
SysCalls::close(fileDescriptor);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ bool OSInterface::isDebugAttachAvailable() const {
|
||||
}
|
||||
|
||||
bool RootDeviceEnvironment::initOsInterface(std::unique_ptr<HwDeviceId> &&hwDeviceId, uint32_t rootDeviceIndex) {
|
||||
Drm *drm = Drm::create(std::move(hwDeviceId), *this);
|
||||
Drm *drm = Drm::create(std::unique_ptr<HwDeviceIdDrm>(hwDeviceId.release()->as<HwDeviceIdDrm>()), *this);
|
||||
if (!drm) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -15,17 +15,45 @@
|
||||
|
||||
namespace NEO {
|
||||
class ExecutionEnvironment;
|
||||
class HwDeviceId;
|
||||
class MemoryManager;
|
||||
enum class DriverModelType { WDDM,
|
||||
DRM };
|
||||
|
||||
class HwDeviceId : public NonCopyableClass {
|
||||
public:
|
||||
HwDeviceId(DriverModelType driverModel) : driverModelType(driverModel) {
|
||||
}
|
||||
|
||||
virtual ~HwDeviceId() = default;
|
||||
|
||||
DriverModelType getDriverModelType() const {
|
||||
return driverModelType;
|
||||
}
|
||||
|
||||
template <typename DerivedType>
|
||||
DerivedType *as() {
|
||||
UNRECOVERABLE_IF(DerivedType::driverModelType != this->driverModelType);
|
||||
return static_cast<DerivedType *>(this);
|
||||
}
|
||||
|
||||
template <typename DerivedType>
|
||||
DerivedType *as() const {
|
||||
UNRECOVERABLE_IF(DerivedType::driverModelType != this->driverModelType);
|
||||
return static_cast<const DerivedType *>(this);
|
||||
}
|
||||
|
||||
protected:
|
||||
DriverModelType driverModelType;
|
||||
};
|
||||
|
||||
class DriverModel : public NonCopyableClass {
|
||||
public:
|
||||
DriverModel(DriverModelType driverModelType)
|
||||
: driverModelType(driverModelType) {
|
||||
}
|
||||
|
||||
virtual ~DriverModel() = default;
|
||||
|
||||
template <typename DerivedType>
|
||||
DerivedType *as() {
|
||||
UNRECOVERABLE_IF(DerivedType::driverModelType != this->driverModelType);
|
||||
@@ -46,8 +74,6 @@ class DriverModel : public NonCopyableClass {
|
||||
return driverModelType;
|
||||
}
|
||||
|
||||
virtual ~DriverModel() = default;
|
||||
|
||||
protected:
|
||||
DriverModelType driverModelType;
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "shared/source/helpers/non_copyable_or_moveable.h"
|
||||
#include "shared/source/os_interface/os_interface.h"
|
||||
#include "shared/source/os_interface/windows/wddm/um_km_data_translator.h"
|
||||
#include "shared/source/os_interface/windows/windows_wrapper.h"
|
||||
|
||||
@@ -17,9 +17,11 @@
|
||||
namespace NEO {
|
||||
class Gdi;
|
||||
struct OsEnvironment;
|
||||
class HwDeviceId : NonCopyableClass {
|
||||
class HwDeviceIdWddm : public HwDeviceId {
|
||||
public:
|
||||
HwDeviceId(D3DKMT_HANDLE adapterIn, LUID adapterLuidIn, OsEnvironment *osEnvironmentIn, std::unique_ptr<UmKmDataTranslator> umKmDataTranslator);
|
||||
static constexpr DriverModelType driverModelType = DriverModelType::WDDM;
|
||||
|
||||
HwDeviceIdWddm(D3DKMT_HANDLE adapterIn, LUID adapterLuidIn, OsEnvironment *osEnvironmentIn, std::unique_ptr<UmKmDataTranslator> umKmDataTranslator);
|
||||
Gdi *getGdi() const;
|
||||
constexpr D3DKMT_HANDLE getAdapter() const {
|
||||
return adapter;
|
||||
@@ -27,7 +29,7 @@ class HwDeviceId : NonCopyableClass {
|
||||
constexpr LUID getAdapterLuid() const {
|
||||
return adapterLuid;
|
||||
}
|
||||
~HwDeviceId();
|
||||
~HwDeviceIdWddm() override;
|
||||
|
||||
UmKmDataTranslator *getUmKmDataTranslator() {
|
||||
return umKmDataTranslator.get();
|
||||
|
||||
@@ -11,18 +11,19 @@
|
||||
#include "shared/source/os_interface/windows/os_environment_win.h"
|
||||
namespace NEO {
|
||||
|
||||
HwDeviceId::~HwDeviceId() {
|
||||
HwDeviceIdWddm::~HwDeviceIdWddm() {
|
||||
NTSTATUS status = STATUS_UNSUCCESSFUL;
|
||||
D3DKMT_CLOSEADAPTER CloseAdapter = {0};
|
||||
CloseAdapter.hAdapter = adapter;
|
||||
status = static_cast<OsEnvironmentWin *>(osEnvironment)->gdi->closeAdapter(&CloseAdapter);
|
||||
DEBUG_BREAK_IF(status != STATUS_SUCCESS);
|
||||
}
|
||||
HwDeviceId::HwDeviceId(D3DKMT_HANDLE adapterIn, LUID adapterLuidIn,
|
||||
OsEnvironment *osEnvironmentIn, std::unique_ptr<UmKmDataTranslator> umKmDataTranslator)
|
||||
: adapter(adapterIn), adapterLuid(adapterLuidIn), osEnvironment(osEnvironmentIn),
|
||||
HwDeviceIdWddm::HwDeviceIdWddm(D3DKMT_HANDLE adapterIn, LUID adapterLuidIn,
|
||||
OsEnvironment *osEnvironmentIn, std::unique_ptr<UmKmDataTranslator> umKmDataTranslator)
|
||||
: HwDeviceId(DriverModelType::WDDM),
|
||||
adapter(adapterIn), adapterLuid(adapterLuidIn), osEnvironment(osEnvironmentIn),
|
||||
umKmDataTranslator(std::move(umKmDataTranslator)) {}
|
||||
Gdi *HwDeviceId::getGdi() const {
|
||||
Gdi *HwDeviceIdWddm::getGdi() const {
|
||||
return static_cast<OsEnvironmentWin *>(osEnvironment)->gdi.get();
|
||||
};
|
||||
} // namespace NEO
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2021 Intel Corporation
|
||||
* Copyright (C) 2020-2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
|
||||
@@ -23,7 +23,9 @@ bool OSInterface::isDebugAttachAvailable() const {
|
||||
}
|
||||
|
||||
bool RootDeviceEnvironment::initOsInterface(std::unique_ptr<HwDeviceId> &&hwDeviceId, uint32_t rootDeviceIndex) {
|
||||
auto wddm(Wddm::createWddm(std::move(hwDeviceId), *this));
|
||||
UNRECOVERABLE_IF(hwDeviceId->getDriverModelType() != DriverModelType::WDDM);
|
||||
auto hwDeviceIdWddm = std::unique_ptr<HwDeviceIdWddm>(reinterpret_cast<HwDeviceIdWddm *>(hwDeviceId.release()));
|
||||
auto wddm(Wddm::createWddm(std::move(hwDeviceIdWddm), *this));
|
||||
if (!wddm->init()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
#include "shared/source/debug_settings/debug_settings_manager.h"
|
||||
#include "shared/source/helpers/debug_helpers.h"
|
||||
#include "shared/source/os_interface/os_library.h"
|
||||
#include "shared/source/os_interface/windows/gdi_interface.h"
|
||||
#include "shared/source/os_interface/windows/os_library_win.h"
|
||||
#include "shared/source/utilities/stackvec.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
@@ -59,7 +59,7 @@ Wddm::GetSystemInfoFcn Wddm::getSystemInfo = getGetSystemInfo();
|
||||
Wddm::VirtualAllocFcn Wddm::virtualAllocFnc = getVirtualAlloc();
|
||||
Wddm::VirtualFreeFcn Wddm::virtualFreeFnc = getVirtualFree();
|
||||
|
||||
Wddm::Wddm(std::unique_ptr<HwDeviceId> hwDeviceIdIn, RootDeviceEnvironment &rootDeviceEnvironment)
|
||||
Wddm::Wddm(std::unique_ptr<HwDeviceIdWddm> hwDeviceIdIn, RootDeviceEnvironment &rootDeviceEnvironment)
|
||||
: DriverModel(DriverModelType::WDDM), hwDeviceId(std::move(hwDeviceIdIn)), rootDeviceEnvironment(rootDeviceEnvironment) {
|
||||
UNRECOVERABLE_IF(!hwDeviceId);
|
||||
featureTable.reset(new FeatureTable());
|
||||
@@ -264,7 +264,7 @@ bool validDriverStorePath(OsEnvironmentWin &osEnvironment, D3DKMT_HANDLE adapter
|
||||
return isCompatibleDriverStore(std::move(deviceRegistryPath));
|
||||
}
|
||||
|
||||
std::unique_ptr<HwDeviceId> createHwDeviceIdFromAdapterLuid(OsEnvironmentWin &osEnvironment, LUID adapterLuid) {
|
||||
std::unique_ptr<HwDeviceIdWddm> createHwDeviceIdFromAdapterLuid(OsEnvironmentWin &osEnvironment, LUID adapterLuid) {
|
||||
D3DKMT_OPENADAPTERFROMLUID OpenAdapterData = {{0}};
|
||||
OpenAdapterData.AdapterLuid = adapterLuid;
|
||||
auto status = osEnvironment.gdi->openAdapterFromLuid(&OpenAdapterData);
|
||||
@@ -295,7 +295,7 @@ std::unique_ptr<HwDeviceId> createHwDeviceIdFromAdapterLuid(OsEnvironmentWin &os
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return std::make_unique<HwDeviceId>(OpenAdapterData.hAdapter, adapterLuid, &osEnvironment, std::move(umKmDataTranslator));
|
||||
return std::make_unique<HwDeviceIdWddm>(OpenAdapterData.hAdapter, adapterLuid, &osEnvironment, std::move(umKmDataTranslator));
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<HwDeviceId>> OSInterface::discoverDevices(ExecutionEnvironment &executionEnvironment) {
|
||||
@@ -347,7 +347,7 @@ std::vector<std::unique_ptr<HwDeviceId>> OSInterface::discoverDevices(ExecutionE
|
||||
|
||||
auto hwDeviceId = createHwDeviceIdFromAdapterLuid(*osEnvironment, adapterDesc.luid);
|
||||
if (hwDeviceId) {
|
||||
hwDeviceIds.push_back(std::move(hwDeviceId));
|
||||
hwDeviceIds.push_back(std::unique_ptr<HwDeviceId>(hwDeviceId.release()));
|
||||
}
|
||||
|
||||
if (hwDeviceIds.size() == numRootDevices) {
|
||||
@@ -600,7 +600,7 @@ NTSTATUS Wddm::createAllocationsAndMapGpuVa(OsHandleStorage &osHandles) {
|
||||
}
|
||||
|
||||
auto osHandle = static_cast<OsHandleWin *>(osHandles.fragmentStorageData[i].osHandleStorage);
|
||||
if (osHandle->handle == (D3DKMT_HANDLE) nullptr && osHandles.fragmentStorageData[i].fragmentSize) {
|
||||
if ((osHandle->handle == (D3DKMT_HANDLE)0) && (osHandles.fragmentStorageData[i].fragmentSize)) {
|
||||
AllocationInfo[allocationCount].pPrivateDriverData = osHandle->gmm->gmmResourceInfo->peekHandle();
|
||||
[[maybe_unused]] auto pSysMem = osHandles.fragmentStorageData[i].cpuPtr;
|
||||
[[maybe_unused]] auto PSysMemFromGmm = osHandle->gmm->gmmResourceInfo->getSystemMemPointer();
|
||||
|
||||
@@ -56,7 +56,7 @@ class Wddm : public DriverModel {
|
||||
|
||||
virtual ~Wddm();
|
||||
|
||||
static Wddm *createWddm(std::unique_ptr<HwDeviceId> hwDeviceId, RootDeviceEnvironment &rootDeviceEnvironment);
|
||||
static Wddm *createWddm(std::unique_ptr<HwDeviceIdWddm> hwDeviceId, RootDeviceEnvironment &rootDeviceEnvironment);
|
||||
bool init();
|
||||
|
||||
MOCKABLE_VIRTUAL bool evict(const D3DKMT_HANDLE *handleList, uint32_t numOfHandles, uint64_t &sizeToTrim);
|
||||
@@ -121,7 +121,7 @@ class Wddm : public DriverModel {
|
||||
|
||||
uint64_t getMaxApplicationAddress() const;
|
||||
|
||||
HwDeviceId *getHwDeviceId() const {
|
||||
HwDeviceIdWddm *getHwDeviceId() const {
|
||||
return hwDeviceId.get();
|
||||
}
|
||||
D3DKMT_HANDLE getAdapter() const { return hwDeviceId->getAdapter(); }
|
||||
@@ -179,7 +179,7 @@ class Wddm : public DriverModel {
|
||||
PhysicalDevicePciBusInfo getPciBusInfo() const;
|
||||
|
||||
protected:
|
||||
std::unique_ptr<HwDeviceId> hwDeviceId;
|
||||
std::unique_ptr<HwDeviceIdWddm> hwDeviceId;
|
||||
D3DKMT_HANDLE device = 0;
|
||||
D3DKMT_HANDLE pagingQueue = 0;
|
||||
D3DKMT_HANDLE pagingQueueSyncObject = 0;
|
||||
@@ -207,7 +207,7 @@ class Wddm : public DriverModel {
|
||||
std::unique_ptr<GmmMemory> gmmMemory;
|
||||
uintptr_t minAddress = 0;
|
||||
|
||||
Wddm(std::unique_ptr<HwDeviceId> hwDeviceId, RootDeviceEnvironment &rootDeviceEnvironment);
|
||||
Wddm(std::unique_ptr<HwDeviceIdWddm> hwDeviceId, RootDeviceEnvironment &rootDeviceEnvironment);
|
||||
MOCKABLE_VIRTUAL bool waitOnGPU(D3DKMT_HANDLE context);
|
||||
bool createDevice(PreemptionMode preemptionMode);
|
||||
bool createPagingQueue();
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "shared/source/os_interface/windows/wddm/wddm.h"
|
||||
|
||||
namespace NEO {
|
||||
Wddm *Wddm::createWddm(std::unique_ptr<HwDeviceId> hwDeviceId, RootDeviceEnvironment &rootDeviceEnvironment) {
|
||||
Wddm *Wddm::createWddm(std::unique_ptr<HwDeviceIdWddm> hwDeviceId, RootDeviceEnvironment &rootDeviceEnvironment) {
|
||||
return new Wddm(std::move(hwDeviceId), rootDeviceEnvironment);
|
||||
}
|
||||
} // namespace NEO
|
||||
|
||||
Reference in New Issue
Block a user