Collection: iPhone Optimization
by Marc Dreamora Schaerer · in iTorque 2D · 10/05/2008 (1:22 pm) · 14 replies
I think for the broader boost of our development, it would be usefull if we talk about how best to optimize your game.
For that reason I will start with my own set of tipps that hopefully will help other users.
1. The iPhone has a "massive" 480x320 screen. This means that 64x64 is the maximum size you will need for a regular objects normally. It makes no sense to have larger textures that you reduce to render at the correct size. Backgrounds might be larger naturally.
2. State changes are expensive. What this means is that especially many distinct textures will hurt performance. If you use tilemaps, collect all the tiles in a single / several 1024x1024 texture(s). If you need more than one texture for your tilemap, put those with regional relation into the same so that the texture has to be switched as rarely as possible.
Also check if you can get a character with all its animation on a single texture (at frame sizes of 64x64, you have 256 frames on a 1024x1024. with 32x32 even 1024 frames).
My personal ones:
1. Disable Filter Pad. It will raise the texture sizes. Without it you have full control over the textures and how they are used. This is important, because you have at maximum 24MB of ram to use for your graphics, thats not that much. I'm still toying around to find out how I can get iTGB to create/load pvrtc2 / pvrtc4 textures which would be the optimum.
2. Even thought TGB, if I remember correctly, does that behind the scene: Make your textures square, power of two.
Suggestions for future optimizations in future iTGB versions
1. Best would be if the quadbatcher would be optimized to sort for state changes and the stuff would use it
Additionation with an optimized tilemap system that merges quads where the neightbor textures are identical to reduce the amount of polygons as well. After all, the iPhone is no magical system that will handle ten tousands of polygons. On different boards I read about 7000-9000 polygons onscreen. So the tilesystem definitely has a lot of potential for optimization, most likely one of the best "optimization benefit per invested hour" ratios for the future of iTGB.
I've not checked how far the engine so far is doing that.
2. What I want to have in the end is a "build game" button that compresses alls png to pvrtc2 or 4, depending on a checkbox (uses alpha?) on the texture I set in the game editor. Additionally an option would exist on the texture to tell iTGB that it shall not compress it ("uncompressed"?). This might be usefull/needed for pixel perfect backgrounds at full screensize I think.
For that reason I will start with my own set of tipps that hopefully will help other users.
1. The iPhone has a "massive" 480x320 screen. This means that 64x64 is the maximum size you will need for a regular objects normally. It makes no sense to have larger textures that you reduce to render at the correct size. Backgrounds might be larger naturally.
2. State changes are expensive. What this means is that especially many distinct textures will hurt performance. If you use tilemaps, collect all the tiles in a single / several 1024x1024 texture(s). If you need more than one texture for your tilemap, put those with regional relation into the same so that the texture has to be switched as rarely as possible.
Also check if you can get a character with all its animation on a single texture (at frame sizes of 64x64, you have 256 frames on a 1024x1024. with 32x32 even 1024 frames).
My personal ones:
1. Disable Filter Pad. It will raise the texture sizes. Without it you have full control over the textures and how they are used. This is important, because you have at maximum 24MB of ram to use for your graphics, thats not that much. I'm still toying around to find out how I can get iTGB to create/load pvrtc2 / pvrtc4 textures which would be the optimum.
2. Even thought TGB, if I remember correctly, does that behind the scene: Make your textures square, power of two.
Suggestions for future optimizations in future iTGB versions
1. Best would be if the quadbatcher would be optimized to sort for state changes and the stuff would use it
Additionation with an optimized tilemap system that merges quads where the neightbor textures are identical to reduce the amount of polygons as well. After all, the iPhone is no magical system that will handle ten tousands of polygons. On different boards I read about 7000-9000 polygons onscreen. So the tilesystem definitely has a lot of potential for optimization, most likely one of the best "optimization benefit per invested hour" ratios for the future of iTGB.
I've not checked how far the engine so far is doing that.
2. What I want to have in the end is a "build game" button that compresses alls png to pvrtc2 or 4, depending on a checkbox (uses alpha?) on the texture I set in the game editor. Additionally an option would exist on the texture to tell iTGB that it shall not compress it ("uncompressed"?). This might be usefull/needed for pixel perfect backgrounds at full screensize I think.
About the author
#2
10/06/2008 (11:26 am)
Thanks Marc. This is great.
#3
10/16/2008 (12:42 am)
Error on my end
#4
10/16/2008 (7:27 am)
Marc - are you talking about simulator framerate there or actual hardware framerate?
#5
10/18/2008 (9:43 am)
I may be wrong on that one, but I think that the Linear Filterring only increase the size of your textures if you are exactly on the power (64,128,256,etc..). if your texture is 62*62 or 126*126 I think it will only round up to the next power which is what you want.
#6
But I know what you mean.
But if you don't create textures to be power of two, you waste space on the texture, that you could have used. Its not like you have texture space on the iphone to waste. You have at maximum 24MB for your application data and the visuals
10/18/2008 (10:02 am)
Filtering does not increase anything actually.But I know what you mean.
But if you don't create textures to be power of two, you waste space on the texture, that you could have used. Its not like you have texture space on the iphone to waste. You have at maximum 24MB for your application data and the visuals
#7
This is what a filterPadding of 1 would do to a 64*64 texture.
********* Packing ImageMap: 'triggerfish2sheetImageMap' *********
Frame Input: 0000 at (0000,0000) sized 0064(w) x 0064(h) padded to size 0066(w) x 0066(h)
Frame Input: 0001 at (0064,0000) sized 0064(w) x 0064(h) padded to size 0066(w) x 0066(h)
Frame Input: 0002 at (0000,0064) sized 0064(w) x 0064(h) padded to size 0066(w) x 0066(h)
Frame Input: 0003 at (0064,0064) sized 0064(w) x 0064(h) padded to size 0066(w) x 0066(h)
Frame Output: 0000 is 0064(w) x 0064(h) - Relocated Src:(0000,0000) to Dst:(0001,0001) on Page 0000)
Frame Output: 0001 is 0064(w) x 0064(h) - Relocated Src:(0064,0000) to Dst:(0001,0067) on Page 0000)
Frame Output: 0002 is 0064(w) x 0064(h) - Relocated Src:(0000,0064) to Dst:(0133,0001) on Page 0000)
Frame Output: 0003 is 0064(w) x 0064(h) - Relocated Src:(0064,0064) to Dst:(0067,0001) on Page 0000)
Texture Page: 0000 is 0256(w) x 0256(h) and contains 0004 frames
Fitted in 0001 texture(s) in 0007 iteration(s) occupying 65536 texel(s) with 48112 unused texel(s).
Fit Percentage is therefore 26.59%
Percentage change from original is 400.00%
Total Time Taken: 0.046 sec(s)
without the padding it would be much better:
********* Packing ImageMap: 'triggerfish2sheetImageMap' *********
Frame Input: 0000 is 0064(w) x 0064(h)
Frame Input: 0001 is 0064(w) x 0064(h)
Frame Input: 0002 is 0064(w) x 0064(h)
Frame Input: 0003 is 0064(w) x 0064(h)
Frame Output: 0000 is 0064(w) x 0064(h) - Relocated Src:(0000,0000) to Dst:(0000,0000) on Page 0000)
Frame Output: 0001 is 0064(w) x 0064(h) - Relocated Src:(0064,0000) to Dst:(0000,0192) on Page 0000)
Frame Output: 0002 is 0064(w) x 0064(h) - Relocated Src:(0000,0064) to Dst:(0000,0128) on Page 0000)
Frame Output: 0003 is 0064(w) x 0064(h) - Relocated Src:(0064,0064) to Dst:(0000,0064) on Page 0000)
Texture Page: 0000 is 0064(w) x 0256(h) and contains 0004 frames
Fitted in 0001 texture(s) in 0009 iteration(s) occupying 16384 texel(s) with 0 unused texel(s).
Fit Percentage is therefore 100.00%
Percentage change from original is 100.00%
Total Time Taken: 0.015 sec(s)
10/18/2008 (2:42 pm)
Yes, it's not the filtering. it's the filter padding if you use it.This is what a filterPadding of 1 would do to a 64*64 texture.
********* Packing ImageMap: 'triggerfish2sheetImageMap' *********
Frame Input: 0000 at (0000,0000) sized 0064(w) x 0064(h) padded to size 0066(w) x 0066(h)
Frame Input: 0001 at (0064,0000) sized 0064(w) x 0064(h) padded to size 0066(w) x 0066(h)
Frame Input: 0002 at (0000,0064) sized 0064(w) x 0064(h) padded to size 0066(w) x 0066(h)
Frame Input: 0003 at (0064,0064) sized 0064(w) x 0064(h) padded to size 0066(w) x 0066(h)
Frame Output: 0000 is 0064(w) x 0064(h) - Relocated Src:(0000,0000) to Dst:(0001,0001) on Page 0000)
Frame Output: 0001 is 0064(w) x 0064(h) - Relocated Src:(0064,0000) to Dst:(0001,0067) on Page 0000)
Frame Output: 0002 is 0064(w) x 0064(h) - Relocated Src:(0000,0064) to Dst:(0133,0001) on Page 0000)
Frame Output: 0003 is 0064(w) x 0064(h) - Relocated Src:(0064,0064) to Dst:(0067,0001) on Page 0000)
Texture Page: 0000 is 0256(w) x 0256(h) and contains 0004 frames
Fitted in 0001 texture(s) in 0007 iteration(s) occupying 65536 texel(s) with 48112 unused texel(s).
Fit Percentage is therefore 26.59%
Percentage change from original is 400.00%
Total Time Taken: 0.046 sec(s)
without the padding it would be much better:
********* Packing ImageMap: 'triggerfish2sheetImageMap' *********
Frame Input: 0000 is 0064(w) x 0064(h)
Frame Input: 0001 is 0064(w) x 0064(h)
Frame Input: 0002 is 0064(w) x 0064(h)
Frame Input: 0003 is 0064(w) x 0064(h)
Frame Output: 0000 is 0064(w) x 0064(h) - Relocated Src:(0000,0000) to Dst:(0000,0000) on Page 0000)
Frame Output: 0001 is 0064(w) x 0064(h) - Relocated Src:(0064,0000) to Dst:(0000,0192) on Page 0000)
Frame Output: 0002 is 0064(w) x 0064(h) - Relocated Src:(0000,0064) to Dst:(0000,0128) on Page 0000)
Frame Output: 0003 is 0064(w) x 0064(h) - Relocated Src:(0064,0064) to Dst:(0000,0064) on Page 0000)
Texture Page: 0000 is 0064(w) x 0256(h) and contains 0004 frames
Fitted in 0001 texture(s) in 0009 iteration(s) occupying 16384 texel(s) with 0 unused texel(s).
Fit Percentage is therefore 100.00%
Percentage change from original is 100.00%
Total Time Taken: 0.015 sec(s)
#8
www.glbenchmark.com/phonedetails.jsp?benchmark=pro&D=Apple%20iPhone&testgroup=lo...
10/20/2008 (1:33 am)
For more technically oriented people, here a link to a OpenGL ES Benchmark with the iPhone to give you an idea what you theoretically can push through or what you should aim for at worst:www.glbenchmark.com/phonedetails.jsp?benchmark=pro&D=Apple%20iPhone&testgroup=lo...
#9
You'll have to test your specific app to see if it runs faster with Thumb deselected. I just tested a non-iTGB program and it ran about 30% faster with Thumb deselected. Here's a thread at Apple about it: http://discussions.apple.com/thread.jspa?threadID=1757686&tstart=75
You can also mess with the Optimization Level in the same Build settings window. By default Xcode sets -Os (fastest, smallest). Fastest (-O3) might give you a tiny bit more.
10/21/2008 (9:02 pm)
Digging around other threads here & other places, I found that the default iPhone SDK project build option of "Compile for Thumb" probably isn't the best for some programs. To disable it, open your project in Xcode, click on your project name under Groups & Files, then go to Info. Once in the Project Info window, click Build & search for "thumb." Deselect "Compile for Thumb."You'll have to test your specific app to see if it runs faster with Thumb deselected. I just tested a non-iTGB program and it ran about 30% faster with Thumb deselected. Here's a thread at Apple about it: http://discussions.apple.com/thread.jspa?threadID=1757686&tstart=75
You can also mess with the Optimization Level in the same Build settings window. By default Xcode sets -Os (fastest, smallest). Fastest (-O3) might give you a tiny bit more.
#10
10/22/2008 (1:31 pm)
@Everyone - Thanks for this valuable information. We are including this in the dev, QA, and documentation processes to aid in the next update.
#11
One real drawing issue on the iPhone is fill rate. We and others have found that trying to draw more than 2 screens worth of pixels cuts the framerate dramatically.
Meaning if you have lots of layers/objects that draw large portions of the screen several times over that will affect the framerate more than the number of polys it takes to draw them.
Hope this helps.
10/22/2008 (4:19 pm)
Great posts guys, we are definitely working hard on optimizations.One real drawing issue on the iPhone is fill rate. We and others have found that trying to draw more than 2 screens worth of pixels cuts the framerate dramatically.
Meaning if you have lots of layers/objects that draw large portions of the screen several times over that will affect the framerate more than the number of polys it takes to draw them.
Hope this helps.
#12
Might explain why the shooter demo suffers a bit with the multilayer parallax background
10/22/2008 (4:22 pm)
Thank you. Yes thats very usefull to know.Might explain why the shooter demo suffers a bit with the multilayer parallax background
#13
10/22/2008 (4:40 pm)
I hate fill rate!
#14
10/22/2008 (6:20 pm)
That's a useful tip Paul thanks. I can see I'm going to have to re-arrange my background and explosions to compensate for this.
Employee Michael Perry
ZombieShortbus