mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-13 06:38:31 +09:00
[Fix]: fix glmark2 crash
- deal with legacy GLSL syntax (attribute/varying/gl_FragColor/texture2D/etc.) - implement glGet GL_SHADER_SOURCE_LENGTH, and make sure returns original shader source - expose proper extensions (GL_ARB_depth_texture) - support env var MOBILEGL_LOG_FILE_PATH - unit tests to test against those changes
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include <MG_Util/Converters/GLToStr/GLEnumConverter.h>
|
||||
#include <MG_Util/ShaderTranspiler/Types.h>
|
||||
#include <MG_Util/ShaderTranspiler/ShaderCompiler.h>
|
||||
#include <MG_Util/ShaderTranspiler/ShaderSourceProcessor.h>
|
||||
#include <MG_Util/Converters/MGToGL/ProgramEnumConverter.h>
|
||||
#include <MG_Util/Converters/SPIRVCrossToGL/SpvcTypeConverter.h>
|
||||
|
||||
@@ -389,10 +390,13 @@ namespace MobileGL::MG_State::GLState {
|
||||
|
||||
// 1. Compile shaders
|
||||
for (SizeT i = 0; i < m_shaders.size(); i++) {
|
||||
auto shaderType = MG_Util::ConvertShaderStageToGLEnum(m_shaders[i]->GetShaderStage());
|
||||
auto shaderStage = m_shaders[i]->GetShaderStage();
|
||||
auto shaderType = MG_Util::ConvertShaderStageToGLEnum(shaderStage);
|
||||
String compileSource = m_shaders[i]->GetShaderSource();
|
||||
PreprocessShaderSource(shaderStage, compileSource);
|
||||
shaderTypes[i] = shaderType;
|
||||
ShaderAttrib attrib{.shaderType = shaderType,
|
||||
.sourceStr = m_shaders[i]->GetShaderSource(),
|
||||
.sourceStr = compileSource,
|
||||
.flags = 0}; // Will need patched glslang to work
|
||||
MGLOG_D("ProgramObject %u: GenerateBinary - compiling shader[%zu] type %u", m_externalIndex, i, shaderType);
|
||||
auto res = ShaderCompiler::CompileShader(attrib);
|
||||
@@ -403,7 +407,7 @@ namespace MobileGL::MG_State::GLState {
|
||||
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());
|
||||
compileSource.c_str());
|
||||
}
|
||||
MOBILEGL_ASSERT(res, "CompileShader failed during binary generation");
|
||||
shaders[i] = res.value();
|
||||
|
||||
@@ -24,13 +24,14 @@ namespace MobileGL::MG_State::GLState {
|
||||
|
||||
void ShaderObject::Compile() {
|
||||
using namespace MG_Util::ShaderTranspiler;
|
||||
MG_Util::ShaderTranspiler::PreprocessShaderSource(m_stage, m_source);
|
||||
String compileSource = m_source;
|
||||
MG_Util::ShaderTranspiler::PreprocessShaderSource(m_stage, compileSource);
|
||||
|
||||
// Compile for OpenGL here, so that we can do validation and link
|
||||
// like a real OpenGL driver at linking stage
|
||||
// Will compile for other backends later.
|
||||
ShaderAttrib attrib{.shaderType = MG_Util::ConvertShaderStageToGLEnum(m_stage),
|
||||
.sourceStr = m_source,
|
||||
.sourceStr = compileSource,
|
||||
.flags = ShaderCompileBits::CompileForOpenGL};
|
||||
|
||||
auto result = ShaderCompiler::CompileShader(attrib);
|
||||
@@ -42,7 +43,7 @@ namespace MobileGL::MG_State::GLState {
|
||||
m_infoLog = result.error().log;
|
||||
MGLOG_D("ShaderObject::Compile: Shader %d compilation failed.\nSource:\n%s\nInfoLog:\n%s\nSetting "
|
||||
"m_compileStatus = false as a result.",
|
||||
m_externalIndex, m_source.c_str(), m_infoLog.c_str());
|
||||
m_externalIndex, compileSource.c_str(), m_infoLog.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user