From 31443aba7aeee91f553cd3d440bb971e51f90974 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Thu, 17 Oct 2019 09:41:00 -0700 Subject: Updated d3d backend initialization + d3d shader model selection --- .../GraphicsEngineD3D12/src/EngineFactoryD3D12.cpp | 11 +++++---- .../src/RenderDeviceD3D12Impl.cpp | 8 +++++-- .../GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp | 26 +++++----------------- 3 files changed, 18 insertions(+), 27 deletions(-) (limited to 'Graphics/GraphicsEngineD3D12') diff --git a/Graphics/GraphicsEngineD3D12/src/EngineFactoryD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/EngineFactoryD3D12.cpp index 0c91b8c9..fcb73975 100644 --- a/Graphics/GraphicsEngineD3D12/src/EngineFactoryD3D12.cpp +++ b/Graphics/GraphicsEngineD3D12/src/EngineFactoryD3D12.cpp @@ -153,16 +153,19 @@ void EngineFactoryD3D12Impl::CreateDeviceAndContextsD3D12(const EngineD3D12Creat HRESULT hr = CreateDXGIFactory1(__uuidof(factory), reinterpret_cast(static_cast(&factory)) ); CHECK_D3D_RESULT_THROW(hr, "Failed to create DXGI factory"); + // Direct3D12 does not support feature levels below 11.0 + const auto MinimumFeatureLevel = EngineCI.MinimumFeatureLevel >= DIRECT3D_FEATURE_LEVEL_11_0 ? EngineCI.MinimumFeatureLevel : DIRECT3D_FEATURE_LEVEL_11_0; + CComPtr hardwareAdapter; if(EngineCI.AdapterId == EngineD3D12CreateInfo::DefaultAdapterId) { - GetHardwareAdapter(factory, &hardwareAdapter, GetD3DFeatureLevel(EngineCI.MinimumFeatureLevel)); + GetHardwareAdapter(factory, &hardwareAdapter, GetD3DFeatureLevel(MinimumFeatureLevel)); if(hardwareAdapter == nullptr) LOG_ERROR_AND_THROW("No suitable hardware adapter found"); } else { - auto Adapters = FindCompatibleAdapters(EngineCI.MinimumFeatureLevel); + auto Adapters = FindCompatibleAdapters(MinimumFeatureLevel); if(EngineCI.AdapterId < Adapters.size()) hardwareAdapter = Adapters[EngineCI.AdapterId]; else @@ -178,7 +181,7 @@ void EngineFactoryD3D12Impl::CreateDeviceAndContextsD3D12(const EngineD3D12Creat } constexpr auto MaxFeatureLevel = DIRECT3D_FEATURE_LEVEL_12_1; - for (auto FeatureLevel = MaxFeatureLevel; FeatureLevel >= EngineCI.MinimumFeatureLevel; FeatureLevel = static_cast(Uint8{FeatureLevel}-1)) + for (auto FeatureLevel = MaxFeatureLevel; FeatureLevel >= MinimumFeatureLevel; FeatureLevel = static_cast(Uint8{FeatureLevel}-1)) { auto d3dFeatureLevel = GetD3DFeatureLevel(FeatureLevel); hr = D3D12CreateDevice(hardwareAdapter, d3dFeatureLevel, __uuidof(d3d12Device), reinterpret_cast(static_cast(&d3d12Device)) ); @@ -196,7 +199,7 @@ void EngineFactoryD3D12Impl::CreateDeviceAndContextsD3D12(const EngineD3D12Creat hr = factory->EnumWarpAdapter( __uuidof(warpAdapter), reinterpret_cast(static_cast(&warpAdapter)) ); CHECK_D3D_RESULT_THROW(hr, "Failed to enum warp adapter"); - for (auto FeatureLevel = MaxFeatureLevel; FeatureLevel >= EngineCI.MinimumFeatureLevel; FeatureLevel = static_cast(Uint8{FeatureLevel}-1)) + for (auto FeatureLevel = MaxFeatureLevel; FeatureLevel >= MinimumFeatureLevel; FeatureLevel = static_cast(Uint8{FeatureLevel}-1)) { auto d3dFeatureLevel = GetD3DFeatureLevel(FeatureLevel); hr = D3D12CreateDevice( warpAdapter, d3dFeatureLevel, __uuidof(d3d12Device), reinterpret_cast(static_cast(&d3d12Device)) ); diff --git a/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp index 27f37dc0..adb16b36 100644 --- a/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp @@ -117,7 +117,6 @@ RenderDeviceD3D12Impl :: RenderDeviceD3D12Impl(IReferenceCounters* pRe case D3D_FEATURE_LEVEL_11_1: m_DeviceCaps.MajorVersion = 11; m_DeviceCaps.MinorVersion = FeatureLevel == D3D_FEATURE_LEVEL_11_1 ? 1 : 0; - m_DeviceCaps.bBindlessSupported = FeatureLevel == D3D_FEATURE_LEVEL_11_1; break; case D3D_FEATURE_LEVEL_10_0: @@ -129,8 +128,13 @@ RenderDeviceD3D12Impl :: RenderDeviceD3D12Impl(IReferenceCounters* pRe default: UNEXPECTED("Unexpected D3D feature level"); } - m_DeviceCaps.bSeparableProgramSupported = True; + m_DeviceCaps.bSeparableProgramSupported = True; m_DeviceCaps.bMultithreadedResourceCreationSupported = True; + + // Direct3D12 supports shader model 5.1 on all feature levels (even on 11.0), + // so bindless resources are always available. + // https://docs.microsoft.com/en-us/windows/win32/direct3d12/hardware-feature-levels#feature-level-support + m_DeviceCaps.bBindlessSupported = True; } RenderDeviceD3D12Impl::~RenderDeviceD3D12Impl() diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp index c189bf3e..f6dfb74d 100644 --- a/Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp @@ -32,29 +32,13 @@ namespace Diligent { -static const char* GetD3D12ShaderModel(RenderDeviceD3D12Impl* pDevice) +static const char* GetD3D12ShaderModel(RenderDeviceD3D12Impl* /*pDevice*/) { - auto d3dDeviceFeatureLevel = pDevice->GetD3DFeatureLevel(); - switch(d3dDeviceFeatureLevel) - { - case D3D_FEATURE_LEVEL_12_1: - case D3D_FEATURE_LEVEL_12_0: - case D3D_FEATURE_LEVEL_11_1: - return "5_1"; - - case D3D_FEATURE_LEVEL_11_0: - return "5_0"; - - case D3D_FEATURE_LEVEL_10_1: - return "4_1"; + //auto d3dDeviceFeatureLevel = pDevice->GetD3DFeatureLevel(); - case D3D_FEATURE_LEVEL_10_0: - return "4_0"; - - default: - UNEXPECTED("Unexpected D3D feature level ", static_cast(d3dDeviceFeatureLevel)); - return "4_0"; - } + // Direct3D12 supports shader model 5.1 on all feature levels. + // https://docs.microsoft.com/en-us/windows/win32/direct3d12/hardware-feature-levels#feature-level-support + return "5_1"; } ShaderD3D12Impl::ShaderD3D12Impl(IReferenceCounters* pRefCounters, -- cgit v1.2.3