[Mesa-dev] [PATCH 1/3] st/mesa/i965: Allow decompressing ETC2 to GL_RGBA
Marek Olšák
maraeo at gmail.com
Mon Jun 18 21:19:21 UTC 2018
What about non-sRGB formats?
Marek
On Wed, May 23, 2018 at 4:54 AM, Tomeu Vizoso <tomeu.vizoso at collabora.com>
wrote:
> When Mesa itself implements ETC2 decompression, it currently
> decompresses to formats in the GL_BGRA component order.
>
> That can be problematic for drivers which cannot upload the texture data
> as GL_BGRA, such as Virgl when it's backed by GLES on the host.
>
> So this commit adds a flag to _mesa_unpack_etc2_format so callers can
> specify the optimal component order.
>
> In Gallium's case, it will be requested if the format isn't in
> PIPE_FORMAT_B8G8R8A8_SRGB format.
>
> For i965, it will remain GL_BGRA, as before.
>
> Signed-off-by: Tomeu Vizoso <tomeu.vizoso at collabora.com>
> ---
> src/mesa/drivers/dri/i965/intel_mipmap_tree.c | 2 +-
> src/mesa/main/texcompress_etc.c | 56 +++++++++++--------
> src/mesa/main/texcompress_etc.h | 4 +-
> src/mesa/state_tracker/st_cb_texture.c | 4 +-
> 4 files changed, 41 insertions(+), 25 deletions(-)
>
> diff --git a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
> b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
> index 67086ee6c0e8..4d9019ebf4ea 100644
> --- a/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
> +++ b/src/mesa/drivers/dri/i965/intel_mipmap_tree.c
> @@ -3370,7 +3370,7 @@ intel_miptree_unmap_etc(struct brw_context *brw,
> else
> _mesa_unpack_etc2_format(dst, mt->surf.row_pitch,
> map->ptr, map->stride,
> - map->w, map->h, mt->etc_format);
> + map->w, map->h, mt->etc_format, true);
>
> intel_miptree_unmap_raw(mt);
> free(map->buffer);
> diff --git a/src/mesa/main/texcompress_etc.c b/src/mesa/main/texcompress_
> etc.c
> index 099787b7f407..ce50ba32f9d4 100644
> --- a/src/mesa/main/texcompress_etc.c
> +++ b/src/mesa/main/texcompress_etc.c
> @@ -719,7 +719,8 @@ etc2_unpack_srgb8(uint8_t *dst_row,
> const uint8_t *src_row,
> unsigned src_stride,
> unsigned width,
> - unsigned height)
> + unsigned height,
> + bool bgra)
> {
> const unsigned bw = 4, bh = 4, bs = 8, comps = 4;
> struct etc2_block block;
> @@ -741,11 +742,14 @@ etc2_unpack_srgb8(uint8_t *dst_row,
> for (i = 0; i < w; i++) {
> etc2_rgb8_fetch_texel(&block, i, j, dst,
> false /* punchthrough_alpha */);
> - /* Convert to MESA_FORMAT_B8G8R8A8_SRGB */
> - tmp = dst[0];
> - dst[0] = dst[2];
> - dst[2] = tmp;
> - dst[3] = 255;
> +
> + if (bgra) {
> + /* Convert to MESA_FORMAT_B8G8R8A8_SRGB */
> + tmp = dst[0];
> + dst[0] = dst[2];
> + dst[2] = tmp;
> + dst[3] = 255;
> + }
>
> dst += comps;
> }
> @@ -801,7 +805,8 @@ etc2_unpack_srgb8_alpha8(uint8_t *dst_row,
> const uint8_t *src_row,
> unsigned src_stride,
> unsigned width,
> - unsigned height)
> + unsigned height,
> + bool bgra)
> {
> /* If internalformat is COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, each 4 × 4
> block
> * of RGBA8888 information is compressed to 128 bits. To decode a
> block, the
> @@ -825,11 +830,13 @@ etc2_unpack_srgb8_alpha8(uint8_t *dst_row,
> for (i = 0; i < w; i++) {
> etc2_rgba8_fetch_texel(&block, i, j, dst);
>
> - /* Convert to MESA_FORMAT_B8G8R8A8_SRGB */
> - tmp = dst[0];
> - dst[0] = dst[2];
> - dst[2] = tmp;
> - dst[3] = dst[3];
> + if (bgra) {
> + /* Convert to MESA_FORMAT_B8G8R8A8_SRGB */
> + tmp = dst[0];
> + dst[0] = dst[2];
> + dst[2] = tmp;
> + dst[3] = dst[3];
> + }
>
> dst += comps;
> }
> @@ -1058,7 +1065,8 @@ etc2_unpack_srgb8_punchthrough_alpha1(uint8_t
> *dst_row,
> const uint8_t *src_row,
> unsigned src_stride,
> unsigned width,
> - unsigned height)
> + unsigned height,
> + bool bgra)
> {
> const unsigned bw = 4, bh = 4, bs = 8, comps = 4;
> struct etc2_block block;
> @@ -1078,11 +1086,14 @@ etc2_unpack_srgb8_punchthrough_alpha1(uint8_t
> *dst_row,
> for (i = 0; i < w; i++) {
> etc2_rgb8_fetch_texel(&block, i, j, dst,
> true /* punchthrough_alpha */);
> - /* Convert to MESA_FORMAT_B8G8R8A8_SRGB */
> - tmp = dst[0];
> - dst[0] = dst[2];
> - dst[2] = tmp;
> - dst[3] = dst[3];
> +
> + if (bgra) {
> + /* Convert to MESA_FORMAT_B8G8R8A8_SRGB */
> + tmp = dst[0];
> + dst[0] = dst[2];
> + dst[2] = tmp;
> + dst[3] = dst[3];
> + }
>
> dst += comps;
> }
> @@ -1206,7 +1217,8 @@ _mesa_unpack_etc2_format(uint8_t *dst_row,
> unsigned src_stride,
> unsigned src_width,
> unsigned src_height,
> - mesa_format format)
> + mesa_format format,
> + bool bgra)
> {
> if (format == MESA_FORMAT_ETC2_RGB8)
> etc2_unpack_rgb8(dst_row, dst_stride,
> @@ -1215,7 +1227,7 @@ _mesa_unpack_etc2_format(uint8_t *dst_row,
> else if (format == MESA_FORMAT_ETC2_SRGB8)
> etc2_unpack_srgb8(dst_row, dst_stride,
> src_row, src_stride,
> - src_width, src_height);
> + src_width, src_height, bgra);
> else if (format == MESA_FORMAT_ETC2_RGBA8_EAC)
> etc2_unpack_rgba8(dst_row, dst_stride,
> src_row, src_stride,
> @@ -1223,7 +1235,7 @@ _mesa_unpack_etc2_format(uint8_t *dst_row,
> else if (format == MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC)
> etc2_unpack_srgb8_alpha8(dst_row, dst_stride,
> src_row, src_stride,
> - src_width, src_height);
> + src_width, src_height, bgra);
> else if (format == MESA_FORMAT_ETC2_R11_EAC)
> etc2_unpack_r11(dst_row, dst_stride,
> src_row, src_stride,
> @@ -1247,7 +1259,7 @@ _mesa_unpack_etc2_format(uint8_t *dst_row,
> else if (format == MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1)
> etc2_unpack_srgb8_punchthrough_alpha1(dst_row, dst_stride,
> src_row, src_stride,
> - src_width, src_height);
> + src_width, src_height, bgra);
> }
>
>
> diff --git a/src/mesa/main/texcompress_etc.h b/src/mesa/main/texcompress_
> etc.h
> index 319b7bea7154..650467ce1f32 100644
> --- a/src/mesa/main/texcompress_etc.h
> +++ b/src/mesa/main/texcompress_etc.h
> @@ -28,6 +28,7 @@
> #include "glheader.h"
> #include "texcompress.h"
> #include "texstore.h"
> +#include "pipe/p_format.h"
>
>
> GLboolean
> @@ -77,7 +78,8 @@ _mesa_unpack_etc2_format(uint8_t *dst_row,
> unsigned src_stride,
> unsigned src_width,
> unsigned src_height,
> - mesa_format format);
> + mesa_format format,
> + bool bgra);
>
> compressed_fetch_func
> _mesa_get_etc_fetch_func(mesa_format format);
> diff --git a/src/mesa/state_tracker/st_cb_texture.c
> b/src/mesa/state_tracker/st_cb_texture.c
> index 8cc8e08a623e..7c0879084ab6 100644
> --- a/src/mesa/state_tracker/st_cb_texture.c
> +++ b/src/mesa/state_tracker/st_cb_texture.c
> @@ -326,10 +326,12 @@ st_UnmapTextureImage(struct gl_context *ctx,
> transfer->box.width,
> transfer->box.height);
> }
> else {
> + bool bgra = stImage->pt->format == PIPE_FORMAT_B8G8R8A8_SRGB;
> _mesa_unpack_etc2_format(itransfer->map, transfer->stride,
> itransfer->temp_data,
> itransfer->temp_stride,
> transfer->box.width,
> transfer->box.height,
> - texImage->TexFormat);
> + texImage->TexFormat,
> + bgra);
> }
> }
>
> --
> 2.17.0
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20180618/cbba9278/attachment.html>
More information about the mesa-dev
mailing list