From 381f66352dfaefcdeaeba3c71183ad558bb70cd6 Mon Sep 17 00:00:00 2001 From: azhirnov Date: Wed, 9 Sep 2020 12:25:47 +0300 Subject: added IDxCompilerLibrary interface. DXCompilerBase moved to platform specific files --- .../include/ShaderD3DBase.hpp | 3 +- .../GraphicsEngineD3DBase/src/ShaderD3DBase.cpp | 55 ++++++---------------- 2 files changed, 17 insertions(+), 41 deletions(-) (limited to 'Graphics/GraphicsEngineD3DBase') diff --git a/Graphics/GraphicsEngineD3DBase/include/ShaderD3DBase.hpp b/Graphics/GraphicsEngineD3DBase/include/ShaderD3DBase.hpp index 3de8b38e..61aa7976 100644 --- a/Graphics/GraphicsEngineD3DBase/include/ShaderD3DBase.hpp +++ b/Graphics/GraphicsEngineD3DBase/include/ShaderD3DBase.hpp @@ -29,6 +29,7 @@ #include #include "Shader.h" +#include "DXILUtils.hpp" /// \file /// Base implementation of a D3D shader @@ -40,7 +41,7 @@ namespace Diligent class ShaderD3DBase { public: - ShaderD3DBase(const ShaderCreateInfo& ShaderCI, ShaderVersion ShaderModel, bool IsD3D12); + ShaderD3DBase(const ShaderCreateInfo& ShaderCI, ShaderVersion ShaderModel, IDxCompilerLibrary* DxCompiler); protected: CComPtr m_pShaderByteCode; diff --git a/Graphics/GraphicsEngineD3DBase/src/ShaderD3DBase.cpp b/Graphics/GraphicsEngineD3DBase/src/ShaderD3DBase.cpp index 8df5330a..d9c5008b 100644 --- a/Graphics/GraphicsEngineD3DBase/src/ShaderD3DBase.cpp +++ b/Graphics/GraphicsEngineD3DBase/src/ShaderD3DBase.cpp @@ -33,7 +33,6 @@ #include "RefCntAutoPtr.hpp" #include #include "ShaderD3DBase.hpp" -#include "DXILUtils.hpp" #include "dxc/dxcapi.h" #include #include @@ -48,7 +47,8 @@ static const Char* g_HLSLDefinitions = #include "HLSLDefinitions_inc.fxh" }; -static HRESULT CompileDxilShader(const char* Source, +static HRESULT CompileDxilShader(IDxCompilerLibrary* DxCompiler, + const char* Source, size_t SourceLength, const ShaderCreateInfo& ShaderCI, LPCSTR profile, @@ -169,15 +169,14 @@ static HRESULT CompileDxilShader(const char* Source, VERIFY_EXPR(__uuidof(ID3DBlob) == __uuidof(IDxcBlob)); - if (!DxcCompile(DXCompilerTarget::Direct3D12, - Source, SourceLength, - ToUnicode(ShaderCI.EntryPoint), - ToUnicode(profile), - D3DMacros.data(), D3DMacros.size(), - pArgs, _countof(pArgs), - ShaderCI.pShaderSourceStreamFactory, - reinterpret_cast(ppBlobOut), - reinterpret_cast(ppCompilerOutput))) + if (!DxCompiler->Compile(Source, SourceLength, + ToUnicode(ShaderCI.EntryPoint), + ToUnicode(profile), + D3DMacros.data(), D3DMacros.size(), + pArgs, _countof(pArgs), + ShaderCI.pShaderSourceStreamFactory, + reinterpret_cast(ppBlobOut), + reinterpret_cast(ppCompilerOutput))) { return E_FAIL; } @@ -311,7 +310,7 @@ static HRESULT CompileShader(const char* Source, } // namespace -ShaderD3DBase::ShaderD3DBase(const ShaderCreateInfo& ShaderCI, ShaderVersion ShaderModel, bool IsD3D12) +ShaderD3DBase::ShaderD3DBase(const ShaderCreateInfo& ShaderCI, const ShaderVersion ShaderModel, IDxCompilerLibrary* DxCompiler) { if (ShaderCI.Source || ShaderCI.FilePath) { @@ -324,37 +323,13 @@ ShaderD3DBase::ShaderD3DBase(const ShaderCreateInfo& ShaderCI, ShaderVersion Sha switch (ShaderCI.ShaderCompiler) { // clang-format off - case SHADER_COMPILER_DEFAULT: IsDXIL = false; break; - case SHADER_COMPILER_DXC: IsDXIL = true; break; - case SHADER_COMPILER_FXC: IsDXIL = false; break; + case SHADER_COMPILER_DEFAULT: IsDXIL = false; break; + case SHADER_COMPILER_DXC: IsDXIL = DxCompiler != nullptr && DxCompiler->IsLoaded(); break; + case SHADER_COMPILER_FXC: IsDXIL = false; break; // clang-format on default: UNEXPECTED("Unsupported shader compiler"); } - // validate shader model - if (IsDXIL) - { - ShaderModel = (ShaderModel.Major >= 6 ? ShaderModel : ShaderVersion{6, 0}); - - // clamp to maximum supported version - ShaderVersion MaxSM; - if (DxcGetMaxShaderModel(DXCompilerTarget::Direct3D12, MaxSM)) - { - if (ShaderModel.Major > MaxSM.Major) - ShaderModel = MaxSM; - - if (ShaderModel.Major == MaxSM.Major && ShaderModel.Minor > MaxSM.Minor) - ShaderModel = MaxSM; - } - else - IsDXIL = false; - } - - if (!IsDXIL) - { - ShaderModel = (ShaderModel.Major < 6 ? ShaderModel : (IsD3D12 ? ShaderVersion{5, 1} : ShaderVersion{5, 0})); - } - std::string strShaderProfile; switch (ShaderCI.Desc.ShaderType) { @@ -403,7 +378,7 @@ ShaderD3DBase::ShaderD3DBase(const ShaderCreateInfo& ShaderCI, ShaderVersion Sha HRESULT hr; if (IsDXIL) - hr = CompileDxilShader(ShaderSource.c_str(), ShaderSource.length(), ShaderCI, strShaderProfile.c_str(), &m_pShaderByteCode, &errors); + hr = CompileDxilShader(DxCompiler, ShaderSource.c_str(), ShaderSource.length(), ShaderCI, strShaderProfile.c_str(), &m_pShaderByteCode, &errors); else hr = CompileShader(ShaderSource.c_str(), ShaderSource.length(), ShaderCI, strShaderProfile.c_str(), &m_pShaderByteCode, &errors); -- cgit v1.2.3