mesa: Simplify UNORM8 conversions for sRGB ASTC textures

The ASTC extension specs state that a vector of UNORM8 values are
returned when decoding sRGB ASTC textures. For the alpha channel
however, they don't seem to specify how to get there from the UNORM16
produced after interpolation (or returned from a void-extent block).

The ASTC decoder in the VK-GL-CTS project treats the alpha channel like
the RGB channels and simply uses the top 8 bits of the UNORM16. For
better performance, we choose to do the same.

In a texture upload microbenchmark, this decreases the upload time for
textures in the sRGB color space by about 13%.

Ref: https://gitlab.khronos.org/egl/DataFormat/-/merge_requests/32
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17195>
This commit is contained in:
Nanley Chery 2022-04-13 15:15:38 -07:00 committed by Marge Bot
parent 81b0862642
commit dab0936141
1 changed files with 4 additions and 2 deletions

View File

@ -1618,12 +1618,13 @@ void Block::write_decoded(const Decoder &decoder, uint16_t *output)
output[idx*4+0] = void_extent_colour_r >> 8;
output[idx*4+1] = void_extent_colour_g >> 8;
output[idx*4+2] = void_extent_colour_b >> 8;
output[idx*4+3] = void_extent_colour_a >> 8;
} else {
output[idx*4+0] = uint16_div_64k_to_half_to_unorm8(void_extent_colour_r);
output[idx*4+1] = uint16_div_64k_to_half_to_unorm8(void_extent_colour_g);
output[idx*4+2] = uint16_div_64k_to_half_to_unorm8(void_extent_colour_b);
output[idx*4+3] = uint16_div_64k_to_half_to_unorm8(void_extent_colour_a);
}
output[idx*4+3] = uint16_div_64k_to_half_to_unorm8(void_extent_colour_a);
} else {
/* Store the color as FP16. */
output[idx*4+0] = _mesa_uint16_div_64k_to_half(void_extent_colour_r);
@ -1703,12 +1704,13 @@ void Block::write_decoded(const Decoder &decoder, uint16_t *output)
output[idx*4+0] = c[0] >> 8;
output[idx*4+1] = c[1] >> 8;
output[idx*4+2] = c[2] >> 8;
output[idx*4+3] = c[3] >> 8;
} else {
output[idx*4+0] = c[0] == 65535 ? 0xff : uint16_div_64k_to_half_to_unorm8(c[0]);
output[idx*4+1] = c[1] == 65535 ? 0xff : uint16_div_64k_to_half_to_unorm8(c[1]);
output[idx*4+2] = c[2] == 65535 ? 0xff : uint16_div_64k_to_half_to_unorm8(c[2]);
output[idx*4+3] = c[3] == 65535 ? 0xff : uint16_div_64k_to_half_to_unorm8(c[3]);
}
output[idx*4+3] = c[3] == 65535 ? 0xff : uint16_div_64k_to_half_to_unorm8(c[3]);
} else {
/* Store the color as FP16. */
output[idx*4+0] = c[0] == 65535 ? FP16_ONE : _mesa_uint16_div_64k_to_half(c[0]);