Support enumerating graphics adapters based on a given GPU preference (#217)
Thanks!
This commit is contained in:
Родитель
09f0262813
Коммит
1e6b2d8723
|
@ -12,8 +12,22 @@
|
|||
using namespace pydml;
|
||||
using Microsoft::WRL::ComPtr;
|
||||
|
||||
Device::Device(bool useGpu, bool useDebugLayer) :
|
||||
m_useGpu(useGpu)
|
||||
// An adapter called the "Microsoft Basic Render Driver" is always present. This adapter is a render-only device that has no display outputs.
|
||||
HRESULT IsWarpAdapter(IDXGIAdapter1* pAdapter, bool* isWarpAdapter)
|
||||
{
|
||||
DXGI_ADAPTER_DESC1 pDesc;
|
||||
ReturnIfFailed(pAdapter->GetDesc1(&pDesc));
|
||||
// see here for documentation on filtering WARP adapter:
|
||||
// https://docs.microsoft.com/en-us/windows/desktop/direct3ddxgi/d3d10-graphics-programming-guide-dxgi#new-info-about-enumerating-adapters-for-windows-8
|
||||
auto isBasicRenderDriverVendorId = pDesc.VendorId == 0x1414;
|
||||
auto isBasicRenderDriverDeviceId = pDesc.DeviceId == 0x8c;
|
||||
auto isSoftwareAdapter = pDesc.Flags == DXGI_ADAPTER_FLAG_SOFTWARE;
|
||||
*isWarpAdapter = isSoftwareAdapter || (isBasicRenderDriverVendorId && isBasicRenderDriverDeviceId);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
Device::Device(bool useGpu, bool useDebugLayer, DXGI_GPU_PREFERENCE gpuPreference) :
|
||||
m_useGpu(useGpu), m_gpuPreference(gpuPreference)
|
||||
{
|
||||
//
|
||||
// Create D3D12 resources
|
||||
|
@ -28,9 +42,26 @@ Device::Device(bool useGpu, bool useDebugLayer) :
|
|||
}
|
||||
}
|
||||
|
||||
ComPtr<IDXGIAdapter> dxgiAdapter;
|
||||
ComPtr<IDXGIAdapter1> dxgiAdapter;
|
||||
if (m_useGpu)
|
||||
{
|
||||
ComPtr<IDXGIFactory6> spFactory;
|
||||
ReturnIfFailed(CreateDXGIFactory1(IID_PPV_ARGS(&spFactory)));
|
||||
UINT i = 0;
|
||||
while (spFactory->EnumAdapterByGpuPreference(i, m_gpuPreference, IID_PPV_ARGS(&dxgiAdapter)) != DXGI_ERROR_NOT_FOUND)
|
||||
{
|
||||
bool isWarpAdapter = false;
|
||||
ReturnIfFailed(IsWarpAdapter(dxgiAdapter.Get(), &isWarpAdapter));
|
||||
if (!isWarpAdapter)
|
||||
{
|
||||
break;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !useGpu
|
||||
|| FAILED(D3D12CreateDevice(nullptr, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&m_d3d12Device))))
|
||||
|| FAILED(D3D12CreateDevice(dxgiAdapter.Get(), D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&m_d3d12Device))))
|
||||
{
|
||||
ComPtr<IDXGIFactory4> dxgiFactory;
|
||||
ThrowIfFailed(CreateDXGIFactory1(IID_PPV_ARGS(&dxgiFactory)));
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace pydml
|
|||
class Device
|
||||
{
|
||||
public:
|
||||
explicit Device(bool useGpu = true, bool useDebugLayer = false);
|
||||
explicit Device(bool useGpu = true, bool useDebugLayer = false, DXGI_GPU_PREFERENCE gpuPreference = DXGI_GPU_PREFERENCE_UNSPECIFIED);
|
||||
|
||||
std::vector<pydml::TensorData*> Compute(
|
||||
IDMLCompiledOperator* op,
|
||||
|
@ -108,5 +108,6 @@ namespace pydml
|
|||
|
||||
bool m_useCpuCustomHeapResources = false;
|
||||
bool m_useGpu = true;
|
||||
DXGI_GPU_PREFERENCE m_gpuPreference;
|
||||
};
|
||||
}
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
// ToDo: dxgi isn't available in WSL.
|
||||
#include <dxgi1_5.h>
|
||||
#include <dxgi1_6.h>
|
||||
#include <dxgidebug.h>
|
||||
|
||||
#include <initguid.h>
|
||||
|
|
Загрузка…
Ссылка в новой задаче