From 18edfefa0a78aed9feb27f390dd8177bf9d73f54 Mon Sep 17 00:00:00 2001 From: Conn O'Griofa Date: Thu, 3 Oct 2019 06:50:24 +0100 Subject: [PATCH] SDL: ensure swap interval is set correctly for SDL2 kmsdrm driver It appears that SDL2's kmsdrm driver ignores the swap interval setting if the SDL context has not yet been created. Moving the call to after context creation allows it to work as expected. Fixes vsync when running ppsspp in a KMS context using the SDL2 kmsdrm driver (which is especially useful for Raspberry Pi 4 B, but is also needed for other systems including Raspberry Pi 3B via firmware KMS & Intel Haswell i965 via KMS on x64). --- SDL/SDLMain.cpp | 4 +++- headless/SDLHeadlessHost.cpp | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/SDL/SDLMain.cpp b/SDL/SDLMain.cpp index ddf6e5cf20..28c3548201 100644 --- a/SDL/SDLMain.cpp +++ b/SDL/SDLMain.cpp @@ -443,7 +443,6 @@ int main(int argc, char *argv[]) { SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - SDL_GL_SetSwapInterval(1); // Force fullscreen if the resolution is too low to run windowed. if (g_DesktopWidth < 480 * 2 && g_DesktopHeight < 272 * 2) { @@ -571,6 +570,9 @@ int main(int argc, char *argv[]) { NativeResized(); } + // Ensure that the swap interval is set after context creation (needed for kmsdrm) + SDL_GL_SetSwapInterval(1); + SDL_AudioSpec fmt, ret_fmt; memset(&fmt, 0, sizeof(fmt)); fmt.freq = 44100; diff --git a/headless/SDLHeadlessHost.cpp b/headless/SDLHeadlessHost.cpp index c5702eabc4..ac04878237 100644 --- a/headless/SDLHeadlessHost.cpp +++ b/headless/SDLHeadlessHost.cpp @@ -119,11 +119,13 @@ bool GLDummyGraphicsContext::InitFromRenderThread(std::string *errorMessage) { SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - SDL_GL_SetSwapInterval(1); screen_ = CreateHiddenWindow(); glContext_ = SDL_GL_CreateContext(screen_); + // Ensure that the swap interval is set after context creation (needed for kmsdrm) + SDL_GL_SetSwapInterval(1); + #ifndef USING_GLES2 // Some core profile drivers elide certain extensions from GL_EXTENSIONS/etc. // glewExperimental allows us to force GLEW to search for the pointers anyway.