From 3cb18e4d28abb6723da8e6540fc8271571fc56c7 Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Wed, 29 Mar 2023 21:06:18 -0700 Subject: [PATCH] [Impeller] Don't use waitUntilScheduled on iOS (flutter/engine#40768) [Impeller] Don't use waitUntilScheduled on iOS --- .../backend/metal/command_buffer_mtl.mm | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/engine/src/flutter/impeller/renderer/backend/metal/command_buffer_mtl.mm b/engine/src/flutter/impeller/renderer/backend/metal/command_buffer_mtl.mm index 27c17b0bae..144ce2c330 100644 --- a/engine/src/flutter/impeller/renderer/backend/metal/command_buffer_mtl.mm +++ b/engine/src/flutter/impeller/renderer/backend/metal/command_buffer_mtl.mm @@ -166,7 +166,28 @@ bool CommandBufferMTL::OnSubmitCommands(CompletionCallback callback) { } [buffer_ commit]; + +#if (FML_OS_MACOSX || FML_OS_IOS_SIMULATOR) + // We're using waitUntilScheduled on macOS and iOS simulator to force a hard + // barrier between the execution of different command buffers. This forces all + // renderable texture access to be synchronous (i.e. a write from a previous + // command buffer will not get scheduled to happen at the same time as a read + // in a future command buffer). + // + // Metal hazard tracks shared memory resources by default, and we don't need + // to do any additional work to synchronize access to MTLTextures and + // MTLBuffers on iOS devices with UMA. However, shared textures are disallowed + // on macOS according to the documentation: + // https://developer.apple.com/documentation/metal/mtlstoragemode/shared + // And so this is a stopgap solution that has been present in Impeller since + // multi-pass rendering/SaveLayer support was first set up. + // + // TODO(bdero): Remove this for all targets once a solution for resource + // tracking that works everywhere is established: + // https://github.com/flutter/flutter/issues/120406 [buffer_ waitUntilScheduled]; +#endif + buffer_ = nil; return true; }