radeon: rework mipmap tree reference counting
authorMaciej Cencora <m.cencora@gmail.com>
Sat, 14 Nov 2009 13:55:13 +0000 (14:55 +0100)
committerMaciej Cencora <m.cencora@gmail.com>
Sat, 14 Nov 2009 15:55:34 +0000 (16:55 +0100)
src/mesa/drivers/dri/r300/r300_tex.c
src/mesa/drivers/dri/r300/r300_texstate.c
src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c
src/mesa/drivers/dri/radeon/radeon_mipmap_tree.h
src/mesa/drivers/dri/radeon/radeon_texture.c

index 427237d200bff773f0963efdfcd95caa2ecdf4c4..7e94e93df2e657dc6df6aaa8758972956af5cec9 100644 (file)
@@ -228,11 +228,8 @@ static void r300TexParameter(GLcontext * ctx, GLenum target,
                 * we just have to rely on loading the right subset of mipmap levels
                 * to simulate a clamped LOD.
                 */
-               if (t->mt) {
-                       radeon_miptree_unreference(t->mt);
-                       t->mt = 0;
-                       t->validated = GL_FALSE;
-               }
+               radeon_miptree_unreference(&t->mt);
+               t->validated = GL_FALSE;
                break;
 
        case GL_DEPTH_TEXTURE_MODE:
@@ -286,10 +283,8 @@ static void r300DeleteTexture(GLcontext * ctx, struct gl_texture_object *texObj)
                t->bo = NULL;
        }
 
-       if (t->mt) {
-               radeon_miptree_unreference(t->mt);
-               t->mt = 0;
-       }
+       radeon_miptree_unreference(&t->mt);
+
        _mesa_delete_texture_object(ctx, texObj);
 }
 
index 4699342994115f8f0c0fccbd7aa7e2ed66c5f1ee..7b1adcf31dcfc4a2bc5d094d863b51a1c272606a 100644 (file)
@@ -438,14 +438,10 @@ void r300SetTexBuffer2(__DRIcontext *pDRICtx, GLint target, GLint glx_texture_fo
                radeon_bo_unref(rImage->bo);
                rImage->bo = NULL;
        }
-       if (t->mt) {
-               radeon_miptree_unreference(t->mt);
-               t->mt = NULL;
-       }
-       if (rImage->mt) {
-               radeon_miptree_unreference(rImage->mt);
-               rImage->mt = NULL;
-       }
+
+       radeon_miptree_unreference(&t->mt);
+       radeon_miptree_unreference(&rImage->mt);
+
        _mesa_init_teximage_fields(radeon->glCtx, target, texImage,
                                   rb->base.Width, rb->base.Height, 1, 0, rb->cpp);
        texImage->RowStride = rb->pitch / rb->cpp;
index dadc72f4c1b142ade5cd0a834563f192adf7048a..f635f58d6ae8fd4a521d8827199b270196485364 100644 (file)
@@ -223,23 +223,31 @@ radeon_mipmap_tree* radeon_miptree_create(radeonContextPtr rmesa, radeonTexObj *
        return mt;
 }
 
-void radeon_miptree_reference(radeon_mipmap_tree *mt)
+void radeon_miptree_reference(radeon_mipmap_tree *mt, radeon_mipmap_tree **ptr)
 {
+       assert(!*ptr);
+
        mt->refcount++;
        assert(mt->refcount > 0);
+
+       *ptr = mt;
 }
 
-void radeon_miptree_unreference(radeon_mipmap_tree *mt)
+void radeon_miptree_unreference(radeon_mipmap_tree **ptr)
 {
+       radeon_mipmap_tree *mt = *ptr;
        if (!mt)
                return;
 
        assert(mt->refcount > 0);
+
        mt->refcount--;
        if (!mt->refcount) {
                radeon_bo_unref(mt->bo);
                free(mt);
        }
+
+       *ptr = 0;
 }
 
 
index db28252da374045d9574811b40c1ea4c03b8cd64..57299ceafac8069bca806568445423204a91d9e5 100644 (file)
@@ -87,8 +87,9 @@ radeon_mipmap_tree* radeon_miptree_create(radeonContextPtr rmesa, radeonTexObj *
                GLenum target, GLenum internal_format, GLuint firstLevel, GLuint lastLevel,
                GLuint width0, GLuint height0, GLuint depth0,
                GLuint bpp, GLuint tilebits, GLuint compressed);
-void radeon_miptree_reference(radeon_mipmap_tree *mt);
-void radeon_miptree_unreference(radeon_mipmap_tree *mt);
+
+void radeon_miptree_reference(radeon_mipmap_tree *mt, radeon_mipmap_tree **ptr);
+void radeon_miptree_unreference(radeon_mipmap_tree **ptr);
 
 GLboolean radeon_miptree_matches_image(radeon_mipmap_tree *mt,
                struct gl_texture_image *texImage, GLuint face, GLuint level);
index 59bc8c34de90219f9d456195683a9fe606673d6c..607ce7864e8ec9d9e294a6d2099e6c050b69d3f6 100644 (file)
@@ -81,8 +81,7 @@ void radeonFreeTexImageData(GLcontext *ctx, struct gl_texture_image *timage)
        radeon_texture_image* image = get_radeon_texture_image(timage);
 
        if (image->mt) {
-               radeon_miptree_unreference(image->mt);
-               image->mt = 0;
+               radeon_miptree_unreference(&image->mt);
                assert(!image->base.Data);
        } else {
                _mesa_free_texture_image_data(ctx, timage);
@@ -240,8 +239,7 @@ static void radeon_generate_mipmap(GLcontext *ctx, GLenum target,
                        image->mtlevel = i;
                        image->mtface = face;
 
-                       radeon_miptree_unreference(image->mt);
-                       image->mt = NULL;
+                       radeon_miptree_unreference(&image->mt);
                }
        }
        
@@ -571,18 +569,16 @@ static void radeon_teximage(
            t->mt->lastLevel == level &&
            t->mt->target != GL_TEXTURE_CUBE_MAP_ARB &&
            !radeon_miptree_matches_image(t->mt, texImage, face, level)) {
-         radeon_miptree_unreference(t->mt);
-         t->mt = NULL;
+         radeon_miptree_unreference(&t->mt);
        }
 
        if (!t->mt)
                radeon_try_alloc_miptree(rmesa, t, image, face, level);
        if (t->mt && radeon_miptree_matches_image(t->mt, texImage, face, level)) {
                radeon_mipmap_level *lvl;
-               image->mt = t->mt;
                image->mtlevel = level - t->mt->firstLevel;
                image->mtface = face;
-               radeon_miptree_reference(t->mt);
+               radeon_miptree_reference(t->mt, &image->mt);
                lvl = &image->mt->levels[image->mtlevel];
                dstRowStride = lvl->rowstride;
        } else {
@@ -894,7 +890,7 @@ static void migrate_image_to_miptree(radeon_mipmap_tree *mt, radeon_texture_imag
                        dstlvl->size);
                radeon_bo_unmap(image->mt->bo);
 
-               radeon_miptree_unreference(image->mt);
+               radeon_miptree_unreference(&image->mt);
        } else {
                uint32_t srcrowstride;
                uint32_t height;
@@ -919,10 +915,9 @@ static void migrate_image_to_miptree(radeon_mipmap_tree *mt, radeon_texture_imag
 
        radeon_bo_unmap(mt->bo);
 
-       image->mt = mt;
        image->mtface = face;
        image->mtlevel = level;
-       radeon_miptree_reference(image->mt);
+       radeon_miptree_reference(mt, &image->mt);
 }
 
 int radeon_validate_texture_miptree(GLcontext * ctx, struct gl_texture_object *texObj)
@@ -954,12 +949,10 @@ int radeon_validate_texture_miptree(GLcontext * ctx, struct gl_texture_object *t
        if (baseimage->mt &&
            baseimage->mt != t->mt &&
            radeon_miptree_matches_texture(baseimage->mt, &t->base)) {
-               radeon_miptree_unreference(t->mt);
-               t->mt = baseimage->mt;
-               radeon_miptree_reference(t->mt);
+               radeon_miptree_unreference(&t->mt);
+               radeon_miptree_reference(baseimage->mt, &t->mt);
        } else if (t->mt && !radeon_miptree_matches_texture(t->mt, &t->base)) {
-               radeon_miptree_unreference(t->mt);
-               t->mt = 0;
+               radeon_miptree_unreference(&t->mt);
        }
 
        if (!t->mt) {