From 654e386263f59acd7995fa14aecae3e6e318de5c Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 25 Feb 2024 18:45:41 -0600 Subject: [PATCH] Only pace presentation if display sync is enabled --- .../video/ffmpeg-renderers/vt_metal.mm | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) 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];