Skip to content

Commit

Permalink
Only call .put if the tick op was canceled (#7152)
Browse files Browse the repository at this point in the history
  • Loading branch information
bejado authored Sep 11, 2023
1 parent 3ab7780 commit d328b64
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions filament/backend/src/opengl/ShaderCompilerService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ GLuint ShaderCompilerService::getProgram(ShaderCompilerService::program_token_t&

token->canceled = true;

token->compiler.cancelTickOp(token);
bool canceled = token->compiler.cancelTickOp(token);

if (token->compiler.mShaderCompilerThreadCount) {
auto job = token->compiler.mCompilerThreadPool.dequeue(token);
Expand All @@ -354,7 +354,7 @@ GLuint ShaderCompilerService::getProgram(ShaderCompilerService::program_token_t&
// order for future callbacks to be successfully called.
token->compiler.mCallbackManager.put(token->handle);
}
} else {
} else if (canceled) {
// Since the tick op was canceled, we need to .put the token here.
token->compiler.mCallbackManager.put(token->handle);
}
Expand Down Expand Up @@ -683,17 +683,19 @@ void ShaderCompilerService::runAtNextTick(CompilerPriorityQueue priority,
SYSTRACE_VALUE32("ShaderCompilerService Jobs", mRunAtNextTickOps.size());
}

void ShaderCompilerService::cancelTickOp(program_token_t token) noexcept {
bool ShaderCompilerService::cancelTickOp(program_token_t token) noexcept {
// We do a linear search here, but this is rare, and we know the list is pretty small.
auto& ops = mRunAtNextTickOps;
auto pos = std::find_if(ops.begin(), ops.end(), [&](const auto& item) {
return std::get<1>(item) == token;
});
if (pos != ops.end()) {
ops.erase(pos);
return true;
}
SYSTRACE_CONTEXT();
SYSTRACE_VALUE32("ShaderCompilerService Jobs", ops.size());
return false;
}

void ShaderCompilerService::executeTickOps() noexcept {
Expand Down
2 changes: 1 addition & 1 deletion filament/backend/src/opengl/ShaderCompilerService.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class ShaderCompilerService {
void runAtNextTick(CompilerPriorityQueue priority,
const program_token_t& token, Job job) noexcept;
void executeTickOps() noexcept;
void cancelTickOp(program_token_t token) noexcept;
bool cancelTickOp(program_token_t token) noexcept;
// order of insertion is important

using ContainerType = std::tuple<CompilerPriorityQueue, program_token_t, Job>;
Expand Down

0 comments on commit d328b64

Please sign in to comment.