From 3eea50654fce43a27e1006cb8984a2f10f9cfc26 Mon Sep 17 00:00:00 2001 From: Brandon Wright Date: Fri, 28 Dec 2018 12:06:00 -0600 Subject: [PATCH] GTK+: OpenGL: Separate glFinish and glFenceSync options. --- gtk/src/gtk_config.cpp | 7 +++++-- gtk/src/gtk_config.h | 1 + gtk/src/gtk_display_driver_opengl.cpp | 22 ++++++++++------------ gtk/src/gtk_preferences.cpp | 2 ++ gtk/src/snes9x.ui | 25 ++++++++++++++++++++----- 5 files changed, 38 insertions(+), 19 deletions(-) diff --git a/gtk/src/gtk_config.cpp b/gtk/src/gtk_config.cpp index b08bc6be..dfec951c 100644 --- a/gtk/src/gtk_config.cpp +++ b/gtk/src/gtk_config.cpp @@ -149,6 +149,7 @@ int Snes9xConfig::load_defaults () use_shaders = 0; shader_filename[0] = '\0'; sync_every_frame = FALSE; + use_fences = FALSE; #endif /* Snes9X Variables */ @@ -263,7 +264,8 @@ int Snes9xConfig::save_config_file () #undef z #define z "OpenGL::" outbool (cf, z"VSync", sync_to_vblank); - outbool (cf, z"ReduceInputLag", sync_every_frame); + outbool (cf, z"glFinish", sync_every_frame); + outbool (cf, z"glFenceSync", use_fences); outbool (cf, z"UsePixelBufferObjects", use_pbos); cf.SetInt (z"PixelBufferObjectBitDepth", pbo_format); outbool (cf, z"UseNonPowerOfTwoTextures", npot_textures); @@ -493,7 +495,8 @@ int Snes9xConfig::load_config_file () #undef z #define z "OpenGL::" inbool (z"VSync", sync_to_vblank); - inbool (z"ReduceInputLag", sync_every_frame); + inbool (z"glFinish", sync_every_frame); + inbool (z"glFenceSync", use_fences); inbool (z"UsePixelBufferObjects", use_pbos); inint (z"PixelBufferObjectBitDepth", pbo_format); inbool (z"UseNonPowerOfTwoTextures", npot_textures); diff --git a/gtk/src/gtk_config.h b/gtk/src/gtk_config.h index 7aad3c31..c173b8d5 100644 --- a/gtk/src/gtk_config.h +++ b/gtk/src/gtk_config.h @@ -150,6 +150,7 @@ class Snes9xConfig unsigned char use_shaders; char shader_filename[PATH_MAX]; unsigned char sync_every_frame; + unsigned char use_fences; #endif JoyDevice **joystick; diff --git a/gtk/src/gtk_display_driver_opengl.cpp b/gtk/src/gtk_display_driver_opengl.cpp index 63cd8d93..16d1d361 100644 --- a/gtk/src/gtk_display_driver_opengl.cpp +++ b/gtk/src/gtk_display_driver_opengl.cpp @@ -646,19 +646,16 @@ void S9xOpenGLDisplayDriver::swap_buffers () { context->swap_buffers (); - if (config->sync_every_frame) + if (config->sync_every_frame && !config->use_fences) { - if (fences) - { - if (fence) - glDeleteSync (fence); - fence = glFenceSync (GL_SYNC_GPU_COMMANDS_COMPLETE, 0); - } - else - { - usleep (0); - glFinish (); - } + usleep (0); + glFinish (); + } + else if (config->use_fences && fences) + { + if (fence) + glDeleteSync (fence); + fence = glFenceSync (GL_SYNC_GPU_COMMANDS_COMPLETE, 0); } } @@ -731,5 +728,6 @@ bool S9xOpenGLDisplayDriver::is_ready () glDeleteSync (fence); fence = NULL; + return true; } diff --git a/gtk/src/gtk_preferences.cpp b/gtk/src/gtk_preferences.cpp index 9df837b5..74968732 100644 --- a/gtk/src/gtk_preferences.cpp +++ b/gtk/src/gtk_preferences.cpp @@ -708,6 +708,7 @@ Snes9xPreferences::move_settings_to_dialog () #ifdef USE_OPENGL set_check ("sync_to_vblank", config->sync_to_vblank); set_check ("sync_every_frame", config->sync_every_frame); + set_check ("use_fences", config->use_fences); set_check ("use_pbos", config->use_pbos); set_combo ("pixel_format", config->pbo_format == 16 ? 0 : 1); set_check ("npot_textures", config->npot_textures); @@ -865,6 +866,7 @@ Snes9xPreferences::get_settings_from_dialog () config->npot_textures = get_check ("npot_textures"); config->use_shaders = get_check ("use_shaders"); config->sync_every_frame = get_check ("sync_every_frame"); + config->use_fences = get_check ("use_fences"); sstrncpy (config->shader_filename, get_entry_text ("fragment_shader"), PATH_MAX); diff --git a/gtk/src/snes9x.ui b/gtk/src/snes9x.ui index bab3eee1..402c1676 100644 --- a/gtk/src/snes9x.ui +++ b/gtk/src/snes9x.ui @@ -3819,7 +3819,7 @@ - Reduce input lag + Reduce input lag with glFinish True True False @@ -3832,6 +3832,21 @@ 1 + + + Reduce input lag with glFenceSync + True + True + False + Sync the program with the video output after every displayed frame to reduce input latency, but allow GUI events to occur in the meantime + True + + + False + True + 2 + + Allow non-power-of-two textures @@ -3844,7 +3859,7 @@ False True - 2 + 3 @@ -3860,7 +3875,7 @@ False True - 3 + 4 @@ -3914,7 +3929,7 @@ False True - 4 + 5 @@ -3972,7 +3987,7 @@ False True - 5 + 6