<div dir="ltr"><div>What about non-sRGB formats?</div><div><br></div><div>Marek<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 23, 2018 at 4:54 AM, Tomeu Vizoso <span dir="ltr"><<a href="mailto:tomeu.vizoso@collabora.com" target="_blank">tomeu.vizoso@collabora.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">When Mesa itself implements ETC2 decompression, it currently<br>
decompresses to formats in the GL_BGRA component order.<br>
<br>
That can be problematic for drivers which cannot upload the texture data<br>
as GL_BGRA, such as Virgl when it's backed by GLES on the host.<br>
<br>
So this commit adds a flag to _mesa_unpack_etc2_format so callers can<br>
specify the optimal component order.<br>
<br>
In Gallium's case, it will be requested if the format isn't in<br>
PIPE_FORMAT_B8G8R8A8_SRGB format.<br>
<br>
For i965, it will remain GL_BGRA, as before.<br>
<br>
Signed-off-by: Tomeu Vizoso <<a href="mailto:tomeu.vizoso@collabora.com">tomeu.vizoso@collabora.com</a>><br>
---<br>
src/mesa/drivers/dri/i965/<wbr>intel_mipmap_tree.c | 2 +-<br>
src/mesa/main/texcompress_etc.<wbr>c | 56 +++++++++++--------<br>
src/mesa/main/texcompress_etc.<wbr>h | 4 +-<br>
src/mesa/state_tracker/st_cb_<wbr>texture.c | 4 +-<br>
4 files changed, 41 insertions(+), 25 deletions(-)<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/<wbr>intel_mipmap_tree.c b/src/mesa/drivers/dri/i965/<wbr>intel_mipmap_tree.c<br>
index 67086ee6c0e8..4d9019ebf4ea 100644<br>
--- a/src/mesa/drivers/dri/i965/<wbr>intel_mipmap_tree.c<br>
+++ b/src/mesa/drivers/dri/i965/<wbr>intel_mipmap_tree.c<br>
@@ -3370,7 +3370,7 @@ intel_miptree_unmap_etc(struct brw_context *brw,<br>
else<br>
_mesa_unpack_etc2_format(dst, mt->surf.row_pitch,<br>
map->ptr, map->stride,<br>
- map->w, map->h, mt->etc_format);<br>
+ map->w, map->h, mt->etc_format, true);<br>
<br>
intel_miptree_unmap_raw(mt);<br>
free(map->buffer);<br>
diff --git a/src/mesa/main/texcompress_<wbr>etc.c b/src/mesa/main/texcompress_<wbr>etc.c<br>
index 099787b7f407..ce50ba32f9d4 100644<br>
--- a/src/mesa/main/texcompress_<wbr>etc.c<br>
+++ b/src/mesa/main/texcompress_<wbr>etc.c<br>
@@ -719,7 +719,8 @@ etc2_unpack_srgb8(uint8_t *dst_row,<br>
const uint8_t *src_row,<br>
unsigned src_stride,<br>
unsigned width,<br>
- unsigned height)<br>
+ unsigned height,<br>
+ bool bgra)<br>
{<br>
const unsigned bw = 4, bh = 4, bs = 8, comps = 4;<br>
struct etc2_block block;<br>
@@ -741,11 +742,14 @@ etc2_unpack_srgb8(uint8_t *dst_row,<br>
for (i = 0; i < w; i++) {<br>
etc2_rgb8_fetch_texel(&block, i, j, dst,<br>
false /* punchthrough_alpha */);<br>
- /* Convert to MESA_FORMAT_B8G8R8A8_SRGB */<br>
- tmp = dst[0];<br>
- dst[0] = dst[2];<br>
- dst[2] = tmp;<br>
- dst[3] = 255;<br>
+<br>
+ if (bgra) {<br>
+ /* Convert to MESA_FORMAT_B8G8R8A8_SRGB */<br>
+ tmp = dst[0];<br>
+ dst[0] = dst[2];<br>
+ dst[2] = tmp;<br>
+ dst[3] = 255;<br>
+ }<br>
<br>
dst += comps;<br>
}<br>
@@ -801,7 +805,8 @@ etc2_unpack_srgb8_alpha8(<wbr>uint8_t *dst_row,<br>
const uint8_t *src_row,<br>
unsigned src_stride,<br>
unsigned width,<br>
- unsigned height)<br>
+ unsigned height,<br>
+ bool bgra)<br>
{<br>
/* If internalformat is COMPRESSED_SRGB8_ALPHA8_ETC2_<wbr>EAC, each 4 × 4 block<br>
* of RGBA8888 information is compressed to 128 bits. To decode a block, the<br>
@@ -825,11 +830,13 @@ etc2_unpack_srgb8_alpha8(<wbr>uint8_t *dst_row,<br>
for (i = 0; i < w; i++) {<br>
etc2_rgba8_fetch_texel(&block, i, j, dst);<br>
<br>
- /* Convert to MESA_FORMAT_B8G8R8A8_SRGB */<br>
- tmp = dst[0];<br>
- dst[0] = dst[2];<br>
- dst[2] = tmp;<br>
- dst[3] = dst[3];<br>
+ if (bgra) {<br>
+ /* Convert to MESA_FORMAT_B8G8R8A8_SRGB */<br>
+ tmp = dst[0];<br>
+ dst[0] = dst[2];<br>
+ dst[2] = tmp;<br>
+ dst[3] = dst[3];<br>
+ }<br>
<br>
dst += comps;<br>
}<br>
@@ -1058,7 +1065,8 @@ etc2_unpack_srgb8_<wbr>punchthrough_alpha1(uint8_t *dst_row,<br>
const uint8_t *src_row,<br>
unsigned src_stride,<br>
unsigned width,<br>
- unsigned height)<br>
+ unsigned height,<br>
+ bool bgra)<br>
{<br>
const unsigned bw = 4, bh = 4, bs = 8, comps = 4;<br>
struct etc2_block block;<br>
@@ -1078,11 +1086,14 @@ etc2_unpack_srgb8_<wbr>punchthrough_alpha1(uint8_t *dst_row,<br>
for (i = 0; i < w; i++) {<br>
etc2_rgb8_fetch_texel(&block, i, j, dst,<br>
true /* punchthrough_alpha */);<br>
- /* Convert to MESA_FORMAT_B8G8R8A8_SRGB */<br>
- tmp = dst[0];<br>
- dst[0] = dst[2];<br>
- dst[2] = tmp;<br>
- dst[3] = dst[3];<br>
+<br>
+ if (bgra) {<br>
+ /* Convert to MESA_FORMAT_B8G8R8A8_SRGB */<br>
+ tmp = dst[0];<br>
+ dst[0] = dst[2];<br>
+ dst[2] = tmp;<br>
+ dst[3] = dst[3];<br>
+ }<br>
<br>
dst += comps;<br>
}<br>
@@ -1206,7 +1217,8 @@ _mesa_unpack_etc2_format(<wbr>uint8_t *dst_row,<br>
unsigned src_stride,<br>
unsigned src_width,<br>
unsigned src_height,<br>
- mesa_format format)<br>
+ mesa_format format,<br>
+ bool bgra)<br>
{<br>
if (format == MESA_FORMAT_ETC2_RGB8)<br>
etc2_unpack_rgb8(dst_row, dst_stride,<br>
@@ -1215,7 +1227,7 @@ _mesa_unpack_etc2_format(<wbr>uint8_t *dst_row,<br>
else if (format == MESA_FORMAT_ETC2_SRGB8)<br>
etc2_unpack_srgb8(dst_row, dst_stride,<br>
src_row, src_stride,<br>
- src_width, src_height);<br>
+ src_width, src_height, bgra);<br>
else if (format == MESA_FORMAT_ETC2_RGBA8_EAC)<br>
etc2_unpack_rgba8(dst_row, dst_stride,<br>
src_row, src_stride,<br>
@@ -1223,7 +1235,7 @@ _mesa_unpack_etc2_format(<wbr>uint8_t *dst_row,<br>
else if (format == MESA_FORMAT_ETC2_SRGB8_ALPHA8_<wbr>EAC)<br>
etc2_unpack_srgb8_alpha8(dst_<wbr>row, dst_stride,<br>
src_row, src_stride,<br>
- src_width, src_height);<br>
+ src_width, src_height, bgra);<br>
else if (format == MESA_FORMAT_ETC2_R11_EAC)<br>
etc2_unpack_r11(dst_row, dst_stride,<br>
src_row, src_stride,<br>
@@ -1247,7 +1259,7 @@ _mesa_unpack_etc2_format(<wbr>uint8_t *dst_row,<br>
else if (format == MESA_FORMAT_ETC2_SRGB8_<wbr>PUNCHTHROUGH_ALPHA1)<br>
etc2_unpack_srgb8_<wbr>punchthrough_alpha1(dst_row, dst_stride,<br>
src_row, src_stride,<br>
- src_width, src_height);<br>
+ src_width, src_height, bgra);<br>
}<br>
<br>
<br>
diff --git a/src/mesa/main/texcompress_<wbr>etc.h b/src/mesa/main/texcompress_<wbr>etc.h<br>
index 319b7bea7154..650467ce1f32 100644<br>
--- a/src/mesa/main/texcompress_<wbr>etc.h<br>
+++ b/src/mesa/main/texcompress_<wbr>etc.h<br>
@@ -28,6 +28,7 @@<br>
#include "glheader.h"<br>
#include "texcompress.h"<br>
#include "texstore.h"<br>
+#include "pipe/p_format.h"<br>
<br>
<br>
GLboolean<br>
@@ -77,7 +78,8 @@ _mesa_unpack_etc2_format(<wbr>uint8_t *dst_row,<br>
unsigned src_stride,<br>
unsigned src_width,<br>
unsigned src_height,<br>
- mesa_format format);<br>
+ mesa_format format,<br>
+ bool bgra);<br>
<br>
compressed_fetch_func<br>
_mesa_get_etc_fetch_func(mesa_<wbr>format format);<br>
diff --git a/src/mesa/state_tracker/st_<wbr>cb_texture.c b/src/mesa/state_tracker/st_<wbr>cb_texture.c<br>
index 8cc8e08a623e..7c0879084ab6 100644<br>
--- a/src/mesa/state_tracker/st_<wbr>cb_texture.c<br>
+++ b/src/mesa/state_tracker/st_<wbr>cb_texture.c<br>
@@ -326,10 +326,12 @@ st_UnmapTextureImage(struct gl_context *ctx,<br>
transfer->box.width, transfer->box.height);<br>
}<br>
else {<br>
+ bool bgra = stImage->pt->format == PIPE_FORMAT_B8G8R8A8_SRGB;<br>
_mesa_unpack_etc2_format(<wbr>itransfer->map, transfer->stride,<br>
itransfer->temp_data, itransfer->temp_stride,<br>
transfer->box.width, transfer->box.height,<br>
- texImage->TexFormat);<br>
+ texImage->TexFormat,<br>
+ bgra);<br>
}<br>
}<br>
<span class="HOEnZb"><font color="#888888"> <br>
-- <br>
2.17.0<br>
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div>