From dffa7a29a4e847fb0cf9ced4c88b0ff38b49339b Mon Sep 17 00:00:00 2001 From: Sungun Park Date: Wed, 4 Jun 2025 16:44:48 +0000 Subject: [PATCH] Fix: Submit callback handle on completion (#8818) This reverts a behavioral regression introduced in commit c3542b135e, which deferred callback submission until the program was first used. This commit restores the correct behavior by submitting the callback handle as soon as the token's work is complete. This occurs either upon successful `gl.program` population or via cancellation, ensuring the caller is properly notified that the resource loading operation has concluded. --- .../src/opengl/ShaderCompilerService.cpp | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/filament/backend/src/opengl/ShaderCompilerService.cpp b/filament/backend/src/opengl/ShaderCompilerService.cpp index 46d0a14eab..d51703c245 100644 --- a/filament/backend/src/opengl/ShaderCompilerService.cpp +++ b/filament/backend/src/opengl/ShaderCompilerService.cpp @@ -23,6 +23,7 @@ #include "OpenGLDriver.h" #include +#include #include #include @@ -110,7 +111,17 @@ struct ShaderCompilerService::OpenGLProgramToken : ProgramToken { cond.wait(l, [this] { return signaled; }); } - CallbackManager::Handle handle{}; + // This is invoked upon token completion, which occurs after a successful `gl.program` + // population or upon cancellation. In either scenario, the callback handle must be submitted + // to notify the caller that resource loading has concluded. + void trySubmittingCallback() noexcept { + if (handle) { + compiler.submitCallbackHandle(*handle); + handle = std::nullopt; + } + } + + std::optional handle{}; BlobCacheKey key; // Used for the `THREAD_POOL` mode. @@ -120,7 +131,7 @@ struct ShaderCompilerService::OpenGLProgramToken : ProgramToken { }; ShaderCompilerService::OpenGLProgramToken::~OpenGLProgramToken() { - compiler.submitCallbackHandle(handle); + trySubmittingCallback(); } /* static */ void ShaderCompilerService::setUserData(const program_token_t& token, @@ -339,7 +350,7 @@ GLuint ShaderCompilerService::getProgram(program_token_t& token) { // Cleanup the token. token->compiler.cancelTickOp(token); - token = nullptr;// This will submit a callback condition (handle) to the callback manager. + token = nullptr; // This will try submitting a callback handle to the callback manager. } void ShaderCompilerService::tick() { @@ -392,7 +403,7 @@ GLuint ShaderCompilerService::initialize(program_token_t& token) { // Cleanup the token. token->compiler.cancelTickOp(token); - token = nullptr;// This will submit a callback condition (handle) to the callback manager. + token = nullptr; return program; } @@ -659,6 +670,7 @@ void ShaderCompilerService::executeTickOps() noexcept { } glLinkProgram(program); token->gl.program = program; + token->trySubmittingCallback(); } /* static */ bool ShaderCompilerService::isLinkCompleted(program_token_t const& token) noexcept {