We upgraded our game to support 960 x 640 resolution on iPhone4 and now we’re having crashing issues due to the fact that the textures (especially large 16-bit GUI images, that we have a lot in the game) are taking too much memory on older devices.
I have tried searching the forum and the web but I haven’t found a clear answer for this yet:
Does anyone know what happens (INTERNALLY!!!) to NPOT textures in older devices? As far as I understand the older hardware does not support NPOT texture sizes at all, even for GUI elements, so I’m assuming that f.ex. 960 x 640 GUI image is actually padded internally into 1024 x 1024 memory block? (see the attached image).
This would explain the horrible memory usage of our game, and if this is the case, we may need to re-format our whole GUI and split the GUI textures into several power-of-two textures, because the memory overhead in our case seems to be unbearable (our game’s memory usage is more than 40mb at the moment).
If I tweak the system to use only lower mipmap levels on older devices (does this work at all for GUI textures?), does it actually mean that the higher level textures are not loaded into memory at all on lower quality settings?
Hmm, I’ll quote myself here - looks like I was right. The device seems to pad the memory, and the memory usage reported by Unity is NOT correct in the texture inspector.
Here’s a quick test that I did, it’s basically rendering 4 24-bit textures inside OnGUI() function.
I checked the device memory allocation with Instruments, here’s the result:
4 x 513 x 513 x 24-bit GUI textures
max peak mem use during loading: 41 mb (!!!)
running stable @ 22.61 mb
3 x 513 x 513 x 24-bit GUI textures
max peak mem use during loading: 37mb
running stable @ 18.61 mb
4 x 512 x 512 x 24-bit GUI textures
max peak mem use during loading: 11.32mb
running stable @ 6.63 mb
3 x 512 x 512 x 24-bit GUI textures
max peak mem use during loading: 10.32mb
running stable @ 6.60 mb
I think Unity should give a warning in this kind of case, because this padding issue is not documented anywhere and the huge growth in memory use is not immediately obvious in case of GUI textures, if you have images that are only slightly larger than the closest power-of-two.
edit:
By the way, this leads me to another suggestion:
Because of this it would be benefical to arrange your GUI textures into large power-of-two texture in iPhone devices, so there should be a GUI.DrawTexture() method where you have could also definine the source rectangle UV coordinates.
I would recommend using a 3rd party GUI system like EZGUI or GUISpriteUI (which we used in Rimelands for the ingame GUI). We ran into the same realization very late in the project, when we didn’t have time to ditch the whole Unity GUI and replace it with a more memory-efficient one.
I’m with you on the fact that in addition to warning about the performance of Unity’s GUI.x, there should also be a note about the texture sizes. The memory requirement goes up very fast in any relatively complex UI.
I managed to drop the memory usage to half simply by splitting the images into smaller pieces … Didn’t take that long to implement in our case, now that I figured out what the problem was.
I really hope the memory allocation of UI textures gets added to the documentation, at the very least!
Would have saved me a lot of time
–offtopic–
Btw, Arzi, I just noticed your company and looks like we have common friends … I’m also one of the guys in Soundreel, and if I remember correctly Tapani did music for your game
I didn’t know you guys use Unity, maybe I should drop by, if you would like to demonstrate GUISpriteUI to me
The downside of that approach is that it increases the draw call count, which may lead to decreased performance. It’s still better than the increased memory usage though.