editing a program in matdbg should not crash the target (#9373)

fix a couple assert in the OpenGL backend. these should not terminate 
the process when a program fails to compile, in MAT_DGB mode.
This commit is contained in:
Mathias Agopian
2025-10-28 10:42:48 -07:00
committed by GitHub
parent ca038169c6
commit 9c8aea115c
2 changed files with 24 additions and 4 deletions
@@ -52,8 +52,8 @@ using namespace backend;
struct OpenGLProgram::LazyInitializationData {
Program::DescriptorSetInfo descriptorBindings;
Program::BindingUniformsInfo bindingUniformInfo;
utils::FixedCapacityVector<Program::PushConstant> vertexPushConstants;
utils::FixedCapacityVector<Program::PushConstant> fragmentPushConstants;
FixedCapacityVector<Program::PushConstant> vertexPushConstants;
FixedCapacityVector<Program::PushConstant> fragmentPushConstants;
};
@@ -141,7 +141,7 @@ void OpenGLProgram::initializeProgramState(OpenGLContext& context, GLuint progra
context.useProgram(program);
UTILS_NOUNROLL
for (backend::descriptor_set_t set = 0; set < MAX_DESCRIPTOR_SET_COUNT; set++) {
for (descriptor_set_t set = 0; set < MAX_DESCRIPTOR_SET_COUNT; set++) {
for (Program::Descriptor const& entry: lazyInitializationData.descriptorBindings[set]) {
switch (entry.type) {
case DescriptorType::UNIFORM_BUFFER:
@@ -214,8 +214,8 @@ void OpenGLProgram::initializeProgramState(OpenGLContext& context, GLuint progra
case DescriptorType::INPUT_ATTACHMENT:
break;
}
CHECK_GL_ERROR()
}
CHECK_GL_ERROR()
}
if (context.isES2()) {
@@ -346,9 +346,18 @@ void ShaderCompilerService::compileProgram(
// Check status of program linking. If it failed, errors will be logged.
bool const linked = checkLinkStatusAndCleanupShaders(token);
// We panic if it failed to create the program.
#if FILAMENT_ENABLE_MATDBG
if (UTILS_UNLIKELY(!linked)) {
LOG(ERROR) << "OpenGL program " << token->name.c_str_safe()
<< " failed to link or compile";
// this will allow us to continue without crashing
token->gl.program = 0;
}
#else
FILAMENT_CHECK_POSTCONDITION(linked)
<< "OpenGL program " << token->name.c_str_safe()
<< " failed to link or compile";
#endif
}
// Now `token->gl.program` must be populated, so we signal the completion
// of the linking. We don't need to check the result of the program here
@@ -479,16 +488,27 @@ GLuint ShaderCompilerService::initialize(program_token_t& token) {
assert_invariant(token);// This function should be called when the token is still alive.
ensureTokenIsReady(token);
#if !FILAMENT_ENABLE_MATDBG
assert_invariant(token->gl.program);
#endif
GLuint const program = token->gl.program;
if (mMode != Mode::THREAD_POOL) {
// Check status of program linking. If it failed, errors will be logged.
bool const linked = checkLinkStatusAndCleanupShaders(token);
#if FILAMENT_ENABLE_MATDBG
if (UTILS_UNLIKELY(!linked)) {
LOG(ERROR)
<< "OpenGL program " << token->name.c_str_safe() << " failed to link or compile";
token->gl.program = 0;
}
#else
// We panic if it failed to create the program.
FILAMENT_CHECK_POSTCONDITION(linked)
<< "OpenGL program " << token->name.c_str_safe() << " failed to link or compile";
#endif
// The program has been successfully created. Try caching the program blob for
// non-THREAD_POOL modes. In the THREAD_POOL mode, caching is performed in the pool.
tryCachingProgram(mBlobCache, mDriver.mPlatform, token);