How is memory usage calculated for textures in Roblox?

I am currently building a plugin to explore textures that are used in a project, it is currently working well and I got a list of textures, usage of them and the resolution.

But to my question:

How do I calculate the memory usage of a texture similar to how it is is done in Developer Console → Memory → Place Memory → GraphicsTexture?

I have tried to reverse engineer it by taking the memory usage / (texture_width * texture_height) (all dimensions are power of 2) but always end up with some odd number such as 5.08 (for a 8-bit greyscale texture). But I guess there is some compression algorithm in play here that will make my life hard. :slight_smile:

By the looks of things, this post here might cover the calculation of size

Thank you for the link - the person that wrote that post is correct when it comes to calculating uncompressed texture VRAM.

But in practice it does not match the actual usage that ends up in the engine.

Take the following example:

AssetId: 9124998130

In-engine reported memory usage: 0.333MB (~341KB)

Dimensions: 256x256
Bits/channel: 8-bit
Channels: 4 (RGBa)
Bits/pixel: 8 * 4 = 32
Pixels: 65,536
Uncompressed VRAM size calculation: 
    (65536 * 32b) / 8 = 262,144 byte = 256KB

This was the asset in question downloaded from Roblox content servers:

99859904e0f3ae6de7e20b3b5e5ec32c

Fired up RenderDoc to look at the textures in memory:

Roblox seems to use different formats depending on the texture and also generates mipmaps for the textures, the formats are also platform specific since they are DX11 formats which means that a calculation that would work for Windows would not be correct for other platforms.

With that said it would be interesting to figure out the logic for when Roblox uses the different formats and how that can be used to reduce the memory impact.

10 minutes after I pretty much gave up I solved it, just calculate and sum all the mipmap levels:

image

There are probably more things that needs to be taken in consideration, but this is a good start at least.