Skip to content

Commit 504d51e

Browse files
committed
Scanline sync corrections
- Stop trying to force vsync off when scanline sync is enabled - Better minimum core time
1 parent 9fc16b6 commit 504d51e

6 files changed

Lines changed: 26 additions & 27 deletions

File tree

gfx/common/vulkan_common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1831,7 +1831,7 @@ bool vulkan_create_swapchain(gfx_ctx_vulkan_data_t *vk,
18311831
VkPresentModeKHR swapchain_present_mode = VK_PRESENT_MODE_FIFO_KHR;
18321832
VkCompositeAlphaFlagBitsKHR composite = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
18331833
settings_t *settings = config_get_ptr();
1834-
bool vsync = settings->bools.video_vsync && !settings->bools.video_scanline_sync;
1834+
bool vsync = settings->bools.video_vsync;
18351835
bool adaptive_vsync = settings->bools.video_adaptive_vsync;
18361836
#ifdef VK_USE_PLATFORM_WIN32_KHR
18371837
bool video_windowed_fullscreen = settings->bools.video_windowed_fullscreen;

gfx/drivers/d3d11.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3240,6 +3240,11 @@ static void *d3d11_gfx_init(const video_info_t* video,
32403240
if (settings->bools.video_waitable_swapchains)
32413241
d3d11->flags |= D3D11_ST_FLAG_WAITABLE_SWAPCHAINS;
32423242

3243+
if (video->vsync)
3244+
d3d11->flags |= D3D11_ST_FLAG_VSYNC;
3245+
else
3246+
d3d11->flags &= ~D3D11_ST_FLAG_VSYNC;
3247+
32433248
#ifdef __WINRT__
32443249
if (!d3d11_init_swapchain(d3d11,
32453250
d3d11->vp.full_width,
@@ -3275,11 +3280,6 @@ static void *d3d11_gfx_init(const video_info_t* video,
32753280
else
32763281
d3d11->flags &= ~D3D11_ST_FLAG_KEEP_ASPECT;
32773282

3278-
if (video->vsync)
3279-
d3d11->flags |= D3D11_ST_FLAG_VSYNC;
3280-
else
3281-
d3d11->flags &= ~D3D11_ST_FLAG_VSYNC;
3282-
32833283
d3d11->format = (video->rgb32)
32843284
? DXGI_FORMAT_B8G8R8X8_UNORM : DXGI_FORMAT_B5G6R5_UNORM;
32853285

gfx/drivers/d3d12.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4288,6 +4288,11 @@ static void *d3d12_gfx_init(const video_info_t* video,
42884288
else
42894289
d3d12->flags &= ~D3D12_ST_FLAG_WAITABLE_SWAPCHAINS;
42904290

4291+
if (video->vsync)
4292+
d3d12->flags |= D3D12_ST_FLAG_VSYNC;
4293+
else
4294+
d3d12->flags &= ~D3D12_ST_FLAG_VSYNC;
4295+
42914296
d3d_input_driver(settings->arrays.input_driver,
42924297
settings->arrays.input_joypad_driver, input, input_data);
42934298

@@ -4427,11 +4432,6 @@ static void *d3d12_gfx_init(const video_info_t* video,
44274432
else
44284433
d3d12->flags &= ~D3D12_ST_FLAG_KEEP_ASPECT;
44294434

4430-
if (video->vsync)
4431-
d3d12->flags |= D3D12_ST_FLAG_VSYNC;
4432-
else
4433-
d3d12->flags &= ~D3D12_ST_FLAG_VSYNC;
4434-
44354435
d3d12->format = (video->rgb32)
44364436
? DXGI_FORMAT_B8G8R8X8_UNORM : DXGI_FORMAT_B5G6R5_UNORM;
44374437

gfx/video_driver.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5323,13 +5323,15 @@ static INLINE void video_driver_scanline_before_frame(video_driver_state_t *vide
53235323
uint16_t frame_time_target,
53245324
uint16_t core_run_time)
53255325
{
5326-
uint16_t video_height = video_st->height;
5327-
int16_t scanline_next = video_st->scanline[SCANLINE_NEXT];
5328-
int16_t scanline_hold = video_st->scanline[SCANLINE_HOLD];
5329-
int16_t scanline = video_driver_scanline_get();
5326+
uint16_t video_height = video_st->height;
5327+
int16_t scanline_next = video_st->scanline[SCANLINE_NEXT];
5328+
int16_t scanline_hold = video_st->scanline[SCANLINE_HOLD];
5329+
int16_t scanline_blank = video_st->scanline[SCANLINE_TOTAL] - video_height;
5330+
int16_t scanline = video_driver_scanline_get();
53305331

5331-
/* Assume at least some usage in menu */
5332-
core_run_time = core_run_time < 1000 ? 1000 : core_run_time;
5332+
/* Minimum usage is vblank */
5333+
uint16_t min_run_time = (scanline_blank > 0) ? (double)scanline_blank / (double)video_height * (double)frame_time_target : 1000;
5334+
core_run_time = (core_run_time < min_run_time) ? min_run_time : core_run_time;
53335335

53345336
/* Disable if unsupported */
53355337
if (scanline < 0)
@@ -5357,8 +5359,7 @@ static INLINE void video_driver_scanline_before_frame(video_driver_state_t *vide
53575359
/* Allow change */
53585360
if (!scanline_hold)
53595361
{
5360-
int16_t scanline_blank = video_st->scanline[SCANLINE_TOTAL] - video_height;
5361-
int16_t corelines = video_height * ((double)core_run_time / (double)frame_time_target);
5362+
int16_t corelines = video_height * ((double)core_run_time / (double)frame_time_target);
53625363

53635364
/* Fine-tuning */
53645365
if ( scanline > -scanline_blank
@@ -5400,7 +5401,9 @@ static INLINE void video_driver_scanline_after_frame(video_driver_state_t *video
54005401
uint16_t video_height = video_st->height;
54015402
int16_t scanline_next = video_st->scanline[SCANLINE_NEXT];
54025403
int16_t scanline_total = video_st->scanline[SCANLINE_TOTAL];
5404+
int16_t scanline_blank = video_st->scanline[SCANLINE_TOTAL] - video_height;
54035405
int16_t scanline_target = (scanline_next < 0) ? video_height + scanline_next : scanline_next;
5406+
uint16_t min_run_time = (scanline_blank > 0) ? (double)scanline_blank / (double)video_height * (double)frame_time_target : 1000;
54045407
bool init = (!scanline_total) ? true : false;
54055408
bool wait = true;
54065409

@@ -5412,6 +5415,9 @@ static INLINE void video_driver_scanline_after_frame(video_driver_state_t *video
54125415
if (scanline_next == 1)
54135416
scanline_target = video_height - 1;
54145417

5418+
/* Minimum usage is vblank */
5419+
core_run_time = (core_run_time < min_run_time) ? min_run_time : core_run_time;
5420+
54155421
/* Use CPU friendlier sleep as much as possible */
54165422
if (wait && frame_time_target > core_run_time)
54175423
{

intl/msg_hash_us.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2616,7 +2616,7 @@ MSG_HASH(
26162616
)
26172617
MSG_HASH(
26182618
MENU_ENUM_SUBLABEL_VIDEO_SCANLINE_SYNC,
2619-
"Synchronize video presentation to scanline position. Reduces latency at the cost of a higher risk of tearing."
2619+
"Synchronize video presentation to scanline position. Reduces latency at the cost of a higher risk of tearing. VSync must be disabled."
26202620
)
26212621
MSG_HASH(
26222622
MENU_ENUM_LABEL_VALUE_VIDEO_FRAME_DELAY,

runloop.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4494,13 +4494,6 @@ void runloop_set_video_swap_interval(
44944494
return;
44954495
}
44964496

4497-
/* Scanline sync needs swap interval 0 */
4498-
if (settings->bools.video_scanline_sync)
4499-
{
4500-
runloop_st->video_swap_interval_auto = 0;
4501-
return;
4502-
}
4503-
45044497
/* > If VRR is enabled, swap interval is irrelevant,
45054498
* just set to 1
45064499
* > If core fps is higher than display refresh rate,

0 commit comments

Comments
 (0)