Skip to content

Commit 8410e61

Browse files
authored
Throttle framerate when V-sync is enabled but window is not focused.
RetroArch hogs an entire CPU core when running in the background with V-sync enabled. It seems that when the window is fully obscured by other windows, V-sync ceases to work, allowing RetroArch to run at an unlimited framerate, thrashing the CPU. As a workaround, the framerate is now throttled when the window is not in focus. I would rather have it throttle when the window is not visible, but there does not seem to be a way of detecting that. Note that this is only known to be the case on Windows: I don't know what the situation is for Linux and other operating systems, though macOS does suffer from this exact same problem, according to this SDL issue: libsdl-org/SDL#4521
1 parent b0624a7 commit 8410e61

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

runloop.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7402,7 +7402,7 @@ int runloop_iterate(void)
74027402
/* Rely on vsync throttling unless VRR is enabled and menu throttle is disabled. */
74037403
if (vrr_runloop_enable && !settings->bools.menu_throttle_framerate)
74047404
return 0;
7405-
else if (settings->bools.video_vsync)
7405+
else if (settings->bools.video_vsync && (runloop_st->flags & RUNLOOP_FLAG_FOCUSED))
74067406
goto end;
74077407

74087408
/* Otherwise run menu in video refresh rate speed. */
@@ -7542,7 +7542,8 @@ int runloop_iterate(void)
75427542
|| (runloop_st->flags & RUNLOOP_FLAG_FASTMOTION)
75437543
#ifdef HAVE_MENU
75447544
|| (menu_state_get_ptr()->flags & MENU_ST_FLAG_ALIVE
7545-
&& !(settings->bools.video_vsync))
7545+
&& (!(settings->bools.video_vsync)
7546+
|| !(runloop_st->flags & RUNLOOP_FLAG_FOCUSED)))
75467547
#endif
75477548
|| (runloop_st->flags & RUNLOOP_FLAG_PAUSED)))
75487549
{

0 commit comments

Comments
 (0)