From 0cc841bc76eda21793f2a158b0ededad5a5ae3bf Mon Sep 17 00:00:00 2001 From: assiduous Date: Wed, 16 Sep 2020 16:11:56 -0700 Subject: Added GPU vendor and memory size detection (API 240071), closed https://github.com/DiligentGraphics/DiligentCore/issues/144. Fixed shader model selection in D3D12 backend --- Graphics/ShaderTools/include/DXCompiler.hpp | 1 + Graphics/ShaderTools/src/DXCompiler.cpp | 25 +++++++++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) (limited to 'Graphics/ShaderTools') diff --git a/Graphics/ShaderTools/include/DXCompiler.hpp b/Graphics/ShaderTools/include/DXCompiler.hpp index 32655a78..6345ad7a 100644 --- a/Graphics/ShaderTools/include/DXCompiler.hpp +++ b/Graphics/ShaderTools/include/DXCompiler.hpp @@ -74,6 +74,7 @@ public: virtual bool Compile(const CompileAttribs& Attribs) = 0; virtual void Compile(const ShaderCreateInfo& ShaderCI, + ShaderVersion ShaderModel, const char* ExtraDefinitions, IDxcBlob** ppByteCodeBlob, std::vector* pByteCode, diff --git a/Graphics/ShaderTools/src/DXCompiler.cpp b/Graphics/ShaderTools/src/DXCompiler.cpp index 50042df4..b35bfefa 100644 --- a/Graphics/ShaderTools/src/DXCompiler.cpp +++ b/Graphics/ShaderTools/src/DXCompiler.cpp @@ -83,6 +83,7 @@ public: bool Compile(const CompileAttribs& Attribs) override final; virtual void Compile(const ShaderCreateInfo& ShaderCI, + ShaderVersion ShaderModel, const char* ExtraDefinitions, IDxcBlob** ppByteCodeBlob, std::vector* pByteCode, @@ -412,6 +413,7 @@ void DXCompilerImpl::GetD3D12ShaderReflection(IDxcBlob* pShaderBy void DXCompilerImpl::Compile(const ShaderCreateInfo& ShaderCI, + ShaderVersion ShaderModel, const char* ExtraDefinitions, IDxcBlob** ppByteCodeBlob, std::vector* pByteCode, @@ -423,15 +425,26 @@ void DXCompilerImpl::Compile(const ShaderCreateInfo& ShaderCI, return; } - // validate shader version - ShaderVersion ShaderModel = ShaderCI.HLSLVersion; - ShaderVersion MaxSM = GetMaxShaderModel(); + ShaderVersion MaxSM = GetMaxShaderModel(); - if (ShaderModel.Major < 6 || ShaderModel.Major > MaxSM.Major) + // validate shader version + if (ShaderModel == ShaderVersion{}) + { ShaderModel = MaxSM; - - if (ShaderModel.Major == MaxSM.Major && ShaderModel.Minor > MaxSM.Minor) + } + else if (ShaderModel.Major < 6) + { + LOG_INFO_MESSAGE("DXC only supports shader model 6.0+. Upgrading the specified shader model ", + Uint32{ShaderModel.Major}, '_', Uint32{ShaderModel.Minor}, " to 6_0"); + ShaderModel = ShaderVersion{6, 0}; + } + else if ((ShaderModel.Major > MaxSM.Major) || + (ShaderModel.Major == MaxSM.Major && ShaderModel.Minor > MaxSM.Minor)) + { + LOG_WARNING_MESSAGE("The maximum supported shader model by DXC is ", Uint32{MaxSM.Major}, '_', Uint32{MaxSM.Minor}, + ". The specified shader model ", Uint32{ShaderModel.Major}, '_', Uint32{ShaderModel.Minor}, " will be downgraded."); ShaderModel = MaxSM; + } const auto Profile = GetHLSLProfileString(ShaderCI.Desc.ShaderType, ShaderModel); const std::wstring wstrProfile{Profile.begin(), Profile.end()}; -- cgit v1.2.3