Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Mesh Memory Usage

Discussion in 'Editor & General Support' started by Richard Bangs, Feb 27, 2014.

  1. Richard Bangs

    Richard Bangs

    Joined:
    Feb 27, 2014
    Posts:
    1
    Hey,

    I've been trying to get a good understanding of the memory usage of assets and the limits of various devices, in doing so I have uncovered something interesting, and I thought I would share this with you in the hope someone can explain what's going on.

    I've got an asset bundle, which contains a mesh and a texture.

    The texture is RGBA, at 1024x1024. This is using 4mb as I would expect, and the memory profiler is registering this allocation under the GfxDriver. Awesome.

    The mesh is a bit more complicated, I've summarised it in the attachment below but TL;DR the vertex data should be 32 bytes per vertex (Position, Normal and UV), and 6 bytes per triangle. I have disabled read/write access for this mesh, as this would double the memory usage.

    The following image gives more of a breakdown of the mesh memory usage:
    $Mesh2.png

    All these tests are running on an iOS device, as it's a lot easier to track memory when the editor isn't interfering.

    What I am seeing on the device is that the total memory usage of the mesh data is twice of what I would expect. I am seeing an increase in size for only the mesh data, using Profiler.GetTotalAllocatedMemory() (which does not track graphics driver allocations). I am also seeing both the 'Unity' and 'GfxDriver' buckets of memory increasing by the size of my mesh data.

    I have run additional tests to confirm this, the following images show allocations from two different test runs.

    1. Basic mesh and texture data, as described above.

    $AFTER LOAD 1 TILE.png

    2. Same texture, but 5 times the mesh data than above.

    $AFTER LOAD 1 TILE - with MEGA MESH.png

    You can see both the 'Unity' and 'GfxDriver' buckets have increased by ~5.4mb.


    Does anyone else see this double allocation for mesh data in their apps?


    Thanks,

    Bangs.
     
  2. Matt-Rubin

    Matt-Rubin

    Joined:
    Mar 18, 2014
    Posts:
    2
    Yes, we are seeing something similar.

    I have a test case which seems to indicate that the memory overhead for mesh assets is more than expected. In this case the native memory size on iOS is more than twice that of the Mac/Windows standalone build targets, but it's hard to ascertain why.

    I have disabled the read/write flag on the imported mesh with approx 50k verts and have cleared out the normals and tangents. so our vertex decl just has position (12 bytes), color (4 byte), uv (8 bytes), and uv2 (8 bytes) yielding a 32-byte stride. By serialising the extracted mesh and inspecting the .asset file on disk, I can see that the vertex buffer stream is approx 1.7MB, and the index buffer stream is approx 0.2 MB. I have verified the allocated GPU memory using the Xcode OpenGL capture utility and enclose a screenshot displaying the GL_BUFFER_SIZE for the vertex stream.

    $Screenshot iOS OpenGL Capture.png

    When I run this test case in the Mac Standalone build target, the reported native memory size in the Unity profiler is less than half (~1.5MB) of the reported native memory size for the same mesh in the iOS build target (~3.6MB). Hard to say what's happening under the hood but I am suspect that the CPU memory is not being released as expected. I have filed a bug report with Unity on this but it would be good to hear if anybody else is seeing this issue or if there are any possible workarounds to bring the mesh memory footprint down on iOS.

    Regards,
    Matt Rubin
     
    Last edited: Mar 18, 2014
  3. Phantom_X

    Phantom_X

    Joined:
    Jul 11, 2013
    Posts:
    305
    Hey,
    Sorry for reviving this old thread, but I'm running into a similar issue.
    I'm making a tool to evaluate the weight in memory of art assets, I do similar calculations that you guys are doing, by adding bytes from vertex, uv, normal etc... and the result I have is about exactly half of what the profiler gives me. Was wondering if you found out why?

    thanks!
     
  4. cxode

    cxode

    Joined:
    Jun 7, 2017
    Posts:
    268
  5. Phantom_X

    Phantom_X

    Joined:
    Jul 11, 2013
    Posts:
    305
    Last edited: May 7, 2018