Android LibGDX Games : FPS drops because of long EGLImpl. eglSwapBuffers call
I’m working on a game for the Android platform, using Java and the LibGDX engine.
I’m having a strange issue where FPS in my game goes from 30-40 frames continuously to 40-40 frames every 57-60 seconds and then down again. Below is a screenshot of the logcat output. The garbage collector is not working at this time (nothing is filtered in the log):
I did some analysis and found that the problem occurred because the EGLImpl.eglSwapBuffers call took more time than usual every 30-40 seconds. In the screenshot below (nothing happens when analyzing the game menu) it takes 3.7 ms:
In my menu render cycle, I just call MyStage.act() and MyStage.draw() to draw a set of ImageButtons – nothing special. My menu frame render time (17ms on average) also seems too long for this simple rendering, but these weird periodic long buffer swap calls are my main concern right now.
By the way
, it gets worse if I dissect during gameplay – these EGLImpl.eglSwapBuffers calls take 15ms or more and drop the FPS to 30 and stay there all the way :
I could really use some advice on how to investigate this.
You need to understand the meaning of swap buffers. This means that you tell OpenGL that you have finished sending all the “render commands” and it can now send the finished rendered image to the screen to display it.
What does this mean? This means that your graphics card has finished rendering! Most GL calls will return immediately without blocking. This means that your CPU continues to work and the GPU will work in parallel to process the queue of rendering commands received from the CPU.
Now, if your CPU is able to complete faster than the GPU, swapping buffers means that the GPU must finish processing the entire queue before it can actually swap buffers and return.
Overall, this means that the problem is not that the actual eglSwapBuffers are taking up too much time, but that your GPU is not keeping up with the CPU. This means that your scene is too complex, for example, your state changes too much, such as texture binding (bind), shader switching, or something like that.
So, by analyzing the CPU side, you won’t really find the real problem. But I can’t really tell you what the problem is. Since you are using libGDX,
GLProfiler may help you here.
PS: The sudden change in FPS can also be caused by your device switching to energy-saving mode.