Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable BFI #11342

Merged
merged 2 commits into from
Sep 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions config.def.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,13 @@
*/
#define DEFAULT_FRAME_DELAY 0

/* Inserts a black frame inbetween frames.
* Useful for 120 Hz monitors who want to play 60 Hz material with eliminated
* ghosting. video_refresh_rate should still be configured as if it
* is a 60 Hz monitor (divide refresh rate by 2).
/* Inserts black frame(s) inbetween frames.
* Useful for Higher Hz monitors (set to multiples of 60 Hz) who want to play 60 Hz
* material with eliminated ghosting. video_refresh_rate should still be configured
* as if it is a 60 Hz monitor (divide refresh rate by multiple of 60 Hz).
*/
#define DEFAULT_BLACK_FRAME_INSERTION false
#define DEFAULT_BLACK_FRAME_INSERTION 0


/* Uses a custom swap interval for VSync.
* Set this to effectively halve monitor refresh rate.
Expand Down
2 changes: 1 addition & 1 deletion configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -1466,7 +1466,6 @@ static struct config_bool_setting *populate_settings_bool(
SETTING_BOOL("video_vsync", &settings->bools.video_vsync, true, DEFAULT_VSYNC, false);
SETTING_BOOL("video_adaptive_vsync", &settings->bools.video_adaptive_vsync, true, DEFAULT_ADAPTIVE_VSYNC, false);
SETTING_BOOL("video_hard_sync", &settings->bools.video_hard_sync, true, DEFAULT_HARD_SYNC, false);
SETTING_BOOL("video_black_frame_insertion", &settings->bools.video_black_frame_insertion, true, DEFAULT_BLACK_FRAME_INSERTION, false);
SETTING_BOOL("video_disable_composition", &settings->bools.video_disable_composition, true, DEFAULT_DISABLE_COMPOSITION, false);
SETTING_BOOL("pause_nonactive", &settings->bools.pause_nonactive, true, DEFAULT_PAUSE_NONACTIVE, false);
SETTING_BOOL("video_gpu_screenshot", &settings->bools.video_gpu_screenshot, true, DEFAULT_GPU_SCREENSHOT, false);
Expand Down Expand Up @@ -2008,6 +2007,7 @@ static struct config_uint_setting *populate_settings_uint(

SETTING_UINT("core_updater_auto_backup_history_size", &settings->uints.core_updater_auto_backup_history_size, true, DEFAULT_CORE_UPDATER_AUTO_BACKUP_HISTORY_SIZE, false);

SETTING_UINT("video_black_frame_insertion", &settings->uints.video_black_frame_insertion, true, DEFAULT_BLACK_FRAME_INSERTION, false);
*size = count;

return tmp;
Expand Down
2 changes: 1 addition & 1 deletion configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ typedef struct settings
unsigned ai_service_source_lang;

unsigned core_updater_auto_backup_history_size;
unsigned video_black_frame_insertion;
} uints;

struct
Expand Down Expand Up @@ -447,7 +448,6 @@ typedef struct settings
bool video_vsync;
bool video_adaptive_vsync;
bool video_hard_sync;
bool video_black_frame_insertion;
bool video_vfilter;
bool video_smooth;
bool video_ctx_scaling;
Expand Down
6 changes: 3 additions & 3 deletions gfx/common/win32_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1600,7 +1600,7 @@ void win32_set_style(MONITORINFOEX *current_mon, HMONITOR *hm_to_use,
bool video_window_save_positions = settings->bools.video_window_save_positions;
float video_refresh = settings->floats.video_refresh_rate;
unsigned swap_interval = settings->uints.video_swap_interval;
bool bfi = settings->bools.video_black_frame_insertion;
unsigned bfi = settings->uints.video_black_frame_insertion;
unsigned window_position_x = settings->uints.window_position_x;
unsigned window_position_y = settings->uints.window_position_y;
unsigned window_position_width = settings->uints.window_position_width;
Expand All @@ -1610,9 +1610,9 @@ void win32_set_style(MONITORINFOEX *current_mon, HMONITOR *hm_to_use,
{
/* Windows only reports the refresh rates for modelines as
* an integer, so video_refresh_rate needs to be rounded. Also, account
* for black frame insertion using video_refresh_rate set to half
* for black frame insertion using video_refresh_rate set to a portion
* of the display refresh rate, as well as higher vsync swap intervals. */
float refresh_mod = bfi ? 2.0f : 1.0f;
float refresh_mod = bfi + 1.0f;
unsigned refresh = roundf(video_refresh * refresh_mod
* swap_interval);

Expand Down
4 changes: 2 additions & 2 deletions gfx/common/x11_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ static bool get_video_mode(
float minimum_fps_diff = 0.0f;
XF86VidModeModeInfo **modes = NULL;
settings_t *settings = config_get_ptr();
bool black_frame_insertion = settings->bools.video_black_frame_insertion;
unsigned black_frame_insertion = settings->uints.video_black_frame_insertion;
float video_refresh_rate = settings->floats.video_refresh_rate;

XF86VidModeGetAllModeLines(dpy, DefaultScreen(dpy), &num_modes, &modes);
Expand All @@ -283,7 +283,7 @@ static bool get_video_mode(

/* If we use black frame insertion, we fake a 60 Hz monitor
* for 120 Hz one, etc, so try to match that. */
refresh_mod = black_frame_insertion ? 0.5f : 1.0f;
refresh_mod = 1.0f / (black_frame_insertion + 1.0f);

for (i = 0; i < num_modes; i++)
{
Expand Down
21 changes: 12 additions & 9 deletions gfx/drivers/d3d8.c
Original file line number Diff line number Diff line change
Expand Up @@ -1497,7 +1497,7 @@ static bool d3d8_frame(void *data, const void *frame,
&video_info->osd_stat_params;
const char *stat_text = video_info->stat_text;
bool statistics_show = video_info->statistics_show;
bool black_frame_insertion = video_info->black_frame_insertion;
unsigned black_frame_insertion = video_info->black_frame_insertion;
#ifdef HAVE_MENU
bool menu_is_alive = video_info->menu_is_alive;
#endif
Expand Down Expand Up @@ -1538,14 +1538,6 @@ static bool d3d8_frame(void *data, const void *frame,
d3d8_set_viewports(d3d->dev, &screen_vp);
d3d8_clear(d3d->dev, 0, 0, D3DCLEAR_TARGET, 0, 1, 0);

/* Insert black frame first, so we
* can screenshot, etc. */
if (black_frame_insertion)
{
if (!d3d8_swap(d3d, d3d->dev) || d3d->needs_restore)
return true;
d3d8_clear(d3d->dev, 0, 0, D3DCLEAR_TARGET, 0, 1, 0);
}

if (!d3d8_renderchain_render(
d3d,
Expand All @@ -1556,6 +1548,17 @@ static bool d3d8_frame(void *data, const void *frame,
return false;
}

if (black_frame_insertion && !d3d->menu->enabled)
{
unsigned n;
for (n = 0; n < video_info->black_frame_insertion; ++n)
{
if (!d3d8_swap(d3d, d3d->dev) || d3d->needs_restore)
return true;
d3d8_clear(d3d->dev, 0, 0, D3DCLEAR_TARGET, 0, 1, 0);
}
}

#ifdef HAVE_MENU
if (d3d->menu && d3d->menu->enabled)
{
Expand Down
22 changes: 12 additions & 10 deletions gfx/drivers/d3d9.c
Original file line number Diff line number Diff line change
Expand Up @@ -1532,7 +1532,7 @@ static bool d3d9_frame(void *data, const void *frame,
unsigned width = video_info->width;
unsigned height = video_info->height;
bool statistics_show = video_info->statistics_show;
bool black_frame_insertion = video_info->black_frame_insertion;
unsigned black_frame_insertion = video_info->black_frame_insertion;
struct font_params *osd_params = (struct font_params*)
&video_info->osd_stat_params;
const char *stat_text = video_info->stat_text;
Expand Down Expand Up @@ -1581,22 +1581,24 @@ static bool d3d9_frame(void *data, const void *frame,
d3d9_set_viewports(d3d->dev, &screen_vp);
d3d9_clear(d3d->dev, 0, 0, D3DCLEAR_TARGET, 0, 1, 0);

/* Insert black frame first, so we
* can screenshot, etc. */
if (black_frame_insertion)
{
if (!d3d9_swap(d3d, d3d->dev) || d3d->needs_restore)
return true;
d3d9_clear(d3d->dev, 0, 0, D3DCLEAR_TARGET, 0, 1, 0);
}

if (!d3d->renderchain_driver->render(
d3d, frame, frame_width, frame_height,
pitch, d3d->dev_rotation))
{
RARCH_ERR("[D3D9]: Failed to render scene.\n");
return false;
}

if (black_frame_insertion && !d3d->menu->enabled)
{
unsigned n;
for (n = 0; n < video_info->black_frame_insertion; ++n)
{
if (!d3d9_swap(d3d, d3d->dev) || d3d->needs_restore)
return true;
d3d9_clear(d3d->dev, 0, 0, D3DCLEAR_TARGET, 0, 1, 0);
}
}

#ifdef HAVE_MENU
if (d3d->menu && d3d->menu->enabled)
Expand Down
33 changes: 20 additions & 13 deletions gfx/drivers/gl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2808,6 +2808,7 @@ static bool gl2_frame(void *data, const void *frame,
bool use_rgba = video_info->use_rgba;
bool statistics_show = video_info->statistics_show;
bool msg_bgcolor_enable = video_info->msg_bgcolor_enable;
unsigned black_frame_insertion = video_info->black_frame_insertion;
bool input_driver_nonblock_state = video_info->input_driver_nonblock_state;
bool hard_sync = video_info->hard_sync;
unsigned hard_sync_frames = video_info->hard_sync_frames;
Expand All @@ -2823,7 +2824,6 @@ static bool gl2_frame(void *data, const void *frame,
#ifndef EMSCRIPTEN
bool runloop_is_slowmotion = video_info->runloop_is_slowmotion;
bool runloop_is_paused = video_info->runloop_is_paused;
bool black_frame_insertion = video_info->black_frame_insertion;
#endif

if (!gl)
Expand Down Expand Up @@ -3088,24 +3088,31 @@ static bool gl2_frame(void *data, const void *frame,
#endif
gl2_pbo_async_readback(gl);

/* Emscripten has to do black frame insertion in its main loop */
if (gl->ctx_driver->swap_buffers)
gl->ctx_driver->swap_buffers(gl->ctx_data);

/* Emscripten has to do black frame insertion in its main loop */
#ifndef EMSCRIPTEN
/* Disable BFI during fast forward, slow-motion,
* and pause to prevent flicker. */
if (
if (
black_frame_insertion
&& !input_driver_nonblock_state
&& !runloop_is_slowmotion
&& !runloop_is_paused)
{
if (gl->ctx_driver->swap_buffers)
gl->ctx_driver->swap_buffers(gl->ctx_data);
glClear(GL_COLOR_BUFFER_BIT);
}
#endif

if (gl->ctx_driver->swap_buffers)
gl->ctx_driver->swap_buffers(gl->ctx_data);
&& !runloop_is_paused
&& !gl->menu_texture_enable)
{
unsigned n;
for (n = 0; n < black_frame_insertion; ++n)
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);

if (gl->ctx_driver->swap_buffers)
gl->ctx_driver->swap_buffers(gl->ctx_data);
}
}
#endif

/* check if we are fast forwarding or in menu,
* if we are ignore hard sync */
Expand Down
27 changes: 18 additions & 9 deletions gfx/drivers/gl1.c
Original file line number Diff line number Diff line change
Expand Up @@ -899,24 +899,33 @@ static bool gl1_gfx_frame(void *data, const void *frame,
4, GL_RGBA, GL_UNSIGNED_BYTE,
gl1->readback_buffer_screenshot);

/* Emscripten has to do black frame insertion in its main loop */

if (gl1->ctx_driver->swap_buffers)
gl1->ctx_driver->swap_buffers(gl1->ctx_data);

/* Emscripten has to do black frame insertion in its main loop */
#ifndef EMSCRIPTEN
/* Disable BFI during fast forward, slow-motion,
* and pause to prevent flicker. */
if (
video_info->black_frame_insertion
&& !video_info->input_driver_nonblock_state
&& !video_info->runloop_is_slowmotion
&& !video_info->runloop_is_paused)
&& !video_info->runloop_is_paused
&& !gl1->menu_texture_enable)
{
if (gl1->ctx_driver->swap_buffers)
gl1->ctx_driver->swap_buffers(gl1->ctx_data);
glClear(GL_COLOR_BUFFER_BIT);
}
#endif

if (gl1->ctx_driver->swap_buffers)
gl1->ctx_driver->swap_buffers(gl1->ctx_data);
unsigned n;
for (n = 0; n < video_info->black_frame_insertion; ++n)
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);

if (gl1->ctx_driver->swap_buffers)
gl1->ctx_driver->swap_buffers(gl1->ctx_data);
}
}
#endif

/* check if we are fast forwarding or in menu, if we are ignore hard sync */
if (hard_sync
Expand Down
34 changes: 23 additions & 11 deletions gfx/drivers/gl_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1853,7 +1853,8 @@ static bool gl_core_frame(void *data, const void *frame,
const char *stat_text = video_info->stat_text;
bool statistics_show = video_info->statistics_show;
bool msg_bgcolor_enable = video_info->msg_bgcolor_enable;
bool black_frame_insertion = video_info->black_frame_insertion;
unsigned black_frame_insertion = video_info->black_frame_insertion;

unsigned hard_sync_frames = video_info->hard_sync_frames;
bool runloop_is_paused = video_info->runloop_is_paused;
bool runloop_is_slowmotion = video_info->runloop_is_slowmotion;
Expand Down Expand Up @@ -1989,21 +1990,32 @@ static bool gl_core_frame(void *data, const void *frame,
gl_core_pbo_async_readback(gl);
}


if (gl->ctx_driver->swap_buffers)
gl->ctx_driver->swap_buffers(gl->ctx_data);

/* Emscripten has to do black frame insertion in its main loop */
#ifndef EMSCRIPTEN
/* Disable BFI during fast forward, slow-motion,
* and pause to prevent flicker. */
if (
if (
black_frame_insertion
&& !input_driver_nonblock_state
&& !runloop_is_slowmotion
&& !runloop_is_paused)
{
if (gl->ctx_driver->swap_buffers)
gl->ctx_driver->swap_buffers(gl->ctx_data);
glClear(GL_COLOR_BUFFER_BIT);
}

if (gl->ctx_driver->swap_buffers)
gl->ctx_driver->swap_buffers(gl->ctx_data);
&& !runloop_is_paused
&& !gl->menu_texture_enable)
{
unsigned n;
for (n = 0; n < black_frame_insertion; ++n)
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);

if (gl->ctx_driver->swap_buffers)
gl->ctx_driver->swap_buffers(gl->ctx_data);
}
}
#endif

if (hard_sync &&
!input_driver_nonblock_state &&
Expand Down
17 changes: 12 additions & 5 deletions gfx/drivers/vulkan.c
Original file line number Diff line number Diff line change
Expand Up @@ -1724,7 +1724,7 @@ static bool vulkan_frame(void *data, const void *frame,
unsigned height = video_info->height;
bool statistics_show = video_info->statistics_show;
const char *stat_text = video_info->stat_text;
bool black_frame_insertion = video_info->black_frame_insertion;
unsigned black_frame_insertion = video_info->black_frame_insertion;
bool input_driver_nonblock_state = video_info->input_driver_nonblock_state;
bool runloop_is_slowmotion = video_info->runloop_is_slowmotion;
bool runloop_is_paused = video_info->runloop_is_paused;
Expand Down Expand Up @@ -2258,18 +2258,25 @@ static bool vulkan_frame(void *data, const void *frame,
vk->should_resize = false;
}

vulkan_check_swapchain(vk);
vulkan_check_swapchain(vk);

/* Disable BFI during fast forward, slow-motion,
* and pause to prevent flicker. */
if (
backbuffer->image != VK_NULL_HANDLE
backbuffer->image != VK_NULL_HANDLE
&& vk->context->has_acquired_swapchain
&& black_frame_insertion
&& !input_driver_nonblock_state
&& !runloop_is_slowmotion
&& !runloop_is_paused)
vulkan_inject_black_frame(vk, video_info, vk->ctx_data);
&& !runloop_is_paused
&& !vk->menu.enable)
{
unsigned n;
for (n = 0; n < black_frame_insertion; ++n)
{
vulkan_inject_black_frame(vk, video_info, vk->ctx_data);
}
}

/* Vulkan doesn't directly support swap_interval > 1,
* so we fake it by duping out more frames. */
Expand Down
5 changes: 2 additions & 3 deletions gfx/drivers_context/drm_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ static bool gfx_ctx_drm_set_video_mode(void *data,
struct drm_fb *fb = NULL;
gfx_ctx_drm_data_t *drm = (gfx_ctx_drm_data_t*)data;
settings_t *settings = config_get_ptr();
bool black_frame_insertion = settings->bools.video_black_frame_insertion;
unsigned black_frame_insertion = settings->uints.video_black_frame_insertion;
float video_refresh_rate = settings->floats.video_refresh_rate;

if (!drm)
Expand All @@ -631,8 +631,7 @@ static bool gfx_ctx_drm_set_video_mode(void *data,
/* If we use black frame insertion,
* we fake a 60 Hz monitor for 120 Hz one,
* etc, so try to match that. */
refresh_mod = black_frame_insertion
? 0.5f : 1.0f;
refresh_mod = 1.0f / (black_frame_insertion + 1.0f);

/* Find desired video mode, and use that.
* If not fullscreen, we get desired windowed size,
Expand Down
2 changes: 1 addition & 1 deletion menu/menu_displaylist.c
Original file line number Diff line number Diff line change
Expand Up @@ -5673,7 +5673,7 @@ unsigned menu_displaylist_build_list(
count++;
if (MENU_DISPLAYLIST_PARSE_SETTINGS_ENUM(list,
MENU_ENUM_LABEL_VIDEO_BLACK_FRAME_INSERTION,
PARSE_ONLY_BOOL, false) == 0)
PARSE_ONLY_UINT, false) == 0)
count++;
#ifdef HAVE_SCREENSHOTS
if (video_driver_supports_viewport_read())
Expand Down
Loading