radeon: pass internal format into the miptree.
authorDave Airlie <airlied@redhat.com>
Thu, 3 Sep 2009 02:01:52 +0000 (12:01 +1000)
committerDave Airlie <airlied@redhat.com>
Thu, 3 Sep 2009 02:02:54 +0000 (12:02 +1000)
We need to figure out if the compression format changes.

without this texcmp segfaults if you change format
enough times.

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 d9f17cfc58ca373676d1b913d27a7f6c5aa7d82e..38db305e2a76e76a9405471843e3f0fc3080a047 100644 (file)
@@ -190,13 +190,14 @@ static void calculate_miptree_layout_r300(radeonContextPtr rmesa, radeon_mipmap_
  * Create a new mipmap tree, calculate its layout and allocate memory.
  */
 radeon_mipmap_tree* radeon_miptree_create(radeonContextPtr rmesa, radeonTexObj *t,
-               GLenum target, GLuint firstLevel, GLuint lastLevel,
+               GLenum target, GLenum internal_format, GLuint firstLevel, GLuint lastLevel,
                GLuint width0, GLuint height0, GLuint depth0,
                GLuint bpp, GLuint tilebits, GLuint compressed)
 {
        radeon_mipmap_tree *mt = CALLOC_STRUCT(_radeon_mipmap_tree);
 
        mt->radeon = rmesa;
+       mt->internal_format = internal_format;
        mt->refcount = 1;
        mt->t = t;
        mt->target = target;
@@ -318,8 +319,8 @@ GLboolean radeon_miptree_matches_image(radeon_mipmap_tree *mt,
        if (face >= mt->faces || level < mt->firstLevel || level > mt->lastLevel)
                return GL_FALSE;
 
-       if ((!texImage->IsCompressed && mt->compressed) ||
-           (texImage->IsCompressed && !mt->compressed))
+       if (texImage->InternalFormat != mt->internal_format ||
+           texImage->IsCompressed != mt->compressed)
                return GL_FALSE;
 
        if (!texImage->IsCompressed &&
@@ -369,9 +370,9 @@ GLboolean radeon_miptree_matches_texture(radeon_mipmap_tree *mt, struct gl_textu
  * given image in the given position.
  */
 void radeon_try_alloc_miptree(radeonContextPtr rmesa, radeonTexObj *t,
-               struct gl_texture_image *texImage, GLuint face, GLuint level)
+               radeon_texture_image *image, GLuint face, GLuint level)
 {
-       GLuint compressed = texImage->IsCompressed ? texImage->TexFormat->MesaFormat : 0;
+       GLuint compressed = image->base.IsCompressed ? image->base.TexFormat->MesaFormat : 0;
        GLuint numfaces = 1;
        GLuint firstLevel, lastLevel;
 
@@ -385,9 +386,10 @@ void radeon_try_alloc_miptree(radeonContextPtr rmesa, radeonTexObj *t,
                return;
 
        t->mt = radeon_miptree_create(rmesa, t, t->base.Target,
+               image->base.InternalFormat,
                firstLevel, lastLevel,
-               texImage->Width, texImage->Height, texImage->Depth,
-               texImage->TexFormat->TexelBytes, t->tile_bits, compressed);
+               image->base.Width, image->base.Height, image->base.Depth,
+               image->base.TexFormat->TexelBytes, t->tile_bits, compressed);
 }
 
 /* Although we use the image_offset[] array to store relative offsets
index 7ece688493dac4d2a6cc26cae14175b0eb124ecb..db28252da374045d9574811b40c1ea4c03b8cd64 100644 (file)
@@ -67,6 +67,7 @@ struct _radeon_mipmap_tree {
        GLuint totalsize; /** total size of the miptree, in bytes */
 
        GLenum target; /** GL_TEXTURE_xxx */
+       GLenum internal_format;
        GLuint faces; /** # of faces: 6 for cubemaps, 1 otherwise */
        GLuint firstLevel; /** First mip level stored in this mipmap tree */
        GLuint lastLevel; /** Last mip level stored in this mipmap tree */
@@ -83,7 +84,7 @@ struct _radeon_mipmap_tree {
 };
 
 radeon_mipmap_tree* radeon_miptree_create(radeonContextPtr rmesa, radeonTexObj *t,
-               GLenum target, GLuint firstLevel, GLuint lastLevel,
+               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);
@@ -93,7 +94,7 @@ GLboolean radeon_miptree_matches_image(radeon_mipmap_tree *mt,
                struct gl_texture_image *texImage, GLuint face, GLuint level);
 GLboolean radeon_miptree_matches_texture(radeon_mipmap_tree *mt, struct gl_texture_object *texObj);
 void radeon_try_alloc_miptree(radeonContextPtr rmesa, radeonTexObj *t,
-                             struct gl_texture_image *texImage, GLuint face, GLuint level);
+                             radeon_texture_image *texImage, GLuint face, GLuint level);
 GLuint radeon_miptree_image_offset(radeon_mipmap_tree *mt,
                                   GLuint face, GLuint level);
 void radeon_miptree_depth_offsets(radeon_mipmap_tree *mt, GLuint level, GLuint *offsets);
index 181b23c3966d19d934a1fa6ebb537f9af8ab45f7..fad3d1cedaf4174ede249dedb7db17cbf2250536 100644 (file)
@@ -579,7 +579,7 @@ static void radeon_teximage(
        }
 
        if (!t->mt)
-               radeon_try_alloc_miptree(rmesa, t, texImage, face, level);
+               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;
@@ -966,7 +966,7 @@ int radeon_validate_texture_miptree(GLcontext * ctx, struct gl_texture_object *t
        if (!t->mt) {
                if (RADEON_DEBUG & RADEON_TEXTURE)
                        fprintf(stderr, " Allocate new miptree\n");
-               radeon_try_alloc_miptree(rmesa, t, &baseimage->base, 0, texObj->BaseLevel);
+               radeon_try_alloc_miptree(rmesa, t, baseimage, 0, texObj->BaseLevel);
                if (!t->mt) {
                        _mesa_problem(ctx, "radeon_validate_texture failed to alloc miptree");
                        return GL_FALSE;