Title: [294290] trunk/Source
Revision
294290
Author
z...@falconsigh.net
Date
2022-05-16 22:52:04 -0700 (Mon, 16 May 2022)

Log Message

[GTK][WPE] Current-context enforcement in ANGLE is expensive
https://bugs.webkit.org/show_bug.cgi?id=240392

Reviewed by Adrian Perez de Castro.

Source/WebCore:

ANGLE's current-context operations are relatively heavy and introduce
detectable overhead when executed for each of many WebGL operation. More
specifically, loads of the current-thread data from thread-local
storage are done under both EGL_GetCurrentContext() and
EGL_MakeCurrent() through the general TLS access model, relying on the
__tls_get_addr function.

Instead, a static thread-local pointer variable is introduced, with the
initial-exec method, containing the address of the current
GraphicsContextGLANGLE object for a given thread. Instead of dipping
into ANGLE to retrieve the current context, the GraphicsContextGLANGLE
object's address is compared to the value of the thread-local variable
and an early return is done if they match.

This model is applied through the TLS_MODEL_INITIAL_EXEC macro that's
defined appropriately if the compiler is detected to support the
required tls_model attribute. This should be the case when targetting
platforms that use ELF, i.e. Unix-like systems but primarily Linux.

The initial-exec TLS model relies on early understanding from the
dynamic linker about what TLS data is required, which enables more
efficient allocation of and access into the required underlying memory.

Caching the current-context data into a static thread-specific variable
with the initial-exec TLS model is the same approach that's taken in the
Mesa library. More on this and other TLS models can be gathered from the
'ELF Handling For Thread-Local Storage' paper by Ulrich Drepper.

* platform/graphics/gbm/GraphicsContextGLGBM.cpp:
(WebCore::GraphicsContextGLANGLE::makeContextCurrent):

Source/WTF:

* wtf/Compiler.h: Define the TLS_MODEL_INITIAL_EXEC macro as the
tls_model attribute with the initial-exec value, to be used on variables
whose TLS model should be adjusted.

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (294289 => 294290)


--- trunk/Source/WTF/ChangeLog	2022-05-17 05:23:02 UTC (rev 294289)
+++ trunk/Source/WTF/ChangeLog	2022-05-17 05:52:04 UTC (rev 294290)
@@ -1,3 +1,14 @@
+2022-05-16  Zan Dobersek  <zdober...@igalia.com>
+
+        [GTK][WPE] Current-context enforcement in ANGLE is expensive
+        https://bugs.webkit.org/show_bug.cgi?id=240392
+
+        Reviewed by Adrian Perez de Castro.
+
+        * wtf/Compiler.h: Define the TLS_MODEL_INITIAL_EXEC macro as the
+        tls_model attribute with the initial-exec value, to be used on variables
+        whose TLS model should be adjusted.
+
 2022-05-16  Mark Lam  <mark....@apple.com>
 
         Add ARM64 disassembler support for symbolic dumping of some well known constants.

Modified: trunk/Source/WTF/wtf/Compiler.h (294289 => 294290)


--- trunk/Source/WTF/wtf/Compiler.h	2022-05-17 05:23:02 UTC (rev 294289)
+++ trunk/Source/WTF/wtf/Compiler.h	2022-05-17 05:52:04 UTC (rev 294290)
@@ -532,3 +532,15 @@
 #if !defined(NO_UNIQUE_ADDRESS)
 #define NO_UNIQUE_ADDRESS
 #endif
+
+/* TLS_MODEL_INITIAL_EXEC */
+
+#if !defined(TLS_MODEL_INITIAL_EXEC) && defined(__has_attribute)
+#if __has_attribute(tls_model)
+#define TLS_MODEL_INITIAL_EXEC __attribute__((tls_model("initial-exec")))
+#endif
+#endif
+
+#if !defined(TLS_MODEL_INITIAL_EXEC)
+#define TLS_MODEL_INITIAL_EXEC
+#endif

Modified: trunk/Source/WebCore/ChangeLog (294289 => 294290)


--- trunk/Source/WebCore/ChangeLog	2022-05-17 05:23:02 UTC (rev 294289)
+++ trunk/Source/WebCore/ChangeLog	2022-05-17 05:52:04 UTC (rev 294290)
@@ -1,3 +1,41 @@
+2022-05-16  Zan Dobersek  <zdober...@igalia.com>
+
+        [GTK][WPE] Current-context enforcement in ANGLE is expensive
+        https://bugs.webkit.org/show_bug.cgi?id=240392
+
+        Reviewed by Adrian Perez de Castro.
+
+        ANGLE's current-context operations are relatively heavy and introduce
+        detectable overhead when executed for each of many WebGL operation. More
+        specifically, loads of the current-thread data from thread-local
+        storage are done under both EGL_GetCurrentContext() and
+        EGL_MakeCurrent() through the general TLS access model, relying on the
+        __tls_get_addr function.
+
+        Instead, a static thread-local pointer variable is introduced, with the
+        initial-exec method, containing the address of the current
+        GraphicsContextGLANGLE object for a given thread. Instead of dipping
+        into ANGLE to retrieve the current context, the GraphicsContextGLANGLE
+        object's address is compared to the value of the thread-local variable
+        and an early return is done if they match.
+
+        This model is applied through the TLS_MODEL_INITIAL_EXEC macro that's
+        defined appropriately if the compiler is detected to support the
+        required tls_model attribute. This should be the case when targetting
+        platforms that use ELF, i.e. Unix-like systems but primarily Linux.
+
+        The initial-exec TLS model relies on early understanding from the
+        dynamic linker about what TLS data is required, which enables more
+        efficient allocation of and access into the required underlying memory.
+
+        Caching the current-context data into a static thread-specific variable
+        with the initial-exec TLS model is the same approach that's taken in the
+        Mesa library. More on this and other TLS models can be gathered from the
+        'ELF Handling For Thread-Local Storage' paper by Ulrich Drepper.
+
+        * platform/graphics/gbm/GraphicsContextGLGBM.cpp:
+        (WebCore::GraphicsContextGLANGLE::makeContextCurrent):
+
 2022-05-16  Mark Lam  <mark....@apple.com>
 
         Add ARM64 disassembler support for symbolic dumping of some well known constants.

Modified: trunk/Source/WebCore/platform/graphics/gbm/GraphicsContextGLGBM.cpp (294289 => 294290)


--- trunk/Source/WebCore/platform/graphics/gbm/GraphicsContextGLGBM.cpp	2022-05-17 05:23:02 UTC (rev 294289)
+++ trunk/Source/WebCore/platform/graphics/gbm/GraphicsContextGLGBM.cpp	2022-05-17 05:52:04 UTC (rev 294290)
@@ -78,11 +78,16 @@
 
 bool GraphicsContextGLANGLE::makeContextCurrent()
 {
+    static thread_local TLS_MODEL_INITIAL_EXEC GraphicsContextGLANGLE* s_currentContext { nullptr };
+
     auto madeCurrent =
         [&] {
-            if (EGL_GetCurrentContext() == m_contextObj)
+            if (s_currentContext == this)
                 return true;
-            return !!EGL_MakeCurrent(m_displayObj, EGL_NO_SURFACE, EGL_NO_SURFACE, m_contextObj);
+            bool current = !!EGL_MakeCurrent(m_displayObj, EGL_NO_SURFACE, EGL_NO_SURFACE, m_contextObj);
+            if (current)
+                s_currentContext = this;
+            return current;
         }();
 
     auto& contextSwapchain = static_cast<GraphicsContextGLGBM&>(*this).swapchain();
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to