From bb69cf0c94da78faf68deb10c2dd904f5e31a935 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Wed, 24 May 2023 11:02:05 -0700 Subject: [PATCH 1/3] [Impeller] fix Xcode frame capture --- impeller/renderer/backend/metal/surface_mtl.mm | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/impeller/renderer/backend/metal/surface_mtl.mm b/impeller/renderer/backend/metal/surface_mtl.mm index 9b06878b76f78..e5114cedadf15 100644 --- a/impeller/renderer/backend/metal/surface_mtl.mm +++ b/impeller/renderer/backend/metal/surface_mtl.mm @@ -188,6 +188,15 @@ ContextMTL::Cast(context.get())->CreateMTLCommandBuffer(); [command_buffer commit]; [command_buffer waitUntilScheduled]; +#else + // On Physical iOS devices we still need to wait if we're taking a frame + // capture. + if ([[MTLCaptureManager sharedCaptureManager] isCapturing]) { + id command_buffer = + ContextMTL::Cast(context.get())->CreateMTLCommandBuffer(); + [command_buffer commit]; + [command_buffer waitUntilScheduled]; + } #endif // ((FML_OS_MACOSX && !FML_OS_IOS) || FML_OS_IOS_SIMULATOR) [drawable_ present]; From 2894a9e7f3f7ad384355985f695dcf95cbb731a7 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Wed, 24 May 2023 11:27:52 -0700 Subject: [PATCH 2/3] Update surface_mtl.mm --- .../renderer/backend/metal/surface_mtl.mm | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/impeller/renderer/backend/metal/surface_mtl.mm b/impeller/renderer/backend/metal/surface_mtl.mm index e5114cedadf15..a1b3067c66f73 100644 --- a/impeller/renderer/backend/metal/surface_mtl.mm +++ b/impeller/renderer/backend/metal/surface_mtl.mm @@ -152,6 +152,20 @@ IRect SurfaceMTL::coverage() const { return IRect::MakeSize(resolve_texture_->GetSize()); } + +static bool ShouldWaitForCommandBuffer() { +#if ((FML_OS_MACOSX && !FML_OS_IOS) || FML_OS_IOS_SIMULATOR) + // If a transaction is present, `presentDrawable` will present too early. And + // so we wait on an empty command buffer to get scheduled instead, which + // forces us to also wait for all of the previous command buffers in the queue + // to get scheduled. + return true; +#else + // On Physical iOS devices we still need to wait if we're taking a frame + // capture. + return [[MTLCaptureManager sharedCaptureManager] isCapturing]; +#endif // ((FML_OS_MACOSX && !FML_OS_IOS) || FML_OS_IOS_SIMULATOR) +} // |Surface| bool SurfaceMTL::Present() const { @@ -179,26 +193,12 @@ } } -#if ((FML_OS_MACOSX && !FML_OS_IOS) || FML_OS_IOS_SIMULATOR) - // If a transaction is present, `presentDrawable` will present too early. And - // so we wait on an empty command buffer to get scheduled instead, which - // forces us to also wait for all of the previous command buffers in the queue - // to get scheduled. - id command_buffer = - ContextMTL::Cast(context.get())->CreateMTLCommandBuffer(); - [command_buffer commit]; - [command_buffer waitUntilScheduled]; -#else - // On Physical iOS devices we still need to wait if we're taking a frame - // capture. - if ([[MTLCaptureManager sharedCaptureManager] isCapturing]) { + if (ShouldWaitForCommandBuffer()) { id command_buffer = ContextMTL::Cast(context.get())->CreateMTLCommandBuffer(); [command_buffer commit]; [command_buffer waitUntilScheduled]; } -#endif // ((FML_OS_MACOSX && !FML_OS_IOS) || FML_OS_IOS_SIMULATOR) - [drawable_ present]; return true; From 29c7b8edb1bc394bc730d79a5f3e16398a439902 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Wed, 24 May 2023 11:47:41 -0700 Subject: [PATCH 3/3] Update surface_mtl.mm --- impeller/renderer/backend/metal/surface_mtl.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/impeller/renderer/backend/metal/surface_mtl.mm b/impeller/renderer/backend/metal/surface_mtl.mm index a1b3067c66f73..05eec4964b49d 100644 --- a/impeller/renderer/backend/metal/surface_mtl.mm +++ b/impeller/renderer/backend/metal/surface_mtl.mm @@ -152,7 +152,7 @@ IRect SurfaceMTL::coverage() const { return IRect::MakeSize(resolve_texture_->GetSize()); } - + static bool ShouldWaitForCommandBuffer() { #if ((FML_OS_MACOSX && !FML_OS_IOS) || FML_OS_IOS_SIMULATOR) // If a transaction is present, `presentDrawable` will present too early. And @@ -164,7 +164,7 @@ static bool ShouldWaitForCommandBuffer() { // On Physical iOS devices we still need to wait if we're taking a frame // capture. return [[MTLCaptureManager sharedCaptureManager] isCapturing]; -#endif // ((FML_OS_MACOSX && !FML_OS_IOS) || FML_OS_IOS_SIMULATOR) +#endif // ((FML_OS_MACOSX && !FML_OS_IOS) || FML_OS_IOS_SIMULATOR) } // |Surface|