mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00

Signed-off-by: Krystian Chmielewski <krystian.chmielewski@intel.com> Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
153 lines
4.1 KiB
C++
153 lines
4.1 KiB
C++
/*
|
|
* Copyright (C) 2021 Intel Corporation
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
// clang-format off
|
|
#include <initguid.h>
|
|
#include <dxcore.h>
|
|
#include <dxgi.h>
|
|
// clang-format on
|
|
|
|
#include <string>
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
typedef unsigned int D3DKMT_HANDLE;
|
|
|
|
namespace NEO {
|
|
|
|
class Gdi;
|
|
class OsLibrary;
|
|
|
|
std::wstring queryAdapterDriverStorePath(const Gdi &gdi, D3DKMT_HANDLE adapter);
|
|
|
|
bool canUseAdapterBasedOnDriverDesc(const char *driverDescription);
|
|
|
|
bool isAllowedDeviceId(uint32_t deviceId);
|
|
|
|
class AdapterFactory {
|
|
public:
|
|
using CreateAdapterFactoryFcn = HRESULT(WINAPI *)(REFIID riid, void **ppFactory);
|
|
|
|
struct AdapterDesc {
|
|
enum class Type {
|
|
Unknown,
|
|
Hardware,
|
|
NotHardware
|
|
};
|
|
|
|
Type type = Type::Unknown;
|
|
std::string driverDescription;
|
|
uint32_t deviceId = {};
|
|
LUID luid = {};
|
|
};
|
|
|
|
virtual ~AdapterFactory() = default;
|
|
|
|
virtual bool createSnapshotOfAvailableAdapters() = 0;
|
|
virtual uint32_t getNumAdaptersInSnapshot() = 0;
|
|
virtual bool getAdapterDesc(uint32_t ordinal, AdapterDesc &outAdapter) = 0;
|
|
virtual bool isSupported() = 0;
|
|
};
|
|
|
|
class DxCoreAdapterFactory : public AdapterFactory {
|
|
public:
|
|
DxCoreAdapterFactory(AdapterFactory::CreateAdapterFactoryFcn createAdapterFactoryFcn);
|
|
|
|
~DxCoreAdapterFactory() override;
|
|
|
|
bool createSnapshotOfAvailableAdapters() override;
|
|
|
|
bool isSupported() {
|
|
return nullptr != adapterFactory;
|
|
}
|
|
|
|
uint32_t getNumAdaptersInSnapshot() override;
|
|
|
|
bool getAdapterDesc(uint32_t ordinal, AdapterDesc &outAdapter) override;
|
|
|
|
protected:
|
|
void destroyCurrentSnapshot();
|
|
|
|
AdapterFactory::CreateAdapterFactoryFcn createAdapterFactoryFcn = nullptr;
|
|
IDXCoreAdapterFactory *adapterFactory = nullptr;
|
|
IDXCoreAdapterList *adaptersInSnapshot = nullptr;
|
|
};
|
|
|
|
class DxgiAdapterFactory : public AdapterFactory {
|
|
public:
|
|
DxgiAdapterFactory(AdapterFactory::CreateAdapterFactoryFcn createAdapterFactoryFcn);
|
|
|
|
~DxgiAdapterFactory() override {
|
|
destroyCurrentSnapshot();
|
|
if (adapterFactory) {
|
|
adapterFactory->Release();
|
|
}
|
|
}
|
|
|
|
bool createSnapshotOfAvailableAdapters() override;
|
|
|
|
bool isSupported() {
|
|
return nullptr != adapterFactory;
|
|
}
|
|
|
|
uint32_t getNumAdaptersInSnapshot() {
|
|
return static_cast<uint32_t>(adaptersInSnapshot.size());
|
|
}
|
|
|
|
bool getAdapterDesc(uint32_t ordinal, AdapterDesc &outAdapter) override;
|
|
|
|
protected:
|
|
void destroyCurrentSnapshot() {
|
|
adaptersInSnapshot.clear();
|
|
}
|
|
|
|
AdapterFactory::CreateAdapterFactoryFcn createAdapterFactoryFcn = nullptr;
|
|
IDXGIFactory1 *adapterFactory = nullptr;
|
|
std::vector<AdapterDesc> adaptersInSnapshot;
|
|
};
|
|
|
|
class WddmAdapterFactory : public AdapterFactory {
|
|
public:
|
|
WddmAdapterFactory(AdapterFactory::CreateAdapterFactoryFcn dxCoreCreateAdapterFactoryF,
|
|
AdapterFactory::CreateAdapterFactoryFcn dxgiCreateAdapterFactoryF) {
|
|
if (nullptr == dxCoreCreateAdapterFactoryF) {
|
|
loadDxCore(dxCoreCreateAdapterFactoryF);
|
|
}
|
|
underlyingFactory = std::make_unique<DxCoreAdapterFactory>(dxCoreCreateAdapterFactoryF);
|
|
if (false == underlyingFactory->isSupported()) {
|
|
underlyingFactory = std::make_unique<DxgiAdapterFactory>(dxgiCreateAdapterFactoryF);
|
|
}
|
|
}
|
|
|
|
~WddmAdapterFactory() override = default;
|
|
|
|
bool createSnapshotOfAvailableAdapters() override {
|
|
return underlyingFactory->createSnapshotOfAvailableAdapters();
|
|
}
|
|
|
|
bool isSupported() override {
|
|
return underlyingFactory->isSupported();
|
|
}
|
|
|
|
uint32_t getNumAdaptersInSnapshot() override {
|
|
return underlyingFactory->getNumAdaptersInSnapshot();
|
|
}
|
|
|
|
bool getAdapterDesc(uint32_t ordinal, AdapterDesc &outAdapter) override {
|
|
return underlyingFactory->getAdapterDesc(ordinal, outAdapter);
|
|
}
|
|
|
|
protected:
|
|
std::unique_ptr<AdapterFactory> underlyingFactory;
|
|
std::unique_ptr<OsLibrary> dxCoreLibrary;
|
|
|
|
void loadDxCore(DxCoreAdapterFactory::CreateAdapterFactoryFcn &outDxCoreCreateAdapterFactoryF);
|
|
};
|
|
} // namespace NEO
|