<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Dec 3, 2014 at 2:20 PM, Ian Romanick <span dir="ltr"><<a href="mailto:idr@freedesktop.org" target="_blank">idr@freedesktop.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">One question below...<br>
<div><div class="h5"><br>
On 12/01/2014 03:04 AM, Iago Toral Quiroga wrote:<br>
> From: Jason Ekstrand <<a href="mailto:jason.ekstrand@intel.com">jason.ekstrand@intel.com</a>><br>
><br>
> Aparently, the packing/unpacking functions for these formats have differed<br>
> from the format description in formats.h. Instead of fixing this, people<br>
> simply left a comment saying it was broken. Let's actually fix it for<br>
> real.<br>
><br>
> Signed-off-by: Jason Ekstrand <<a href="mailto:jason.ekstrand@intel.com">jason.ekstrand@intel.com</a>><br>
> ---<br>
> src/mesa/main/format_pack.c | 10 ++--------<br>
> src/mesa/main/format_unpack.c | 10 ++--------<br>
> src/mesa/main/formats.c | 12 ++++++------<br>
> src/mesa/main/texstore.c | 2 +-<br>
> src/mesa/swrast/s_texfetch_tmp.h | 8 ++++----<br>
> 5 files changed, 15 insertions(+), 27 deletions(-)<br>
><br>
> diff --git a/src/mesa/main/format_pack.c b/src/mesa/main/format_pack.c<br>
> index 31c9f77..20d2b1a 100644<br>
> --- a/src/mesa/main/format_pack.c<br>
> +++ b/src/mesa/main/format_pack.c<br>
> @@ -458,17 +458,11 @@ pack_row_float_B5G6R5_UNORM(GLuint n, const GLfloat src[][4], void *dst)<br>
> }<br>
><br>
><br>
> -/*<br>
> - * MESA_FORMAT_R5G6B5_UNORM<br>
> - * Warning: these functions do not match the current Mesa definition<br>
> - * of MESA_FORMAT_R5G6B5_UNORM.<br>
> - */<br>
> -<br>
> static void<br>
> pack_ubyte_R5G6B5_UNORM(const GLubyte src[4], void *dst)<br>
> {<br>
> GLushort *d = ((GLushort *) dst);<br>
> - *d = PACK_COLOR_565_REV(src[RCOMP], src[GCOMP], src[BCOMP]);<br>
> + *d = PACK_COLOR_565(src[BCOMP], src[GCOMP], src[RCOMP]);<br>
> }<br>
><br>
> static void<br>
> @@ -479,7 +473,7 @@ pack_float_R5G6B5_UNORM(const GLfloat src[4], void *dst)<br>
> UNCLAMPED_FLOAT_TO_UBYTE(r, src[RCOMP]);<br>
> UNCLAMPED_FLOAT_TO_UBYTE(g, src[GCOMP]);<br>
> UNCLAMPED_FLOAT_TO_UBYTE(b, src[BCOMP]);<br>
> - *d = PACK_COLOR_565_REV(r, g, b);<br>
> + *d = PACK_COLOR_565(b, g, r);<br>
> }<br>
><br>
> static void<br>
> diff --git a/src/mesa/main/format_unpack.c b/src/mesa/main/format_unpack.c<br>
> index d5628a9..f5ab966 100644<br>
> --- a/src/mesa/main/format_unpack.c<br>
> +++ b/src/mesa/main/format_unpack.c<br>
> @@ -207,9 +207,6 @@ unpack_B5G6R5_UNORM(const void *src, GLfloat dst[][4], GLuint n)<br>
> static void<br>
> unpack_R5G6B5_UNORM(const void *src, GLfloat dst[][4], GLuint n)<br>
> {<br>
> - /* Warning: this function does not match the current Mesa definition<br>
> - * of MESA_FORMAT_R5G6B5_UNORM.<br>
> - */<br>
> const GLushort *s = ((const GLushort *) src);<br>
> GLuint i;<br>
> for (i = 0; i < n; i++) {<br>
<br>
</div></div>This removes the comment, but it doesn't change the code. Was the code<br>
actually correct before?<br></blockquote><div><br></div><div>Looking at mesa master on cgit, it looks like it's wrong. It won't matter because the later patches autogenerate this fill and do so correctly.<br></div><div>--Jason<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5"><br>
> @@ -2764,16 +2761,13 @@ unpack_ubyte_B5G6R5_UNORM(const void *src, GLubyte dst[][4], GLuint n)<br>
> static void<br>
> unpack_ubyte_R5G6B5_UNORM(const void *src, GLubyte dst[][4], GLuint n)<br>
> {<br>
> - /* Warning: this function does not match the current Mesa definition<br>
> - * of MESA_FORMAT_R5G6B5_UNORM.<br>
> - */<br>
> const GLushort *s = ((const GLushort *) src);<br>
> GLuint i;<br>
> for (i = 0; i < n; i++) {<br>
> GLuint t = (s[i] >> 8) | (s[i] << 8); /* byte swap */<br>
> - dst[i][RCOMP] = EXPAND_5_8((t >> 11) & 0x1f);<br>
> + dst[i][RCOMP] = EXPAND_5_8( t & 0x1f);<br>
> dst[i][GCOMP] = EXPAND_6_8((t >> 5 ) & 0x3f);<br>
> - dst[i][BCOMP] = EXPAND_5_8( t & 0x1f);<br>
> + dst[i][BCOMP] = EXPAND_5_8((t >> 11) & 0x1f);<br>
> dst[i][ACOMP] = 0xff;<br>
> }<br>
> }<br>
> diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c<br>
> index 58c32e2..1315d36 100644<br>
> --- a/src/mesa/main/formats.c<br>
> +++ b/src/mesa/main/formats.c<br>
> @@ -1462,14 +1462,14 @@ _mesa_format_matches_format_and_type(mesa_format mesa_format,<br>
> return format == GL_RGB && type == GL_UNSIGNED_BYTE && littleEndian;<br>
><br>
> case MESA_FORMAT_B5G6R5_UNORM:<br>
> - return format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5 && !swapBytes;<br>
> + return ((format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5) ||<br>
> + (format == GL_BGR && type == GL_UNSIGNED_SHORT_5_6_5_REV)) &&<br>
> + !swapBytes;<br>
><br>
> case MESA_FORMAT_R5G6B5_UNORM:<br>
> - /* Some of the 16-bit MESA_FORMATs that would seem to correspond to<br>
> - * GL_UNSIGNED_SHORT_* are byte-swapped instead of channel-reversed,<br>
> - * according to formats.h, so they can't be matched.<br>
> - */<br>
> - return GL_FALSE;<br>
> + return ((format == GL_BGR && type == GL_UNSIGNED_SHORT_5_6_5) ||<br>
> + (format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5_REV)) &&<br>
> + !swapBytes;<br>
><br>
> case MESA_FORMAT_B4G4R4A4_UNORM:<br>
> return format == GL_BGRA && type == GL_UNSIGNED_SHORT_4_4_4_4_REV &&<br>
> diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c<br>
> index f858cef..3ac8bcf 100644<br>
> --- a/src/mesa/main/texstore.c<br>
> +++ b/src/mesa/main/texstore.c<br>
> @@ -923,7 +923,7 @@ _mesa_texstore_rgb565(TEXSTORE_PARAMS)<br>
> }<br>
> else {<br>
> for (col = 0; col < srcWidth; col++) {<br>
> - dstUS[col] = PACK_COLOR_565_REV( srcUB[0], srcUB[1], srcUB[2] );<br>
> + dstUS[col] = PACK_COLOR_565( srcUB[2], srcUB[1], srcUB[0] );<br>
> srcUB += 3;<br>
> }<br>
> }<br>
> diff --git a/src/mesa/swrast/s_texfetch_tmp.h b/src/mesa/swrast/s_texfetch_tmp.h<br>
> index 7ff30f6..23db48d 100644<br>
> --- a/src/mesa/swrast/s_texfetch_tmp.h<br>
> +++ b/src/mesa/swrast/s_texfetch_tmp.h<br>
> @@ -417,10 +417,10 @@ FETCH(R5G6B5_UNORM)(const struct swrast_texture_image *texImage,<br>
> GLint i, GLint j, GLint k, GLfloat *texel)<br>
> {<br>
> const GLushort *src = TEXEL_ADDR(GLushort, texImage, i, j, k, 1);<br>
> - const GLushort s = (*src >> 8) | (*src << 8); /* byte swap */<br>
> - texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf8) | ((s >> 13) & 0x7) );<br>
> - texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 3) & 0xfc) | ((s >> 9) & 0x3) );<br>
> - texel[BCOMP] = UBYTE_TO_FLOAT( ((s << 3) & 0xf8) | ((s >> 2) & 0x7) );<br>
> + const GLushort s = *src;<br>
> + texel[RCOMP] = ((s ) & 0x1f) * (1.0F / 31.0F);<br>
> + texel[GCOMP] = ((s >> 5 ) & 0x3f) * (1.0F / 63.0F);<br>
> + texel[BCOMP] = ((s >> 11) & 0x1f) * (1.0F / 31.0F);<br>
> texel[ACOMP] = 1.0F;<br>
> }<br>
><br>
><br>
<br>
</div></div><div class="HOEnZb"><div class="h5">_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</div></div></blockquote></div><br></div></div>