(HW) DXTx VS BC7 Compression - VRAM/RAM usage vs HDD usage

Discuss Daggerfall Unity and Daggerfall Tools for Unity.
Post Reply
User avatar
King of Worms
Posts: 3708
Joined: Mon Oct 17, 2016 11:18 pm
Location: Scourg Barrow (CZ)
Contact:

(HW) DXTx VS BC7 Compression - VRAM/RAM usage vs HDD usage

Post by King of Worms »

Hi, Im really wondering...

In Unity I can set up either Normal (DXTx) or High (BC7) quality of texture compression.

BC7 is on average 2x the size of the file on HDD. Question is, if it is also 2x the size when actually loaded in the VRAM/RAM?

To me it appears its not, but its not so easy to test it properly, doing the same type of long gameplay twice etc.
I just tested it with terrain texture in both variants and the VRAM/RAM usage was exactly the same.

So this leads me to the conclusion, that once its loaded in the VRAM or RAM, these formats take up the same space.

Am I right about it? Or am I missing something?

Also, any general opinions on DXTx vs BC7 in DREAM/DFU? Like
"use BC7 in these cases and DXT in these cases" etc?
"BC7 for normals, DXT for rest?"
"BC7 for sprites with alpha...?"
"Never use XX...?"

Thanks a lot!

PS: Found this very detailed compression article, really good stuff, but no answers to my questions it seems :lol:
http://sv-journal.org/2014-1/06/en/index.php?lang=en

User avatar
MasonFace
Posts: 524
Joined: Tue Nov 27, 2018 7:28 pm
Location: Tennessee, USA
Contact:

Re: (HW) DXTx VS BC7 Compression - VRAM/RAM usage vs HDD usage

Post by MasonFace »

BC7 is on average 2x the size of the file on HDD. Question is, if it is also 2x the size when actually loaded in the VRAM/RAM?

To me it appears its not, but its not so easy to test it properly, doing the same type of long gameplay twice etc.
I just tested it with terrain texture in both variants and the VRAM/RAM usage was exactly the same.

So this leads me to the conclusion, that once its loaded in the VRAM or RAM, these formats take up the same space.

Am I right about it? Or am I missing something?
I think you're mostly right about that. From my limited understanding, the main purpose of compressing textures has more to do with keeping the bandwidth between the RAM and the GPU down to a reasonable level. The GPU will then decompress the texture once it has been transferred to the graphics card.

Decompression on the GPU is FAAAAAAAST, but moving the data over to the GPU is a bit slower, especially when you consider the massive amount of data that is getting transferred (textures aren't the only data being transferred, but they are the largest portion). You want to keep that bottleneck as clear and open as you can and that means simply sending less data to the GPU.

Take a look at the tables in the Unity Documentation here: Texture Compression Formats

I think the key difference between DXT5 and BC7 is the compression quality, so I would expect that there would be fewer compression artifacts when using BC7 at the cost of longer compression time, but this would happen in the editor and have no effect on the player's experience. I'd speculate that decompression time for BC7 may be just slightly slower, but I can't say that for sure; it isn't mentioned anywhere that I've read, so I'd assume the difference is trivial.

Aside from that, they appear to be very very similar. They both work with both RGB or RGBA images, so either format can be used with sprites with transparency.

-------------------------------------------------------------------

Now, as for a recommendation, I would suggest just letting Unity pick the compression method; just leave it set to 'automatic'. I believe it already picks the most optimal choice for desktops, but if it doesn't, then follow this quote from the above link:
For devices with DirectX 11 or better class GPUs, where support for BC7 and BC6H formats is guaranteed to be available, the recommended choice of compression formats is: RGB textures - DXT1 at four bits/pixel. RGBA textures - BC7 (higher quality, slower to compress) or DXT5 (faster to compress), both at eight bits/pixel. *HDR textures - BC6H at eight bits/pixel.
*HDR textures probably aren't relevant to anything you're doing, so you can ignore that bit.

So to summarize:
  • Use BC7 or DXT5 for all textures that have an alpha channel, but use DXT1 for textures that don't. Again, I think Unity chooses these by default for targeting desktops. DXT1 will use only 4 bits per pixel instead of 8, so the texture would be half the size! If the compression causes too much distortion, then use BC7 instead for that particular texture. This would be most appropriate for albedo and maybe height textures.
  • If you're torn between BC7 and DXT5, I would tend to use DTX5 as my default and use BC7 as the exception when I notice compression problems in a specific albedo texture, but that's just my preference.
  • For normal maps, just select 'automatic'.
    Spoiler!
    The technical reason for this is that ordinary compression causes some major issues with a normal map's lighting calculations, so a lossless format is needed to better preserve the data. However, we still need these textures to take up less memory when transferred over the the GPU. The solution is that BC5 only stores two color channels (R and G in this case) then decompresses with high quality (low noise/artifacts that can spoil the lighting calculations) and computes the missing B channel on the GPU after the texture has been transferred. Pretty clever solution.
  • Don't ever use 'crunch' compression. That will just make it slower for the sake of saving disc space. I think it's mostly used for mobile devices and maybe texture streaming from the web(?).
-------------------------------------------------------------------

If you're interested in saving disc space, RAM, and VRAM, then I'd suggest lowering the resolution of some of your PBR textures (other than the albedo texture). I don't know, but maybe you're already doing this, but with my PVE mod, I found that I could get good results on certain textures with a lower resolution normal map for the macro details, then supplement it with a small (like 64x64) generic tiled secondary normal map with its UV scaled to like 4 or 8 to show some fine detail up close. a small set of like 3 or 4 secondary normal maps can be used for lots of different textures, this way it doesn't add anything else to the memory footprint.

This technique worked really well for rough textures like stone and also textile textures like the flags and banners.

The unfortunate side effect of using lower resolution PBR maps is that they get pixelated if you drop the resolution down too low and they player doesn't enable bilinear or trilinear filtering in their DFU options... that's why I suggest that people play PVE with those filtering options on. I'd wager that most people who play with DREAM will also have these filters enabled.

-------------------------------------------------------------------


Anyhow, I hope this information helps. I'm pretty sure what I've said is accurate, but maybe someone else can confirm or correct if there are any errors.
Last edited by MasonFace on Thu Dec 17, 2020 4:51 pm, edited 5 times in total.

User avatar
King of Worms
Posts: 3708
Joined: Mon Oct 17, 2016 11:18 pm
Location: Scourg Barrow (CZ)
Contact:

Re: (HW) DXTx VS BC7 Compression - VRAM/RAM usage vs HDD usage

Post by King of Worms »

Thanks a lot for this reply mate. I think this will be next step in Dream optimalization and I will return to your reply to refresh my knowledge on it. Very informative 👍

I also plan to further optimize sound/music loading. I made some good changes in that area for the incomming Dream release. But theres more to do.

Post Reply