tree: 9d66e0613f73671ffaa6855ca02dc62495b4d2db [path history] [tgz]
  1. cxx.rs
  2. dither.rs
  3. lib.rs
  4. lib_tests.rs
  5. OWNERS
  6. quant.rs
  7. quant_tests.rs
  8. README.md
  9. selectors.rs
  10. selectors_tests.rs
  11. tests.rs
ui/android/texture_compressor/README.md

Texture Compressor

This directory contains a compressor for GPU texture formats. It is primarily meant for compressing thumbnails to save memory. Currently, only the ETC1 format is supported, and this is only used on Android.

Goals

  • Fast: Compressing a 4K screenshot takes less than 100ms (roughly 100 megapixels/s). Currently, it can achieve 220 megapixels/s on x64 desktop.
  • Safe: Free of memory safety issues and suitable for running in the privileged browser process.
  • Portable: SIMD code shared across x86 (SSE) and ARM (NEON). Easy to modify and validate for correctness.

Algorithm

Vectorization is done by assigning each 4x4 SIMD lane to a different block. This minimizes cross-lane shuffle operations (which are typically architecture dependent) and makes the code significantly more portable.

Compression of ETC1 is done by first searching through the flip / no-flip and individual / differential space to decide on the quantization of average, then searching through selector tables and values for each subblock.

Detailed comments about the algorithm can be found in the source.

Similar projects

  • etcpak heavily inspired this project. Most of the algorithm (except vectorization scheme) and math tricks are borrowed from etcpak.
  • ISPC Texture Compressor influenced the vectorization scheme. Unlike this project, the compressor is written in ISPC and requires a dedicated compiler.
  • AOSP ETC1 library also uses a similar search algorithm and is easier to read, thanks to the scalar implementation.

While reading the code, the ETC1 specification should also be useful.

(Currently) Missing Pieces

This project is functional, but still a work-in-progress. The following pieces are missing:

  • Testing coverage
  • Dynamic dispatch (multiversioning) and AVX2 support
  • Running on stable toolchain (using the wide crate instead of #[feature(portable_simd)])