r300: fix depth write regression (found by Nicolai Haehnle)
[mesa.git] / src / mesa / drivers / dri / r300 / r300_texmem.c
index 13178e9973ccec44bc943a546b2d5d306bbd6d81..b03eefaa7c56afdf20744ebddcd02d97d977fa67 100644 (file)
@@ -28,29 +28,27 @@ SOFTWARE.
 
 **************************************************************************/
 
-/*
- * Authors:
- *   Kevin E. Martin <martin@valinux.com>
- *   Gareth Hughes <gareth@valinux.com>
+/**
+ * \file
+ *
+ * \author Gareth Hughes <gareth@valinux.com>
  *
+ * \author Kevin E. Martin <martin@valinux.com>
  */
 
 #include <errno.h>
 
-#include "glheader.h"
-#include "imports.h"
-#include "context.h"
-#include "colormac.h"
-#include "macros.h"
-#include "simple_list.h"
+#include "main/glheader.h"
+#include "main/imports.h"
+#include "main/context.h"
+#include "main/colormac.h"
+#include "main/macros.h"
+#include "main/simple_list.h"
 #include "radeon_reg.h"                /* gets definition for usleep */
 #include "r300_context.h"
 #include "r300_state.h"
 #include "r300_cmdbuf.h"
 #include "radeon_ioctl.h"
-/*
-#include "r300_swtcl.h"
-*/
 #include "r300_tex.h"
 #include "r300_ioctl.h"
 #include <unistd.h>            /* for usleep() */
@@ -65,29 +63,16 @@ SOFTWARE.
  */
 void r300DestroyTexObj(r300ContextPtr rmesa, r300TexObjPtr t)
 {
+       int i;
+
        if (RADEON_DEBUG & DEBUG_TEXTURE) {
                fprintf(stderr, "%s( %p, %p )\n", __FUNCTION__,
                        (void *)t, (void *)t->base.tObj);
        }
 
-       if (rmesa != NULL) {
-               unsigned i;
-
-               for (i = 0; i < rmesa->radeon.glCtx->Const.MaxTextureUnits; i++) {
-                       if (t == rmesa->state.texture.unit[i].texobj) {
-                               rmesa->state.texture.unit[i].texobj = NULL;
-                               /* This code below is meant to shorten state
-                                  pushed to the hardware by not programming
-                                  unneeded units.
-
-                                  This does not appear to be worthwhile on R300 */
-#if 0
-                               remove_from_list(&rmesa->hw.tex[i]);
-                               make_empty_list(&rmesa->hw.tex[i]);
-                               remove_from_list(&rmesa->hw.cube[i]);
-                               make_empty_list(&rmesa->hw.cube[i]);
-#endif
-                       }
+       for (i = 0; i < rmesa->radeon.glCtx->Const.MaxTextureUnits; i++) {
+               if (rmesa->state.texture.unit[i].texobj == t) {
+                       rmesa->state.texture.unit[i].texobj = NULL;
                }
        }
 }
@@ -298,10 +283,10 @@ static void r300UploadRectSubImage(r300ContextPtr rmesa,
  * Upload the texture image associated with texture \a t at the specified
  * level at the address relative to \a start.
  */
-static void uploadSubImage(r300ContextPtr rmesa, r300TexObjPtr t,
-                          GLint hwlevel,
-                          GLint x, GLint y, GLint width, GLint height,
-                          GLuint face)
+static void r300UploadSubImage(r300ContextPtr rmesa, r300TexObjPtr t,
+                              GLint hwlevel,
+                              GLint x, GLint y, GLint width, GLint height,
+                              GLuint face)
 {
        struct gl_texture_image *texImage = NULL;
        GLuint offset;
@@ -364,7 +349,7 @@ static void uploadSubImage(r300ContextPtr rmesa, r300TexObjPtr t,
        imageWidth = texImage->Width;
        imageHeight = texImage->Height;
 
-       offset = t->bufAddr + t->base.totalSize / 6 * face;
+       offset = t->bufAddr;
 
        if (RADEON_DEBUG & (DEBUG_TEXTURE | DEBUG_IOCTL)) {
                GLint imageX = 0;
@@ -510,6 +495,9 @@ int r300UploadTexImages(r300ContextPtr rmesa, r300TexObjPtr t, GLuint face)
 {
        const int numLevels = t->base.lastLevel - t->base.firstLevel + 1;
 
+       if (t->image_override)
+               return 0;
+
        if (RADEON_DEBUG & (DEBUG_TEXTURE | DEBUG_IOCTL)) {
                fprintf(stderr, "%s( %p, %p ) sz=%d lvls=%d-%d\n", __FUNCTION__,
                        (void *)rmesa->radeon.glCtx, (void *)t->base.tObj,
@@ -517,7 +505,7 @@ int r300UploadTexImages(r300ContextPtr rmesa, r300TexObjPtr t, GLuint face)
                        t->base.lastLevel);
        }
 
-       if (!t || t->base.totalSize == 0)
+       if (t->base.totalSize == 0)
                return 0;
 
        if (RADEON_DEBUG & DEBUG_SYNC) {
@@ -546,10 +534,6 @@ int r300UploadTexImages(r300ContextPtr rmesa, r300TexObjPtr t, GLuint face)
                        /* hope it's safe to add that here... */
                        t->offset |= t->tile_bits;
                }
-
-               /* Mark this texobj as dirty on all units:
-                */
-               t->dirty_state = TEX_ALL;
        }
 
        /* Let the world know we've used this memory recently.
@@ -565,9 +549,10 @@ int r300UploadTexImages(r300ContextPtr rmesa, r300TexObjPtr t, GLuint face)
                             dirty_images[face] & (1 <<
                                                   (i + t->base.firstLevel))) !=
                            0) {
-                               uploadSubImage(rmesa, t, i, 0, 0,
-                                              t->image[face][i].width,
-                                              t->image[face][i].height, face);
+                               r300UploadSubImage(rmesa, t, i, 0, 0,
+                                                  t->image[face][i].width,
+                                                  t->image[face][i].height,
+                                                  face);
                        }
                }
                t->base.dirty_images[face] = 0;