Only pace presentation if display sync is enabled

This commit is contained in:
Cameron Gutman 2024-02-25 18:45:41 -06:00
parent 76d0eb6b63
commit 654e386263

View File

@ -199,6 +199,7 @@ public:
return; return;
} }
if (m_MetalLayer.displaySyncEnabled) {
// Pace ourselves by waiting if too many frames are pending presentation // Pace ourselves by waiting if too many frames are pending presentation
SDL_LockMutex(m_PresentationMutex); SDL_LockMutex(m_PresentationMutex);
if (m_PendingPresentationCount > 2) { if (m_PendingPresentationCount > 2) {
@ -209,6 +210,7 @@ public:
} }
SDL_UnlockMutex(m_PresentationMutex); SDL_UnlockMutex(m_PresentationMutex);
} }
}
}} }}
virtual void cleanupRenderContext() override virtual void cleanupRenderContext() override
@ -492,6 +494,7 @@ public:
[renderEncoder endEncoding]; [renderEncoder endEncoding];
if (m_MetalLayer.displaySyncEnabled) {
// Queue a completion callback on the drawable to pace our rendering // Queue a completion callback on the drawable to pace our rendering
SDL_LockMutex(m_PresentationMutex); SDL_LockMutex(m_PresentationMutex);
m_PendingPresentationCount++; m_PendingPresentationCount++;
@ -502,6 +505,7 @@ public:
SDL_CondSignal(m_PresentationCond); SDL_CondSignal(m_PresentationCond);
SDL_UnlockMutex(m_PresentationMutex); SDL_UnlockMutex(m_PresentationMutex);
}]; }];
}
// Flip to the newly rendered buffer // Flip to the newly rendered buffer
[commandBuffer presentDrawable:m_NextDrawable]; [commandBuffer presentDrawable:m_NextDrawable];