I am trying to profile my renderer and I see some strange profiling behavior that I cannot explain.
I am using glSurfaceView, which I have set up to render continuously.
This is how my onDrawFrame() structured
public void onDrawFrame(GL10 unused) { GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); executeAllDrawCommands(); }
This showed up slowly under light load, so I created a timer class and started working on some of them. I was very surprised to see.
I put some probes in my onDrawFrame method as follows:
public void onDrawFrame(GL10 unused) { swapTimer.end(); clearTimer.start(); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); clearTimer.end(); drawTimer.start(); executeAllDrawCommands(); drawTimer.end(); swapTimer.start(); }
clearTimer measures the time it takes to call glClear, drawTimer measures the time it takes to complete all my drawing calls, and swapTimer measures the time from when onDrawFrame exited and when it returns (time spent calling eglSwapBuffers).
When I launched a very busy scene, I got some really strange numbers that I can not explain:
swapTimer : 20ms (average) clearTimer : 11ms (average) drawTimer : 2ms (average)
I expected the swap time to be somewhat longer, since I believe the device had vsync forcibly turned on at ~ 30 frames per second, although I don't know why the actual βclearβ call is blocked for 11 milliseconds? I thought it was just supposed to issue an asynchronous command and return?
When I draw a much more loaded scene, the numbers change quite a bit:
swapTimer : 2ms (average) clearTimer : 0ms (average) drawTimer : 44ms (average)
In this scene, my drawing calls take so much time that it looks like it hides a lot of vsync time, and the block with the clear call completely leaves.
Is there any explanation why glClear blocks my slightly loaded scene?
Link to my Timer class source code if someone is suspicious of my measuring technique: http://pastebin.com/bhXt368W