summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineD3D12
diff options
context:
space:
mode:
authorazhirnov <zh1dron@gmail.com>2020-09-09 09:25:47 +0000
committerazhirnov <zh1dron@gmail.com>2020-09-09 15:56:51 +0000
commit381f66352dfaefcdeaeba3c71183ad558bb70cd6 (patch)
treea18b2fa0763a310317f6926677d87d91666bf4b6 /Graphics/GraphicsEngineD3D12
parentMerge branch 'master' into mesh_shader (diff)
downloadDiligentCore-381f66352dfaefcdeaeba3c71183ad558bb70cd6.tar.gz
DiligentCore-381f66352dfaefcdeaeba3c71183ad558bb70cd6.zip
added IDxCompilerLibrary interface. DXCompilerBase moved to platform specific files
Diffstat (limited to 'Graphics/GraphicsEngineD3D12')
-rw-r--r--Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.hpp9
-rw-r--r--Graphics/GraphicsEngineD3D12/include/ShaderResourcesD3D12.hpp5
-rw-r--r--Graphics/GraphicsEngineD3D12/src/EngineFactoryD3D12.cpp3
-rw-r--r--Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp56
-rw-r--r--Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp30
-rw-r--r--Graphics/GraphicsEngineD3D12/src/ShaderResourcesD3D12.cpp11
6 files changed, 71 insertions, 43 deletions
diff --git a/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.hpp b/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.hpp
index b6cd4280..627b270d 100644
--- a/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.hpp
+++ b/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.hpp
@@ -40,6 +40,7 @@
#include "CommandQueueD3D12.h"
#include "GenerateMips.hpp"
#include "QueryManagerD3D12.hpp"
+#include "DXILUtils.hpp"
namespace Diligent
{
@@ -151,11 +152,13 @@ public:
const GenerateMipsHelper& GetMipsGenerator() const { return m_MipsGenerator; }
QueryManagerD3D12& GetQueryManager() { return m_QueryMgr; }
+ IDxCompilerLibrary* GetDxCompiler() const { return m_pDxCompiler.get(); }
+
#ifdef D12_H_HAS_MESH_SHADER
ID3D12Device2* GetD3D12Device2();
#endif
- D3D_SHADER_MODEL GetShaderModel() const;
+ ShaderVersion GetShaderModel() const;
D3D_FEATURE_LEVEL GetD3DFeatureLevel() const;
private:
@@ -188,6 +191,10 @@ private:
GenerateMipsHelper m_MipsGenerator;
QueryManagerD3D12 m_QueryMgr;
+
+ D3D_SHADER_MODEL m_ShaderModel = D3D_SHADER_MODEL_5_1;
+
+ std::unique_ptr<IDxCompilerLibrary> m_pDxCompiler;
};
} // namespace Diligent
diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderResourcesD3D12.hpp b/Graphics/GraphicsEngineD3D12/include/ShaderResourcesD3D12.hpp
index 23f9882b..b1c12f90 100644
--- a/Graphics/GraphicsEngineD3D12/include/ShaderResourcesD3D12.hpp
+++ b/Graphics/GraphicsEngineD3D12/include/ShaderResourcesD3D12.hpp
@@ -92,7 +92,10 @@ class ShaderResourcesD3D12 final : public ShaderResources
{
public:
// Loads shader resources from the compiled shader bytecode
- ShaderResourcesD3D12(ID3DBlob* pShaderBytecode, const ShaderDesc& ShdrDesc, const char* CombinedSamplerSuffix);
+ ShaderResourcesD3D12(ID3DBlob* pShaderBytecode,
+ const ShaderDesc& ShdrDesc,
+ const char* CombinedSamplerSuffix,
+ class RenderDeviceD3D12Impl* pRenderDeviceD3D12);
// clang-format off
ShaderResourcesD3D12 (const ShaderResourcesD3D12&) = delete;
diff --git a/Graphics/GraphicsEngineD3D12/src/EngineFactoryD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/EngineFactoryD3D12.cpp
index ac747d62..65991753 100644
--- a/Graphics/GraphicsEngineD3D12/src/EngineFactoryD3D12.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/EngineFactoryD3D12.cpp
@@ -42,7 +42,6 @@
#include "StringTools.hpp"
#include "EngineMemory.h"
#include "CommandQueueD3D12Impl.hpp"
-#include "DXILUtils.hpp"
#ifndef NOMINMAX
# define NOMINMAX
@@ -380,8 +379,6 @@ void EngineFactoryD3D12Impl::CreateDeviceAndContextsD3D12(const EngineD3D12Creat
std::array<ICommandQueueD3D12*, 1> CmdQueues = {pCmdQueueD3D12};
AttachToD3D12Device(d3d12Device, CmdQueues.size(), CmdQueues.data(), EngineCI, ppDevice, ppContexts);
-
- DxcLoadLibrary(DXCompilerTarget::Direct3D12, EngineCI.pDxCompilerPath);
}
diff --git a/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp
index 445458e2..ea4d62a8 100644
--- a/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp
@@ -65,29 +65,9 @@ static CComPtr<IDXGIAdapter1> DXGIAdapterFromD3D12Device(ID3D12Device* pd3d12Dev
return nullptr;
}
-D3D_SHADER_MODEL RenderDeviceD3D12Impl::GetShaderModel() const
+ShaderVersion RenderDeviceD3D12Impl::GetShaderModel() const
{
- // Header may not have constants for D3D_SHADER_MODEL_6_5 and above.
- const D3D_SHADER_MODEL Models[] = {
- D3D_SHADER_MODEL(0x65), // for mesh shader
- D3D_SHADER_MODEL(0x64),
- D3D_SHADER_MODEL(0x63),
- D3D_SHADER_MODEL(0x62),
- D3D_SHADER_MODEL(0x61),
- D3D_SHADER_MODEL_6_0};
-
- // Get maximum supported shader model.
- D3D12_FEATURE_DATA_SHADER_MODEL ShaderModel = {};
- for (auto Model : Models)
- {
- ShaderModel.HighestShaderModel = Model;
- if (SUCCEEDED(m_pd3d12Device->CheckFeatureSupport(D3D12_FEATURE_SHADER_MODEL, &ShaderModel, sizeof(ShaderModel))))
- return ShaderModel.HighestShaderModel;
- }
-
- // 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 D3D_SHADER_MODEL_5_1;
+ return ShaderVersion{Uint8((m_ShaderModel >> 4) & 0xF), Uint8(m_ShaderModel & 0xF)};
}
D3D_FEATURE_LEVEL RenderDeviceD3D12Impl::GetD3DFeatureLevel() const
@@ -170,7 +150,8 @@ RenderDeviceD3D12Impl::RenderDeviceD3D12Impl(IReferenceCounters* pRefCo
m_ContextPool (STD_ALLOCATOR_RAW_MEM(PooledCommandContext, GetRawAllocator(), "Allocator for vector<PooledCommandContext>")),
m_DynamicMemoryManager{GetRawAllocator(), *this, EngineCI.NumDynamicHeapPagesToReserve, EngineCI.DynamicHeapPageSize},
m_MipsGenerator {pd3d12Device},
- m_QueryMgr {pd3d12Device, EngineCI.QueryPoolSizes}
+ m_QueryMgr {pd3d12Device, EngineCI.QueryPoolSizes},
+ m_pDxCompiler {CreateDXCompiler(DXCompilerTarget::Direct3D12, EngineCI.pDxCompilerPath)}
// clang-format on
{
m_DeviceCaps.DevType = RENDER_DEVICE_TYPE_D3D12;
@@ -221,7 +202,32 @@ RenderDeviceD3D12Impl::RenderDeviceD3D12Impl(IReferenceCounters* pRefCo
m_DeviceCaps.Features.VertexPipelineUAVWritesAndAtomics = True;
- const D3D_SHADER_MODEL ShaderModel = GetShaderModel();
+ // Detect maximum shader model.
+ {
+ // 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
+ m_ShaderModel = D3D_SHADER_MODEL_5_1;
+
+ // Header may not have constants for D3D_SHADER_MODEL_6_1 and above.
+ const D3D_SHADER_MODEL Models[] = {
+ D3D_SHADER_MODEL(0x65), // for mesh shader
+ D3D_SHADER_MODEL(0x64),
+ D3D_SHADER_MODEL(0x63),
+ D3D_SHADER_MODEL(0x62),
+ D3D_SHADER_MODEL(0x61),
+ D3D_SHADER_MODEL_6_0};
+
+ D3D12_FEATURE_DATA_SHADER_MODEL ShaderModel = {};
+ for (auto Model : Models)
+ {
+ ShaderModel.HighestShaderModel = Model;
+ if (SUCCEEDED(m_pd3d12Device->CheckFeatureSupport(D3D12_FEATURE_SHADER_MODEL, &ShaderModel, sizeof(ShaderModel))))
+ {
+ m_ShaderModel = ShaderModel.HighestShaderModel;
+ break;
+ }
+ }
+ }
// Check if mesh shader is supported.
#ifdef D12_H_HAS_MESH_SHADER
@@ -230,7 +236,7 @@ RenderDeviceD3D12Impl::RenderDeviceD3D12Impl(IReferenceCounters* pRefCo
bool SupportsMeshShader = SUCCEEDED(m_pd3d12Device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS7, &FeatureData, sizeof(FeatureData))) &&
FeatureData.MeshShaderTier != D3D12_MESH_SHADER_TIER_NOT_SUPPORTED;
- m_DeviceCaps.Features.MeshShaders = (ShaderModel >= D3D_SHADER_MODEL_6_5 && SupportsMeshShader);
+ m_DeviceCaps.Features.MeshShaders = (m_ShaderModel >= D3D_SHADER_MODEL_6_5 && SupportsMeshShader);
}
#endif
diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp
index d14eb122..0634bcf1 100644
--- a/Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp
@@ -36,17 +36,25 @@
namespace Diligent
{
-static ShaderVersion GetD3D12ShaderModel(RenderDeviceD3D12Impl* pDevice, const ShaderVersion& HLSLVersion)
+static ShaderVersion GetD3D12ShaderModel(RenderDeviceD3D12Impl* pDevice, const ShaderVersion& HLSLVersion, SHADER_COMPILER ShaderCompiler)
{
+ if (ShaderCompiler != SHADER_COMPILER_DXC)
+ return HLSLVersion.Major == 0 ? ShaderVersion{5, 1} : HLSLVersion;
+
+ ShaderVersion DeviceSM = pDevice->GetShaderModel();
+ ShaderVersion CompilerSM = pDevice->GetDxCompiler() && pDevice->GetDxCompiler()->IsLoaded() ? pDevice->GetDxCompiler()->GetMaxShaderModel() : ShaderVersion{5, 1};
+ ShaderVersion MaxSM;
+
+ MaxSM = DeviceSM.Major == CompilerSM.Major ?
+ (DeviceSM.Minor > CompilerSM.Minor ? CompilerSM : DeviceSM) :
+ (DeviceSM.Major > CompilerSM.Major ? CompilerSM : DeviceSM);
+
if (HLSLVersion.Major == 0 && HLSLVersion.Minor == 0)
- {
- D3D_SHADER_MODEL ver = pDevice->GetShaderModel();
- return ShaderVersion{Uint8((ver >> 4) & 0xF), Uint8(ver & 0xF)};
- }
- else
- {
- return HLSLVersion;
- }
+ return MaxSM;
+
+ return HLSLVersion.Major == MaxSM.Major ?
+ (HLSLVersion.Minor > MaxSM.Minor ? MaxSM : HLSLVersion) :
+ (HLSLVersion.Major > MaxSM.Major ? MaxSM : HLSLVersion);
}
ShaderD3D12Impl::ShaderD3D12Impl(IReferenceCounters* pRefCounters,
@@ -59,13 +67,13 @@ ShaderD3D12Impl::ShaderD3D12Impl(IReferenceCounters* pRefCounters,
pRenderDeviceD3D12,
ShaderCI.Desc
},
- ShaderD3DBase{ShaderCI, GetD3D12ShaderModel(pRenderDeviceD3D12, ShaderCI.HLSLVersion), true}
+ ShaderD3DBase{ShaderCI, GetD3D12ShaderModel(pRenderDeviceD3D12, ShaderCI.HLSLVersion, ShaderCI.ShaderCompiler), pRenderDeviceD3D12->GetDxCompiler()}
// clang-format on
{
// Load shader resources
auto& Allocator = GetRawAllocator();
auto* pRawMem = ALLOCATE(Allocator, "Allocator for ShaderResources", ShaderResourcesD3D12, 1);
- auto* pResources = new (pRawMem) ShaderResourcesD3D12(m_pShaderByteCode, m_Desc, ShaderCI.UseCombinedTextureSamplers ? ShaderCI.CombinedSamplerSuffix : nullptr);
+ auto* pResources = new (pRawMem) ShaderResourcesD3D12(m_pShaderByteCode, m_Desc, ShaderCI.UseCombinedTextureSamplers ? ShaderCI.CombinedSamplerSuffix : nullptr, pRenderDeviceD3D12);
m_pShaderResources.reset(pResources, STDDeleterRawMem<ShaderResourcesD3D12>(Allocator));
}
diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderResourcesD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderResourcesD3D12.cpp
index bcb34226..01726d00 100644
--- a/Graphics/GraphicsEngineD3D12/src/ShaderResourcesD3D12.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/ShaderResourcesD3D12.cpp
@@ -32,12 +32,16 @@
#include "ShaderD3DBase.hpp"
#include "ShaderBase.hpp"
#include "DXILUtils.hpp"
+#include "RenderDeviceD3D12Impl.hpp"
namespace Diligent
{
-ShaderResourcesD3D12::ShaderResourcesD3D12(ID3DBlob* pShaderBytecode, const ShaderDesc& ShdrDesc, const char* CombinedSamplerSuffix) :
+ShaderResourcesD3D12::ShaderResourcesD3D12(ID3DBlob* pShaderBytecode,
+ const ShaderDesc& ShdrDesc,
+ const char* CombinedSamplerSuffix,
+ RenderDeviceD3D12Impl* pRenderDeviceD3D12) :
ShaderResources{ShdrDesc.ShaderType}
{
class NewResourceHandler
@@ -54,9 +58,12 @@ ShaderResourcesD3D12::ShaderResourcesD3D12(ID3DBlob* pShaderBytecode, const Shad
};
CComPtr<ID3D12ShaderReflection> pShaderReflection;
+ auto* DxCompiler = pRenderDeviceD3D12->GetDxCompiler();
- if (!DxcGetShaderReflection(reinterpret_cast<IDxcBlob*>(pShaderBytecode), &pShaderReflection))
+ // At first try to get shader reflection with a DXC.
+ if (!DxcGetShaderReflection(DxCompiler, reinterpret_cast<IDxcBlob*>(pShaderBytecode), &pShaderReflection))
{
+ // Use FXC to get reflection.
HRESULT hr = D3DReflect(pShaderBytecode->GetBufferPointer(), pShaderBytecode->GetBufferSize(), __uuidof(pShaderReflection), reinterpret_cast<void**>(&pShaderReflection));
CHECK_D3D_RESULT_THROW(hr, "Failed to get the shader reflection");
}