From 965877b46d457db4ae531fdadd3801b1bf5d366a Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Wed, 29 Mar 2023 12:58:09 -0700 Subject: [PATCH 1/2] [Impeller] Don't use waitUntilScheduled on iOS --- impeller/renderer/backend/metal/command_buffer_mtl.mm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/impeller/renderer/backend/metal/command_buffer_mtl.mm b/impeller/renderer/backend/metal/command_buffer_mtl.mm index 27c17b0bae21a..00cbe540b070c 100644 --- a/impeller/renderer/backend/metal/command_buffer_mtl.mm +++ b/impeller/renderer/backend/metal/command_buffer_mtl.mm @@ -166,7 +166,9 @@ static bool LogMTLCommandBufferErrorIfPresent(id buffer) { } [buffer_ commit]; +#if (FML_OS_MACOSX || FML_OS_IOS_SIMULATOR) [buffer_ waitUntilScheduled]; +#endif buffer_ = nil; return true; } From befea9065e527effde33e4acd71764877d6ba19e Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Wed, 29 Mar 2023 15:43:39 -0700 Subject: [PATCH 2/2] Add comment --- .../backend/metal/command_buffer_mtl.mm | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/impeller/renderer/backend/metal/command_buffer_mtl.mm b/impeller/renderer/backend/metal/command_buffer_mtl.mm index 00cbe540b070c..144ce2c330ef1 100644 --- a/impeller/renderer/backend/metal/command_buffer_mtl.mm +++ b/impeller/renderer/backend/metal/command_buffer_mtl.mm @@ -166,9 +166,28 @@ static bool LogMTLCommandBufferErrorIfPresent(id buffer) { } [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; }