Mircea Ispas
Mircea Ispas

Reputation: 20780

OpenGL ES presentRenderBuffer duration depends on frameInterval value

I'm using CADisplayLink to fire the "update" event for a very simple OpenGL ES animation on iOS. The animation has around 10 textured quads. I tried to run this at 60 FPS and I saw some glitches. When changing this to 30 FPS the animation runs smoother. After profiling this I saw that the most of the time is spent in presentRenderBuffer.

These are the results:

m_displayLink.frameInterval = 2;

[379406923.204] Update time 0.000358
[379406923.206] Render time 0.001402
[379406923.207] Present time 0.001136
[379406923.238] Update time 0.000370
[379406923.239] Render time 0.001393
[379406923.241] Present time 0.001148
[379406923.271] Update time 0.000368
[379406923.273] Render time 0.001377
[379406923.274] Present time 0.001226
[379406923.305] Update time 0.000380
[379406923.307] Render time 0.001390
[379406923.308] Present time 0.001183
[379406923.338] Update time 0.000375
[379406923.339] Render time 0.001376
[379406923.341] Present time 0.001178
[379406923.372] Update time 0.000981
[379406923.375] Render time 0.001418
[379406923.379] Present time 0.004452

From the results from m_displayLink.frameInterval = 2 profiling I can see that the total frame time is more than enough to achieve 60 FPS, but when changing m_displayLink.frameInterval value to 1 the results are unexpected:

m_displayLink.frameInterval = 1;  

[379407317.151] Update time 0.000204 
[379407317.152] Render time 0.000827 
[379407317.172] Present time 0.019173 
[379407317.172] Update time 0.000231 
[379407317.173] Render time 0.000856 
[379407317.201] Present time 0.027540 
[379407317.202] Update time 0.000204 
[379407317.202] Render time 0.000834 
[379407317.218] Present time 0.015187 
[379407317.218] Update time 0.000192 
[379407317.219] Render time 0.000803 
[379407317.251] Present time 0.031392 
[379407317.252] Update time 0.000215 
[379407317.253] Render time 0.000858 
[379407317.267] Present time 0.014433 
[379407317.268] Update time 0.000196 
[379407317.269] Render time 0.001248 
[379407317.301] Present time 0.031312

As you can see the present time it several times bigger when using

m_displayLink.frameInterval = 1;

Please note that last command from Render() is glFinish()

Do you have any idea why there is this unexpected behaviour? Is it possible to achieve 60 FPS(from the first profiling I have around 500FPS!)?

Upvotes: 1

Views: 1292

Answers (1)

Mircea Ispas
Mircea Ispas

Reputation: 20780

I solved the problem (pure luck!) by moving OpenGL initialization from view initWithFrame. I know this sounds very awkward, but this reduced my GPU usage from 96% to 6%. Now the simple application runs very smooth at 60 FPS with 2% CPU and 6% GPU usage(as it should be!).

Upvotes: 2

Related Questions