diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2021-03-02 20:59:46 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2021-03-19 00:38:14 +0000 |
| commit | 0f3196742401a6871f41f9bbacf5cbbf33883c5c (patch) | |
| tree | f480a3d060e1c6c9ef1bab04ef2b6c595e891a26 /Graphics | |
| parent | RunTimeResourceArray Test: added RW textures and buffers (diff) | |
| download | DiligentCore-0f3196742401a6871f41f9bbacf5cbbf33883c5c.tar.gz DiligentCore-0f3196742401a6871f41f9bbacf5cbbf33883c5c.zip | |
Added shader compiler macros to shader source
Diffstat (limited to 'Graphics')
| -rw-r--r-- | Graphics/GraphicsEngineD3DBase/src/ShaderD3DBase.cpp | 4 | ||||
| -rw-r--r-- | Graphics/ShaderTools/src/DXCompiler.cpp | 8 | ||||
| -rw-r--r-- | Graphics/ShaderTools/src/GLSLangUtils.cpp | 5 |
3 files changed, 11 insertions, 6 deletions
diff --git a/Graphics/GraphicsEngineD3DBase/src/ShaderD3DBase.cpp b/Graphics/GraphicsEngineD3DBase/src/ShaderD3DBase.cpp index 49566626..322ccd50 100644 --- a/Graphics/GraphicsEngineD3DBase/src/ShaderD3DBase.cpp +++ b/Graphics/GraphicsEngineD3DBase/src/ShaderD3DBase.cpp @@ -124,8 +124,10 @@ static HRESULT CompileShader(const char* Source, } } + D3D_SHADER_MACRO Macros[] = {{"D3DCOMPILER", ""}, {}}; + D3DIncludeImpl IncludeImpl{ShaderCI.pShaderSourceStreamFactory}; - return D3DCompile(Source, SourceLength, NULL, nullptr, &IncludeImpl, ShaderCI.EntryPoint, profile, dwShaderFlags, 0, ppBlobOut, ppCompilerOutput); + return D3DCompile(Source, SourceLength, nullptr, Macros, &IncludeImpl, ShaderCI.EntryPoint, profile, dwShaderFlags, 0, ppBlobOut, ppCompilerOutput); } ShaderD3DBase::ShaderD3DBase(const ShaderCreateInfo& ShaderCI, const ShaderVersion ShaderModel, IDXCompiler* DxCompiler) diff --git a/Graphics/ShaderTools/src/DXCompiler.cpp b/Graphics/ShaderTools/src/DXCompiler.cpp index 681c7cb0..c76546b6 100644 --- a/Graphics/ShaderTools/src/DXCompiler.cpp +++ b/Graphics/ShaderTools/src/DXCompiler.cpp @@ -739,14 +739,16 @@ void DXCompilerImpl::Compile(const ShaderCreateInfo& ShaderCI, IDXCompiler::CompileAttribs CA; - auto Source = BuildHLSLSourceString(ShaderCI, ExtraDefinitions); + const auto Source = BuildHLSLSourceString(ShaderCI, ExtraDefinitions); + + DxcDefine Defines[] = {{L"DXCOMPILER", L""}}; CA.Source = Source.c_str(); CA.SourceLength = static_cast<Uint32>(Source.length()); CA.EntryPoint = wstrEntryPoint.c_str(); CA.Profile = wstrProfile.c_str(); - CA.pDefines = nullptr; - CA.DefinesCount = 0; + CA.pDefines = Defines; + CA.DefinesCount = _countof(Defines); CA.pArgs = DxilArgs.data(); CA.ArgsCount = static_cast<Uint32>(DxilArgs.size()); CA.pShaderSourceStreamFactory = ShaderCI.pShaderSourceStreamFactory; diff --git a/Graphics/ShaderTools/src/GLSLangUtils.cpp b/Graphics/ShaderTools/src/GLSLangUtils.cpp index e74f663d..1618fe81 100644 --- a/Graphics/ShaderTools/src/GLSLangUtils.cpp +++ b/Graphics/ShaderTools/src/GLSLangUtils.cpp @@ -525,7 +525,8 @@ std::vector<unsigned int> HLSLtoSPIRV(const ShaderCreateInfo& ShaderCI, const char* SourceCode = ReadShaderSourceFile(ShaderCI.Source, ShaderCI.pShaderSourceStreamFactory, ShaderCI.FilePath, pFileData, SourceCodeLen); - std::string Defines = g_HLSLDefinitions; + std::string Defines{"#define GLSLANG\n\n"}; + Defines.append(g_HLSLDefinitions); AppendShaderTypeDefinitions(Defines, ShaderCI.Desc.ShaderType); if (ExtraDefinitions != nullptr) @@ -614,7 +615,7 @@ std::vector<unsigned int> GLSLtoSPIRV(SHADER_TYPE ShaderTyp int Lenghts[] = {SourceCodeLen}; Shader.setStringsWithLengths(ShaderStrings, Lenghts, 1); - std::string Defines; + std::string Defines{"#define GLSLANG\n\n"}; if (Macros != nullptr) { AppendShaderMacros(Defines, Macros); |
