Title: [261075] trunk/Source/WebCore
Revision
261075
Author
[email protected]
Date
2020-05-04 00:28:39 -0700 (Mon, 04 May 2020)

Log Message

[gtk] isMainThread() assert when running minibrowser in debug builds.
https://bugs.webkit.org/show_bug.cgi?id=211355

Reviewed by Mark Lam.

Using NeverDestroyed<const AtomString> is discouraged if it is in the non main thread. This can be quite easily wrong:
if the running thread is one of WorkerPool, then this is wrong since AtomStringTable will be destroyed every time underlying
Thread is shutdown. If this is invoked by AutomaticThread, this is also wrong due to the same reason etc. This is why
we introduced MainThreadNeverDestroyed and use it for const AtomString. This restriction found the bug that we are using
`NeverDestroyed<const AtomString>` in non main thread. We should not do that.

This patch fixes the issue by introducing TextureMapperShaderProgram::Variable instead of using AtomString. Then this code
no longer has thread affinity.

* platform/graphics/texmap/TextureMapperShaderProgram.cpp:
(WebCore::TextureMapperShaderProgram::getLocation): Deleted.
* platform/graphics/texmap/TextureMapperShaderProgram.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (261074 => 261075)


--- trunk/Source/WebCore/ChangeLog	2020-05-04 07:16:48 UTC (rev 261074)
+++ trunk/Source/WebCore/ChangeLog	2020-05-04 07:28:39 UTC (rev 261075)
@@ -1,3 +1,23 @@
+2020-05-04  Yusuke Suzuki  <[email protected]>
+
+        [gtk] isMainThread() assert when running minibrowser in debug builds.
+        https://bugs.webkit.org/show_bug.cgi?id=211355
+
+        Reviewed by Mark Lam.
+
+        Using NeverDestroyed<const AtomString> is discouraged if it is in the non main thread. This can be quite easily wrong:
+        if the running thread is one of WorkerPool, then this is wrong since AtomStringTable will be destroyed every time underlying
+        Thread is shutdown. If this is invoked by AutomaticThread, this is also wrong due to the same reason etc. This is why
+        we introduced MainThreadNeverDestroyed and use it for const AtomString. This restriction found the bug that we are using
+        `NeverDestroyed<const AtomString>` in non main thread. We should not do that.
+
+        This patch fixes the issue by introducing TextureMapperShaderProgram::Variable instead of using AtomString. Then this code
+        no longer has thread affinity.
+
+        * platform/graphics/texmap/TextureMapperShaderProgram.cpp:
+        (WebCore::TextureMapperShaderProgram::getLocation): Deleted.
+        * platform/graphics/texmap/TextureMapperShaderProgram.h:
+
 2020-05-04  Emilio Cobos Álvarez  <[email protected]>
 
         Put lh / rlh units behind a flag until bug 211351 is sorted out.

Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperShaderProgram.cpp (261074 => 261075)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperShaderProgram.cpp	2020-05-04 07:16:48 UTC (rev 261074)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperShaderProgram.cpp	2020-05-04 07:28:39 UTC (rev 261075)
@@ -587,16 +587,15 @@
     glUniformMatrix4fv(location, 1, false, floatMatrix.data());
 }
 
-GLuint TextureMapperShaderProgram::getLocation(const AtomString& name, VariableType type)
+GLuint TextureMapperShaderProgram::getLocation(VariableID variable, ASCIILiteral name, VariableType type)
 {
-    auto addResult = m_variables.ensure(name,
+    auto addResult = m_variables.ensure(variable,
         [this, &name, type] {
-            CString nameCString = name.string().utf8();
             switch (type) {
             case UniformVariable:
-                return glGetUniformLocation(m_id, nameCString.data());
+                return glGetUniformLocation(m_id, name);
             case AttribVariable:
-                return glGetAttribLocation(m_id, nameCString.data());
+                return glGetAttribLocation(m_id, name);
             }
             ASSERT_NOT_REACHED();
             return 0;

Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperShaderProgram.h (261074 => 261075)


--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperShaderProgram.h	2020-05-04 07:16:48 UTC (rev 261074)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperShaderProgram.h	2020-05-04 07:28:39 UTC (rev 261075)
@@ -32,16 +32,48 @@
 
 namespace WebCore {
 
+#define TEXMAP_ATTRIBUTE_VARIABLES(macro) \
+    macro(vertex) \
+
+#define TEXMAP_UNIFORM_VARIABLES(macro) \
+    macro(modelViewMatrix) \
+    macro(projectionMatrix) \
+    macro(textureSpaceMatrix) \
+    macro(textureColorSpaceMatrix) \
+    macro(opacity) \
+    macro(color) \
+    macro(expandedQuadEdgesInScreenSpace) \
+    macro(yuvToRgb) \
+    macro(filterAmount) \
+    macro(gaussianKernel) \
+    macro(blurRadius) \
+    macro(shadowOffset) \
+
+#define TEXMAP_SAMPLER_VARIABLES(macro) \
+    macro(sampler) \
+    macro(samplerY) \
+    macro(samplerU) \
+    macro(samplerV) \
+    macro(mask) \
+    macro(contentTexture) \
+    macro(externalOESTexture) \
+
+#define TEXMAP_VARIABLES(macro) \
+    TEXMAP_ATTRIBUTE_VARIABLES(macro) \
+    TEXMAP_UNIFORM_VARIABLES(macro) \
+    TEXMAP_SAMPLER_VARIABLES(macro) \
+
 #define TEXMAP_DECLARE_VARIABLE(Accessor, Name, Type) \
     GLuint Accessor##Location() { \
-        static MainThreadNeverDestroyed<const AtomString> name(Name, AtomString::ConstructFromLiteral); \
-        return getLocation(name.get(), Type); \
+        return getLocation(VariableID::Accessor, Name, Type); \
     }
 
-#define TEXMAP_DECLARE_UNIFORM(Accessor) TEXMAP_DECLARE_VARIABLE(Accessor, "u_"#Accessor, UniformVariable)
-#define TEXMAP_DECLARE_ATTRIBUTE(Accessor) TEXMAP_DECLARE_VARIABLE(Accessor, "a_"#Accessor, AttribVariable)
-#define TEXMAP_DECLARE_SAMPLER(Accessor) TEXMAP_DECLARE_VARIABLE(Accessor, "s_"#Accessor, UniformVariable)
+#define TEXMAP_DECLARE_UNIFORM(Accessor) TEXMAP_DECLARE_VARIABLE(Accessor, "u_"#Accessor""_s, UniformVariable)
+#define TEXMAP_DECLARE_ATTRIBUTE(Accessor) TEXMAP_DECLARE_VARIABLE(Accessor, "a_"#Accessor""_s, AttribVariable)
+#define TEXMAP_DECLARE_SAMPLER(Accessor) TEXMAP_DECLARE_VARIABLE(Accessor, "s_"#Accessor""_s, UniformVariable)
 
+#define TEXMAP_DECLARE_VARIABLE_ENUM(name) name,
+
 class TextureMapperShaderProgram : public RefCounted<TextureMapperShaderProgram> {
 public:
     enum Option {
@@ -69,6 +101,10 @@
         TextureExternalOES = 1L << 22,
     };
 
+    enum class VariableID {
+        TEXMAP_VARIABLES(TEXMAP_DECLARE_VARIABLE_ENUM)
+    };
+
     typedef unsigned Options;
 
     static Ref<TextureMapperShaderProgram> create(Options);
@@ -76,29 +112,11 @@
 
     GLuint programID() const { return m_id; }
 
-    TEXMAP_DECLARE_ATTRIBUTE(vertex)
 
-    TEXMAP_DECLARE_UNIFORM(modelViewMatrix)
-    TEXMAP_DECLARE_UNIFORM(projectionMatrix)
-    TEXMAP_DECLARE_UNIFORM(textureSpaceMatrix)
-    TEXMAP_DECLARE_UNIFORM(textureColorSpaceMatrix)
-    TEXMAP_DECLARE_UNIFORM(opacity)
-    TEXMAP_DECLARE_UNIFORM(color)
-    TEXMAP_DECLARE_UNIFORM(expandedQuadEdgesInScreenSpace)
-    TEXMAP_DECLARE_UNIFORM(yuvToRgb)
-    TEXMAP_DECLARE_SAMPLER(sampler)
-    TEXMAP_DECLARE_SAMPLER(samplerY)
-    TEXMAP_DECLARE_SAMPLER(samplerU)
-    TEXMAP_DECLARE_SAMPLER(samplerV)
-    TEXMAP_DECLARE_SAMPLER(mask)
+    TEXMAP_ATTRIBUTE_VARIABLES(TEXMAP_DECLARE_ATTRIBUTE)
+    TEXMAP_UNIFORM_VARIABLES(TEXMAP_DECLARE_UNIFORM)
+    TEXMAP_SAMPLER_VARIABLES(TEXMAP_DECLARE_SAMPLER)
 
-    TEXMAP_DECLARE_UNIFORM(filterAmount)
-    TEXMAP_DECLARE_UNIFORM(gaussianKernel)
-    TEXMAP_DECLARE_UNIFORM(blurRadius)
-    TEXMAP_DECLARE_UNIFORM(shadowOffset)
-    TEXMAP_DECLARE_SAMPLER(contentTexture)
-    TEXMAP_DECLARE_SAMPLER(externalOESTexture)
-
     void setMatrix(GLuint, const TransformationMatrix&);
 
 private:
@@ -108,10 +126,10 @@
     GLuint m_fragmentShader;
 
     enum VariableType { UniformVariable, AttribVariable };
-    GLuint getLocation(const AtomString&, VariableType);
+    GLuint getLocation(VariableID, ASCIILiteral, VariableType);
 
     GLuint m_id;
-    HashMap<AtomString, GLuint> m_variables;
+    HashMap<VariableID, GLuint, WTF::IntHash<VariableID>, WTF::StrongEnumHashTraits<VariableID>> m_variables;
 };
 
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to