diff options
| author | azhirnov <zh1dron@gmail.com> | 2020-09-09 09:25:47 +0000 |
|---|---|---|
| committer | azhirnov <zh1dron@gmail.com> | 2020-09-09 15:56:51 +0000 |
| commit | 381f66352dfaefcdeaeba3c71183ad558bb70cd6 (patch) | |
| tree | a18b2fa0763a310317f6926677d87d91666bf4b6 /Graphics/GraphicsEngineD3DBase | |
| parent | Merge branch 'master' into mesh_shader (diff) | |
| download | DiligentCore-381f66352dfaefcdeaeba3c71183ad558bb70cd6.tar.gz DiligentCore-381f66352dfaefcdeaeba3c71183ad558bb70cd6.zip | |
added IDxCompilerLibrary interface. DXCompilerBase moved to platform specific files
Diffstat (limited to 'Graphics/GraphicsEngineD3DBase')
| -rw-r--r-- | Graphics/GraphicsEngineD3DBase/include/ShaderD3DBase.hpp | 3 | ||||
| -rw-r--r-- | Graphics/GraphicsEngineD3DBase/src/ShaderD3DBase.cpp | 55 |
2 files changed, 17 insertions, 41 deletions
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 <d3dcommon.h> #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<ID3DBlob> 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 <atlcomcli.h> #include "ShaderD3DBase.hpp" -#include "DXILUtils.hpp" #include "dxc/dxcapi.h" #include <locale> #include <cwchar> @@ -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<IDxcBlob**>(ppBlobOut), - reinterpret_cast<IDxcBlob**>(ppCompilerOutput))) + if (!DxCompiler->Compile(Source, SourceLength, + ToUnicode(ShaderCI.EntryPoint), + ToUnicode(profile), + D3DMacros.data(), D3DMacros.size(), + pArgs, _countof(pArgs), + ShaderCI.pShaderSourceStreamFactory, + reinterpret_cast<IDxcBlob**>(ppBlobOut), + reinterpret_cast<IDxcBlob**>(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); |
