summaryrefslogtreecommitdiffstats
path: root/Graphics/ShaderTools
diff options
context:
space:
mode:
authorazhirnov <zh1dron@gmail.com>2020-09-20 07:44:19 +0000
committerazhirnov <zh1dron@gmail.com>2020-09-20 07:44:19 +0000
commit6447cc4b0c06bc018c02ecc3040f4f925e9a2b2c (patch)
tree85218fb5251030beb968660e262f694f450ef7ee /Graphics/ShaderTools
parentCMake utils: added package_required_dlls to enable packaging shader compiler ... (diff)
downloadDiligentCore-6447cc4b0c06bc018c02ecc3040f4f925e9a2b2c.tar.gz
DiligentCore-6447cc4b0c06bc018c02ecc3040f4f925e9a2b2c.zip
added ability to use #include in glsl
Diffstat (limited to 'Graphics/ShaderTools')
-rw-r--r--Graphics/ShaderTools/include/GLSLangUtils.hpp9
-rw-r--r--Graphics/ShaderTools/src/GLSLangUtils.cpp20
2 files changed, 19 insertions, 10 deletions
diff --git a/Graphics/ShaderTools/include/GLSLangUtils.hpp b/Graphics/ShaderTools/include/GLSLangUtils.hpp
index 67a0ef18..c7c9d90f 100644
--- a/Graphics/ShaderTools/include/GLSLangUtils.hpp
+++ b/Graphics/ShaderTools/include/GLSLangUtils.hpp
@@ -40,10 +40,11 @@ namespace GLSLangUtils
void InitializeGlslang();
void FinalizeGlslang();
-std::vector<unsigned int> GLSLtoSPIRV(SHADER_TYPE ShaderType,
- const char* ShaderSource,
- int SourceCodeLen,
- IDataBlob** ppCompilerOutput);
+std::vector<unsigned int> GLSLtoSPIRV(SHADER_TYPE ShaderType,
+ const char* ShaderSource,
+ int SourceCodeLen,
+ IShaderSourceInputStreamFactory* pShaderSourceStreamFactory,
+ IDataBlob** ppCompilerOutput);
std::vector<unsigned int> HLSLtoSPIRV(const ShaderCreateInfo& Attribs,
const char* ExtraDefinitions,
diff --git a/Graphics/ShaderTools/src/GLSLangUtils.cpp b/Graphics/ShaderTools/src/GLSLangUtils.cpp
index 79d5edeb..000af866 100644
--- a/Graphics/ShaderTools/src/GLSLangUtils.cpp
+++ b/Graphics/ShaderTools/src/GLSLangUtils.cpp
@@ -419,11 +419,11 @@ public:
// For the "local"-only aspect of a "" include. Should not search in the
// "system" paths, because on returning a failure, the parser will
// call includeSystem() to look in the "system" locations.
- virtual IncludeResult* includeLocal(const char* /*headerName*/,
- const char* /*includerName*/,
- size_t /*inclusionDepth*/)
+ virtual IncludeResult* includeLocal(const char* headerName,
+ const char* includerName,
+ size_t inclusionDepth)
{
- return nullptr;
+ return includeSystem(headerName, includerName, inclusionDepth);
}
// Signals that the parser will no longer use the contents of the
@@ -502,7 +502,11 @@ std::vector<unsigned int> HLSLtoSPIRV(const ShaderCreateInfo& ShaderCI,
}
}
-std::vector<unsigned int> GLSLtoSPIRV(const SHADER_TYPE ShaderType, const char* ShaderSource, int SourceCodeLen, IDataBlob** ppCompilerOutput)
+std::vector<unsigned int> GLSLtoSPIRV(SHADER_TYPE ShaderType,
+ const char* ShaderSource,
+ int SourceCodeLen,
+ IShaderSourceInputStreamFactory* pShaderSourceStreamFactory,
+ IDataBlob** ppCompilerOutput)
{
EShLanguage ShLang = ShaderTypeToShLanguage(ShaderType);
::glslang::TShader Shader(ShLang);
@@ -513,7 +517,11 @@ std::vector<unsigned int> GLSLtoSPIRV(const SHADER_TYPE ShaderType, const char*
int Lenghts[] = {SourceCodeLen};
Shader.setStringsWithLengths(ShaderStrings, Lenghts, 1);
- auto SPIRV = CompileShaderInternal(Shader, messages, nullptr, ShaderSource, SourceCodeLen, ppCompilerOutput);
+ IncluderImpl Includer{pShaderSourceStreamFactory};
+
+ auto SPIRV = CompileShaderInternal(Shader, messages, &Includer, ShaderSource, SourceCodeLen, ppCompilerOutput);
+ if (SPIRV.empty())
+ return SPIRV;
spvtools::Optimizer SpirvOptimizer(SPV_ENV_VULKAN_1_0);
SpirvOptimizer.RegisterPerformancePasses();