[Chore] (MG_Util/ShaderSourceProcessor): trim unnecessary part of shader source

This commit is contained in:
2025-11-12 18:03:29 +08:00
parent 755b4605e4
commit 6e65942891
2 changed files with 23 additions and 1 deletions
@@ -363,8 +363,12 @@ namespace MobileGL {
MGLOG_E("ProgramObject %u: GenerateBinary - CompileShader failed for shader[%zu], aborting "
"binary generation",
m_externalIndex, i);
assert(res); // keep original assert but log first
MGLOG_E("ProgramObject %u: GenerateBinary - CompileShader return code %d, log:\n%s",
m_externalIndex, res.error().errc, res.error().log.c_str());
MGLOG_E("ProgramObject %u: GenerateBinary - last compiled shader src: \n%s",
m_externalIndex, m_shaders[i]->GetShaderSource().c_str());
}
assert(res); // keep original assert but log first
shaders[i] = res.value();
MGLOG_D("ProgramObject %u: GenerateBinary - compiled shader[%zu] -> TShader ptr %p",
m_externalIndex, i, shaders[i].get());
@@ -4,6 +4,24 @@ namespace MobileGL {
namespace MG_Util {
namespace ShaderTranspiler {
void PreprocessShaderSource(ShaderStage stage, String& source) {
// remove #line directives
SizeT linedirPos = source.find("#line");
while (linedirPos != std::string::npos) {
SizeT newlinePos = source.find('\n', linedirPos);
source = source.replace(linedirPos, newlinePos - linedirPos, "");
linedirPos = source.find("#line", linedirPos);
}
// remove multi-line comment
size_t commentStartPos = source.find("/*");
while (commentStartPos != std::string::npos) {
size_t commentEndPos = source.find("*/", commentStartPos);
// + length of "*/"
source = source.replace(commentStartPos, commentEndPos - commentStartPos + 2, "");
commentStartPos = source.find("/*", commentStartPos);
}
// force #version
ShaderProfile profile = ShaderProfile::Core;
SizeT versionPos = source.find("#version");