Diff
Modified: trunk/Source/WebCore/ChangeLog (279623 => 279624)
--- trunk/Source/WebCore/ChangeLog 2021-07-06 22:27:21 UTC (rev 279623)
+++ trunk/Source/WebCore/ChangeLog 2021-07-06 22:33:57 UTC (rev 279624)
@@ -1,3 +1,29 @@
+2021-07-06 Kimmo Kinnunen <kkinnu...@apple.com>
+
+ WebGL video to texture upload spends time clearing the uploaded-to texture
+ https://bugs.webkit.org/show_bug.cgi?id=227582
+ <rdar://problem/80020335>
+
+ Reviewed by Kenneth Russell.
+
+ Disable robust resource initiaization for the shared ANGLE context that is used
+ to copy video frames to WebGL textures. Otherwise ANGLE would spend time
+ initializing the texture in `gl::DrawArrays`.
+
+ No new tests, we currently do not have WebGL perf tests.
+
+ * platform/graphics/angle/GraphicsContextGLANGLE.cpp:
+ (WebCore::GraphicsContextGLOpenGL::texImage2DDirect):
+ Add the direct texImage2D call so that the texture seed can be
+ somehow updated. This will be removed once the texture image version
+ management is fixed to be a bit more robust.
+
+ * platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm:
+ (WebCore::GraphicsContextGLOpenGL::GraphicsContextGLOpenGL):
+ * platform/graphics/cv/GraphicsContextGLCVANGLE.cpp:
+ (WebCore::GraphicsContextGLCVANGLE::copyPixelBufferToTexture):
+ * platform/graphics/opengl/GraphicsContextGLOpenGL.h:
+
2021-07-06 Simon Fraser <simon.fra...@apple.com>
RenderLayer does not need a virtual destructor
Modified: trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp (279623 => 279624)
--- trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp 2021-07-06 22:27:21 UTC (rev 279623)
+++ trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp 2021-07-06 22:33:57 UTC (rev 279624)
@@ -930,6 +930,14 @@
gl::CompileShader(shader);
}
+void GraphicsContextGLOpenGL::texImage2DDirect(GCGLenum target, GCGLint level, GCGLenum internalformat, GCGLsizei width, GCGLsizei height, GCGLint border, GCGLenum format, GCGLenum type, const void* pixels)
+{
+ if (!makeContextCurrent())
+ return;
+ gl::TexImage2D(target, level, internalformat, width, height, border, format, type, pixels);
+ m_state.textureSeedCount.add(m_state.currentBoundTexture());
+}
+
void GraphicsContextGLOpenGL::copyTexImage2D(GCGLenum target, GCGLint level, GCGLenum internalformat, GCGLint x, GCGLint y, GCGLsizei width, GCGLsizei height, GCGLint border)
{
if (!makeContextCurrent())
Modified: trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm (279623 => 279624)
--- trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm 2021-07-06 22:27:21 UTC (rev 279623)
+++ trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm 2021-07-06 22:33:57 UTC (rev 279624)
@@ -267,10 +267,13 @@
// context.
eglContextAttributes.append(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE);
eglContextAttributes.append(EGL_TRUE);
+ // WebGL requires that all resources are cleared at creation.
+ // FIXME: performing robust resource initialization in the VideoTextureCopier adds a large amount of overhead
+ // so it would be nice to avoid that there (we should always be touching every pixel as we copy).
+ eglContextAttributes.append(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE);
+ eglContextAttributes.append(EGL_TRUE);
}
- // WebGL requires that all resources are cleared at creation.
- eglContextAttributes.append(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE);
- eglContextAttributes.append(EGL_TRUE);
+
// WebGL doesn't allow client arrays.
eglContextAttributes.append(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE);
eglContextAttributes.append(EGL_FALSE);
Modified: trunk/Source/WebCore/platform/graphics/cv/GraphicsContextGLCVANGLE.cpp (279623 => 279624)
--- trunk/Source/WebCore/platform/graphics/cv/GraphicsContextGLCVANGLE.cpp 2021-07-06 22:27:21 UTC (rev 279623)
+++ trunk/Source/WebCore/platform/graphics/cv/GraphicsContextGLCVANGLE.cpp 2021-07-06 22:33:57 UTC (rev 279624)
@@ -428,6 +428,31 @@
return iterator->second;
}
+namespace {
+
+// Scoped holder of a cleanup function. Calls the function at the end of the scope.
+// Note: Releases the reference to the function only after the scope, not
+// at the time of `reset()` call.
+template <typename F>
+class ScopedCleanup {
+public:
+ explicit ScopedCleanup(F&& function)
+ : m_function(WTFMove(function))
+ {
+ }
+ ~ScopedCleanup()
+ {
+ if (m_shouldCall)
+ m_function();
+ }
+ void reset() { m_shouldCall = false; }
+private:
+ bool m_shouldCall = true;
+ const F m_function;
+};
+
+}
+
GraphicsContextGLCVANGLE::GraphicsContextGLCVANGLE(GraphicsContextGLOpenGL& context)
: m_context(GraphicsContextGLOpenGL::createShared(context))
, m_framebuffer(m_context->createFramebuffer())
@@ -603,6 +628,15 @@
m_context->bindFramebuffer(GraphicsContextGL::FRAMEBUFFER, m_framebuffer);
+ // The outputTexture might contain uninitialized content on early-outs. Clear it in cases
+ // autoClearTextureOnError is not reset.
+ auto autoClearTextureOnError = ScopedCleanup {
+ [outputTexture, level, internalFormat, format, type, context = m_context.ptr()] {
+ context->bindTexture(GraphicsContextGL::TEXTURE_2D, outputTexture);
+ context->texImage2DDirect(GL_TEXTURE_2D, level, internalFormat, 0, 0, 0, format, type, nullptr);
+ context->bindTexture(GraphicsContextGL::TEXTURE_2D, 0);
+ }
+ };
// Allocate memory for the output texture.
m_context->bindTexture(GraphicsContextGL::TEXTURE_2D, outputTexture);
m_context->texParameteri(GraphicsContextGL::TEXTURE_2D, GraphicsContextGL::TEXTURE_MAG_FILTER, GraphicsContextGL::LINEAR);
@@ -609,7 +643,7 @@
m_context->texParameteri(GraphicsContextGL::TEXTURE_2D, GraphicsContextGL::TEXTURE_MIN_FILTER, GraphicsContextGL::LINEAR);
m_context->texParameteri(GraphicsContextGL::TEXTURE_2D, GraphicsContextGL::TEXTURE_WRAP_S, GraphicsContextGL::CLAMP_TO_EDGE);
m_context->texParameteri(GraphicsContextGL::TEXTURE_2D, GraphicsContextGL::TEXTURE_WRAP_T, GraphicsContextGL::CLAMP_TO_EDGE);
- gl::TexImage2D(GL_TEXTURE_2D, level, internalFormat, width, height, 0, format, type, nullptr);
+ m_context->texImage2DDirect(GL_TEXTURE_2D, level, internalFormat, width, height, 0, format, type, nullptr);
m_context->framebufferTexture2D(GraphicsContextGL::FRAMEBUFFER, GraphicsContextGL::COLOR_ATTACHMENT0, GraphicsContextGL::TEXTURE_2D, outputTexture, level);
GCGLenum status = m_context->checkFramebufferStatus(GraphicsContextGL::FRAMEBUFFER);
@@ -682,7 +716,7 @@
m_lastSurfaceSeed = newSurfaceSeed;
m_lastTextureSeed.set(outputTexture, m_context->textureSeed(outputTexture));
m_lastFlipY = flipY;
-
+ autoClearTextureOnError.reset();
return true;
}
Modified: trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h (279623 => 279624)
--- trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h 2021-07-06 22:27:21 UTC (rev 279623)
+++ trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h 2021-07-06 22:33:57 UTC (rev 279624)
@@ -138,10 +138,10 @@
// Compile a shader without going through ANGLE.
void compileShaderDirect(PlatformGLObject);
-#if !USE(ANGLE)
// Equivalent to ::glTexImage2D(). Allows pixels==0 with no allocation.
void texImage2DDirect(GCGLenum target, GCGLint level, GCGLenum internalformat, GCGLsizei width, GCGLsizei height, GCGLint border, GCGLenum format, GCGLenum type, const void* pixels);
+#if !USE(ANGLE)
// Helper to texImage2D with pixel==0 case: pixels are initialized to 0.
// Return true if no GL error is synthesized.
// By default, alignment is 4, the OpenGL default setting.