At the end of _mesa_meta_GenerateMipmap, is the following sequence:
_mesa_TexParameteri(target, GL_TEXTURE_MAX_LEVEL, maxLevelSave);
_mesa_TexParameteri(target, GL_GENERATE_MIPMAP, genMipmapSave);
_mesa_TexParameteriv(target, GL_TEXTURE_SWIZZLE_RGBA, swizzle);
maxLevelSave, genMipmapSave, and swizzle all came from the texture object passed into the function. This may not be the texture bound to ctx->Texture.CurrentUnit when the function is called!
We need a simple test case to verify this bug.
1. Create two textures, A and B, and fill each with some data.
2. Bind A and set GL_TEXTURE_MAX_LEVEL, GL_GENERATE_MIPMAP, and GL_TEXTURE_SWIZZLE_RGBA (assuming either GL_EXT_texture_swizzle or GL_ARB_texture_swizzle is supported).
3. While A is bound (but B is not bound), call glGenerateMipmaps on B.
4. Verify the GL_TEXTURE_MAX_LEVEL, GL_GENERATE_MIPMAP, and GL_TEXTURE_SWIZZLE_RGBA state of A.
It may be worth making this test generic so that other meta operations (and other texture state) could be tested in the future.
I have sent out a piglit test that reproduces the problem. It turns out that the only way to expose the problem is using glGenerateTextureMipmap. glGenerateMipmap operates on the texture bound to the currently active texture unit. The call to _mesa_meta_end restores all of that state, so the _mesa_TexParameter calls after that hit the correct texture (somewhat by luck).
I also have a Mesa patch that fixes the problem.
Should be fixed by the following commit.
Author: Ian Romanick <email@example.com>
Date: Tue Jan 12 16:37:27 2016 -0800
meta: Use internal functions to set texture parameters
_mesa_texture_parameteriv is used because (the more obvious)
_mesa_texture_parameteri just stuffs the parameter in an array and calls
_mesa_texture_parameteriv. This just cuts out the middleman.
As a side bonus we no longer need check that ARB_stencil_texturing is
supported. The test doesn't allow non-supporting implementations to
avoid any work, and it's redundant with the value-changed test.
Fix bug #93717 because the state restore commands at the bottom of
_mesa_meta_GenerateMipmap no longer depend on the bound state.
Fixes piglit arb_direct_state_access-generatetexturemipmap with the
changes recently sent to the piglit mailing list. See the bugzilla
entry for more info.
Signed-off-by: Ian Romanick <firstname.lastname@example.org>
Cc: "11.0 11.1" <email@example.com>
Reviewed-by: Jason Ekstrand <firstname.lastname@example.org>
Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct.