[Mesa-dev] [PATCH] meta: save and restore swizzle for _GenerateMipmap

Chris Forbes chrisf at ijw.co.nz
Mon Jun 9 14:17:42 PDT 2014


It would be good to have a piglit test which demonstrates the need for this.

Reviewed-by: Chris Forbes <chrisf at ijw.co.nz>

On Tue, Jun 10, 2014 at 2:48 AM, Robert Bragg <robert at sixbynine.org> wrote:
> This makes sure to use a no-op swizzle while iteratively rendering each
> level of a mipmap otherwise we may loose components and effectively
> apply the swizzle twice by the time these levels are sampled.
> ---
>  src/mesa/drivers/common/meta_generate_mipmap.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
>
> diff --git a/src/mesa/drivers/common/meta_generate_mipmap.c b/src/mesa/drivers/common/meta_generate_mipmap.c
> index d12806c..4b1718d 100644
> --- a/src/mesa/drivers/common/meta_generate_mipmap.c
> +++ b/src/mesa/drivers/common/meta_generate_mipmap.c
> @@ -43,6 +43,7 @@
>  #include "main/varray.h"
>  #include "main/viewport.h"
>  #include "drivers/common/meta.h"
> +#include "program/prog_instruction.h"
>
>
>  /**
> @@ -168,6 +169,8 @@ _mesa_meta_GenerateMipmap(struct gl_context *ctx, GLenum target,
>     GLenum faceTarget;
>     GLuint dstLevel;
>     GLuint samplerSave;
> +   GLint swizzle[4];
> +   GLboolean swizzleSaved = GL_FALSE;
>
>     if (fallback_required(ctx, target, texObj)) {
>        _mesa_generate_mipmap(ctx, target, texObj);
> @@ -231,6 +234,13 @@ _mesa_meta_GenerateMipmap(struct gl_context *ctx, GLenum target,
>
>     _mesa_TexParameteri(target, GL_GENERATE_MIPMAP, GL_FALSE);
>
> +   if (texObj->_Swizzle != SWIZZLE_NOOP) {
> +      static const GLint swizzleNoop[4] = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA };
> +      memcpy(swizzle, texObj->Swizzle, sizeof(swizzle));
> +      swizzleSaved = GL_TRUE;
> +      _mesa_TexParameteriv(target, GL_TEXTURE_SWIZZLE_RGBA, swizzleNoop);
> +   }
> +
>     /* Silence valgrind warnings about reading uninitialized stack. */
>     memset(verts, 0, sizeof(verts));
>
> @@ -347,4 +357,6 @@ _mesa_meta_GenerateMipmap(struct gl_context *ctx, GLenum target,
>     _mesa_TexParameteri(target, GL_TEXTURE_MAX_LEVEL, maxLevelSave);
>     if (genMipmapSave)
>        _mesa_TexParameteri(target, GL_GENERATE_MIPMAP, genMipmapSave);
> +   if (swizzleSaved)
> +      _mesa_TexParameteriv(target, GL_TEXTURE_SWIZZLE_RGBA, swizzle);
>  }
> --
> 1.9.2
>
> _______________________________________________
> 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