[Feature Request] Variable vsync swap interval support
Hello there,
It has been some time since I tried Amiberry, and I have built it today from latest GIT sources to see how it has evolved. I use an VRR capable monitor now (AdaptiveSync in Wayland terms) which is running at it's default frequency of ~120Hz. VRR works for all SDL2 games I throw at it, for MAME, etc.
Now, Amiberry seems to be unable to use it properly: it uses classic VSYNC apparently, so if I set an NTSC chipset configuration on my 120Hz video mode, games run twice as fast as they are supposed to. That's all right: VRR is not that great for emulation (frametime variations cause a different set of problems that I won't mention here: VRR is great for native games and that's about it).
But using 120Hz video mode for NTSC content and 100Hz for PAL content is great: it prevents input lag and prevents ghosting to a great degree! On RetroArch, for example, it's possible to set "Vsync Swap Interval" to 2, and that lets 60Hz content run at the correct speed in 120Hz video modes, or 50Hz content to run at the correct speed in 100Hz video modes. I have been ticking / unticking the Display options in Amiberry to no avail for hours, but none of them seems to to this. Could such an option be added, please?
Thanks!
VRR isn't supported in SDL2, so there's no easy way to add that. Perhaps only with the OpenGL back-end, if it matures enough to become the default option. Or perhaps when we move to SDL3, if there's native support there (haven't checked).
VRR isn't supported in SDL2, so there's no easy way to add that. Perhaps only with the OpenGL back-end, if it matures enough to become the default option. Or perhaps when we move to SDL3, if there's native support there (haven't checked).
There's nothing to support really: SDL2 supports VRR... by doing nothing special, simply issuing buffer swaps, and the windowing subsystem (Wayland in my case) takes care of VRR via it's extensions. Please forget about VRR: my initial post was confusing.
What is really needed for proper speeds at 120/100Hz is the ability to set Vsync Swap Interval to 2, just like RetroArch does. For example, with an NTSC (~60Hz) emulated Amiga on a 120Hz video mode, vsync swap period set to 2 would allow correct emulation speed and correct frame pacing.
Forget about VRR, I was trying to explain more than needed.
Maybe I'm missing something, but I think that's only possible with the OpenGL back-end (where you can set the GL swap interval). Otherwise, you just have the Presenter VSYNC option, which has no configuration, it will show one frame per Vsync.
Maybe I'm missing something, but I think that's only possible with the OpenGL back-end (where you can set the GL swap interval). Otherwise, you just have the Presenter VSYNC option, which has no configuration, it will show one frame per Vsync.
In OpenGL there's glSwapInterval() that would allow 60FPS to be properly timed(=paced) on a 120Hz video mode or 50FPS to be ok on a 100Hz video mode, by issuing glSwapInterval(2).
But that's as you said an OpenGL specific thing.
On SDL2, without needing to go down to OpenGL (SDL2 uses OpenGL under the hood anyway, but you know what I mean), you can do something like:
int vblanks_to_wait = 2;
for (i=0; i < vblanks_to_wait - 1; i++) {
SDL_RenderPresent(main_window_renderer);
}
SDL_RenderClear(main_window_renderer);
SDL_RenderCopy(main_window_renderer, main_window_texture, NULL, &dst_rect);
SDL_RenderPresent(main_window_renderer);
...and it would have a similar effect, but you could even do vblanks_to_wait = 4 for 60FPS on 240Hz or 50FPS on 100Hz.
You can find out the number of blanks to wait by dividing HZ / FPS.
Thanks for the feedback. I'll try these ideas it and see.