diff --git a/engine/src/flutter/impeller/renderer/backend/metal/context_mtl.h b/engine/src/flutter/impeller/renderer/backend/metal/context_mtl.h index 820c0e216e..85f9f3a868 100644 --- a/engine/src/flutter/impeller/renderer/backend/metal/context_mtl.h +++ b/engine/src/flutter/impeller/renderer/backend/metal/context_mtl.h @@ -84,7 +84,7 @@ class ContextMTL final : public Context, // |Context| bool UpdateOffscreenLayerPixelFormat(PixelFormat format) override; - id CreateMTLCommandBuffer() const; + id CreateMTLCommandBuffer(const std::string& label) const; const std::shared_ptr& GetWorkerTaskRunner() const; diff --git a/engine/src/flutter/impeller/renderer/backend/metal/context_mtl.mm b/engine/src/flutter/impeller/renderer/backend/metal/context_mtl.mm index cc4ea365ca..04dba5c39d 100644 --- a/engine/src/flutter/impeller/renderer/backend/metal/context_mtl.mm +++ b/engine/src/flutter/impeller/renderer/backend/metal/context_mtl.mm @@ -343,8 +343,13 @@ bool ContextMTL::UpdateOffscreenLayerPixelFormat(PixelFormat format) { return true; } -id ContextMTL::CreateMTLCommandBuffer() const { - return [command_queue_ commandBuffer]; +id ContextMTL::CreateMTLCommandBuffer( + const std::string& label) const { + auto buffer = [command_queue_ commandBuffer]; + if (!label.empty()) { + [buffer setLabel:@(label.data())]; + } + return buffer; } } // namespace impeller diff --git a/engine/src/flutter/impeller/renderer/backend/metal/surface_mtl.mm b/engine/src/flutter/impeller/renderer/backend/metal/surface_mtl.mm index 7f9a86717e..450302d89d 100644 --- a/engine/src/flutter/impeller/renderer/backend/metal/surface_mtl.mm +++ b/engine/src/flutter/impeller/renderer/backend/metal/surface_mtl.mm @@ -262,9 +262,13 @@ bool SurfaceMTL::Present() const { } if (drawable_) { + // In certain situations, we need to wait until the command queue has been + // flushed before presenting to the onscreen texture. See the comments in + // `ShouldWaitForCommandBuffer` for more details. if (ShouldWaitForCommandBuffer()) { id command_buffer = - ContextMTL::Cast(context.get())->CreateMTLCommandBuffer(); + ContextMTL::Cast(context.get()) + ->CreateMTLCommandBuffer("Present Waiter Command Buffer"); [command_buffer commit]; [command_buffer waitUntilScheduled]; }