From 29f9cd9358ee470ced793627139de86f799a8981 Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Fri, 22 Feb 2019 10:59:14 +0100 Subject: [PATCH] Synchronize replaceRegion calls. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the Discussion part of https://developer.apple.com/documentation/metal/mtltexture/1515679-replaceregion it seems like we should sync the calls to replaceRegion (inside setupTexturesForFrame) in RTCMTLRenderer and not just the command buffer. This is a speculative fix for the linked bug, but we don't have any clear repro case. Have done basic testing in AppRTCMobile and don't see any obvious regressions, so might be worth trying. Bug: webrtc:10024 Change-Id: Id6848691129fba8845f38c3dfe0ba53b9e5a27ce Reviewed-on: https://webrtc-review.googlesource.com/c/123766 Reviewed-by: Kári Helgason Commit-Queue: Anders Carlsson Cr-Commit-Position: refs/heads/master@{#26819} --- sdk/objc/components/renderer/metal/RTCMTLRenderer.mm | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sdk/objc/components/renderer/metal/RTCMTLRenderer.mm b/sdk/objc/components/renderer/metal/RTCMTLRenderer.mm index fb478d2533..63cf225bac 100644 --- a/sdk/objc/components/renderer/metal/RTCMTLRenderer.mm +++ b/sdk/objc/components/renderer/metal/RTCMTLRenderer.mm @@ -274,10 +274,6 @@ static const NSInteger kMaxInflightBuffers = 1; } - (void)render { - // Wait until the inflight (curently sent to GPU) command buffer - // has completed the GPU work. - dispatch_semaphore_wait(_inflight_semaphore, DISPATCH_TIME_FOREVER); - id commandBuffer = [_commandQueue commandBuffer]; commandBuffer.label = commandBufferLabel; @@ -317,8 +313,14 @@ static const NSInteger kMaxInflightBuffers = 1; - (void)drawFrame:(RTCVideoFrame *)frame { @autoreleasepool { + // Wait until the inflight (curently sent to GPU) command buffer + // has completed the GPU work. + dispatch_semaphore_wait(_inflight_semaphore, DISPATCH_TIME_FOREVER); + if ([self setupTexturesForFrame:frame]) { [self render]; + } else { + dispatch_semaphore_signal(_inflight_semaphore); } } }