Why is a 50kb .png spritesheet using over 18 MiB of video RAM?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By jerryjrowe

I am using several very small spritesheets, but somehow I am using over 200 MiB in video memory, according to the Godot Debugger’s Video RAM tab.

I wouldn’t even complain about it except that I can see a performance issue.
But I have no idea why this would be happening, or how to isolate the problem.

Every file I am using is tiny, but the video RAM is showing them to be using comparatively massive resources.

I’ve seen a few completely unanswered questions about this same topic. Any help would be appreciated.

:bust_in_silhouette: Reply From: Calinou

This is because textures in video memory do not support lossless compression such as PNG. Lossy compression with variable compression rates such as JPEG and WebP is not supported by GPUs either. GPUs need fast random access to do their work, so variable compression rates are a bad fit for them. Therefore, from the GPU’s perspective, there are only two states of compression:

  • Uncompressed (use RGB data as-is). This is recommended for small textures, as VRAM compression destroys their quality for no performance benefit.
    • If you use Lossless, Lossy (WebP) or Uncompressed as the compression mode in Godot, this is the data that is uploaded to the GPU.
  • VRAM compressed (S3TC, ETC1, ETC2, …). This is a fixed compression ratio regardless of the image complexity (typically 1:4 or 1:6). This is always lossy compression, and is not recommended for use in 2D projects. VRAM-compressed textures load faster than uncompressed textures, so they’re often used in 3D projects (except for pixel art where uncompressed is a better choice).

Note that using 200 MB of video RAM is far from excessive nowadays, since pretty much any GPU still in use for modern gaming has at least 2 GB of VRAM (and preferably 3 GB or more).

See the Compression section in the Importing images documentation for details.

This is super informative and helpful.

My plan was to use lots of small files (like the 50kb ones), but if they’re all going to be inflated to over 300x their size in VRAM usage, I’m going to be in trouble.

After playing around with reimporting the assets with different settings, I can definitely see the problems with trying to do VRAM compression on those sprites…! The artifacting makes them not look great for what I am doing.

So…Is there some other file format then that might allow for better compression? Or is there another solution I might be overlooking?

Thanks again for your help!..

jerryjrowe | 2022-04-22 17:00