Search Unity

Evaluating Texture memory

Discussion in 'Scripting' started by tabulatouch, Nov 29, 2018.

  1. tabulatouch

    tabulatouch

    Joined:
    Mar 12, 2015
    Posts:
    23
    Hello,
    I need to load massive amount of images on the GPU (on Windows desktop platform using Direct3D11) and i am trying to estimate the available "real" texture memory to know in advance how many textures i can allocate.
    I did some experiments with Texture2D.LoadImage(), pre-creating the texture with the compressed or uncompressed format, then loading with that function.
    However, the results i am getting are somewhat "weird".

    As a test I am loading JPGs:
    • 32 images of 1920x1080 resolution
    • 16 images of 3000x2250 resolution
    The uncompressed format is RGB24 so the estimated memory per-texture should be: (Width x Height x 3 bytes) and when using mipmaps multiply that size for 1,33.
    The total expected memory size is: 697.420.800 bytes (or 927.569.664 with mipmaps).
    I check GPU memory using Windows 10 task manager as well as CPU-Z, the results are the same.
    • Test #1: RGB24 without mipmaps, allocated GPU memory = 726.336.000
    • Test #2: RGB24 with mipmaps, allocated GPU memory =
      281.856.000
    • Test #3: DXT5 without mipmaps, allocated GPU memory =
      663.408.000
    • Test #4: DXT5 with mipmaps, allocated GPU memory =
      391.824.000
    Test #1 is close to the base calculation.
    Test #2 is really strange, why mipmaps enabled don't raise the memory used?
    Test #3 is very similar to Test #1, the compression seems to help too little.
    Test #4 is lower but still higher than test #2, here also it seems the mipmaps help lowering memory.

    As a side note, when loading compressed, i create the Texture2D with DXT1 compression (as the manual refers to that format for JPGs), but after the LoadImage() the texture becomes DXT5
    Mipmaps, that should rise the memory, seem to lower that in any case.

    All textures are visible on screen.

    I am really baffled, what exactly is going on here?
    Also, memory estimate for DXT1 and DXT5 should be (as i read in other forums) divided by 8 and 16, clearly not what is happening.

    Thank you!

    SB