Search Unity

Video memory allocation issue

Discussion in 'PSM' started by Spidyy, May 9, 2014.

  1. Spidyy

    Spidyy

    Joined:
    Mar 6, 2011
    Posts:
    184
    Hey there,

    At last, I'm starting to port my tech demo to the Vita, and here I have some issues with the memory spec of the console and the render textures.

    At some point, I'm having this stuff appearing after all my rendertextures were first allocated :
    What is the GXM mapped main memory?

    How many VRAM does the Vita have?

    Does it have to do with me using RenderTexture.GetTemporary instead of calling new RenderTexture() ?

    ______________________________________________________________________________

    EDIT to summary all I've learned in this topic :

    The Vita have about 170MB of memory available for your game, after substracting Unity's memory consumption and the Vita's system usage, and 128MB of VRAM.

    Only use DXT5 compressed texture to avoid filling the memory too fast. Do not use non-power of two (NPOT) textures, as they won't be compressed at all.

    To see the texture usage on the Vita memory, use the Unity's Profiler (Pro only), and use the detailed memory profiling. Check the Asset->Texture2D lines to see how much memory your textures are using.
     
    Last edited: May 30, 2014
    MihaPro_CarX likes this.
  2. blackbird

    blackbird

    Joined:
    Aug 9, 2011
    Posts:
    591
    i got that message before my scene works perfects i can't tell you really what is it , but maybe it's addditional ram which is only active if you use more than 133 mb , as far as i know The PlayStation Vita has 512 MB of system RAM and 128 MB of VRAM .... i wish somebody clarify that ... i m just replay to you so maybe somebody from sony answer it ...

    ps: my scene don 't use any rendertexture function
     
    Last edited: May 12, 2014
  3. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    All this means is that the graphics memory has been exhausted and that Unity falls back to using system memory as "backup".
    While this is not as efficient as using "real" graphics memory, it will allow your title to continue to run.

    Hardware memory specs according to Wikipedia : 512 MB RAM, 128 MB VRAM.
    Please note that because of various reasons the full memory is not available to a Unity title.
    Mostly because the engine itself uses memory for various buffers etc.
    We aim to have the memory restrictions clarified once we reach 'offical release' (which should be the next update).

    Both of those could probably lead to this scenario.
     
  4. Spidyy

    Spidyy

    Joined:
    Mar 6, 2011
    Posts:
    184
    Thank you for this clarification. :)
     
  5. Spidyy

    Spidyy

    Joined:
    Mar 6, 2011
    Posts:
    184
    But no thank you! :eek:

    I just realised. Using the statistics window in the Unity Editor, my scene don't take much more than 22MB of VRAM, all of sheer textures. (RenderTextures are deactivated.)

    When I load my scene, I got all of this stuff :
    By addind it, it raise the count up to 40.5MB of stuff that couldn't be added to the VRAM.

    It is twice the used VRAM indicated by the statistics, and it means... What? 128MB of VRAM already used by the Unity engine?

    I got all of this while I'm using the Application.LoadLevelASync() function to preload my level before on a really simplistic loading screen.

    I obtain the same behaviour by having only my game scene in the build.

    Either I didn't understood how it works, either something's wrong. :(
     
    Last edited: May 13, 2014
  6. PeterD

    PeterD

    Joined:
    Feb 6, 2013
    Posts:
    120
    This does indeed seem like some odd use of memory. Given the frame buffers and the zbuffer etc. Either Unity is using or reserving all 128mb for itself and then loading all game content into main memory or I too am missing something.
     
  7. MDaveUK

    MDaveUK

    Joined:
    Apr 27, 2014
    Posts:
    14
    I think 256MB of system memory is reserved for the OS (cross game chat, music player, internet browser, playstation store can all be loaded at once in this while game/app is running), so that leaves a single game/app with the remaining 256MB? This seems to make sense why we are seeing roughly 160MB free for us if UnityPSM is allocating a chunk of that 256MB for itself.
     
  8. Spidyy

    Spidyy

    Joined:
    Mar 6, 2011
    Posts:
    184
    All seems fair about the system RAM, we are talking about the VRAM here. :p
     
  9. PeterD

    PeterD

    Joined:
    Feb 6, 2013
    Posts:
    120
    Exactly. It seems that Unity is somehow simply taking all VRam for itself and then loading our texture content into main memory. Whether Unity then copies those textures to VRam during the actual application run is another matter but, given the log output it doesn't seem that Unity is ever freeing any VRam for our apps at all. Leaving the vita to use the slower main memory. Given that Unity is supposed to be using VRam to render our content tis seems rather odd.
     
  10. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    Eh, no.
    As I explained previously - a texture will go into VRAM if there is VRAM available. When the VRAM is exhausted it will instead allocate 'system' memory for the texture resource.
    You can check this yourself by creating an empty project with a script that allocates textures repeatedly until it runs out of VRAM (which it will after about 85-90MB). Something like this
    Code (csharp):
    1.  
    2. m_textures[m_numtextures] = new Texture2D(1024, 1024, TextureFormat.Alpha8,false);
    3. m_textures[m_numtextures++].Apply(false,true);
    4.  
     
  11. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    Yes, this is correct. Unity (and all subsystems, such as Mono etc) consumes roughly 50MB during startup. Add to that the size of Unity's executable (plus that of all subsystems) roughly 15MB. And add some waste / the entire 256MB isn't available as a contiguous range.
    That gives you about 170MB or so with an almost empty scene.

    Please note : these are the ballpark numbers for the Public Preview.
    We will define these in more detail with the Official Release, and also try to optimize them going forward.
     
  12. PeterD

    PeterD

    Joined:
    Feb 6, 2013
    Posts:
    120
    Ok that better explains why I'm seeing memory paging so early on in my scenes! Back to the optimisation drawing board. I can see why borderlands 2 looks so um... visually challenged now.
     
  13. Spidyy

    Spidyy

    Joined:
    Mar 6, 2011
    Posts:
    184
    So that would mean my project really have too much textures loaded. But the Statistics windows indicate 20MB VRAM used in the Editor, and when starting a level it raise up to the VRAM full + 40MB of additional textures. (the ones from the logs I pasted)

    Isn't there a way to see which texture is loaded in VRAM during runtime? At my previous job in a mobile game company, we had tools to see which texture is loaded in VRAM at any moment, thanks to some indexation process. Any way to have something equivalent in Unity?
     
  14. MDaveUK

    MDaveUK

    Joined:
    Apr 27, 2014
    Posts:
    14
    Thanks for confirming, and providing stats :) we know what we have available to work with much more clearly!

    EDIT: Do'h, just seen your previous reply, I see now that UnityPSM uses about 43 - 48 MB VRAM before we put any textures into it.

    Do you happen to know how much VRAM unity allocates for itself? Memory for the screen (backbuffer, frontbuffer, depth buffer) and memory for shadow maps if used, that could take up a lot I guess, compressed textures I assume work in VRAM, and then vertex buffer objects etc

    I guess the odd thing here is that mobile devices don't seem to have an issue with VRAM? I don't think my Nexus 4 has any, hah. But it renders shadow maps at high resolution settings, and we have a ridiculously little amount for shadow map size on Vita, based on the math here: http://docs.unity3d.com/Documentation/Manual/ShadowSizeDetails.html

     
    Last edited: May 15, 2014
  15. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    Unity allocates around 16-17MBs of VRAM for screen buffers etc - I think the Unity profiler is actually quite close to the real number.
    The rest is 'reserved' memory - ~105MB is available on the VRAM heap before we start up the Unity renderer, IIRC.
     
  16. Spidyy

    Spidyy

    Joined:
    Mar 6, 2011
    Posts:
    184
    I still don't get how I can have such difference between the VRAM on the Statistic window and the actual used VRAM.

    I worked one year to a game company as a developper and we had a nice tool that allow us to see which textures were in VRAM at any moment. Would it be possible to have such a tool in Unity in the future?

    Even just listing the names of the textures in VRAM would be a huge help to find which textures are there but aren't actually used by the game.
     
  17. Spidyy

    Spidyy

    Joined:
    Mar 6, 2011
    Posts:
    184
    Hey,

    I discovered the Memory profiler in Unity Pro, until now it just gave me the total memory usage, but I saw we can have a detailed listing of all the memory usage, and what I saw is my textures use WAY MORE memory than the Statistics window indicate.

    Time for some texture resizing.
     
  18. blackbird

    blackbird

    Joined:
    Aug 9, 2011
    Posts:
    591
    how big are your textures ? i mean the resolution
     
    Last edited: May 29, 2014
  19. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    That sounds like a bug.
    I tried running a simple project that allocates 60 1024x1024 Alpha8 textures, and the profiler tells me the GfxDriver has allocated 76.6MB, which makes sense as it starts with 16.6MB allocated.

    If you could report that bug, with some kind of repro project attached, then that would be most helpful. If possible - some screenshots of what numbers you are looking at would be useful (to rule out any confusion).

    Thanks.
     
  20. Spidyy

    Spidyy

    Joined:
    Mar 6, 2011
    Posts:
    184
    HAHA yeah, something's wrong.

    I use 4 NPOT textures of 600x4000 pixels on a single material, assigned to a sprite in the scene to have a background.

    The profiler, when playing from the editor, indicate the texture's size is 4.6MB each, automatic compressed, but when I get the textures size playing the scene from the Vita, the textures grow up to 20MB each, automatic compressed.

    I'm submitting a bug report.
     
  21. eriQue

    eriQue

    Unity Technologies

    Joined:
    May 25, 2010
    Posts:
    595
    Those NPOT textures are most probably not compressed - since the Vita doesn't support NPOT DXT compression.

    $Only_POT_textures_can_be_compressed_to_DXT1_format.png

    If you want to track memory usage, you must use the profiler connected to the device. Or the Profiler.* script API.
    The editor will not compensate for anything that happens at runtime on the device.
     
  22. Spidyy

    Spidyy

    Joined:
    Mar 6, 2011
    Posts:
    184
    Huh... Yeah... That's it...

    I changed the size of the textures from 600x4000 to 1024x4096, their size is downed to 4.0MB on the Vita.

    Haha, not amused. :(
     
  23. Spidyy

    Spidyy

    Joined:
    Mar 6, 2011
    Posts:
    184
    I converted all my textures to POT textures, I don't have any Out of Memory warning anymore.
     
    MihaPro_CarX likes this.