views:

963

answers:

5

I'm trying to track down the bottleneck in an IPhone OpenGL game I'm writing. The game itself is in 2d, and contains a couple hundred textured sprites, each alpha blended.

In terms of textures, I only use a single 512x512 atlas that I bind once, so I don't think its a bandwidth issue (at least not from the upload of textures).

I used instruments to track the CPU usage, memory usage and OpenGL ES usage. At a heavy point in the game, I was getting seeing the following:

FPS: 20 CPU: 60% Real Mem: 17Mb Tiler utilisation : 21% Rendered utilisation : 45%

I'm a little confused as to what could be the bottleneck? How high can the CPU usage go (I'm aware that there are other applications running at the same time) before it becomes the bottleneck? Does 60% sound about right?

Or could it be the amount of graphics? I'm guessing not if the tiler + renderer utilisation are that low down. But I must confess I'm not expert in reading these results.

Any pointers on either what my likely bottleneck is, or where else to look for one would be gratefully received!

+2  A: 

The CPU sounds a bit high, are you using a lot of trigonometric functions like sin/cos? Sometimes those are used badly, ie for particle-systems. Try to keep them to a minimum or if possible use a lookup-table instead.

Here is a good discussion for approximations

epatel
+1  A: 

Have you checked to see which lines of your code are running the majority of the time? I'm pretty sure there is a tool for this in Instruments.

samoz
Called a 'profiler.'
strager
Yes, I just wasn't sure what it is in Instruments.
samoz
Shark is the tool to use for mac/iphone, a runtime sampler...but remember to start and stop it only when the app is running on the iphone, well...what I have heard.
epatel
http://developer.apple.com/tools/shark_optimize.html
epatel
+1  A: 

While your 'rendered' utilisation is low I'm assuming this is the CPU side of the OpenGL calls. You can think of this part as building up a list of things for the GPU to do when you glFlush/glFinish. Once you call one of these the GPU actually has to do the things you set up.

While I haven't worked on the iPhone it sounds like you are GPU bound. So here is a list of things I would check (having not worked directly on the iPhone) in order of how long they would take to investigate:

  1. Are you calling glFinish? If so try using glFlush - glFinish blocks while the GPU does its thing.

  2. If you disable alpha blending do you see an appreciable speed up? I don't think this one is very likely, but it should be quick to check.

  3. Are you doing any sort of culling on your objects, or are you rendering all of your objects each frame?

Does the iPhone have any sort of GPU profiler?

Andrew Khosravian
+3  A: 

If you haven't already, read through Optimizing OpenGL ES for iPhone OS, it's got a lot of useful tidbits on how to write speedy OpenGL applications on the iPhone.

Adam Rosenfield
A: 

How have you implemented your 2D game? Is each individual sprite rendered onto its own triangle paired polygon? or do you render each sprite onto the 512x512 texture surface?

For the latter method, altering the texture for each frame can induce a large performance penalty and isn't recommended in the documentation; Which is a little bit of pain really, glDrawTex may provide a work around, but I haven't tested this and I'm not confident it'll work.

Phill