diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2020-09-09 16:40:36 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2020-09-09 16:40:36 +0000 |
| commit | 6f86cf0e9a3aa7f675fad67877398b7d261f778c (patch) | |
| tree | 2824d76ddc677a1d8b023aff62c62b04936dcdce /Graphics/GraphicsEngineD3D12 | |
| parent | Few minor updated to ShaderResourcesD3D12 (diff) | |
| download | DiligentCore-6f86cf0e9a3aa7f675fad67877398b7d261f778c.tar.gz DiligentCore-6f86cf0e9a3aa7f675fad67877398b7d261f778c.zip | |
Fixed merge conflicts
Diffstat (limited to 'Graphics/GraphicsEngineD3D12')
3 files changed, 27 insertions, 32 deletions
diff --git a/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.hpp b/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.hpp index dc8d594e..bac52b9e 100644 --- a/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.hpp +++ b/Graphics/GraphicsEngineD3D12/include/RenderDeviceD3D12Impl.hpp @@ -158,7 +158,7 @@ public: ID3D12Device2* GetD3D12Device2(); #endif - D3D_SHADER_MODEL GetMaxShaderModel() const; + ShaderVersion GetMaxShaderModel() const; D3D_FEATURE_LEVEL GetD3DFeatureLevel() const; private: diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp index 753fcbf8..80025b36 100644 --- a/Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp @@ -38,15 +38,23 @@ namespace Diligent 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->GetMaxShaderModel(); + 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->GetMaxShaderModel(); - 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, diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderResourcesD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderResourcesD3D12.cpp index fb061ca0..01726d00 100644 --- a/Graphics/GraphicsEngineD3D12/src/ShaderResourcesD3D12.cpp +++ b/Graphics/GraphicsEngineD3D12/src/ShaderResourcesD3D12.cpp @@ -32,13 +32,16 @@ #include "ShaderD3DBase.hpp" #include "ShaderBase.hpp" #include "DXILUtils.hpp" -#include "dxc/dxcapi.h" +#include "RenderDeviceD3D12Impl.hpp" namespace Diligent { -ShaderResourcesD3D12::ShaderResourcesD3D12(ID3DBlob* pShaderBytecode, bool isDXIL, const ShaderDesc& ShdrDesc, const char* CombinedSamplerSuffix) : +ShaderResourcesD3D12::ShaderResourcesD3D12(ID3DBlob* pShaderBytecode, + const ShaderDesc& ShdrDesc, + const char* CombinedSamplerSuffix, + RenderDeviceD3D12Impl* pRenderDeviceD3D12) : ShaderResources{ShdrDesc.ShaderType} { class NewResourceHandler @@ -55,29 +58,13 @@ ShaderResourcesD3D12::ShaderResourcesD3D12(ID3DBlob* pShaderBytecode, bool isDXI }; CComPtr<ID3D12ShaderReflection> pShaderReflection; + auto* DxCompiler = pRenderDeviceD3D12->GetDxCompiler(); - if (isDXIL) + // At first try to get shader reflection with a DXC. + if (!DxcGetShaderReflection(DxCompiler, reinterpret_cast<IDxcBlob*>(pShaderBytecode), &pShaderReflection)) { - CComPtr<IDxcContainerReflection> pReflection; - - auto hr = D3D12DxcCreateInstance(CLSID_DxcContainerReflection, IID_PPV_ARGS(&pReflection)); - CHECK_D3D_RESULT_THROW(hr, "Failed to create shader reflection instance"); - - hr = pReflection->Load(reinterpret_cast<IDxcBlob*>(pShaderBytecode)); - CHECK_D3D_RESULT_THROW(hr, "Failed to load shader reflection from bytecode"); - - UINT32 shaderIdx = 0; - constexpr UINT32 DFCC_DXIL = UINT32{'D'} | (UINT32{'X'} << 8) | (UINT32{'I'} << 16) | (UINT32{'L'} << 24); - - hr = pReflection->FindFirstPartKind(DFCC_DXIL, &shaderIdx); - CHECK_D3D_RESULT_THROW(hr, "Failed to find DXIL part"); - - hr = pReflection->GetPartReflection(shaderIdx, __uuidof(pShaderReflection), reinterpret_cast<void**>(&pShaderReflection)); - CHECK_D3D_RESULT_THROW(hr, "Failed to get the shader reflection"); - } - else - { - auto hr = D3DReflect(pShaderBytecode->GetBufferPointer(), pShaderBytecode->GetBufferSize(), __uuidof(pShaderReflection), reinterpret_cast<void**>(&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"); } |
