Skip to content

Commit 4ea00f5

Browse files
committed
Fix GLSL include handler issue
1 parent f64d491 commit 4ea00f5

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

src/nbl/asset/utils/CGLSLCompiler.cpp

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -126,32 +126,28 @@ std::string CGLSLCompiler::preprocessShader(std::string&& code, IShader::E_SHADE
126126
{
127127
insertExtraDefines(code, preprocessOptions.extraDefines);
128128
}
129+
IShaderCompiler::disableAllDirectivesExceptIncludes(code);
130+
disableGlDirectives(code);
131+
shaderc::Compiler comp;
132+
shaderc::CompileOptions options;
133+
options.SetTargetSpirv(shaderc_spirv_version_1_6);
134+
129135
if (preprocessOptions.includeFinder != nullptr)
130136
{
131-
IShaderCompiler::disableAllDirectivesExceptIncludes(code);
132-
disableGlDirectives(code);
133-
shaderc::Compiler comp;
134-
shaderc::CompileOptions options;
135-
options.SetTargetSpirv(shaderc_spirv_version_1_6);
136-
137137
options.SetIncluder(std::make_unique<impl::Includer>(preprocessOptions.includeFinder, m_system.get(), preprocessOptions.maxSelfInclusionCount + 1u));//custom #include handler
138-
const shaderc_shader_kind scstage = stage == IShader::ESS_UNKNOWN ? shaderc_glsl_infer_from_source : ESStoShadercEnum(stage);
139-
auto res = comp.PreprocessGlsl(code, scstage, preprocessOptions.sourceIdentifier.data(), options);
140-
141-
if (res.GetCompilationStatus() != shaderc_compilation_status_success) {
142-
preprocessOptions.logger.log(res.GetErrorMessage(), system::ILogger::ELL_ERROR);
143-
return nullptr;
144-
}
145-
146-
auto resolvedString = std::string(res.cbegin(), std::distance(res.cbegin(), res.cend()));
147-
IShaderCompiler::reenableDirectives(resolvedString);
148-
reenableGlDirectives(resolvedString);
149-
return resolvedString;
150138
}
151-
else
152-
{
153-
return code;
139+
const shaderc_shader_kind scstage = stage == IShader::ESS_UNKNOWN ? shaderc_glsl_infer_from_source : ESStoShadercEnum(stage);
140+
auto res = comp.PreprocessGlsl(code, scstage, preprocessOptions.sourceIdentifier.data(), options);
141+
142+
if (res.GetCompilationStatus() != shaderc_compilation_status_success) {
143+
preprocessOptions.logger.log(res.GetErrorMessage(), system::ILogger::ELL_ERROR);
144+
return nullptr;
154145
}
146+
147+
auto resolvedString = std::string(res.cbegin(), std::distance(res.cbegin(), res.cend()));
148+
IShaderCompiler::reenableDirectives(resolvedString);
149+
reenableGlDirectives(resolvedString);
150+
return resolvedString;
155151
}
156152

157153
core::smart_refctd_ptr<ICPUShader> CGLSLCompiler::compileToSPIRV(const char* code, const IShaderCompiler::SCompilerOptions& options) const

0 commit comments

Comments
 (0)