[Mesa-dev] Bug in _mesa_meta_GenerateMipmap

Brian Paul brianp at vmware.com
Fri Jul 16 15:17:06 PDT 2010

On 07/11/2010 09:06 AM, Maciej Cencora wrote:
> Hi,
> while working on failing piglit tests I've stumbled on a problem with
> _mesa_meta_GenerateMipmap. The function creates new texture images for lower
> mipmap levels, but during call to glTexImage the format and type are hardcoded
> to GL_RGBA and GL_UNSIGNED_BYTE respectivily. And that's where the problem
> arise because base image (the one that other levels are generated from) could
> have other format and type specified (in failing test texturing/gen-teximage
> these are GL_RGBA, GL_FLOAT).
> The result is that for base image MESA_FORMAT_ARGB8888 is chosen and for next
> levels it's MESA_FORMAT_RGBA8888_REV. Of course such texture with images of
> different formats is invalid and will be missampled by GPU.
> As the fix is not straightforward for me (not sure where to get format and type
> from, since the gl_texture_image doesn't hold them) could someone more
> familiar with core mesa take a look at this?

I've worked with Maciej off-line to come up with a solution for this.

Maciej has already tested the attached patch but I thought I'd post it 
for review first to see if anyone sees any problems.

This patch changes when the ctx->Driver.ChooseTextureFormat() function 
is called.

The idea is when defining mipmap level 'L' and level L-1 exists and 
the new level's internalFormat matches level L-1's internalFormat, 
then use the same hardware format.  Otherwise, do the regular 
ctx->Driver.ChooseTextureFormat() call.

The root problem is the ChooseTextureFormat() implementation in some 
drivers uses the user's glTexImage format/type parameters in the 
choosing heuristic.  Later mipmap levels might be generated without 
calls to glTexImage2D() (ex: glCopyTexImage()) so we don't always have 
format/type info and the driver may choose a different format.

Just using the previous level's format avoids this problem.

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: new-choose-tex-format.patch
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20100716/0c153593/attachment.ksh>

More information about the mesa-dev mailing list