richgel999 / bc7enc_rdo

State of the art RDO BC1-7 GPU texture encoders
Other
180 stars 30 forks source link

bc7e: Improve accuracy of some solid color blocks encoding #4

Closed aras-p closed 3 years ago

aras-p commented 3 years ago

Out of 16 million possible opaque solid color blocks, previous code was not encoding all of them perfectly.

In slow,veryslow,slowest perceptual modes: 1038 colors (out of 16M) not encoded identically. In basic perceptual mode: 3056 colors (out of 16M) not encoded perfectly (most obvious being pure red: 255,0,0,255 decodes as 253,0,0,255).

Similar issues are with alpha solid color blocks.

First I tried adding a dedicated "detect if pure solid color block, encode all the solid color modes no matter the settings" path. E.g. default perceptual basic mode never uses modes 2,4 or 5, and neither of mode 1 or 6 can encode pure opaque red for example. Anyway, adding that path gave better results, similar to how "slow" modes do.

But then I added optimal endpoint tables for modes 3 and 5, similar to how other endpoint tables are done. And that's when I found that all the opaque solid color blocks can be encoded with just mode 5 perfectly. So the final code change is fairly simple, just:

I tested all 16M possible opaque colors, and a bunch of ones with alpha too, and they all can be encoded perfectly now.

richgel999 commented 3 years ago

Thank you. Just browsed it and it looks good - I'll do a thorough benchmark this weekend or early next week.