Bug 4543

Summary: _mesa_BindTexture handles (re)binding of current bound texture incorrectly
Product: Mesa Reporter: Ian Romanick <idr>
Component: Mesa coreAssignee: mesa-dev
Status: RESOLVED WORKSFORME QA Contact:
Severity: normal    
Priority: low    
Version: git   
Hardware: All   
OS: All   
Whiteboard:
i915 platform: i915 features:

Description Ian Romanick 2005-09-21 15:18:12 UTC
_mesa_BindTexture performs no operation if the texture being bound is the same
as the texture that is already bound.  There is a comment in the code that
suggests that this optimization may not be correct in certain multicontext cases.

After some discussions at the ARB meeting, I believe that this optimization is
wrong for 3 reasons.

1. The synchronization issue mentioned in the code.

2. glBindTexture is defined as unbinding the currently bound texture, then
binding the named texture.  In the multicontext case, given contexts A and B, it
is possible for context A to delete the texture while it is bound in context B.
 If B binds the texture while it is bound, the implicit unbind would cause the
texture to be destroyed.  By short circuiting that step, the behavior is changed.

3. While the multicontext cases are a bit esoteric, the case where a texture is
bound as a texture and attached to a framebuffer object is not.  The same
synchronization issue mentioned in the code WRT the multicontext case exists in
the case of a single context with a framebuffer object.

Even if this optimization were removed, the code would not be correct.  In
effect, the existing code binds the new texture, then unbinds the old texture. 
I believe the correct fix is to replace the short circuit with code from the end
of the function that decrements the refernce count on the texture object and, if
the count is zero, deletes the object.
Comment 1 Adam Jackson 2009-08-24 12:23:26 UTC
Mass version move, cvs -> git
Comment 2 Timothy Arceri 2018-04-10 06:32:31 UTC
The optimisation no longer appears to be there. Likely this was fixed a while ago considering how old this bug is. Either way it doesn't seem to be something people are running into. Closing.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.