Skip to content

Commit

Permalink
Added supported device selection logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Devaniti committed Dec 17, 2022
1 parent 7f50c39 commit 279c14e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 59 deletions.
63 changes: 49 additions & 14 deletions D3D12Backend/APIWrappers/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace Boolka

Device::Device()
: m_Device(nullptr)
, m_Adapter(nullptr)
{
}

Expand Down Expand Up @@ -68,24 +69,12 @@ namespace Boolka

BLK_CPU_SCOPE("Device::Initialize");

DebugProfileTimer timer;
timer.Start();
HRESULT hr = ::D3D12CreateDevice(nullptr, D3D_FEATURE_LEVEL_12_0, IID_PPV_ARGS(&m_Device));
timer.Stop(L"D3D12CreateDevice");

if (FAILED(hr))
{
::MessageBoxW(0, L"DirectX 12.0 Feature Level 12_0 required",
L"GPU and/or driver unsupported", MB_OK | MB_ICONERROR);
BLK_CRITICAL_DEBUG_BREAK();
if (!SelectAndCreateDevice(factory))
return false;
}

BLK_RENDER_PROFILING_ONLY(InitializeProfiling());
BLK_RENDER_DEBUG_ONLY(InitializeDebug());

if (!m_FeatureSupportHelper.Initialize(*this))
return false;
if (!m_DStorageFactory.Initialize())
return false;
if (!m_GraphicQueue.Initialize(*this))
Expand All @@ -109,7 +98,6 @@ namespace Boolka
m_ComputeQueue.Unload();
m_GraphicQueue.Unload();
m_DStorageFactory.Unload();
m_FeatureSupportHelper.Unload();

BLK_RENDER_DEBUG_ONLY(ReportObjectLeaks());

Expand Down Expand Up @@ -150,6 +138,53 @@ namespace Boolka
}
}

bool Device::SelectAndCreateDevice(Factory& factory)
{
UINT i = 0;
while (true)
{
IDXGIAdapter4* adapter = nullptr;
HRESULT hr = factory->EnumAdapterByGpuPreference(
i, DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE, IID_PPV_ARGS(&adapter));

if (hr == DXGI_ERROR_NOT_FOUND)
break;

BLK_ASSERT(SUCCEEDED(hr));

ID3D12Device6* device = nullptr;

DebugProfileTimer timer;
timer.Start();
hr = ::D3D12CreateDevice(adapter, D3D_FEATURE_LEVEL_12_0, IID_PPV_ARGS(&device));
timer.Stop(L"D3D12CreateDevice");

if (FAILED(hr))
{
adapter->Release();
continue;
}

if (!FeatureSupportHelper::IsSupported(device))
{
adapter->Release();
device->Release();
continue;
}

m_Adapter = adapter;
m_Device = device;
return true;
}

::MessageBoxW(0,
L"No supported GPUs found.\nRequired features are:\nResource Binding Tier 3\n"
L"Shader Model 6.5\nRaytracing Tier 1.0\nMesh Shaders",
L"GPU and/or driver unsupported", MB_OK | MB_ICONERROR);
BLK_CRITICAL_DEBUG_BREAK();
return false;
}

#ifdef BLK_RENDER_PROFILING
void Device::InitializeProfiling()
{
Expand Down
3 changes: 2 additions & 1 deletion D3D12Backend/APIWrappers/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace Boolka
void RemoveLastMessageFilter();
#endif
private:
bool SelectAndCreateDevice(Factory& factory);
#ifdef BLK_RENDER_PROFILING
void InitializeProfiling();
#endif
Expand All @@ -50,6 +51,7 @@ namespace Boolka
void ReportObjectLeaks();
#endif

IDXGIAdapter4* m_Adapter;
ID3D12Device6* m_Device;

DStorageFactory m_DStorageFactory;
Expand All @@ -58,7 +60,6 @@ namespace Boolka
ComputeQueue m_ComputeQueue;
CopyQueue m_CopyQueue;
DStorageQueue m_DStorageQueue;
FeatureSupportHelper m_FeatureSupportHelper;
};

} // namespace Boolka
43 changes: 4 additions & 39 deletions D3D12Backend/FeatureSupportHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,13 @@
namespace Boolka
{

FeatureSupportHelper::FeatureSupportHelper()
bool FeatureSupportHelper::IsSupported(ID3D12Device* device)
{
}

FeatureSupportHelper::~FeatureSupportHelper()
{
}

bool FeatureSupportHelper::Initialize(Device& device)
{
D3D12_FEATURE_DATA_SHADER_CACHE shaderCache{};
HRESULT hr = device->CheckFeatureSupport(D3D12_FEATURE_SHADER_CACHE, &shaderCache,
sizeof(shaderCache));
if (FAILED(hr) || ((shaderCache.SupportFlags & D3D12_SHADER_CACHE_SUPPORT_LIBRARY) == 0))
{
::MessageBoxW(0, L"ID3D12PipelineLibrary support required",
L"GPU and/or driver unsupported", MB_OK | MB_ICONERROR);
BLK_CRITICAL_DEBUG_BREAK();
return false;
}

D3D12_FEATURE_DATA_D3D12_OPTIONS options{};
hr = device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS, &options, sizeof(options));
HRESULT hr =
device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS, &options, sizeof(options));
if (FAILED(hr) || options.ResourceBindingTier < D3D12_RESOURCE_BINDING_TIER_3)
{
::MessageBoxW(0, L"Resource Binding Tier 3 Required", L"GPU and/or driver unsupported",
MB_OK | MB_ICONERROR);
BLK_CRITICAL_DEBUG_BREAK();
return false;
}

Expand All @@ -43,37 +22,23 @@ namespace Boolka
sizeof(shaderModel));
if (FAILED(hr) || shaderModel.HighestShaderModel < D3D_SHADER_MODEL_6_5)
{
::MessageBoxW(0, L"Shader Model 6.5 Required", L"GPU and/or driver unsupported",
MB_OK | MB_ICONERROR);
BLK_CRITICAL_DEBUG_BREAK();
return false;
}

D3D12_FEATURE_DATA_D3D12_OPTIONS5 options5{};
hr = device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS5, &options5, sizeof(options5));
if (FAILED(hr) || options5.RaytracingTier < D3D12_RAYTRACING_TIER_1_0)
{
::MessageBoxW(0, L"Raytracing Tier 1.0 Required", L"GPU and/or driver unsupported",
MB_OK | MB_ICONERROR);
BLK_CRITICAL_DEBUG_BREAK();
return false;
}

D3D12_FEATURE_DATA_D3D12_OPTIONS7 options7{};
hr = device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS7, &options7, sizeof(options7));
if (FAILED(hr) || options7.MeshShaderTier == D3D12_MESH_SHADER_TIER_NOT_SUPPORTED)
if (FAILED(hr) || options7.MeshShaderTier < D3D12_MESH_SHADER_TIER_1)
{
::MessageBoxW(0, L"Mesh Shaders Required", L"GPU and/or driver unsupported",
MB_OK | MB_ICONERROR);
BLK_CRITICAL_DEBUG_BREAK();
return false;
}

return true;
}

void FeatureSupportHelper::Unload()
{
}

} // namespace Boolka
6 changes: 1 addition & 5 deletions D3D12Backend/FeatureSupportHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ namespace Boolka
class FeatureSupportHelper
{
public:
FeatureSupportHelper();
~FeatureSupportHelper();

bool Initialize(Device& device);
void Unload();
[[nodiscard]] static bool IsSupported(ID3D12Device* device);
};

} // namespace Boolka

0 comments on commit 279c14e

Please sign in to comment.