diff --git a/config.def.h b/config.def.h index 232b745997..aae6d51880 100644 --- a/config.def.h +++ b/config.def.h @@ -284,6 +284,9 @@ static unsigned swap_interval = 1; // Threaded video. Will possibly increase performance significantly at cost of worse synchronization and latency. static const bool video_threaded = false; +// Set to true if HW render cores should get their private context. +static const bool video_shared_context = false; + // Smooths picture static const bool video_smooth = true; diff --git a/general.h b/general.h index 466a1a2282..ea28fa0f10 100644 --- a/general.h +++ b/general.h @@ -183,6 +183,7 @@ struct settings bool gpu_screenshot; bool allow_rotate; + bool shared_context; } video; #ifdef HAVE_MENU diff --git a/gfx/gfx_context.c b/gfx/gfx_context.c index 04576bf578..eea953a0bc 100644 --- a/gfx/gfx_context.c +++ b/gfx/gfx_context.c @@ -79,7 +79,11 @@ const gfx_ctx_driver_t *gfx_ctx_init_first(void *data, enum gfx_ctx_api api, uns if (gfx_ctx_drivers[i]->bind_api(data, api, major, minor)) { if (gfx_ctx_drivers[i]->bind_hw_render) - gfx_ctx_drivers[i]->bind_hw_render(data, hw_render_ctx); + { + gfx_ctx_drivers[i]->bind_hw_render(data, + g_settings.video.shared_context && hw_render_ctx); + } + if (gfx_ctx_drivers[i]->init(data)) return gfx_ctx_drivers[i]; } diff --git a/gfx/gl.c b/gfx/gl.c index df3ced4538..77cb55af7a 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -1929,7 +1929,7 @@ static const gfx_ctx_driver_t *gl_get_context(gl_t *gl) // Enables or disables offscreen HW context. if (ctx->bind_hw_render) - ctx->bind_hw_render(gl, cb->context_type != RETRO_HW_CONTEXT_NONE); + ctx->bind_hw_render(gl, g_settings.video.shared_context && cb->context_type != RETRO_HW_CONTEXT_NONE); if (!ctx->init(gl)) { diff --git a/retroarch.cfg b/retroarch.cfg index 99ee5738ec..dafdfc6292 100644 --- a/retroarch.cfg +++ b/retroarch.cfg @@ -122,6 +122,10 @@ # Use threaded video driver. Using this might improve performance at possible cost of latency and more video stuttering. # video_threaded = false +# Use a shared context for HW rendered libretro cores. +# Avoids having to assume GL state changes inbetween frames. +# video_shared_context = false + # Smoothens picture with bilinear filtering. Should be disabled if using pixel shaders. # video_smooth = true diff --git a/settings.c b/settings.c index 8bd41900fe..0db5d507d6 100644 --- a/settings.c +++ b/settings.c @@ -252,6 +252,7 @@ void config_set_defaults(void) g_settings.video.black_frame_insertion = black_frame_insertion; g_settings.video.swap_interval = swap_interval; g_settings.video.threaded = video_threaded; + g_settings.video.shared_context = video_shared_context; g_settings.video.smooth = video_smooth; g_settings.video.force_aspect = force_aspect; g_settings.video.scale_integer = scale_integer; @@ -775,6 +776,7 @@ bool config_load_file(const char *path, bool set_defaults) g_settings.video.swap_interval = max(g_settings.video.swap_interval, 1); g_settings.video.swap_interval = min(g_settings.video.swap_interval, 4); CONFIG_GET_BOOL(video.threaded, "video_threaded"); + CONFIG_GET_BOOL(video.shared_context, "video_shared_context"); CONFIG_GET_BOOL(video.smooth, "video_smooth"); CONFIG_GET_BOOL(video.force_aspect, "video_force_aspect"); CONFIG_GET_BOOL(video.scale_integer, "video_scale_integer"); @@ -1280,6 +1282,7 @@ bool config_save_file(const char *path) config_set_bool(conf, "video_scale_integer", g_settings.video.scale_integer); config_set_bool(conf, "video_smooth", g_settings.video.smooth); config_set_bool(conf, "video_threaded", g_settings.video.threaded); + config_set_bool(conf, "video_shared_context", g_settings.video.shared_context); config_set_bool(conf, "video_fullscreen", g_settings.video.fullscreen); config_set_float(conf, "video_refresh_rate", g_settings.video.refresh_rate); config_set_int(conf, "video_monitor_index", g_settings.video.monitor_index);