Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Texture memory-usage

Discussion in 'General Graphics' started by Lab42Unity, Aug 13, 2019.

  1. Lab42Unity

    Lab42Unity

    Joined:
    Mar 15, 2019
    Posts:
    3
    Hi,

    I was hoping to get confirmation of my understanding as to how texture memory is handled in Unity.

    Based on a few tests with the new memory-profiler in a standalone build using a 4k, ~10MB, compressed texture (~22MB uncompressed), my understanding is:
    • Loaded, compressed textures that are in-use are stored in both RAM and VRAM (memory-profiler reports ~10MB for the tested texture)
    • When the isReadable flag is set, the texture data is stored in RAM uncompressed in order to allow access to pixel-data (shows as ~22MB, as expected). VRAM usage is unchanged.This leads to the general advice to check whether they require this flag when people encounter memory issues.
    What's causing ambiguity for me, is the assertion in some threads I've read that once compressed texture data has been uploaded to VRAM, the RAM representation is discarded, meaning that memory is once again available. This does not appear to be the case - which is fine - but it would be extremely useful to have this definitively clarified once and for all.

    If Unity should be releasing the texture-data in RAM, then coaxing it into doing so is unclear. The test case used to determine this information simply consisted of a standard material with the test-texture in its albedo slot applied to a cube in an otherwise empty scene.

    Any clarification would be greatly appreciated!
     
  2. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,432
    Hi,

    That is mostly correct, yes. Just, whenever a texture is read/write enabled, it is kept in RAM even after upload, so that the CPU can keep accessing it. Also, depending on the platform, the memory might not technically discard after the upload, if the memory is shared between CPU and GPU, it just gets marked as belonging to the GPU.