Possible vsync bug when drawing with two viewports?

jasjuang wrote on Tuesday, April 21, 2015:

vsync is switched on and off with glfwSwapInterval(1) or glfwSwapInterval(0)

single viewport is glClear --> glViewport(0, 0, win_w,win_h) -->
drawscene() --> glfwSwapBuffers in the rendering loop

double viewport is glClear --> glViewport(0, 0, win_w/2,win_h) -->
drawscene() --> glViewport(win_w/2, 0, win_w/2,win_h) --> drawscene()
–>glfwSwapBuffers in the rendering loop

My scene single viewport with no vsync --> 140 fps

My scene double viewport with no vsync --> 70 fps (as expected since it is
drawing the same scene twice)

My scene single viewport with vsync --> 60 fps (as expected because my
monitor refresh rate is 60Hz)

My scene double viewport with vsync --> 30 fps (??? I am expecting 60 fps
here because it is achieving 70 > 60 fps without vsync, is there any extra
GLFW function that I have to call?)

dougbinks wrote on Wednesday, April 22, 2015:

I doubt this is an issue with glfw, more likely there is a small extra overhead when vsync is on causing you to get frame times of more than 16.6ms (60FPS) from the non vsync’d 14.3ms (70FPS) and so getting the next vsync interval of 33.3ms (30FPS). If you try optimizing your rendering or reducing the load you should be able to achieve 16.6ms.

I see about an extra 2ms of CPU time lost on average due to vsync under some circumstances, so this seems to be a likely explanation.

jasjuang wrote on Wednesday, April 22, 2015:

Thanks for the excellent explanation!