Stuck at 30 fps until alt-tab =/

Hey Everybody,

I’ve got a very strange frame rate bug in my game and I’m totally stuck trying to figure this out:

From time to time my game starts and stays at 30 fps until I alt-tab away from it and back, at which point it goes to 60 fps as its supposed to. So weird!
My setup is NVidia GeForce GT 640M, Windows 10, dual monitor.

When profiling while the problem is occurring, I see that SwapBuffers is averaging 22ms. After alt-tab, SwapBuffers averages a more reasonable time.

I’ve tried adding/removing sleeps, removing shaders, adding window focus requests, glFlush, glFinish… none of it made a difference. The only thing that seems to solve the issue is enabling Triple Buffering in the NVidia control panel.

Any ideas?
Thanks!

What exactly do you render? And how is that stored on the GPU? Do you have code snippets?
And what GL version do you use?

Although you’re seeing the time spend in glfwSwapBuffers, this does very little other than wrap the underlying OS API for buffer swapping, and it’s likely that this is waiting for the GPU to render and buffers to swap. So the problem is likely a generic OpenGL one, and other forums may be helpful in addition to this one.

Greater detail could be provided with Nvidia Nsight or GPUView the later being the best but hardest to use.

I’ve seen this sort of behaviour a few times, in all sorts of apps, but haven’t pursued the details of why. I’m suspicious it may be caused by the GPU clocking down due to lower utilisation, pushing up the render time over one vsync period and causing a feedback because now most of the 2 vsync period does not make use of the GPU. This is a guess though, as I’ve not profiled it in combo with watching the GPU clock.

If it’s possible to detect this happening you can also turn off and on vsync by setting the swap interval to 0 for a frame then back on.

@PadMad I’m using cocos2d-x. It’s a long scene graph of 2D sprites. OpenGL 2.0. Here’s the specific branch I’m using:


Have you seen this happen with specific versions of GL or GPUs?

@dougbinks Interesting idea to toggle the swap interval… I’ll look into that - thanks. I profiled with NSight, but other than seeing SwapBuffers take extra long, there was nothing obvious. Also, because of the window focus issue, every time I click on the NSight window to capture a frame, the game’s frame rate returns to normal =[ (capturing from the in-game HUD isn’t working for some reason). Your guess about what could be causing this is interesting too: alt-tab always returns the fps to normal, but there is another more rare way to do so involving moving the player character around a lot and triggering some shaders to turn on. Maybe at that point the GPU clocks back up and the fps turns back to normal?

This is the only bug keeping me from shipping my game and the only solution I have right now is to put into our troubleshooting guide a recommendation for enabling triple buffering. The silver lining though is that this doesn’t seem to happen on all NVidia devices.

GPUView is likely the better profiler in this case as it can be started before the app is run and stopped afterwards. Using it is a bit of a black art but it’s very powerful. It’s based on ETW which has a lot of good information on Bruce Dawson’s blog.

Thanks for the info @dougbinks
I’ll take a look into it…