r300: fixup mipmap + texsubimage issues
authorDave Airlie <airlied@redhat.com>
Mon, 2 Feb 2009 23:49:45 +0000 (09:49 +1000)
committerDave Airlie <airlied@redhat.com>
Mon, 2 Feb 2009 23:49:45 +0000 (09:49 +1000)
This fixes a few regression in piglit, and adds some debug to the mipmap code

src/mesa/drivers/dri/r300/r300_tex.c
src/mesa/drivers/dri/r300/r300_texstate.c
src/mesa/drivers/dri/radeon/common_misc.c
src/mesa/drivers/dri/radeon/common_misc.h
src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c

index 11e89ffd0f0bc6ef13d45d4fb58517bed808bd0f..989aa462aead0389da99b5a96a8c692e8edc11f8 100644 (file)
@@ -334,7 +334,7 @@ void r300InitTextureFuncs(struct dd_function_table *functions)
        functions->CompressedTexImage2D = radeonCompressedTexImage2D;
        functions->CompressedTexSubImage2D = radeonCompressedTexSubImage2D;
 
-       functions->GenerateMipmap = radeon_generate_mipmap;
+       functions->GenerateMipmap = radeonGenerateMipmap;
 
        driInitTextureFormats();
 }
index 7ffc15fe39dbfc28954b2d5a3878b44279122b3a..6e2b1309c5d052495bf2ed54b68d8b0702de545a 100644 (file)
@@ -225,8 +225,9 @@ static void setup_hardware_state(r300ContextPtr rmesa, radeonTexObj *t)
                t->pp_txformat |= R300_TX_FORMAT_3D;
 
        t->pp_txsize = (((firstImage->Width - 1) << R300_TX_WIDTHMASK_SHIFT)
-               | ((firstImage->Height - 1) << R300_TX_HEIGHTMASK_SHIFT))
-               | ((t->mt->lastLevel - t->mt->firstLevel) << R300_TX_MAX_MIP_LEVEL_SHIFT);
+                       | ((firstImage->Height - 1) << R300_TX_HEIGHTMASK_SHIFT)
+                       | ((firstImage->DepthLog2) << R300_TX_DEPTHMASK_SHIFT)
+                       | ((t->mt->lastLevel - t->mt->firstLevel) << R300_TX_MAX_MIP_LEVEL_SHIFT));
 
        if (t->base.Target == GL_TEXTURE_RECTANGLE_NV) {
                unsigned int align = (64 / t->mt->bpp) - 1;
index bc84b67f001899b4808da1c8d8c4afebe25ba138..162057ca9e958e678664bdf7080383f1503c8428 100644 (file)
@@ -1476,13 +1476,42 @@ GLuint radeon_face_for_target(GLenum target)
  * This relies on internal details of _mesa_generate_mipmap, in particular
  * the fact that the memory for recreated texture images is always freed.
  */
-void radeon_generate_mipmap(GLcontext* ctx, GLenum target, struct gl_texture_object *texObj)
+void radeon_generate_mipmap(GLcontext *ctx, GLenum target,
+                           struct gl_texture_object *texObj)
+{
+       radeonTexObj* t = radeon_tex_obj(texObj);
+       GLuint nr_faces = (t->base.Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1;
+       int i, face;
+
+
+       _mesa_generate_mipmap(ctx, target, texObj);
+
+       for (face = 0; face < nr_faces; face++) {
+               for (i = texObj->BaseLevel + 1; i < texObj->MaxLevel; i++) {
+                       radeon_texture_image *image;
+
+                       image = get_radeon_texture_image(texObj->Image[face][i]);
+
+                       if (image == NULL)
+                               break;
+
+                       image->mtlevel = i;
+                       image->mtface = face;
+
+                       radeon_miptree_unreference(image->mt);
+                       image->mt = NULL;
+               }
+       }
+       
+}
+
+void radeonGenerateMipmap(GLcontext* ctx, GLenum target, struct gl_texture_object *texObj)
 {
        GLuint face = radeon_face_for_target(target);
        radeon_texture_image *baseimage = get_radeon_texture_image(texObj->Image[face][texObj->BaseLevel]);
 
        radeon_teximage_map(baseimage, GL_FALSE);
-       _mesa_generate_mipmap(ctx, target, texObj);
+       radeon_generate_mipmap(ctx, target, texObj);
        radeon_teximage_unmap(baseimage);
 }
 
@@ -1803,15 +1832,17 @@ static void radeon_teximage(
                                _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage");
                }
 
-               radeon_teximage_unmap(image);
        }
 
-       _mesa_unmap_teximage_pbo(ctx, packing);
-
        /* SGIS_generate_mipmap */
        if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
-               ctx->Driver.GenerateMipmap(ctx, texObj->Target, texObj);
+               radeon_generate_mipmap(ctx, texObj->Target, texObj);
        }
+       radeon_teximage_unmap(image);
+
+       _mesa_unmap_teximage_pbo(ctx, packing);
+
+
 }
 
 void radeonTexImage1D(GLcontext * ctx, GLenum target, GLint level,
@@ -1878,13 +1909,15 @@ static void radeon_texsubimage(GLcontext* ctx, int dims, int level,
                const struct gl_pixelstore_attrib *packing,
                struct gl_texture_object *texObj,
                struct gl_texture_image *texImage,
-               int compressed)
+                              int compressed)
 {
        radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
+       radeonTexObj* t = radeon_tex_obj(texObj);
        radeon_texture_image* image = get_radeon_texture_image(texImage);
 
        rmesa->vtbl.flush_vertices(rmesa);
 
+       t->validated = GL_FALSE;
        pixels = _mesa_validate_pbo_teximage(ctx, dims,
                width, height, depth, format, type, pixels, packing, "glTexSubImage1D");
 
@@ -1896,7 +1929,7 @@ static void radeon_texsubimage(GLcontext* ctx, int dims, int level,
                        radeon_mipmap_level *lvl = &image->mt->levels[image->mtlevel];
                        dstRowStride = lvl->rowstride;
                } else {
-                       dstRowStride = texImage->Width * texImage->TexFormat->TexelBytes;
+                       dstRowStride = texImage->RowStride * texImage->TexFormat->TexelBytes;
                }
 
                if (!texImage->TexFormat->StoreImage(ctx, dims, texImage->_BaseFormat,
@@ -1908,15 +1941,18 @@ static void radeon_texsubimage(GLcontext* ctx, int dims, int level,
                                format, type, pixels, packing))
                        _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage");
 
-               radeon_teximage_unmap(image);
-       }
 
-       _mesa_unmap_teximage_pbo(ctx, packing);
+       }
 
        /* GL_SGIS_generate_mipmap */
        if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
-               ctx->Driver.GenerateMipmap(ctx, texObj->Target, texObj);
+               radeon_generate_mipmap(ctx, texObj->Target, texObj);
        }
+       radeon_teximage_unmap(image);
+
+       _mesa_unmap_teximage_pbo(ctx, packing);
+
+
 }
 
 void radeonTexSubImage1D(GLcontext * ctx, GLenum target, GLint level,
index 44e464eb139c10534a40ded3bda786f8eee75f23..9bb1d03a0972d5e3cad2bc9bbac9451977d08f4b 100644 (file)
@@ -42,7 +42,7 @@ void radeon_teximage_map(radeon_texture_image *image, GLboolean write_enable);
 void radeon_teximage_unmap(radeon_texture_image *image);
 void radeonMapTexture(GLcontext *ctx, struct gl_texture_object *texObj);
 void radeonUnmapTexture(GLcontext *ctx, struct gl_texture_object *texObj);
-void radeon_generate_mipmap(GLcontext* ctx, GLenum target, struct gl_texture_object *texObj);
+void radeonGenerateMipmap(GLcontext* ctx, GLenum target, struct gl_texture_object *texObj);
 int radeon_validate_texture_miptree(GLcontext * ctx, struct gl_texture_object *texObj);
 GLuint radeon_face_for_target(GLenum target);
 const struct gl_texture_format *radeonChooseTextureFormat(GLcontext * ctx,
index 955d4b71ed515fee333e8cd4b22faf3058308978..323726c57496d6f281309c217811b5e33d437438 100644 (file)
@@ -101,6 +101,11 @@ static void compute_tex_image_offset(radeon_mipmap_tree *mt,
        *curOffset = (*curOffset + 0x1f) & ~0x1f;
        lvl->faces[face].offset = *curOffset;
        *curOffset += lvl->size;
+
+       if (RADEON_DEBUG & DEBUG_TEXTURE)
+         fprintf(stderr,
+                 "level %d, face %d: rs:%d %dx%d at %d\n",
+                 level, face, lvl->rowstride, lvl->width, lvl->height, lvl->faces[face].offset);
 }
 
 static GLuint minify(GLuint size, GLuint levels)