diff --git a/app/streaming/video/ffmpeg-renderers/vt_metal.mm b/app/streaming/video/ffmpeg-renderers/vt_metal.mm index 005b2b74..f4aaf98c 100644 --- a/app/streaming/video/ffmpeg-renderers/vt_metal.mm +++ b/app/streaming/video/ffmpeg-renderers/vt_metal.mm @@ -199,15 +199,17 @@ public: return; } - // Pace ourselves by waiting if too many frames are pending presentation - SDL_LockMutex(m_PresentationMutex); - if (m_PendingPresentationCount > 2) { - if (SDL_CondWaitTimeout(m_PresentationCond, m_PresentationMutex, 100) == SDL_MUTEX_TIMEDOUT) { - SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, - "Presentation wait timed out after 100 ms"); + if (m_MetalLayer.displaySyncEnabled) { + // Pace ourselves by waiting if too many frames are pending presentation + SDL_LockMutex(m_PresentationMutex); + if (m_PendingPresentationCount > 2) { + if (SDL_CondWaitTimeout(m_PresentationCond, m_PresentationMutex, 100) == SDL_MUTEX_TIMEDOUT) { + SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, + "Presentation wait timed out after 100 ms"); + } } + SDL_UnlockMutex(m_PresentationMutex); } - SDL_UnlockMutex(m_PresentationMutex); } }} @@ -492,16 +494,18 @@ public: [renderEncoder endEncoding]; - // Queue a completion callback on the drawable to pace our rendering - SDL_LockMutex(m_PresentationMutex); - m_PendingPresentationCount++; - SDL_UnlockMutex(m_PresentationMutex); - [m_NextDrawable addPresentedHandler:^(id) { + if (m_MetalLayer.displaySyncEnabled) { + // Queue a completion callback on the drawable to pace our rendering SDL_LockMutex(m_PresentationMutex); - m_PendingPresentationCount--; - SDL_CondSignal(m_PresentationCond); + m_PendingPresentationCount++; SDL_UnlockMutex(m_PresentationMutex); - }]; + [m_NextDrawable addPresentedHandler:^(id) { + SDL_LockMutex(m_PresentationMutex); + m_PendingPresentationCount--; + SDL_CondSignal(m_PresentationCond); + SDL_UnlockMutex(m_PresentationMutex); + }]; + } // Flip to the newly rendered buffer [commandBuffer presentDrawable:m_NextDrawable];