Commit 067687f4 by Geoff Lang Committed by Commit Bot

Removal global locks from GL entry points. Always lock in EGL.

The ANGLE Vulkan backend is now thread safe for non-share group contexts. This means that a global GL lock only adds overhead for most use cases. Remove the angle_force_thread_safety gn argument. BUG=angleproject:2464 Change-Id: Ic6ba89e18b46e5dd72aa83d0f409097441fcca3a Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1635749 Commit-Queue: Geoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarTobin Ehlis <tobine@google.com>
parent 9d275db4
...@@ -92,10 +92,6 @@ config("internal_config") { ...@@ -92,10 +92,6 @@ config("internal_config") {
defines += [ "ANGLE_IS_32_BIT_CPU" ] defines += [ "ANGLE_IS_32_BIT_CPU" ]
} }
if (angle_force_thread_safety) {
defines += [ "ANGLE_FORCE_THREAD_SAFETY=1" ]
}
if (angle_enable_vulkan) { if (angle_enable_vulkan) {
if (angle_enable_vulkan_gpu_trace_events) { if (angle_enable_vulkan_gpu_trace_events) {
defines += [ "ANGLE_ENABLE_VULKAN_GPU_TRACE_EVENTS=1" ] defines += [ "ANGLE_ENABLE_VULKAN_GPU_TRACE_EVENTS=1" ]
......
...@@ -63,7 +63,6 @@ declare_args() { ...@@ -63,7 +63,6 @@ declare_args() {
angle_enable_null = true angle_enable_null = true
angle_enable_essl = true angle_enable_essl = true
angle_enable_glsl = true angle_enable_glsl = true
angle_force_thread_safety = false
} }
declare_args() { declare_args() {
......
...@@ -116,7 +116,6 @@ template_entry_point_decl = """ANGLE_EXPORT {return_type}GL_APIENTRY {name}{expl ...@@ -116,7 +116,6 @@ template_entry_point_decl = """ANGLE_EXPORT {return_type}GL_APIENTRY {name}{expl
template_entry_point_def = """{return_type}GL_APIENTRY {name}{explicit_context_suffix}({explicit_context_param}{explicit_context_comma}{params}) template_entry_point_def = """{return_type}GL_APIENTRY {name}{explicit_context_suffix}({explicit_context_param}{explicit_context_comma}{params})
{{ {{
ANGLE_SCOPED_GLOBAL_LOCK();
{event_comment}EVENT("({format_params})"{comma_if_needed}{pass_params}); {event_comment}EVENT("({format_params})"{comma_if_needed}{pass_params});
Context *context = {context_getter}; Context *context = {context_getter};
......
...@@ -94,7 +94,7 @@ ...@@ -94,7 +94,7 @@
"GL/EGL entry points:scripts/entry_point_packed_gl_enums.json": "GL/EGL entry points:scripts/entry_point_packed_gl_enums.json":
"45513f3dd0e9cf5a93de3172b92636f4", "45513f3dd0e9cf5a93de3172b92636f4",
"GL/EGL entry points:scripts/generate_entry_points.py": "GL/EGL entry points:scripts/generate_entry_points.py":
"df89665814d74ffd16c70f017f0ef4d7", "1e493331ee0ab7d5e210a125cb248f0b",
"GL/EGL entry points:scripts/gl.xml": "GL/EGL entry points:scripts/gl.xml":
"b470cb06b06cbbe7adb2c8129ec85708", "b470cb06b06cbbe7adb2c8129ec85708",
"GL/EGL entry points:scripts/gl_angle_ext.xml": "GL/EGL entry points:scripts/gl_angle_ext.xml":
...@@ -124,23 +124,23 @@ ...@@ -124,23 +124,23 @@
"GL/EGL entry points:src/libGLESv2/entry_points_enum_autogen.h": "GL/EGL entry points:src/libGLESv2/entry_points_enum_autogen.h":
"8d4af523c6da76ff7c47302c8dc5b30d", "8d4af523c6da76ff7c47302c8dc5b30d",
"GL/EGL entry points:src/libGLESv2/entry_points_gles_1_0_autogen.cpp": "GL/EGL entry points:src/libGLESv2/entry_points_gles_1_0_autogen.cpp":
"196771da8ad7a5beded1dc878410ac11", "153739031e8ae415fe42ecc9c132ffb2",
"GL/EGL entry points:src/libGLESv2/entry_points_gles_1_0_autogen.h": "GL/EGL entry points:src/libGLESv2/entry_points_gles_1_0_autogen.h":
"77fa8d307ebf839838f8812786cddc1a", "77fa8d307ebf839838f8812786cddc1a",
"GL/EGL entry points:src/libGLESv2/entry_points_gles_2_0_autogen.cpp": "GL/EGL entry points:src/libGLESv2/entry_points_gles_2_0_autogen.cpp":
"4f86bb77e2f29c6c1994448ab55d772f", "835cbe8088a7670776a82ee4099fdc54",
"GL/EGL entry points:src/libGLESv2/entry_points_gles_2_0_autogen.h": "GL/EGL entry points:src/libGLESv2/entry_points_gles_2_0_autogen.h":
"3bbaf1cf42fba5d675e5b54cd1d14df7", "3bbaf1cf42fba5d675e5b54cd1d14df7",
"GL/EGL entry points:src/libGLESv2/entry_points_gles_3_0_autogen.cpp": "GL/EGL entry points:src/libGLESv2/entry_points_gles_3_0_autogen.cpp":
"94cf20c29469d508af7f5e0a791ccd6a", "f460f746355e979a10529124efa43c4c",
"GL/EGL entry points:src/libGLESv2/entry_points_gles_3_0_autogen.h": "GL/EGL entry points:src/libGLESv2/entry_points_gles_3_0_autogen.h":
"395f6978219abd5182bbe80cc367e40c", "395f6978219abd5182bbe80cc367e40c",
"GL/EGL entry points:src/libGLESv2/entry_points_gles_3_1_autogen.cpp": "GL/EGL entry points:src/libGLESv2/entry_points_gles_3_1_autogen.cpp":
"72188430258b99258cef9048f0f4b4ee", "f4cc6820dc6c734cfd4b919d61ed4322",
"GL/EGL entry points:src/libGLESv2/entry_points_gles_3_1_autogen.h": "GL/EGL entry points:src/libGLESv2/entry_points_gles_3_1_autogen.h":
"043d09a964c740067bf4279e0b544aed", "043d09a964c740067bf4279e0b544aed",
"GL/EGL entry points:src/libGLESv2/entry_points_gles_ext_autogen.cpp": "GL/EGL entry points:src/libGLESv2/entry_points_gles_ext_autogen.cpp":
"b07363bbb245fb1b229e5391280c9f43", "b56592ebcd1bed250682e9a9230543ea",
"GL/EGL entry points:src/libGLESv2/entry_points_gles_ext_autogen.h": "GL/EGL entry points:src/libGLESv2/entry_points_gles_ext_autogen.h":
"ad2d05812814ba9016080ba56e6c4218", "ad2d05812814ba9016080ba56e6c4218",
"GL/EGL entry points:src/libGLESv2/libGLESv2_autogen.cpp": "GL/EGL entry points:src/libGLESv2/libGLESv2_autogen.cpp":
......
...@@ -55,11 +55,6 @@ ...@@ -55,11 +55,6 @@
// Controls if our threading code uses std::async or falls back to single-threaded operations. // Controls if our threading code uses std::async or falls back to single-threaded operations.
#if !defined(ANGLE_STD_ASYNC_WORKERS) #if !defined(ANGLE_STD_ASYNC_WORKERS)
# define ANGLE_STD_ASYNC_WORKERS ANGLE_ENABLED # define ANGLE_STD_ASYNC_WORKERS ANGLE_ENABLED
#endif // !defined(ANGLE_STD_ASYNC_WORKERS) #endif // !defined(ANGLE_STD_ASYNC_WORKERS)
// Force thread safety in all of ANGLE by locking a global mutex in every ANGLE entry point.
#if !defined(ANGLE_FORCE_THREAD_SAFETY)
# define ANGLE_FORCE_THREAD_SAFETY ANGLE_DISABLED
#endif // !defined(ANGLE_FORCE_THREAD_SAFETY)
#endif // LIBANGLE_FEATURES_H_ #endif // LIBANGLE_FEATURES_H_
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -35,6 +35,11 @@ namespace ...@@ -35,6 +35,11 @@ namespace
{ {
static TLSIndex threadTLS = TLS_INVALID_INDEX; static TLSIndex threadTLS = TLS_INVALID_INDEX;
Debug *g_Debug = nullptr; Debug *g_Debug = nullptr;
std::atomic<std::mutex *> g_Mutex;
static_assert(std::is_trivially_constructible<decltype(g_Mutex)>::value,
"global mutex is not trivially constructible");
static_assert(std::is_trivially_destructible<decltype(g_Mutex)>::value,
"global mutex is not trivially destructible");
Thread *AllocateCurrentThread() Thread *AllocateCurrentThread()
{ {
...@@ -56,15 +61,34 @@ Thread *AllocateCurrentThread() ...@@ -56,15 +61,34 @@ Thread *AllocateCurrentThread()
void AllocateDebug() void AllocateDebug()
{ {
// TODO(geofflang): Lock around global allocation. http://anglebug.com/2464 // All EGL calls use a global lock, this is thread safe
if (g_Debug == nullptr) if (g_Debug == nullptr)
{ {
g_Debug = new Debug(); g_Debug = new Debug();
} }
} }
void AllocateMutex()
{
if (g_Mutex == nullptr)
{
std::unique_ptr<std::mutex> newMutex(new std::mutex());
std::mutex *expected = nullptr;
if (g_Mutex.compare_exchange_strong(expected, newMutex.get()))
{
newMutex.release();
}
}
}
} // anonymous namespace } // anonymous namespace
std::mutex &GetGlobalMutex()
{
AllocateMutex();
return *g_Mutex;
}
Thread *GetCurrentThread() Thread *GetCurrentThread()
{ {
// Create a TLS index if one has not been created for this DLL // Create a TLS index if one has not been created for this DLL
...@@ -109,21 +133,6 @@ void SetContextCurrent(Thread *thread, gl::Context *context) ...@@ -109,21 +133,6 @@ void SetContextCurrent(Thread *thread, gl::Context *context)
} }
} // namespace egl } // namespace egl
#if ANGLE_FORCE_THREAD_SAFETY == ANGLE_ENABLED
namespace angle
{
namespace
{
std::mutex g_Mutex;
} // anonymous namespace
std::mutex &GetGlobalMutex()
{
return g_Mutex;
}
} // namespace angle
#endif
#ifdef ANGLE_PLATFORM_WINDOWS #ifdef ANGLE_PLATFORM_WINDOWS
namespace egl namespace egl
{ {
...@@ -143,11 +152,19 @@ void DealocateDebug() ...@@ -143,11 +152,19 @@ void DealocateDebug()
SafeDelete(g_Debug); SafeDelete(g_Debug);
} }
void DealocateMutex()
{
std::mutex *mutex = g_Mutex.exchange(nullptr);
SafeDelete(mutex);
}
bool InitializeProcess() bool InitializeProcess()
{ {
ASSERT(g_Debug == nullptr); ASSERT(g_Debug == nullptr);
AllocateDebug(); AllocateDebug();
AllocateMutex();
threadTLS = CreateTLSIndex(); threadTLS = CreateTLSIndex();
if (threadTLS == TLS_INVALID_INDEX) if (threadTLS == TLS_INVALID_INDEX)
{ {
...@@ -161,6 +178,8 @@ bool TerminateProcess() ...@@ -161,6 +178,8 @@ bool TerminateProcess()
{ {
DealocateDebug(); DealocateDebug();
DealocateMutex();
if (!DeallocateCurrentThread()) if (!DeallocateCurrentThread())
{ {
return false; return false;
......
...@@ -21,11 +21,15 @@ namespace egl ...@@ -21,11 +21,15 @@ namespace egl
class Debug; class Debug;
class Thread; class Thread;
std::mutex &GetGlobalMutex();
Thread *GetCurrentThread(); Thread *GetCurrentThread();
Debug *GetDebug(); Debug *GetDebug();
void SetContextCurrent(Thread *thread, gl::Context *context); void SetContextCurrent(Thread *thread, gl::Context *context);
} // namespace egl } // namespace egl
#define ANGLE_SCOPED_GLOBAL_LOCK() \
std::lock_guard<std::mutex> globalMutexLock(egl::GetGlobalMutex())
namespace gl namespace gl
{ {
extern Context *gSingleThreadedContext; extern Context *gSingleThreadedContext;
...@@ -54,16 +58,4 @@ ANGLE_INLINE Context *GetValidGlobalContext() ...@@ -54,16 +58,4 @@ ANGLE_INLINE Context *GetValidGlobalContext()
} // namespace gl } // namespace gl
#if ANGLE_FORCE_THREAD_SAFETY == ANGLE_ENABLED
namespace angle
{
std::mutex &GetGlobalMutex();
} // namespace angle
# define ANGLE_SCOPED_GLOBAL_LOCK() \
std::lock_guard<std::mutex> globalMutexLock(angle::GetGlobalMutex())
#else
# define ANGLE_SCOPED_GLOBAL_LOCK()
#endif
#endif // LIBGLESV2_GLOBALSTATE_H_ #endif // LIBGLESV2_GLOBALSTATE_H_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment