Title: [294877] trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/ContextMtl.mm
Revision
294877
Author
commit-qu...@webkit.org
Date
2022-05-26 07:00:35 -0700 (Thu, 26 May 2022)

Log Message

Uniform buffer reuse causes flush, creates invalid state
https://bugs.webkit.org/show_bug.cgi?id=240896

Patch by Kimmo Kinnunen <kkinnu...@apple.com> on 2022-05-26
Patch by Kyle Piddington.

Reviewed by Kimmo Kinnunen.

A flush during draw setup would leave the render command encoder
not started and render pipeline unset. This would assert in debug
and leak memory with corrupted draws in release.

This would happen for example when uniform buffer pool would run
out of uniform memory. If the pool is maxed out, we flush the
existing rendering to obtain free buffers. After the flush,
we need to re-run the setup.

Test is tracked in bug 240948.

* Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/ContextMtl.mm:
(rx::ContextMtl::setupDraw):
(rx::ContextMtl::setupDrawImpl):

Canonical link: https://commits.webkit.org/251007@main

Modified Paths

Diff

Modified: trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/ContextMtl.mm (294876 => 294877)


--- trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/ContextMtl.mm	2022-05-26 12:13:28 UTC (rev 294876)
+++ trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/ContextMtl.mm	2022-05-26 14:00:35 UTC (rev 294877)
@@ -2216,6 +2216,32 @@
                                     const void *indices,
                                     bool xfbPass)
 {
+    ANGLE_TRY(setupDrawImpl(context, mode, firstVertex, vertexOrIndexCount, instances,
+                            indexTypeOrNone, indices, xfbPass));
+    if (!mRenderEncoder.valid())
+    {
+        // Flush occurred during setup, due to running out of memory while setting up the render
+        // pass state. This would happen for example when there is no more space in the uniform
+        // buffers in the uniform buffer pool. The rendering would be flushed to free the uniform
+        // buffer memory for new usage. In this case, re-run the setup.
+        ANGLE_TRY(setupDrawImpl(context, mode, firstVertex, vertexOrIndexCount, instances,
+                                indexTypeOrNone, indices, xfbPass));
+        // Setup with flushed state should either produce a working encoder or fail with an error
+        // result.
+        ASSERT(mRenderEncoder.valid());
+    }
+    return angle::Result::Continue;
+}
+
+angle::Result ContextMtl::setupDrawImpl(const gl::Context *context,
+                                        gl::PrimitiveMode mode,
+                                        GLint firstVertex,
+                                        GLsizei vertexOrIndexCount,
+                                        GLsizei instances,
+                                        gl::DrawElementsType indexTypeOrNone,
+                                        const void *indices,
+                                        bool xfbPass)
+{
     ASSERT(mProgram);
 
     // instances=0 means no instanced draw.
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to