[Mesa-dev] [PATCH] mesa: preserve 10 bits of precision in the texstore general path for ARGB2101010
Brian Paul
brian.e.paul at gmail.com
Mon Jan 3 07:47:08 PST 2011
Looks good.
-Brian
On Wed, Dec 22, 2010 at 12:50 PM, Marek Olšák <maraeo at gmail.com> wrote:
> Use make_temp_float_image instead of _make_temp_chan_image.
> The latter converts the texture to 8 bits/component, losing 2 bits.
>
> This is a follow-up to my last patch series.
> ---
> src/mesa/main/colormac.h | 6 +++++-
> src/mesa/main/texfetch_tmp.h | 2 +-
> src/mesa/main/texstore.c | 32 +++++++++++++++++++-------------
> 3 files changed, 25 insertions(+), 15 deletions(-)
>
> diff --git a/src/mesa/main/colormac.h b/src/mesa/main/colormac.h
> index 065f9f9..a328dcd 100644
> --- a/src/mesa/main/colormac.h
> +++ b/src/mesa/main/colormac.h
> @@ -198,10 +198,14 @@ do { \
> ((((B) & 0xf8) >> 1) | (((G) & 0xc0) >> 6) | (((G) & 0x38) << 10) | (((R) & 0xf8) << 5) | \
> ((A) ? 0x80 : 0))
>
> -#define PACK_COLOR_2101010( A, B, G, R ) \
> +#define PACK_COLOR_2101010_UB( A, B, G, R ) \
> (((B) << 22) | ((G) << 12) | ((R) << 2) | \
> (((A) & 0xc0) << 24))
>
> +#define PACK_COLOR_2101010_US( A, B, G, R ) \
> + ((((B) >> 6) << 20) | (((G) >> 6) << 10) | ((R) >> 6) | \
> + (((A) >> 14) << 30))
> +
> #define PACK_COLOR_4444( R, G, B, A ) \
> ((((R) & 0xf0) << 8) | (((G) & 0xf0) << 4) | ((B) & 0xf0) | ((A) >> 4))
>
> diff --git a/src/mesa/main/texfetch_tmp.h b/src/mesa/main/texfetch_tmp.h
> index 2de41f3..6439803 100644
> --- a/src/mesa/main/texfetch_tmp.h
> +++ b/src/mesa/main/texfetch_tmp.h
> @@ -837,7 +837,7 @@ static void store_texel_argb2101010(struct gl_texture_image *texImage,
> {
> const GLubyte *rgba = (const GLubyte *) texel;
> GLuint *dst = TEXEL_ADDR(GLuint, texImage, i, j, k, 1);
> - *dst = PACK_COLOR_2101010(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
> + *dst = PACK_COLOR_2101010_UB(rgba[ACOMP], rgba[RCOMP], rgba[GCOMP], rgba[BCOMP]);
> }
> #endif
>
> diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c
> index acb390b..de99e6c 100644
> --- a/src/mesa/main/texstore.c
> +++ b/src/mesa/main/texstore.c
> @@ -2063,13 +2063,14 @@ _mesa_texstore_argb2101010(TEXSTORE_PARAMS)
> }
> else {
> /* general path */
> - const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
> + const GLfloat *tempImage = make_temp_float_image(ctx, dims,
> baseInternalFormat,
> baseFormat,
> srcWidth, srcHeight, srcDepth,
> srcFormat, srcType, srcAddr,
> - srcPacking);
> - const GLchan *src = tempImage;
> + srcPacking,
> + ctx->_ImageTransferState);
> + const GLfloat *src = tempImage;
> GLint img, row, col;
> if (!tempImage)
> return GL_FALSE;
> @@ -2080,24 +2081,29 @@ _mesa_texstore_argb2101010(TEXSTORE_PARAMS)
> + dstXoffset * texelBytes;
> if (baseInternalFormat == GL_RGBA) {
> for (row = 0; row < srcHeight; row++) {
> - GLuint *dstUS = (GLuint *) dstRow;
> + GLuint *dstUI = (GLuint *) dstRow;
> for (col = 0; col < srcWidth; col++) {
> - dstUS[col] = PACK_COLOR_2101010( CHAN_TO_UBYTE(src[ACOMP]),
> - CHAN_TO_UBYTE(src[RCOMP]),
> - CHAN_TO_UBYTE(src[GCOMP]),
> - CHAN_TO_UBYTE(src[BCOMP]) );
> + GLushort a,r,g,b;
> +
> + UNCLAMPED_FLOAT_TO_USHORT(a, src[ACOMP]);
> + UNCLAMPED_FLOAT_TO_USHORT(r, src[RCOMP]);
> + UNCLAMPED_FLOAT_TO_USHORT(g, src[GCOMP]);
> + UNCLAMPED_FLOAT_TO_USHORT(b, src[BCOMP]);
> + dstUI[col] = PACK_COLOR_2101010_US(a, r, g, b);
> src += 4;
> }
> dstRow += dstRowStride;
> }
> } else if (baseInternalFormat == GL_RGB) {
> for (row = 0; row < srcHeight; row++) {
> - GLuint *dstUS = (GLuint *) dstRow;
> + GLuint *dstUI = (GLuint *) dstRow;
> for (col = 0; col < srcWidth; col++) {
> - dstUS[col] = PACK_COLOR_2101010( 0xff,
> - CHAN_TO_UBYTE(src[RCOMP]),
> - CHAN_TO_UBYTE(src[GCOMP]),
> - CHAN_TO_UBYTE(src[BCOMP]) );
> + GLushort r,g,b;
> +
> + UNCLAMPED_FLOAT_TO_USHORT(r, src[RCOMP]);
> + UNCLAMPED_FLOAT_TO_USHORT(g, src[GCOMP]);
> + UNCLAMPED_FLOAT_TO_USHORT(b, src[BCOMP]);
> + dstUI[col] = PACK_COLOR_2101010_US(0xffff, r, g, b);
> src += 4;
> }
> dstRow += dstRowStride;
> --
> 1.7.1
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
More information about the mesa-dev
mailing list