Search Unity

Why use crunch compression?

Discussion in 'General Graphics' started by NestorAlgieri, Nov 11, 2018.

  1. NestorAlgieri

    NestorAlgieri

    Joined:
    Sep 11, 2011
    Posts:
    299
    I noticed that if my textures are in an asset bundle they already get compressed. The different b/t crunched and not crunched doesn't make my file much different in size. So if the only advantage is for the slightly smaller size

    - Are there any other advantages?
    - Does it use less RAM at runtime? From my profiling, crunch compression makes no difference.
    - From what I have read, it will cause SOME CPU overhead.

    If anyone else can confirm this that'd be great!
     
    Last edited: Nov 11, 2018
    Helllllllo likes this.
  2. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    3,037
    Maximum compression for individual files is probably best, as any good compression algorithm will simply store already compressed data (since the gains will be zero or sometimes practically zero). So heavily compressed data is really just stored without the outer compression, which gives you quick access, and decompression is split into smaller operations. This improves perceived load-time for large games.

    You'll likely save more overall if different file types use different algorithms for their types of data too. One for textures, another for sound and perhaps a specialised one for text if you're really hardcore about squeezing out every byte :p

    Even if the decompression is slower per byte it'll likely be quicker when you're not simply loading every texture you have all at once. For the final product this is definitely what you want, but during testing it's up to you if you want to sit through the build process if compression is taking longer.
     
    NestorAlgieri likes this.
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
    The benefit of crunched textures is two fold.

    One is shipping on disk / download size. Crunched textures use less disk space than basic texture compression using the usual GPU friendly image compression formats alone.

    The second benefit is loading time. A crunched image decompresses directly into DXT1 or DXT5 with no additional steps, and decompresses quickly. The idea is a crunched texture can be read from the disk and decompressed into a DXT5 faster than reading a DXT5 straight.

    PNG or JPG images are smaller, but are actually quite slow to decode, and way slower to compress into a GPU friendly format if that's possible at all. So reading a PNG from disk into memory might be faster than a crunched texture, but the crunched texture be in a GPU friendly format ready to be used, and likey even uploaded to the GPU, before the PNG has even finished decoding.

    Images generally don't compress well using general purpose compression algorithms alone, which is why there are so many image compressiom formats out there: you need an algorithm that is designed for images specifically to get the most benefit. However most image formats are slow to decompress, or don’t give that much compression. GPU friendly compression formats are designed to give a constant compression ratio and fast decompression rather than the best compression or quality possible. This is because GPUs need to be able to quickl get the color value of any texel without having to decode the entire image first. PNG and JPG are designed around getting the smallest image possible either losslessly or lossy, but you have to decode the entire image to get the color of any pixel which makes them ill suited for GPU usage. The speed of decoding also wasn’t a huge factor as when the formats were written the expectation was your computer would decompress them as it was slowly downloaded over a modem.

    Crunched textures are essentially a DXT1 or DXT5 texture that's been tweaked so that it can compress better using essentially a general purpose compression algorithm. The result is an image that isn't quite as good as straight DXT5 can do in terms of image quality, and not as small as a JPG on disk, but gets you some of the benefits of each.


    Note, if it wasn’t clear from the above, once a crunched texture is read from disk, it exists in memory using the exact same amount of space as the DXT1 or DXT5 you might otherwise use as at that’s point it is just a DXT1 or DXT5 texture.
     
  4. NestorAlgieri

    NestorAlgieri

    Joined:
    Sep 11, 2011
    Posts:
    299
    Thx for the detailed explanation. But will this benefit carry over to Android devices or will there be more disadvantages due to Android not using DXT?
     
    Holoday likes this.
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
    Unity added support for crunched ETC, so the benefit is still available. DXTC isn't supported by a lot of Android devices, and so crunched DXTC assets get loaded normally, then converted to uncompressed textures before being uploaded to the GPU.
     
    EddyNottingham and NestorAlgieri like this.
  6. GXMark

    GXMark

    Joined:
    Oct 13, 2012
    Posts:
    514
    Something else also worth noticing is that Crunch did actually go through an update on 2017.3. Although this is good providing up to a 2.5 speed increase it did mean that all crunched texture done prior to this were not backward compatible. This is ok in a purely build game where you can simply issue another version release but for a procedural dynamic world saving texture on a remote server this would be a major issue. I know that unity did have a git repo of the crunch which i did use but its not up to date with the latest unity ( i think, does someone know this as a fact ? ). So bare in mind the caveats to crunch as well. Since DXT1/5 are likely to be standards for a long time to come.
     
    tw00275 likes this.