@@ -6,8 +6,7 @@ to reduce the size of application distribution bundles, providing finer-grained
66control over storage size than simply reducing ASTC block size.
77
88> [ !NOTE]
9- > The RDO implementation in ` astcenc ` currently supports 2D LDR textures, using
10- > either the linear or sRGB color profile.
9+ > The RDO implementation in ` astcenc ` currently only supports LDR textures.
1110
1211## How RDO works
1312
@@ -20,12 +19,12 @@ compression, such as ZIP or LZ4.
2019
2120The RDO transform is lossy, sacrificing image quality to improve data
2221compressibility. The amount of allowed quality loss is controlled by a lambda
23- setting, where a higher lambda values allow more image distortion in exchange
24- for a more compressible pattern. Lambda values between 0.0 (no RDO) and 0.3
25- (moderate RDO) give a reasoanble tradeoff between quality and storage. Lambda
26- values above 0.3 quickly loose image quality for relatively little saving in
27- packaged file size, and it is usally a better option to choose a larger ASTC
28- block footprint .
22+ setting, ` -rdo-lambda ` for the command line tool, where a higher lambda values
23+ allow more image distortion in exchange for a more compressible pattern. A
24+ lambda value of zero disables the RDO transform. We recommend using a value
25+ of 20 as a starting point, which give a reasonable tradeoff between quality
26+ and storage. Normal maps are more sensitive to introduced error, so a lower
27+ lambda value might be required .
2928
3029The ASTC blocks after RDO has been applied are still standard ASTC data blocks.
3130RDO does not require a special GPU decoder, and it does not change the number of
@@ -42,108 +41,32 @@ data that needs to be packaged, or you can choose to use RDO to make data more
4241compressible.
4342
4443Where possible we recommend using a larger ASTC block size. This gives you
45- reliable savings to run-time memory footprint and memory bandwidth, in
46- addition to the packging size reduction.
44+ additional savings to run-time memory bandwidth, in addition to the packging size reduction.
4745
4846We recommend using RDO to fine-tune packaging size when dropping to the next
4947lowest ASTC bitrate is not an option. This could be because the next bitrate
5048option loses too much detail, or suffers from more visible block artifacts.
5149
52- ## Building with RDO
53-
54- RDO support in the codec is disabled by default. Enable it using the
55- ` ASTCENC_RDO ` CMake option. For example, from the repository root on an
56- x86 machine supporting AVX2:
57-
58- ``` shell
59- cmake -S . -B build-rdo -DCMAKE_BUILD_TYPE=Release \
60- -DCMAKE_CXX_COMPILER=clang++ -DASTCENC_ISA_AVX2=ON -DASTCENC_RDO=ON
61-
62- cmake --build build-rdo --config Release --parallel
63- ```
64-
65- > [ !NOTE]
66- > See [ Building ASTC Encoder] ( Building.md ) for compiler requirements and other
67- > build configurations.
68-
69- On Linux, optionally add ` -DASTCENC_RDO_SIZE=ON ` when configuring to report the
70- serialized file size and its DEFLATE-compressed size. This requires the zlib
71- development package to be installed in your system:
72-
73- ``` shell
74- sudo apt-get install zlib1g-dev
75- ```
76-
77- Reporting the saving using DEFLATE does not actually compress the output file;
78- your packaging pipeline must still perform lossless compression.
79-
8050## Compressing with RDO
8151
8252Use the ` -rdo-lambda ` command line option to enable RDO and set its strength.
83- Setting 0.0 disables RDO, higher values increase the amount of quality loss
53+ Setting 0 disables RDO, higher values increase the amount of quality loss
8454permitted.
8555
8656``` shell
8757# Reference encode without RDO
8858build-rdo/Source/astcenc-avx2 -cl input.png reference.astc 5x5 -thorough \
8959 -rdo-lambda 0
9060
91- # Same footprint and search preset, with RDO enabled
61+ # Same footprint and search preset, with a light RDO pass enabled
9262build-rdo/Source/astcenc-avx2 -cl input.png rdo.astc 5x5 -thorough \
93- -rdo-lambda 0.2
63+ -rdo-lambda 20
9464```
9565
9666The RDO lambda value is a heuristic to control tradeoffs, not a specific target
9767bitrate or PSNR threshold. Lower positive values favor fidelity; higher values
98- place more weight on storage savings. A useful initial experiment is to compare
99- 0.0, 0.1, 0.2, and 0.5 at the same block footprint and quality preset. Measure
100- quality and final packaged size for your own content.
101-
102- ## Morton order file layout
103-
104- Ordinary ` .astc ` files, and other formats such as KTX, store ASTC blocks in
105- scanline order. Nearby rows in the image, that are likely to have more similar
106- colors, can therefore be far apart in the byte stream.
107-
108- The ` .astcm ` file format is a variant of the ` .astc ` format that stores the
109- astc blocks in the image as a sequence of 2D "tiles" of ASTC blocks arranged
110- in Morton order. This groups spatial neighbors together, which improves the
111- efficiency of the RDO data conditioning and the effectiveness of the
112- packaging-level compression.
113-
114- Select Morton order by writing to an ` .astcm ` file:
115-
116- ``` shell
117- build-rdo/Source/astcenc-avx2 -cl input.png rdo.astcm 5x5 -thorough \
118- -rdo-lambda 0.2
119- ```
120-
121- The ` .astcm ` file layout stores 8x8 tiles of ASTC blocks, with tiles being
122- stored sequentially in scanline order. Blocks within each tile are stored in
123- Morton order. Partial edge tiles omit blocks that fall outside the image.
124-
125- > [ !NOTE]
126- > See [ File formats] ( FileFormat.md#the-astcm-format ) for the header and exact
127- > block traversal.
128-
129- ### Data loading
130-
131- The ` .astcm ` data ordering is a storage layout that improves packing
132- efficiency, but it is not the layout that the graphcis APs expect.
133- Before you can upload the data to OpenGL ES or Vulkan you must convert
134- the data back into scanline block order:
135-
136- ### Morton order in the library API
137-
138- When passing ` ASTCENC_FLG_USE_MORTON ` to the library API, it will issue tasks
139- to the compressor in blocks of one or more 8x8 Morton-order "tiles". This
140- allows the RDO transform to exploit 2D similarity in the image.
141-
142- However, it is important to note that the compressed ASTC data returned by the
143- codec API will be returned in block-by-block scanline order. Tool file
144- serialization must also apply the 8x8 Morton transform to realize the packaging
145- benefits. If you are not using Morton-order storage files, it is recommended
146- that you do not pass ` ASTCENC_FLG_USE_MORTON ` to the library API,
68+ place more weight on storage savings. You much measure quality and check that
69+ it is suitable for your content.
14770
14871- - -
14972
0 commit comments