Mesa (mesa_7_7_branch): st/mesa: fix texture deallocation bug
Brian Paul
brianp at kemper.freedesktop.org
Tue Feb 2 02:03:41 UTC 2010
Module: Mesa
Branch: mesa_7_7_branch
Commit: 43e4b584227534e30e487e7fb7e99d6501cbcd85
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=43e4b584227534e30e487e7fb7e99d6501cbcd85
Author: Brian Paul <brianp at vmware.com>
Date: Mon Feb 1 18:45:36 2010 -0700
st/mesa: fix texture deallocation bug
This fixes a bug reported by Christoph Bumiller on mesa3d-dev.
When a texture is first created as RGBA, then re-defined with
glTexImage(internalFormat=GL_DEPTH_COMPONENT) we failed to deallocate
the original texture. When this texture was bound as a FBO surface,
the depth/Z surface format was RGBA instead of Z. Depending on the
driver this led to a failed assertion or FBO validation failure.
This patch does three things:
1. Remove ancient code that mysteriously tested if we were replacing
the smallest mipmap level and tested if the texture was not a cube map
texture. I can't see any reason for those tests.
2. Move the width=height=depth=0 test to after the code which frees
texture data. Calling glTexImage with width=height=depth=0 and data=NULL
is a way to free a single mipmap level.
3. Update the code comments.
There are no apparent conform, glean or piglit regressions from this change.
---
src/mesa/state_tracker/st_cb_texture.c | 22 ++++++++++------------
1 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c
index a0dc016..0858a36 100644
--- a/src/mesa/state_tracker/st_cb_texture.c
+++ b/src/mesa/state_tracker/st_cb_texture.c
@@ -543,22 +543,15 @@ st_TexImage(GLcontext * ctx,
_mesa_align_free(texImage->Data);
}
- if (width == 0 || height == 0 || depth == 0) {
- /* stop after freeing old image */
- return;
- }
-
- /* If this is the only mipmap level in the texture, could call
- * bmBufferData with NULL data to free the old block and avoid
- * waiting on any outstanding fences.
+ /*
+ * See if the new image is somehow incompatible with the existing
+ * mipmap. If so, free the old mipmap.
*/
if (stObj->pt) {
if (stObj->teximage_realloc ||
level > (GLint) stObj->pt->last_level ||
- (stObj->pt->last_level == level &&
- stObj->pt->target != PIPE_TEXTURE_CUBE &&
- !st_texture_match_image(stObj->pt, &stImage->base,
- stImage->face, stImage->level))) {
+ !st_texture_match_image(stObj->pt, &stImage->base,
+ stImage->face, stImage->level)) {
DBG("release it\n");
pipe_texture_reference(&stObj->pt, NULL);
assert(!stObj->pt);
@@ -566,6 +559,11 @@ st_TexImage(GLcontext * ctx,
}
}
+ if (width == 0 || height == 0 || depth == 0) {
+ /* stop after freeing old image */
+ return;
+ }
+
if (!stObj->pt) {
guess_and_alloc_texture(ctx->st, stObj, stImage);
if (!stObj->pt) {
More information about the mesa-commit
mailing list