Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Added assert for opengles thread safety #56585

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions impeller/renderer/backend/gles/proc_table_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ ProcTableGLES::ProcTableGLES( // NOLINT(google-readability-function-size)

capabilities_ = std::make_shared<CapabilitiesGLES>(*this);

// This this will force glUseProgram to only be used on one thread in debug
// builds to identify threading violations in the engine.
UseProgram.enforce_one_thread = true;

is_valid_ = true;
}

Expand Down
20 changes: 20 additions & 0 deletions impeller/renderer/backend/gles/proc_table_gles.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#define FLUTTER_IMPELLER_RENDERER_BACKEND_GLES_PROC_TABLE_GLES_H_

#include <functional>
#include <mutex>
#include <string>
#include <thread>

#include "flutter/fml/logging.h"
#include "flutter/fml/mapping.h"
Expand Down Expand Up @@ -99,6 +101,14 @@ struct GLProc {
///
bool log_calls = false;

//----------------------------------------------------------------------------
/// Whether the OpenGL call asserts it is only used from / one thread in
/// IMPELLER_DEBUG builds.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMPELLER_DEBUG is debug/profile mode. !defined(NDEBUG) means unopt local engine IIRC, that should be fine.

///
/// This is used to block drawing calls from happening anywhere but the raster
/// thread.
bool enforce_one_thread = false;

//----------------------------------------------------------------------------
/// @brief Call the GL function with the appropriate parameters. Lookup
/// the documentation for the GL function being called to
Expand All @@ -118,6 +128,16 @@ struct GLProc {
FML_LOG(IMPORTANT) << name
<< BuildGLArguments(std::forward<Args>(args)...);
}
if (enforce_one_thread) {
static std::thread::id allowed_thread;
static std::once_flag flag;
std::call_once(flag,
[]() { allowed_thread = std::this_thread::get_id(); });
FML_CHECK(std::this_thread::get_id() == allowed_thread)
<< "This symbol is expected to be called from one thread, the raster "
"thread. As of this addition, the design of the engine should be "
"using non-raster threads only for uploading images.";
}
#endif // defined(IMPELLER_DEBUG) && !defined(NDEBUG)
return function(std::forward<Args>(args)...);
}
Expand Down