Unity Debug Diaries

Unity Debug Diaries: Mip Map Memory Reduction

First off, I must apologize for the weird tense swapping that happens in these articles. I write stuff as it happens and do not want to do too much editing lest these become too tedious to write and then I just stop completely. So if you can deal, I will continue to write 🙂

Today, I am attacking using Mip Maps on UI for multi-resolution rendering. Enabling Mip Maps and managing which of the maps are loaded into memory is the easiest way to handle texture memory on lower end devices. Now, I believed this but did not see the reduction in the profiler on device. So then I figured it was a fallacy because the data suggested otherwise. I then switched to TK2D to handle a lot of my multi sized sprites but the lack of clarity on the issue always bugged me. So now, I want to find out for sure. I cant get a straight answer out of anyone so its time to set up some tests.

First, I am going to make a separate project in iOS to have a clean environment and have nothing muddy my results. I am choosing iOS because its got its own set of profiling tools that will help me isolate if the Unity Profiler is telling porky pies (lies).
Results: Lies lies lies! So profiling in iOS showed a radical drop in memory based on the appropriate quality settings. I have four 2048×2048 at 32 bit. The results in the profiler are:

  • Full resolution: 107.66mb
  • Half resolution: 43.68mb
  • Quater resolution: 27.69mb

These results feel on par but now makes me question, how off is the Unity Profiler? Is it just the detail memory view that is off or the whole thing. So I did some tests. We know that no matter the quality setting, the details view does not give the correct memory size for the texture but is this because of Android (my initial test device), texture compression or just the profiler itself.

  • Full resolution
    • Total: 96.3mb
    • GFX: 85.2mb
    • Detailed Texture: 85.1mb
  • Half resolution
    • Total: 32.4mb
    • GFX: 21.4mb
    • Detailed Texture: 21mb
  • Quater resolution
    • Total: 16.5mb
    • GFX: 5.4mb
    • Detailed Texture: 5.3mb

So… WTF! The profiler is working perfectly! Now my question is, was I just wrong or crazy? Whats left is checking Android and texture compression settings. If not, I will own up to being crazy. So next up is texture compressions.
Result: Unity Profiler reports correctly! I might be going crazy but is the Android stuff reports correctly, the only option is to check if the previous version of Unity that I was using was broken somehow. The results were

  • Full resolution
    • Total: 21.8mb
    • GFX: 10.7mb
    • Detail: 10.7mb
  • Half resolution
    • Total: 13.8mb
    • GFX: 2.7mb
    • Detail: 2.7mb

So now, to test Android. My god I hope I find something so I dont have to check myself into a clinic for psych evaluation… Hahahaha. Psych.Eval(Roger);
Result: Thank god, I am sane! Here is the data for and Android build on a Kindle Fire HD 8.9 using ETC1 texture compression.

  • Full resolution
    • Total: 27.4mb
    • GFX: 12.6mb
    • Detail: 10.7mb (4 x 2.7)
  • Half resolution
    • Total: 27.4mb
    • GFX: 12.6mb
    • Detail: 10.7mb (4 x 2.7)

Now that I have identified that there actually is a problem, I am going to test another texture compression format to make sure its not just ETC1. After that, I should check on another Android device to make sure its just not device based.
Result: Same results for uncompressed, mip map memory reduction does not reflect. I will spare you the numbers on this one.

Now for sh!ts and giggles, we are going to try the device GPU specific hardware compression. In this case, PVRTC for the PowerVR processor.
Results: No dice, its the same. No change in GPU. Now I need to check if the mip maps are actually working… yip, they are working. The textures do have multiple levels. So now, lets find out if its only the Unity profiler or the maps are not dumping. P.S I checked on another device and had the same results.

So now I need to profile the video memory on Android. And that sucks. I have been trying for a while now and cant find a way of checking the Androids video memory. I tried tools in DDMS and the OpenGL Tracer, but alas, no love! My last option, is brute force. I started adding textures until the app crashed and then tried the lowest mip map quality level. If the mips were stripped, the app should not crash. If the mips were not, it should.
Result: Varied :/ I was able to get a crash on the highest quality setting and not on the others but when adding more textures, all crashed, even when the mips were set to strip to an eighth of the size. If the Mip map stripping was working, this should have cut and dry results. Sooooo

Conclusion: I am forced to conclude that Mip Map stripping from the quality settings is not working on Android using Unity 4.6.4p2.

My last step is to check Unity 5. If its not working there, then its not working and I can go home.
Result: Its fixed! Fixed in Unity 5! So if you are using 4.x… sorry for you… and me.