From 54b58d3a24fe4bf60163757455679b4b3ffbaded Mon Sep 17 00:00:00 2001 From: Laura Hermanns Date: Wed, 12 Jun 2024 09:30:49 -0400 Subject: [PATCH] [Metal] Use 'setDisplaySyncEnabled' on CAMetalLayer to control vsync in MTSwapChain (fixes #117). --- sources/Renderer/Metal/MTSwapChain.mm | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sources/Renderer/Metal/MTSwapChain.mm b/sources/Renderer/Metal/MTSwapChain.mm index 5cdca812ff..32264ce8c9 100644 --- a/sources/Renderer/Metal/MTSwapChain.mm +++ b/sources/Renderer/Metal/MTSwapChain.mm @@ -123,11 +123,14 @@ - (void)mtkView:(nonnull MTKView *)view drawableSizeWillChange:(CGSize)size view_.preferredFramesPerSecond = static_cast(display->GetDisplayMode().refreshRate / vsyncInterval); else view_.preferredFramesPerSecond = defaultRefreshRate / static_cast(vsyncInterval); + + /* Enable display sync in CAMetalLayer */ + [(CAMetalLayer*)[view_ layer] setDisplaySyncEnabled:YES]; } else { - /* Set preferred frame rate to default value */ - view_.preferredFramesPerSecond = defaultRefreshRate; + /* Disable display sync in CAMetalLayer */ + [(CAMetalLayer*)[view_ layer] setDisplaySyncEnabled:NO]; } return true; }