From 9c8aea115c2a59ddee6318faa8af8aad314413f2 Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Tue, 28 Oct 2025 10:42:48 -0700 Subject: [PATCH] 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. --- filament/backend/src/opengl/OpenGLProgram.cpp | 8 ++++---- .../src/opengl/ShaderCompilerService.cpp | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/filament/backend/src/opengl/OpenGLProgram.cpp b/filament/backend/src/opengl/OpenGLProgram.cpp index 1b80b7e484..8975d001f6 100644 --- a/filament/backend/src/opengl/OpenGLProgram.cpp +++ b/filament/backend/src/opengl/OpenGLProgram.cpp @@ -52,8 +52,8 @@ using namespace backend; struct OpenGLProgram::LazyInitializationData { Program::DescriptorSetInfo descriptorBindings; Program::BindingUniformsInfo bindingUniformInfo; - utils::FixedCapacityVector vertexPushConstants; - utils::FixedCapacityVector fragmentPushConstants; + FixedCapacityVector vertexPushConstants; + FixedCapacityVector 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()) { diff --git a/filament/backend/src/opengl/ShaderCompilerService.cpp b/filament/backend/src/opengl/ShaderCompilerService.cpp index dcd751e860..b9545176e1 100644 --- a/filament/backend/src/opengl/ShaderCompilerService.cpp +++ b/filament/backend/src/opengl/ShaderCompilerService.cpp @@ -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);