From 6447cc4b0c06bc018c02ecc3040f4f925e9a2b2c Mon Sep 17 00:00:00 2001 From: azhirnov Date: Sun, 20 Sep 2020 10:44:19 +0300 Subject: added ability to use #include in glsl --- Graphics/ShaderTools/include/GLSLangUtils.hpp | 9 +++++---- Graphics/ShaderTools/src/GLSLangUtils.cpp | 20 ++++++++++++++------ 2 files changed, 19 insertions(+), 10 deletions(-) (limited to 'Graphics/ShaderTools') 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 GLSLtoSPIRV(SHADER_TYPE ShaderType, - const char* ShaderSource, - int SourceCodeLen, - IDataBlob** ppCompilerOutput); +std::vector GLSLtoSPIRV(SHADER_TYPE ShaderType, + const char* ShaderSource, + int SourceCodeLen, + IShaderSourceInputStreamFactory* pShaderSourceStreamFactory, + IDataBlob** ppCompilerOutput); std::vector 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 HLSLtoSPIRV(const ShaderCreateInfo& ShaderCI, } } -std::vector GLSLtoSPIRV(const SHADER_TYPE ShaderType, const char* ShaderSource, int SourceCodeLen, IDataBlob** ppCompilerOutput) +std::vector 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 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(); -- cgit v1.2.3