185 lines
5.3 KiB
Diff
185 lines
5.3 KiB
Diff
From 3cba1bd283e2174049c3871070e19a7325875598 Mon Sep 17 00:00:00 2001
|
|
From: Alvin Wong <alvinhochun@gmail.com>
|
|
Date: Fri, 25 Mar 2022 16:36:39 +0800
|
|
Subject: [PATCH 17/17] Replace `extern thread_local` to avoid GCC mingw-w64
|
|
bug
|
|
|
|
GCC generates broken code for mingw-w64 target when accessing `extern
|
|
thread_local` variables from another compilation unit.
|
|
|
|
GCC bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104862
|
|
---
|
|
src/libANGLE/Context.cpp | 14 +++++++++-----
|
|
src/libANGLE/Context.h | 4 ----
|
|
src/libGLESv2/global_state.cpp | 30 +++++++++---------------------
|
|
src/libGLESv2/global_state.h | 12 ------------
|
|
4 files changed, 18 insertions(+), 42 deletions(-)
|
|
|
|
diff --git a/src/libANGLE/Context.cpp b/src/libANGLE/Context.cpp
|
|
index bd9e3cd6a..fd5e51cfb 100644
|
|
--- a/src/libANGLE/Context.cpp
|
|
+++ b/src/libANGLE/Context.cpp
|
|
@@ -387,7 +387,15 @@ void SetCurrentValidContextTLS(Context *context)
|
|
SetTLSValue(CurrentValidContextIndex, context);
|
|
}
|
|
#else
|
|
-thread_local Context *gCurrentValidContext = nullptr;
|
|
+static thread_local Context *gCurrentValidContext = nullptr;
|
|
+Context *GetCurrentValidContextTLS()
|
|
+{
|
|
+ return gCurrentValidContext;
|
|
+}
|
|
+void SetCurrentValidContextTLS(Context *context)
|
|
+{
|
|
+ gCurrentValidContext = context;
|
|
+}
|
|
#endif
|
|
|
|
Context::Context(egl::Display *display,
|
|
@@ -2907,11 +2915,7 @@ void Context::setContextLost()
|
|
mSkipValidation = false;
|
|
|
|
// Make sure we update TLS.
|
|
-#if defined(ANGLE_PLATFORM_APPLE)
|
|
SetCurrentValidContextTLS(nullptr);
|
|
-#else
|
|
- gCurrentValidContext = nullptr;
|
|
-#endif
|
|
}
|
|
|
|
GLenum Context::getGraphicsResetStatus()
|
|
diff --git a/src/libANGLE/Context.h b/src/libANGLE/Context.h
|
|
index 42cfde7c0..c6fda14ba 100644
|
|
--- a/src/libANGLE/Context.h
|
|
+++ b/src/libANGLE/Context.h
|
|
@@ -855,12 +855,8 @@ class ANGLE_NO_DISCARD ScopedContextRef
|
|
};
|
|
|
|
// Thread-local current valid context bound to the thread.
|
|
-#if defined(ANGLE_PLATFORM_APPLE)
|
|
extern Context *GetCurrentValidContextTLS();
|
|
extern void SetCurrentValidContextTLS(Context *context);
|
|
-#else
|
|
-extern thread_local Context *gCurrentValidContext;
|
|
-#endif
|
|
|
|
} // namespace gl
|
|
|
|
diff --git a/src/libGLESv2/global_state.cpp b/src/libGLESv2/global_state.cpp
|
|
index f29b0b6c8..e7e3bf5c4 100644
|
|
--- a/src/libGLESv2/global_state.cpp
|
|
+++ b/src/libGLESv2/global_state.cpp
|
|
@@ -52,21 +52,13 @@ Thread *AllocateCurrentThread()
|
|
// Global thread intentionally leaked
|
|
ANGLE_SCOPED_DISABLE_LSAN();
|
|
thread = new Thread();
|
|
-#if defined(ANGLE_PLATFORM_APPLE)
|
|
SetCurrentThreadTLS(thread);
|
|
-#else
|
|
- gCurrentThread = thread;
|
|
-#endif
|
|
}
|
|
|
|
// Initialize fast TLS slot
|
|
SetContextToAndroidOpenGLTLSSlot(nullptr);
|
|
|
|
-#if defined(ANGLE_PLATFORM_APPLE)
|
|
gl::SetCurrentValidContextTLS(nullptr);
|
|
-#else
|
|
- gl::gCurrentValidContext = nullptr;
|
|
-#endif
|
|
|
|
#if defined(ANGLE_PLATFORM_ANDROID)
|
|
static pthread_once_t keyOnce = PTHREAD_ONCE_INIT;
|
|
@@ -142,7 +134,15 @@ void SetCurrentThreadTLS(Thread *thread)
|
|
SetTLSValue(CurrentThreadIndex, thread);
|
|
}
|
|
#else
|
|
-thread_local Thread *gCurrentThread = nullptr;
|
|
+static thread_local Thread *gCurrentThread = nullptr;
|
|
+Thread *GetCurrentThreadTLS()
|
|
+{
|
|
+ return gCurrentThread;
|
|
+}
|
|
+void SetCurrentThreadTLS(Thread *thread)
|
|
+{
|
|
+ gCurrentThread = thread;
|
|
+}
|
|
#endif
|
|
|
|
angle::GlobalMutex &GetGlobalMutex()
|
|
@@ -171,30 +171,18 @@ void SetGlobalLastContext(gl::Context *context)
|
|
// It also causes a flaky false positive in TSAN. http://crbug.com/1223970
|
|
ANGLE_NO_SANITIZE_MEMORY ANGLE_NO_SANITIZE_THREAD Thread *GetCurrentThread()
|
|
{
|
|
-#if defined(ANGLE_PLATFORM_APPLE)
|
|
Thread *current = GetCurrentThreadTLS();
|
|
-#else
|
|
- Thread *current = gCurrentThread;
|
|
-#endif
|
|
return (current ? current : AllocateCurrentThread());
|
|
}
|
|
|
|
void SetContextCurrent(Thread *thread, gl::Context *context)
|
|
{
|
|
-#if defined(ANGLE_PLATFORM_APPLE)
|
|
Thread *currentThread = GetCurrentThreadTLS();
|
|
-#else
|
|
- Thread *currentThread = gCurrentThread;
|
|
-#endif
|
|
ASSERT(currentThread);
|
|
currentThread->setCurrent(context);
|
|
SetContextToAndroidOpenGLTLSSlot(context);
|
|
|
|
-#if defined(ANGLE_PLATFORM_APPLE)
|
|
gl::SetCurrentValidContextTLS(context);
|
|
-#else
|
|
- gl::gCurrentValidContext = context;
|
|
-#endif
|
|
|
|
#if defined(ANGLE_FORCE_CONTEXT_CHECK_EVERY_CALL)
|
|
DirtyContextIfNeeded(context);
|
|
diff --git a/src/libGLESv2/global_state.h b/src/libGLESv2/global_state.h
|
|
index 41d7db82c..b410c8f3c 100644
|
|
--- a/src/libGLESv2/global_state.h
|
|
+++ b/src/libGLESv2/global_state.h
|
|
@@ -93,12 +93,8 @@ namespace egl
|
|
class Debug;
|
|
class Thread;
|
|
|
|
-#if defined(ANGLE_PLATFORM_APPLE)
|
|
extern Thread *GetCurrentThreadTLS();
|
|
extern void SetCurrentThreadTLS(Thread *thread);
|
|
-#else
|
|
-extern thread_local Thread *gCurrentThread;
|
|
-#endif
|
|
|
|
angle::GlobalMutex &GetGlobalMutex();
|
|
angle::GlobalMutex &GetGlobalSurfaceMutex();
|
|
@@ -141,11 +137,7 @@ ANGLE_INLINE Context *GetGlobalContext()
|
|
}
|
|
#endif
|
|
|
|
-#if defined(ANGLE_PLATFORM_APPLE)
|
|
egl::Thread *currentThread = egl::GetCurrentThreadTLS();
|
|
-#else
|
|
- egl::Thread *currentThread = egl::gCurrentThread;
|
|
-#endif
|
|
ASSERT(currentThread);
|
|
return currentThread->getContext();
|
|
}
|
|
@@ -165,11 +157,7 @@ ANGLE_INLINE Context *GetValidGlobalContext()
|
|
}
|
|
#endif
|
|
|
|
-#if defined(ANGLE_PLATFORM_APPLE)
|
|
return GetCurrentValidContextTLS();
|
|
-#else
|
|
- return gCurrentValidContext;
|
|
-#endif
|
|
}
|
|
|
|
// Generate a context lost error on the context if it is non-null and lost.
|
|
--
|
|
2.24.1.windows.2
|
|
|