From 38275f90566c58f21df47df0dce0dcb4745f6590 Mon Sep 17 00:00:00 2001 From: riperiperi Date: Thu, 1 Sep 2022 21:57:50 +0100 Subject: [PATCH] Change vsync signal to happen at 60hz, regardless of swap interval (#3642) * Change vsync signal to happen at 60hz, regardless of swap interval * Update Ryujinx.HLE/HOS/Services/SurfaceFlinger/SurfaceFlinger.cs Co-authored-by: gdkchan * Fix softlock when toggling vsync Co-authored-by: gdkchan --- .../HOS/Services/SurfaceFlinger/SurfaceFlinger.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Ryujinx.HLE/HOS/Services/SurfaceFlinger/SurfaceFlinger.cs b/Ryujinx.HLE/HOS/Services/SurfaceFlinger/SurfaceFlinger.cs index 8fa27905..b24a94db 100644 --- a/Ryujinx.HLE/HOS/Services/SurfaceFlinger/SurfaceFlinger.cs +++ b/Ryujinx.HLE/HOS/Services/SurfaceFlinger/SurfaceFlinger.cs @@ -35,6 +35,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger private long _1msTicks; private int _swapInterval; + private int _swapIntervalDelay; private readonly object Lock = new object(); @@ -91,7 +92,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger } else { - _ticksPerFrame = Stopwatch.Frequency / (TargetFps / _swapInterval); + _ticksPerFrame = Stopwatch.Frequency / TargetFps; } } @@ -322,7 +323,13 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger if (_ticks >= _ticksPerFrame) { - Compose(); + if (_swapIntervalDelay-- == 0) + { + Compose(); + + // When a frame is presented, delay the next one by its swap interval value. + _swapIntervalDelay = Math.Max(0, _swapInterval - 1); + } _device.System?.SignalVsync();