[Mesa-dev] [PATCH 1/3] mesa: move gl_texture_image::Data, RowStride, ImageOffsets to swrast

Brian Paul brian.e.paul at gmail.com
Mon Oct 10 19:27:44 PDT 2011


From: Brian Paul <brianp at vmware.com>

Only swrast and the drivers that fall back to swrast need these fields now.
This removes the last of the fields related to software rendering from
gl_texture_image.
---
 src/mesa/drivers/dri/intel/intel_mipmap_tree.c   |   10 +-
 src/mesa/drivers/dri/intel/intel_tex.c           |   31 ++++++-
 src/mesa/drivers/dri/intel/intel_tex_image.c     |    2 +-
 src/mesa/drivers/dri/intel/intel_tex_validate.c  |   21 +----
 src/mesa/drivers/dri/nouveau/nouveau_texture.c   |   24 +++--
 src/mesa/drivers/dri/nouveau/nouveau_texture.h   |    4 +-
 src/mesa/drivers/dri/r200/r200_texstate.c        |    2 +-
 src/mesa/drivers/dri/r300/r300_texstate.c        |    2 +-
 src/mesa/drivers/dri/r600/evergreen_tex.c        |    2 +-
 src/mesa/drivers/dri/r600/r600_texstate.c        |    2 +-
 src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c |    8 +-
 src/mesa/drivers/dri/radeon/radeon_texstate.c    |    2 +-
 src/mesa/drivers/dri/radeon/radeon_texture.c     |  103 +++++++++------------
 src/mesa/drivers/dri/swrast/swrast.c             |    5 +-
 src/mesa/main/mtypes.h                           |    5 -
 src/mesa/main/texcompress.c                      |    4 +-
 src/mesa/main/texcompress_fxt1.c                 |    4 +-
 src/mesa/main/texcompress_rgtc.c                 |   24 +++---
 src/mesa/main/texcompress_s3tc.c                 |   18 ++--
 src/mesa/main/teximage.c                         |   14 ++--
 src/mesa/main/texstore.c                         |    1 -
 src/mesa/swrast/s_context.h                      |   16 +---
 src/mesa/swrast/s_texfetch_tmp.h                 |    8 +-
 src/mesa/swrast/s_texfilter.c                    |    6 +-
 src/mesa/swrast/s_texrender.c                    |    2 +-
 src/mesa/swrast/s_texture.c                      |   40 +++++++--
 src/mesa/swrast/s_triangle.c                     |   18 +++-
 27 files changed, 201 insertions(+), 177 deletions(-)

diff --git a/src/mesa/drivers/dri/intel/intel_mipmap_tree.c b/src/mesa/drivers/dri/intel/intel_mipmap_tree.c
index dbdc5ef..6b15c42 100644
--- a/src/mesa/drivers/dri/intel/intel_mipmap_tree.c
+++ b/src/mesa/drivers/dri/intel/intel_mipmap_tree.c
@@ -417,8 +417,8 @@ intel_miptree_copy_teximage(struct intel_context *intel,
 	     dst_mt, dst_x, dst_y, dst_mt->region->pitch * dst_mt->region->cpp,
 	     width, height);
 
-	 src = intelImage->base.Base.Data;
-	 src += (intelImage->base.Base.RowStride *
+	 src = intelImage->base.Data;
+	 src += (intelImage->base.RowStride *
 		 intelImage->base.Base.Height *
 		 dst_mt->region->cpp *
 		 slice);
@@ -429,7 +429,7 @@ intel_miptree_copy_teximage(struct intel_context *intel,
 			 dst_x, dst_y,
 			 width, height,
 			 src,
-			 intelImage->base.Base.RowStride,
+			 intelImage->base.RowStride,
 			 0, 0);
 
 	 intel_region_unmap(intel, dst_mt->region);
@@ -437,8 +437,8 @@ intel_miptree_copy_teximage(struct intel_context *intel,
    }
 
    if (!src_mt) {
-      _mesa_free_texmemory(intelImage->base.Base.Data);
-      intelImage->base.Base.Data = NULL;
+      _mesa_free_texmemory(intelImage->base.Data);
+      intelImage->base.Data = NULL;
    }
 
    intel_miptree_reference(&intelImage->mt, dst_mt);
diff --git a/src/mesa/drivers/dri/intel/intel_tex.c b/src/mesa/drivers/dri/intel/intel_tex.c
index 83ba50e..7cbd0f5 100644
--- a/src/mesa/drivers/dri/intel/intel_tex.c
+++ b/src/mesa/drivers/dri/intel/intel_tex.c
@@ -59,6 +59,7 @@ intel_alloc_texture_image_buffer(struct gl_context *ctx,
    struct intel_texture_image *intel_image = intel_texture_image(image);
    struct gl_texture_object *texobj = image->TexObject;
    struct intel_texture_object *intel_texobj = intel_texture_object(texobj);
+   GLuint slices;
 
    /* Because the driver uses AllocTextureImageBuffer() internally, it may end
     * up mismatched with FreeTextureImageBuffer(), but that is safe to call
@@ -71,6 +72,21 @@ intel_alloc_texture_image_buffer(struct gl_context *ctx,
       intel_tex_image_s8z24_create_renderbuffers(intel, intel_image);
    }
 
+   /* Allocate the swrast_texture_image::ImageOffsets array now */
+   switch (texobj->Target) {
+   case GL_TEXTURE_3D:
+   case GL_TEXTURE_2D_ARRAY:
+      slices = image->Depth;
+      break;
+   case GL_TEXTURE_1D_ARRAY:
+      slices = image->Height;
+      break;
+   default:
+      slices = 1;
+   }
+   assert(!intel_image->base.ImageOffsets);
+   intel_image->base.ImageOffsets = malloc(slices * sizeof(GLuint));
+
    if (intel_texobj->mt &&
        intel_miptree_match_image(intel_texobj->mt, image)) {
       intel_miptree_reference(&intel_image->mt, intel_texobj->mt);
@@ -113,9 +129,14 @@ intel_free_texture_image_buffer(struct gl_context * ctx,
 
    intel_miptree_release(&intelImage->mt);
 
-   if (texImage->Data) {
-      _mesa_free_texmemory(texImage->Data);
-      texImage->Data = NULL;
+   if (intelImage->base.Data) {
+      _mesa_free_texmemory(intelImage->base.Data);
+      intelImage->base.Data = NULL;
+   }
+
+   if (intelImage->base.ImageOffsets) {
+      free(intelImage->base.ImageOffsets);
+      intelImage->base.ImageOffsets = NULL;
    }
 
    _mesa_reference_renderbuffer(&intelImage->depth_rb, NULL);
@@ -187,11 +208,11 @@ intel_map_texture_image(struct gl_context *ctx,
       assert(map);
 
       *stride = _mesa_format_row_stride(tex_image->TexFormat, width);
-      *map = tex_image->Data + (slice * height + y) * *stride + x * texelSize;
+      *map = intel_image->base.Data + (slice * height + y) * *stride + x * texelSize;
 
       DBG("%s: %d,%d %dx%d from data %p = %p/%d\n", __FUNCTION__,
 	  x, y, w, h,
-	  tex_image->Data, *map, *stride);
+	  intel_image->base.Data, *map, *stride);
    }
 }
 
diff --git a/src/mesa/drivers/dri/intel/intel_tex_image.c b/src/mesa/drivers/dri/intel/intel_tex_image.c
index 6c6e8a7..c34b4c5 100644
--- a/src/mesa/drivers/dri/intel/intel_tex_image.c
+++ b/src/mesa/drivers/dri/intel/intel_tex_image.c
@@ -454,7 +454,7 @@ intel_set_texture_image_region(struct gl_context *ctx,
    if (intel_image->mt == NULL)
        return;
 
-   image->RowStride = region->pitch;
+   intel_image->base.RowStride = region->pitch;
 }
 
 void
diff --git a/src/mesa/drivers/dri/intel/intel_tex_validate.c b/src/mesa/drivers/dri/intel/intel_tex_validate.c
index 50dc8c0..cce4519 100644
--- a/src/mesa/drivers/dri/intel/intel_tex_validate.c
+++ b/src/mesa/drivers/dri/intel/intel_tex_validate.c
@@ -143,40 +143,29 @@ intel_tex_map_image_for_swrast(struct intel_context *intel,
        mt->target == GL_TEXTURE_1D_ARRAY) {
       int i;
 
-      if (mt->target == GL_TEXTURE_2D_ARRAY ||
-          mt->target == GL_TEXTURE_1D_ARRAY) {
-         /* Mesa only allocates one entry for these, but we really do have an
-          * offset per depth.
-          */
-         free(intel_image->base.Base.ImageOffsets);
-         intel_image->base.Base.ImageOffsets = malloc(mt->level[level].depth *
-                                                      sizeof(GLuint));
-      }
-
       /* ImageOffsets[] is only used for swrast's fetch_texel_3d, so we can't
        * share code with the normal path.
        */
       for (i = 0; i < mt->level[level].depth; i++) {
 	 intel_miptree_get_image_offset(mt, level, face, i, &x, &y);
-	 intel_image->base.Base.ImageOffsets[i] = x + y * mt->region->pitch;
+	 intel_image->base.ImageOffsets[i] = x + y * mt->region->pitch;
       }
 
       DBG("%s \n", __FUNCTION__);
 
-      intel_image->base.Base.Data = intel_region_map(intel, mt->region);
+      intel_image->base.Data = intel_region_map(intel, mt->region);
    } else {
       assert(mt->level[level].depth == 1);
       intel_miptree_get_image_offset(mt, level, face, 0, &x, &y);
-      intel_image->base.Base.ImageOffsets[0] = 0;
 
       DBG("%s: (%d,%d) -> (%d, %d)/%d\n",
 	  __FUNCTION__, face, level, x, y, mt->region->pitch * mt->cpp);
 
-      intel_image->base.Base.Data = intel_region_map(intel, mt->region) +
+      intel_image->base.Data = intel_region_map(intel, mt->region) +
 	 (x + y * mt->region->pitch) * mt->cpp;
    }
 
-   intel_image->base.Base.RowStride = mt->region->pitch;
+   intel_image->base.RowStride = mt->region->pitch;
 }
 
 static void
@@ -185,7 +174,7 @@ intel_tex_unmap_image_for_swrast(struct intel_context *intel,
 {
    if (intel_image && intel_image->mt) {
       intel_region_unmap(intel, intel_image->mt->region);
-      intel_image->base.Base.Data = NULL;
+      intel_image->base.Data = NULL;
    }
 }
 
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_texture.c b/src/mesa/drivers/dri/nouveau/nouveau_texture.c
index 2212d89..08ec03e 100644
--- a/src/mesa/drivers/dri/nouveau/nouveau_texture.c
+++ b/src/mesa/drivers/dri/nouveau/nouveau_texture.c
@@ -68,7 +68,7 @@ nouveau_teximage_new(struct gl_context *ctx)
 {
 	struct nouveau_teximage *nti = CALLOC_STRUCT(nouveau_teximage);
 
-	return &nti->base;
+	return &nti->base.Base;
 }
 
 static void
@@ -103,7 +103,7 @@ nouveau_teximage_map(struct gl_context *ctx, struct gl_texture_image *ti,
 			nti->transfer.x = x;
 			nti->transfer.y = y;
 
-			ti->Data = nouveau_get_scratch(ctx, st->pitch * h,
+			nti->base.Data = nouveau_get_scratch(ctx, st->pitch * h,
 						       &st->bo, &st->offset);
 
 		} else {
@@ -119,7 +119,7 @@ nouveau_teximage_map(struct gl_context *ctx, struct gl_texture_image *ti,
 				assert(!ret);
 			}
 
-			ti->Data = s->bo->map + y * s->pitch + x * s->cpp;
+			nti->base.Data = s->bo->map + y * s->pitch + x * s->cpp;
 		}
 	}
 }
@@ -141,7 +141,7 @@ nouveau_teximage_unmap(struct gl_context *ctx, struct gl_texture_image *ti)
 		nouveau_bo_unmap(s->bo);
 	}
 
-	ti->Data = NULL;
+	nti->base.Data = NULL;
 }
 
 
@@ -197,7 +197,7 @@ nouveau_map_texture_image(struct gl_context *ctx,
 			*stride = s->pitch;
 		}
 	} else {
-		*map = ti->Data + y * s->pitch + x * s->cpp;
+		*map = nti->base.Data + y * s->pitch + x * s->cpp;
 		*stride = s->pitch;
 	}
 }
@@ -220,7 +220,7 @@ nouveau_unmap_texture_image(struct gl_context *ctx, struct gl_texture_image *ti,
 		nouveau_bo_unmap(s->bo);
 	}
 
-	ti->Data = NULL;
+	nti->base.Data = NULL;
 }
 
 static gl_format
@@ -461,12 +461,13 @@ nouveau_teximage(struct gl_context *ctx, GLint dims, GLenum target, GLint level,
 		 struct gl_texture_image *ti)
 {
 	struct nouveau_surface *s = &to_nouveau_teximage(ti)->surface;
+	struct nouveau_teximage *nti = to_nouveau_teximage(ti);
 	int ret;
 
 	/* Allocate a new bo for the image. */
 	nouveau_surface_alloc(ctx, s, LINEAR, get_teximage_placement(ti),
 			      ti->TexFormat, width, height);
-	ti->RowStride = s->pitch / s->cpp;
+	nti->base.RowStride = s->pitch / s->cpp;
 
 	pixels = _mesa_validate_pbo_teximage(ctx, dims, width, height, depth,
 					     format, type, pixels, packing,
@@ -479,7 +480,7 @@ nouveau_teximage(struct gl_context *ctx, GLint dims, GLenum target, GLint level,
 		ret = _mesa_texstore(ctx, dims, ti->_BaseFormat,
 				     ti->TexFormat,
 				     0, 0, 0, s->pitch,
-                                     (GLubyte **) &ti->Data,
+                                     &nti->base.Data,
 				     width, height, depth,
 				     format, type, pixels, packing);
 		assert(ret);
@@ -555,6 +556,7 @@ nouveau_texsubimage(struct gl_context *ctx, GLint dims, GLenum target, GLint lev
 		    struct gl_texture_image *ti)
 {
 	struct nouveau_surface *s = &to_nouveau_teximage(ti)->surface;
+	struct nouveau_teximage *nti = to_nouveau_teximage(ti);
 	int ret;
 
 	pixels = _mesa_validate_pbo_teximage(ctx, dims, width, height, depth,
@@ -566,7 +568,7 @@ nouveau_texsubimage(struct gl_context *ctx, GLint dims, GLenum target, GLint lev
 
 		ret = _mesa_texstore(ctx, 3, ti->_BaseFormat, ti->TexFormat,
                                      0, 0, 0, s->pitch,
-				     (GLubyte **) &ti->Data,
+				     &nti->base.Data,
                                      width, height, depth,
 				     format, type, pixels, packing);
 		assert(ret);
@@ -654,10 +656,12 @@ nouveau_set_texbuffer(__DRIcontext *dri_ctx,
 		fb->Attachment[BUFFER_FRONT_LEFT].Renderbuffer;
 	struct gl_texture_object *t = _mesa_get_current_tex_object(ctx, target);
 	struct gl_texture_image *ti;
+	struct nouveau_teximage *nti;
 	struct nouveau_surface *s;
 
 	_mesa_lock_texture(ctx, t);
 	ti = _mesa_get_tex_image(ctx, t, target, 0);
+	nti = to_nouveau_teximage(ti);
 	s = &to_nouveau_teximage(ti)->surface;
 
 	/* Update the texture surface with the given drawable. */
@@ -669,7 +673,7 @@ nouveau_set_texbuffer(__DRIcontext *dri_ctx,
 	/* Update the image fields. */
 	_mesa_init_teximage_fields(ctx, target, ti, s->width, s->height,
 				   1, 0, s->cpp, s->format);
-	ti->RowStride = s->pitch / s->cpp;
+	nti->base.RowStride = s->pitch / s->cpp;
 
 	/* Try to validate it. */
 	if (!validate_teximage(ctx, t, 0, 0, 0, 0, s->width, s->height, 1))
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_texture.h b/src/mesa/drivers/dri/nouveau/nouveau_texture.h
index 56e61c7..562429f 100644
--- a/src/mesa/drivers/dri/nouveau/nouveau_texture.h
+++ b/src/mesa/drivers/dri/nouveau/nouveau_texture.h
@@ -27,8 +27,10 @@
 #ifndef __NOUVEAU_TEXTURE_H__
 #define __NOUVEAU_TEXTURE_H__
 
+#include "swrast/s_context.h"
+
 struct nouveau_teximage {
-	struct gl_texture_image base;
+	struct swrast_texture_image base;
 	struct nouveau_surface surface;
 	struct {
 		struct nouveau_surface surface;
diff --git a/src/mesa/drivers/dri/r200/r200_texstate.c b/src/mesa/drivers/dri/r200/r200_texstate.c
index cb3f245..0261840 100644
--- a/src/mesa/drivers/dri/r200/r200_texstate.c
+++ b/src/mesa/drivers/dri/r200/r200_texstate.c
@@ -846,7 +846,7 @@ void r200SetTexBuffer2(__DRIcontext *pDRICtx, GLint target, GLint texture_format
 	_mesa_init_teximage_fields(radeon->glCtx, target, texImage,
 				   rb->base.Width, rb->base.Height, 1, 0,
 				   rb->cpp, texFormat);
-	texImage->RowStride = rb->pitch / rb->cpp;
+	rImage->base.RowStride = rb->pitch / rb->cpp;
 
 
         t->pp_txsize = ((rb->base.Width - 1) << RADEON_TEX_USIZE_SHIFT)
diff --git a/src/mesa/drivers/dri/r300/r300_texstate.c b/src/mesa/drivers/dri/r300/r300_texstate.c
index e73e79b..26ab0e5 100644
--- a/src/mesa/drivers/dri/r300/r300_texstate.c
+++ b/src/mesa/drivers/dri/r300/r300_texstate.c
@@ -498,7 +498,7 @@ void r300SetTexBuffer2(__DRIcontext *pDRICtx, GLint target, GLint texture_format
 	_mesa_init_teximage_fields(radeon->glCtx, target, texImage,
 				   rb->base.Width, rb->base.Height, 1, 0,
 				   rb->cpp, texFormat);
-	texImage->RowStride = rb->pitch / rb->cpp;
+	rImage->base.RowStride = rb->pitch / rb->cpp;
 
 
 	pitch_val--;
diff --git a/src/mesa/drivers/dri/r600/evergreen_tex.c b/src/mesa/drivers/dri/r600/evergreen_tex.c
index b2b67b0..c94a717 100644
--- a/src/mesa/drivers/dri/r600/evergreen_tex.c
+++ b/src/mesa/drivers/dri/r600/evergreen_tex.c
@@ -1404,7 +1404,7 @@ void evergreenSetTexBuffer(__DRIcontext *pDRICtx, GLint target, GLint glx_textur
 	_mesa_init_teximage_fields(radeon->glCtx, target, texImage,
 				   rb->base.Width, rb->base.Height, 1, 0,
 				   rb->cpp, texFormat);
-	texImage->RowStride = rb->pitch / rb->cpp;
+	rImage->base.RowStride = rb->pitch / rb->cpp;
 
 	pitch_val = (pitch_val + R700_TEXEL_PITCH_ALIGNMENT_MASK)
 		& ~R700_TEXEL_PITCH_ALIGNMENT_MASK;
diff --git a/src/mesa/drivers/dri/r600/r600_texstate.c b/src/mesa/drivers/dri/r600/r600_texstate.c
index b3fe544..e0c5011 100644
--- a/src/mesa/drivers/dri/r600/r600_texstate.c
+++ b/src/mesa/drivers/dri/r600/r600_texstate.c
@@ -1257,7 +1257,7 @@ void r600SetTexBuffer2(__DRIcontext *pDRICtx, GLint target, GLint glx_texture_fo
 	_mesa_init_teximage_fields(radeon->glCtx, target, texImage,
 				   rb->base.Width, rb->base.Height, 1, 0,
 				   rb->cpp, texFormat);
-	texImage->RowStride = rb->pitch / rb->cpp;
+	rImage->base.RowStride = rb->pitch / rb->cpp;
 
 	pitch_val = (pitch_val + R700_TEXEL_PITCH_ALIGNMENT_MASK)
 		& ~R700_TEXEL_PITCH_ALIGNMENT_MASK;
diff --git a/src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c b/src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c
index f1febd3..8daeb5e 100644
--- a/src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c
+++ b/src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c
@@ -480,7 +480,7 @@ static void migrate_image_to_miptree(radeon_mipmap_tree *mt,
 		radeon_bo_unmap(image->mt->bo);
 
 		radeon_miptree_unreference(&image->mt);
-	} else if (image->base.Base.Data) {
+	} else if (image->base.Data) {
 		/* This condition should be removed, it's here to workaround
 		 * a segfault when mapping textures during software fallbacks.
 		 */
@@ -496,11 +496,11 @@ static void migrate_image_to_miptree(radeon_mipmap_tree *mt,
 			rows = (rows + blockHeight - 1) / blockHeight;
 		}
 
-		copy_rows(dest, dstlvl->rowstride, image->base.Base.Data, srcrowstride,
+		copy_rows(dest, dstlvl->rowstride, image->base.Data, srcrowstride,
 				  rows, srcrowstride);
 
-		_mesa_free_texmemory(image->base.Base.Data);
-		image->base.Base.Data = 0;
+		_mesa_free_texmemory(image->base.Data);
+		image->base.Data = 0;
 	}
 
 	radeon_bo_unmap(mt->bo);
diff --git a/src/mesa/drivers/dri/radeon/radeon_texstate.c b/src/mesa/drivers/dri/radeon/radeon_texstate.c
index 5c5cd8b..b677678 100644
--- a/src/mesa/drivers/dri/radeon/radeon_texstate.c
+++ b/src/mesa/drivers/dri/radeon/radeon_texstate.c
@@ -720,7 +720,7 @@ void radeonSetTexBuffer2(__DRIcontext *pDRICtx, GLint target, GLint texture_form
 	_mesa_init_teximage_fields(radeon->glCtx, target, texImage,
 				   rb->base.Width, rb->base.Height, 1, 0,
 				   rb->cpp, texFormat);
-	texImage->RowStride = rb->pitch / rb->cpp;
+	rImage->base.RowStride = rb->pitch / rb->cpp;
 
 	t->pp_txpitch &= (1 << 13) -1;
 	pitch_val = rb->pitch;
diff --git a/src/mesa/drivers/dri/radeon/radeon_texture.c b/src/mesa/drivers/dri/radeon/radeon_texture.c
index 24e40e9..2d17d30 100644
--- a/src/mesa/drivers/dri/radeon/radeon_texture.c
+++ b/src/mesa/drivers/dri/radeon/radeon_texture.c
@@ -104,7 +104,7 @@ void radeonFreeTextureImageBuffer(struct gl_context *ctx, struct gl_texture_imag
 
 	if (image->mt) {
 		radeon_miptree_unreference(&image->mt);
-		assert(!image->base.Base.Data);
+		assert(!image->base.Data);
 	} else {
 		_mesa_free_texture_image_data(ctx, timage);
 	}
@@ -112,9 +112,14 @@ void radeonFreeTextureImageBuffer(struct gl_context *ctx, struct gl_texture_imag
 		radeon_bo_unref(image->bo);
 		image->bo = NULL;
 	}
-	if (timage->Data) {
-		_mesa_free_texmemory(timage->Data);
-		timage->Data = NULL;
+	if (image->base.Data) {
+		_mesa_free_texmemory(image->base.Data);
+		image->base.Data = NULL;
+	}
+
+	if (image->base.ImageOffsets) {
+		free(image->base.ImageOffsets);
+		image->base.ImageOffsets = NULL;
 	}
 }
 
@@ -132,8 +137,8 @@ static void teximage_set_map_data(radeon_texture_image *image)
 
 	lvl = &image->mt->levels[image->mtlevel];
 
-	image->base.Base.Data = image->mt->bo->ptr + lvl->faces[image->mtface].offset;
-	image->base.Base.RowStride = lvl->rowstride / _mesa_get_format_bytes(image->base.Base.TexFormat);
+	image->base.Data = image->mt->bo->ptr + lvl->faces[image->mtface].offset;
+	image->base.RowStride = lvl->rowstride / _mesa_get_format_bytes(image->base.Base.TexFormat);
 }
 
 
@@ -147,7 +152,7 @@ void radeon_teximage_map(radeon_texture_image *image, GLboolean write_enable)
 			__func__, image,
 			write_enable ? "true": "false");
 	if (image->mt) {
-		assert(!image->base.Base.Data);
+		assert(!image->base.Data);
 
 		radeon_bo_map(image->mt->bo, write_enable);
 		teximage_set_map_data(image);
@@ -161,9 +166,9 @@ void radeon_teximage_unmap(radeon_texture_image *image)
 			"%s(img %p)\n",
 			__func__, image);
 	if (image->mt) {
-		assert(image->base.Base.Data);
+		assert(image->base.Data);
 
-		image->base.Base.Data = 0;
+		image->base.Data = 0;
 		radeon_bo_unmap(image->mt->bo);
 	}
 }
@@ -174,7 +179,7 @@ static void map_override(struct gl_context *ctx, radeonTexObj *t)
 
 	radeon_bo_map(t->bo, GL_FALSE);
 
-	img->base.Base.Data = t->bo->ptr;
+	img->base.Data = t->bo->ptr;
 }
 
 static void unmap_override(struct gl_context *ctx, radeonTexObj *t)
@@ -183,7 +188,7 @@ static void unmap_override(struct gl_context *ctx, radeonTexObj *t)
 
 	radeon_bo_unmap(t->bo);
 
-	img->base.Base.Data = NULL;
+	img->base.Data = NULL;
 }
 
 /**
@@ -243,8 +248,11 @@ void radeonUnmapTexture(struct gl_context *ctx, struct gl_texture_object *texObj
 	  return;
 
 	for(face = 0; face < t->mt->faces; ++face) {
-		for(level = t->minLod; level <= t->maxLod; ++level)
-			texObj->Image[face][level]->Data = 0;
+		for(level = t->minLod; level <= t->maxLod; ++level) {
+			radeon_texture_image *image =
+				get_radeon_texture_image(texObj->Image[face][level]);
+			image->base.Data = NULL;
+		}
 	}
 	radeon_bo_unmap(t->mt->bo);
 }
@@ -306,7 +314,7 @@ radeon_map_texture_image(struct gl_context *ctx,
 		assert(map);
 
 		*stride = _mesa_format_row_stride(texImage->TexFormat, width);
-		*map = texImage->Data + (slice * height) * *stride;
+		*map = image->base.Data + (slice * height) * *stride;
 	}
 
 	*map += y * *stride + x * texel_size;
@@ -690,26 +698,6 @@ static void teximage_assign_miptree(radeonContextPtr rmesa,
 				"%s Failed to allocate miptree.\n", __func__);
 }
 
-static GLuint * allocate_image_offsets(struct gl_context *ctx,
-	unsigned alignedWidth,
-	unsigned height,
-	unsigned depth)
-{
-	int i;
-	GLuint *offsets;
-
-	offsets = malloc(depth * sizeof(GLuint)) ;
-	if (!offsets) {
-		_mesa_error(ctx, GL_OUT_OF_MEMORY, "glTex[Sub]Image");
-		return NULL;
-	}
-
-	for (i = 0; i < depth; ++i) {
-		offsets[i] = alignedWidth * height * i;
-	}
-
-	return offsets;
-}
 
 /**
  * Update a subregion of the given texture image.
@@ -728,9 +716,11 @@ static void radeon_store_teximage(struct gl_context* ctx, int dims,
 	radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
 	radeonTexObj *t = radeon_tex_obj(texObj);
 	radeon_texture_image* image = get_radeon_texture_image(texImage);
+	GLuint texel_size = _mesa_get_format_bytes(texImage->TexFormat);
 
 	GLuint dstRowStride;
-	GLuint *dstImageOffsets;
+	GLuint alignedWidth;
+	GLint i;
 
 	radeon_print(RADEON_TEXTURE, RADEON_TRACE,
 			"%s(%p, tex %p, image %p) compressed %d\n",
@@ -747,16 +737,13 @@ static void radeon_store_teximage(struct gl_context* ctx, int dims,
 
 	assert(dstRowStride);
 
-	if (dims == 3) {
-		unsigned alignedWidth = dstRowStride/_mesa_get_format_bytes(texImage->TexFormat);
-		dstImageOffsets = allocate_image_offsets(ctx, alignedWidth, texImage->Height, texImage->Depth);
-		if (!dstImageOffsets) {
-			radeon_warning("%s Failed to allocate dstImaeOffset.\n", __func__);
-			return;
-		}
-	} else {
-		dstImageOffsets = texImage->ImageOffsets;
+	/* fill in the ImageOffsets array */
+	alignedWidth = dstRowStride / texel_size;
+	for (i = 0; i < texImage->Depth; ++i) {
+		image->base.ImageOffsets[i] = alignedWidth * texImage->Height * i;
 	}
+	/* and fill in RowStride (in texels) */
+	image->base.RowStride = alignedWidth;
 
 	radeon_teximage_map(image, GL_TRUE);
 
@@ -770,13 +757,13 @@ static void radeon_store_teximage(struct gl_context* ctx, int dims,
 			dstRowStride = _mesa_format_row_stride(texImage->TexFormat, texImage->Width);
 			img_start = _mesa_compressed_image_address(xoffset, yoffset, 0,
 									texImage->TexFormat,
-									texImage->Width, texImage->Data);
+									texImage->Width, image->base.Data);
 		}
 		else {
 			uint32_t offset;
-			offset = dstRowStride / _mesa_get_format_bytes(texImage->TexFormat) * yoffset / block_height + xoffset / block_width;
-			offset *= _mesa_get_format_bytes(texImage->TexFormat);
-			img_start = texImage->Data + offset;
+			offset = dstRowStride / texel_size * yoffset / block_height + xoffset / block_width;
+			offset *= texel_size;
+			img_start = image->base.Data + offset;
 		}
 		srcRowStride = _mesa_format_row_stride(texImage->TexFormat, width);
 		bytesPerRow = srcRowStride;
@@ -786,12 +773,11 @@ static void radeon_store_teximage(struct gl_context* ctx, int dims,
 	}
 	else {
 		GLubyte *slices[512];
-		GLuint texelBytes = _mesa_get_format_bytes(texImage->TexFormat);
 		GLuint i;
 		assert(depth <= 512);
 		for (i = 0; i < depth; i++) {
-			slices[i] = (GLubyte *) texImage->Data
-				+ dstImageOffsets[i] * texelBytes;
+			slices[i] = (GLubyte *) image->base.Data
+				+ image->base.ImageOffsets[i] * texel_size;
 		}
 		if (!_mesa_texstore(ctx, dims, texImage->_BaseFormat,
 					texImage->TexFormat,
@@ -804,10 +790,6 @@ static void radeon_store_teximage(struct gl_context* ctx, int dims,
 		}
 	}
 
-	if (dims == 3) {
-		free(dstImageOffsets);
-	}
-
 	radeon_teximage_unmap(image);
 }
 
@@ -837,7 +819,6 @@ static void radeon_teximage(
 
 	t->validated = GL_FALSE;
 
-	/* Mesa core only clears texImage->Data but not image->mt */
 	radeonFreeTextureImageBuffer(ctx, texImage);
 
 	if (!t->bo) {
@@ -847,11 +828,11 @@ static void radeon_teximage(
 								texImage->Width,
 								texImage->Height,
 								texImage->Depth);
-			texImage->Data = _mesa_alloc_texmemory(size);
+			image->base.Data = _mesa_alloc_texmemory(size);
 			radeon_print(RADEON_TEXTURE, RADEON_VERBOSE,
 					"%s %dd: texObj %p, texImage %p, "
 					" no miptree assigned, using local memory %p\n",
-					__func__, dims, texObj, texImage, texImage->Data);
+					__func__, dims, texObj, texImage, image->base.Data);
 		}
 	}
 
@@ -867,6 +848,10 @@ static void radeon_teximage(
 		}
 	}
 
+	image->base.ImageOffsets =
+		(GLuint *) malloc(texImage->Depth * sizeof(GLuint));
+
+
 	/* Upload texture image; note that the spec allows pixels to be NULL */
 	if (compressed) {
 		pixels = _mesa_validate_pbo_compressed_teximage(
@@ -1090,7 +1075,7 @@ void radeon_image_target_texture_2d(struct gl_context *ctx, GLenum target,
 	texImage->Depth = 1;
 	texImage->_BaseFormat = GL_RGBA;
 	texImage->TexFormat = image->format;
-	texImage->RowStride = image->pitch;
+	radeonImage->base.RowStride = image->pitch;
 	texImage->InternalFormat = image->internal_format;
 
 	if(t->mt)
diff --git a/src/mesa/drivers/dri/swrast/swrast.c b/src/mesa/drivers/dri/swrast/swrast.c
index d2c74b9..75d2525 100644
--- a/src/mesa/drivers/dri/swrast/swrast.c
+++ b/src/mesa/drivers/dri/swrast/swrast.c
@@ -52,6 +52,7 @@
 #include "main/texstate.h"
 
 #include "swrast_priv.h"
+#include "swrast/s_context.h"
 
 
 /**
@@ -67,6 +68,7 @@ static void swrastSetTexBuffer2(__DRIcontext *pDRICtx, GLint target,
     struct gl_texture_unit *texUnit;
     struct gl_texture_object *texObj;
     struct gl_texture_image *texImage;
+    struct swrast_texture_image *swImage;
     uint32_t internalFormat;
     gl_format texFormat;
 
@@ -77,6 +79,7 @@ static void swrastSetTexBuffer2(__DRIcontext *pDRICtx, GLint target,
     texUnit = _mesa_get_current_tex_unit(&dri_ctx->Base);
     texObj = _mesa_select_tex_object(&dri_ctx->Base, texUnit, target);
     texImage = _mesa_get_tex_image(&dri_ctx->Base, texObj, target, 0);
+    swImage = swrast_texture_image(texImage);
 
     _mesa_lock_texture(&dri_ctx->Base, texObj);
 
@@ -90,7 +93,7 @@ static void swrastSetTexBuffer2(__DRIcontext *pDRICtx, GLint target,
     _mesa_init_teximage_fields(&dri_ctx->Base, target, texImage,
 			       w, h, 1, 0, internalFormat, texFormat);
 
-    sPriv->swrast_loader->getImage(dPriv, x, y, w, h, (char *)texImage->Data,
+    sPriv->swrast_loader->getImage(dPriv, x, y, w, h, (char *)swImage->Data,
 				   dPriv->loaderPrivate);
 
     _mesa_unlock_texture(&dri_ctx->Base, texObj);
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 749324d..f18c6ae 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -1261,11 +1261,6 @@ struct gl_texture_image
    GLuint Level;                /**< Which mipmap level am I? */
    /** Cube map face: index into gl_texture_object::Image[] array */
    GLuint Face;
-
-   GLuint RowStride;		/**< Padded width in units of texels */
-   GLuint *ImageOffsets;        /**< if 3D texture: array [Depth] of offsets to
-                                     each 2D slice in 'Data', in texels */
-   GLvoid *Data;		/**< Image data, accessed via FetchTexel() */
 };
 
 
diff --git a/src/mesa/main/texcompress.c b/src/mesa/main/texcompress.c
index 03e05d5..0458b9b 100644
--- a/src/mesa/main/texcompress.c
+++ b/src/mesa/main/texcompress.c
@@ -461,8 +461,8 @@ _mesa_decompress_image(gl_format format, GLuint width, GLuint height,
 
    /* setup dummy texture image info */
    memset(&texImage, 0, sizeof(texImage));
-   texImage.Base.Data = (void *) src;
-   texImage.Base.RowStride = srcRowStride;
+   texImage.Data = (void *) src;
+   texImage.RowStride = srcRowStride;
 
    switch (format) {
    /* DXT formats */
diff --git a/src/mesa/main/texcompress_fxt1.c b/src/mesa/main/texcompress_fxt1.c
index 41630a4..d5c73e3 100644
--- a/src/mesa/main/texcompress_fxt1.c
+++ b/src/mesa/main/texcompress_fxt1.c
@@ -177,7 +177,7 @@ _mesa_fetch_texel_2d_f_rgba_fxt1( const struct swrast_texture_image *texImage,
    /* just sample as GLubyte and convert to float here */
    GLubyte rgba[4];
    (void) k;
-   fxt1_decode_1(texImage->Base.Data, texImage->Base.RowStride, i, j, rgba);
+   fxt1_decode_1(texImage->Data, texImage->RowStride, i, j, rgba);
    texel[RCOMP] = UBYTE_TO_FLOAT(rgba[RCOMP]);
    texel[GCOMP] = UBYTE_TO_FLOAT(rgba[GCOMP]);
    texel[BCOMP] = UBYTE_TO_FLOAT(rgba[BCOMP]);
@@ -192,7 +192,7 @@ _mesa_fetch_texel_2d_f_rgb_fxt1( const struct swrast_texture_image *texImage,
    /* just sample as GLubyte and convert to float here */
    GLubyte rgba[4];
    (void) k;
-   fxt1_decode_1(texImage->Base.Data, texImage->Base.RowStride, i, j, rgba);
+   fxt1_decode_1(texImage->Data, texImage->RowStride, i, j, rgba);
    texel[RCOMP] = UBYTE_TO_FLOAT(rgba[RCOMP]);
    texel[GCOMP] = UBYTE_TO_FLOAT(rgba[GCOMP]);
    texel[BCOMP] = UBYTE_TO_FLOAT(rgba[BCOMP]);
diff --git a/src/mesa/main/texcompress_rgtc.c b/src/mesa/main/texcompress_rgtc.c
index b03cd28..3586fc3 100644
--- a/src/mesa/main/texcompress_rgtc.c
+++ b/src/mesa/main/texcompress_rgtc.c
@@ -325,7 +325,7 @@ _mesa_fetch_texel_2d_f_red_rgtc1(const struct swrast_texture_image *texImage,
 				 GLint i, GLint j, GLint k, GLfloat *texel)
 {
    GLubyte red;
-   unsigned_fetch_texel_rgtc(texImage->Base.RowStride, (GLubyte *)(texImage->Base.Data),
+   unsigned_fetch_texel_rgtc(texImage->RowStride, texImage->Data,
 		       i, j, &red, 1);
    texel[RCOMP] = UBYTE_TO_FLOAT(red);
    texel[GCOMP] = 0.0;
@@ -338,7 +338,7 @@ _mesa_fetch_texel_2d_f_signed_red_rgtc1(const struct swrast_texture_image *texIm
 					GLint i, GLint j, GLint k, GLfloat *texel)
 {
    GLbyte red;
-   signed_fetch_texel_rgtc(texImage->Base.RowStride, (GLbyte *)(texImage->Base.Data),
+   signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Data),
 		       i, j, &red, 1);
    texel[RCOMP] = BYTE_TO_FLOAT_TEX(red);
    texel[GCOMP] = 0.0;
@@ -351,9 +351,9 @@ _mesa_fetch_texel_2d_f_rg_rgtc2(const struct swrast_texture_image *texImage,
 				 GLint i, GLint j, GLint k, GLfloat *texel)
 {
    GLubyte red, green;
-   unsigned_fetch_texel_rgtc(texImage->Base.RowStride, (GLubyte *)(texImage->Base.Data),
+   unsigned_fetch_texel_rgtc(texImage->RowStride, texImage->Data,
 		     i, j, &red, 2);
-   unsigned_fetch_texel_rgtc(texImage->Base.RowStride, (GLubyte *)(texImage->Base.Data) + 8,
+   unsigned_fetch_texel_rgtc(texImage->RowStride, texImage->Data + 8,
 		     i, j, &green, 2);
    texel[RCOMP] = UBYTE_TO_FLOAT(red);
    texel[GCOMP] = UBYTE_TO_FLOAT(green);
@@ -366,9 +366,9 @@ _mesa_fetch_texel_2d_f_signed_rg_rgtc2(const struct swrast_texture_image *texIma
 				       GLint i, GLint j, GLint k, GLfloat *texel)
 {
    GLbyte red, green;
-   signed_fetch_texel_rgtc(texImage->Base.RowStride, (GLbyte *)(texImage->Base.Data),
+   signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Data),
 		     i, j, &red, 2);
-   signed_fetch_texel_rgtc(texImage->Base.RowStride, (GLbyte *)(texImage->Base.Data) + 8,
+   signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Data) + 8,
 		     i, j, &green, 2);
    texel[RCOMP] = BYTE_TO_FLOAT_TEX(red);
    texel[GCOMP] = BYTE_TO_FLOAT_TEX(green);
@@ -381,7 +381,7 @@ _mesa_fetch_texel_2d_f_l_latc1(const struct swrast_texture_image *texImage,
                                  GLint i, GLint j, GLint k, GLfloat *texel)
 {
    GLubyte red;
-   unsigned_fetch_texel_rgtc(texImage->Base.RowStride, (GLubyte *)(texImage->Base.Data),
+   unsigned_fetch_texel_rgtc(texImage->RowStride, texImage->Data,
                        i, j, &red, 1);
    texel[RCOMP] =
    texel[GCOMP] =
@@ -394,7 +394,7 @@ _mesa_fetch_texel_2d_f_signed_l_latc1(const struct swrast_texture_image *texImag
                                         GLint i, GLint j, GLint k, GLfloat *texel)
 {
    GLbyte red;
-   signed_fetch_texel_rgtc(texImage->Base.RowStride, (GLbyte *)(texImage->Base.Data),
+   signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Data),
                        i, j, &red, 1);
    texel[RCOMP] =
    texel[GCOMP] =
@@ -407,9 +407,9 @@ _mesa_fetch_texel_2d_f_la_latc2(const struct swrast_texture_image *texImage,
                                  GLint i, GLint j, GLint k, GLfloat *texel)
 {
    GLubyte red, green;
-   unsigned_fetch_texel_rgtc(texImage->Base.RowStride, (GLubyte *)(texImage->Base.Data),
+   unsigned_fetch_texel_rgtc(texImage->RowStride, texImage->Data,
                      i, j, &red, 2);
-   unsigned_fetch_texel_rgtc(texImage->Base.RowStride, (GLubyte *)(texImage->Base.Data) + 8,
+   unsigned_fetch_texel_rgtc(texImage->RowStride, texImage->Data + 8,
                      i, j, &green, 2);
    texel[RCOMP] =
    texel[GCOMP] =
@@ -422,9 +422,9 @@ _mesa_fetch_texel_2d_f_signed_la_latc2(const struct swrast_texture_image *texIma
                                        GLint i, GLint j, GLint k, GLfloat *texel)
 {
    GLbyte red, green;
-   signed_fetch_texel_rgtc(texImage->Base.RowStride, (GLbyte *)(texImage->Base.Data),
+   signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Data),
                      i, j, &red, 2);
-   signed_fetch_texel_rgtc(texImage->Base.RowStride, (GLbyte *)(texImage->Base.Data) + 8,
+   signed_fetch_texel_rgtc(texImage->RowStride, (GLbyte *)(texImage->Data) + 8,
                      i, j, &green, 2);
    texel[RCOMP] =
    texel[GCOMP] =
diff --git a/src/mesa/main/texcompress_s3tc.c b/src/mesa/main/texcompress_s3tc.c
index 904aa45..ed7eae4 100644
--- a/src/mesa/main/texcompress_s3tc.c
+++ b/src/mesa/main/texcompress_s3tc.c
@@ -398,8 +398,8 @@ fetch_texel_2d_rgb_dxt1( const struct swrast_texture_image *texImage,
 {
    (void) k;
    if (fetch_ext_rgb_dxt1) {
-      fetch_ext_rgb_dxt1(texImage->Base.RowStride,
-                         (GLubyte *)(texImage)->Base.Data, i, j, texel);
+      fetch_ext_rgb_dxt1(texImage->RowStride,
+                         texImage->Data, i, j, texel);
    }
    else
       _mesa_debug(NULL, "attempted to decode s3tc texture without library available: fetch_texel_2d_rgb_dxt1");
@@ -426,8 +426,8 @@ fetch_texel_2d_rgba_dxt1( const struct swrast_texture_image *texImage,
 {
    (void) k;
    if (fetch_ext_rgba_dxt1) {
-      fetch_ext_rgba_dxt1(texImage->Base.RowStride,
-                          (GLubyte *)(texImage)->Base.Data, i, j, texel);
+      fetch_ext_rgba_dxt1(texImage->RowStride,
+                          texImage->Data, i, j, texel);
    }
    else
       _mesa_debug(NULL, "attempted to decode s3tc texture without library available: fetch_texel_2d_rgba_dxt1\n");
@@ -454,9 +454,8 @@ fetch_texel_2d_rgba_dxt3( const struct swrast_texture_image *texImage,
 {
    (void) k;
    if (fetch_ext_rgba_dxt3) {
-      fetch_ext_rgba_dxt3(texImage->Base.RowStride,
-                          (GLubyte *)(texImage)->Base.Data,
-                          i, j, texel);
+      fetch_ext_rgba_dxt3(texImage->RowStride,
+                          texImage->Data, i, j, texel);
    }
    else
       _mesa_debug(NULL, "attempted to decode s3tc texture without library available: fetch_texel_2d_rgba_dxt3\n");
@@ -483,9 +482,8 @@ fetch_texel_2d_rgba_dxt5( const struct swrast_texture_image *texImage,
 {
    (void) k;
    if (fetch_ext_rgba_dxt5) {
-      fetch_ext_rgba_dxt5(texImage->Base.RowStride,
-                          (GLubyte *)(texImage)->Base.Data,
-                          i, j, texel);
+      fetch_ext_rgba_dxt5(texImage->RowStride,
+                          texImage->Data, i, j, texel);
    }
    else
       _mesa_debug(NULL, "attempted to decode s3tc texture without library available: fetch_texel_2d_rgba_dxt5\n");
diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
index 8efe715..3a96693 100644
--- a/src/mesa/main/teximage.c
+++ b/src/mesa/main/teximage.c
@@ -612,12 +612,14 @@ _mesa_free_texture_image_data(struct gl_context *ctx,
 {
    (void) ctx;
 
+#if 0
    if (texImage->Data) {
       /* free the old texture data */
       _mesa_free_texmemory(texImage->Data);
    }
 
    texImage->Data = NULL;
+#endif
 }
 
 
@@ -639,10 +641,12 @@ _mesa_delete_texture_image(struct gl_context *ctx,
    ASSERT(ctx->Driver.FreeTextureImageBuffer);
    ctx->Driver.FreeTextureImageBuffer( ctx, texImage );
 
+#if 0
    ASSERT(texImage->Data == NULL);
    if (texImage->ImageOffsets)
       free(texImage->ImageOffsets);
    free(texImage);
+#endif
 }
 
 
@@ -1084,18 +1088,19 @@ clear_teximage_fields(struct gl_texture_image *img)
    img->Width = 0;
    img->Height = 0;
    img->Depth = 0;
+#if 0
    img->RowStride = 0;
    if (img->ImageOffsets) {
       free(img->ImageOffsets);
       img->ImageOffsets = NULL;
    }
+#endif
    img->Width2 = 0;
    img->Height2 = 0;
    img->Depth2 = 0;
    img->WidthLog2 = 0;
    img->HeightLog2 = 0;
    img->DepthLog2 = 0;
-   img->Data = NULL;
    img->TexFormat = MESA_FORMAT_NONE;
 }
 
@@ -1123,8 +1128,6 @@ _mesa_init_teximage_fields(struct gl_context *ctx, GLenum target,
                            GLint border, GLenum internalFormat,
                            gl_format format)
 {
-   GLint i;
-
    ASSERT(img);
    ASSERT(width >= 0);
    ASSERT(height >= 0);
@@ -1161,6 +1164,7 @@ _mesa_init_teximage_fields(struct gl_context *ctx, GLenum target,
 
    img->MaxLog2 = MAX2(img->WidthLog2, img->HeightLog2);
 
+#if 0
    /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
    img->RowStride = width;
    /* Allocate the ImageOffsets array and initialize to typical values.
@@ -1173,6 +1177,7 @@ _mesa_init_teximage_fields(struct gl_context *ctx, GLenum target,
    for (i = 0; i < depth; i++) {
       img->ImageOffsets[i] = i * width * height;
    }
+#endif
 
    img->TexFormat = format;
 }
@@ -2442,7 +2447,6 @@ teximage(struct gl_context *ctx, GLuint dims,
 
             ctx->Driver.FreeTextureImageBuffer(ctx, texImage);
 
-            ASSERT(texImage->Data == NULL);
             texFormat = _mesa_choose_texture_format(ctx, texObj, target, level,
                                                     internalFormat, format,
                                                     type);
@@ -2581,7 +2585,6 @@ _mesa_EGLImageTargetTexture2DOES (GLenum target, GLeglImageOES image)
    } else {
       ctx->Driver.FreeTextureImageBuffer(ctx, texImage);
 
-      ASSERT(texImage->Data == NULL);
       ctx->Driver.EGLImageTargetTexture2D(ctx, target,
 					  texObj, texImage, image);
 
@@ -3403,7 +3406,6 @@ compressedteximage(struct gl_context *ctx, GLuint dims,
             gl_format texFormat;
 
             ctx->Driver.FreeTextureImageBuffer(ctx, texImage);
-            ASSERT(texImage->Data == NULL);
 
             texFormat = _mesa_choose_texture_format(ctx, texObj, target, level,
                                                     internalFormat, GL_NONE,
diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c
index cc9fbc0..cd92496 100644
--- a/src/mesa/main/texstore.c
+++ b/src/mesa/main/texstore.c
@@ -4906,7 +4906,6 @@ _mesa_store_compressed_teximage2d(struct gl_context *ctx,
    ASSERT(texImage->Width > 0);
    ASSERT(texImage->Height > 0);
    ASSERT(texImage->Depth == 1);
-   ASSERT(texImage->Data == NULL); /* was freed in glCompressedTexImage2DARB */
 
    /* allocate storage for texture data */
    if (!ctx->Driver.AllocTextureImageBuffer(ctx, texImage, texImage->TexFormat,
diff --git a/src/mesa/swrast/s_context.h b/src/mesa/swrast/s_context.h
index ec8451e..55f7c31 100644
--- a/src/mesa/swrast/s_context.h
+++ b/src/mesa/swrast/s_context.h
@@ -138,20 +138,14 @@ struct swrast_texture_image
    /** used for mipmap LOD computation */
    GLfloat WidthScale, HeightScale, DepthScale;
 
-#if 0
-   GLubyte *Data;    /**< The actual texture data in malloc'd memory */
-
-   GLint TexelSize;  /**< bytes per texel block */
-#endif
+   /** These fields only valid when texture memory is mapped */
+   GLint RowStride;		/**< Padded width in units of texels */
+   GLuint *ImageOffsets;        /**< if 3D texture: array [Depth] of offsets to
+                                     each 2D slice in 'Data', in texels */
+   GLubyte *Data;		/**< Image data, accessed via FetchTexel() */
 
    FetchTexelFunc FetchTexel;
    StoreTexelFunc Store;
-
-#if 0
-   /** These fields only valid when texture memory is mapped */
-   GLubyte **SliceMaps;  /**< points to OneMap or a malloc'd array */
-   GLint RowStride;  /**< bytes per row of blocks */
-#endif
 };
 
 
diff --git a/src/mesa/swrast/s_texfetch_tmp.h b/src/mesa/swrast/s_texfetch_tmp.h
index c63b204..8b7e930 100644
--- a/src/mesa/swrast/s_texfetch_tmp.h
+++ b/src/mesa/swrast/s_texfetch_tmp.h
@@ -43,7 +43,7 @@
 #if DIM == 1
 
 #define TEXEL_ADDR( type, image, i, j, k, size ) \
-	((void) (j), (void) (k), ((type *)(image)->Base.Data + (i) * (size)))
+	((void) (j), (void) (k), ((type *)(image)->Data + (i) * (size)))
 
 #define FETCH(x) fetch_texel_1d_##x
 
@@ -51,15 +51,15 @@
 
 #define TEXEL_ADDR( type, image, i, j, k, size )			\
 	((void) (k),							\
-	 ((type *)(image)->Base.Data + ((image)->Base.RowStride * (j) + (i)) * (size)))
+	 ((type *)(image)->Data + ((image)->RowStride * (j) + (i)) * (size)))
 
 #define FETCH(x) fetch_texel_2d_##x
 
 #elif DIM == 3
 
 #define TEXEL_ADDR( type, image, i, j, k, size )			\
-	((type *)(image)->Base.Data + ((image)->Base.ImageOffsets[k]		\
-             + (image)->Base.RowStride * (j) + (i)) * (size))
+	((type *)(image)->Data + ((image)->ImageOffsets[k]		\
+             + (image)->RowStride * (j) + (i)) * (size))
 
 #define FETCH(x) fetch_texel_3d_##x
 
diff --git a/src/mesa/swrast/s_texfilter.c b/src/mesa/swrast/s_texfilter.c
index f8b0fa1..9de5c02 100644
--- a/src/mesa/swrast/s_texfilter.c
+++ b/src/mesa/swrast/s_texfilter.c
@@ -1375,7 +1375,7 @@ opt_sample_rgb_2d(struct gl_context *ctx,
       GLint i = IFLOOR(texcoords[k][0] * width) & colMask;
       GLint j = IFLOOR(texcoords[k][1] * height) & rowMask;
       GLint pos = (j << shift) | i;
-      GLubyte *texel = ((GLubyte *) img->Data) + 3*pos;
+      GLubyte *texel = swImg->Data + 3 * pos;
       rgba[k][RCOMP] = UBYTE_TO_FLOAT(texel[2]);
       rgba[k][GCOMP] = UBYTE_TO_FLOAT(texel[1]);
       rgba[k][BCOMP] = UBYTE_TO_FLOAT(texel[0]);
@@ -1419,7 +1419,7 @@ opt_sample_rgba_2d(struct gl_context *ctx,
       const GLint col = IFLOOR(texcoords[i][0] * width) & colMask;
       const GLint row = IFLOOR(texcoords[i][1] * height) & rowMask;
       const GLint pos = (row << shift) | col;
-      const GLuint texel = *((GLuint *) img->Data + pos);
+      const GLuint texel = *((GLuint *) swImg->Data + pos);
       rgba[i][RCOMP] = UBYTE_TO_FLOAT( (texel >> 24)        );
       rgba[i][GCOMP] = UBYTE_TO_FLOAT( (texel >> 16) & 0xff );
       rgba[i][BCOMP] = UBYTE_TO_FLOAT( (texel >>  8) & 0xff );
@@ -1442,7 +1442,7 @@ sample_lambda_2d(struct gl_context *ctx,
 
    const GLboolean repeatNoBorderPOT = (tObj->Sampler.WrapS == GL_REPEAT)
       && (tObj->Sampler.WrapT == GL_REPEAT)
-      && (tImg->Border == 0 && (tImg->Width == tImg->RowStride))
+      && (tImg->Border == 0 && (tImg->Width == swImg->RowStride))
       && swImg->_IsPowerOfTwo;
 
    ASSERT(lambda != NULL);
diff --git a/src/mesa/swrast/s_texrender.c b/src/mesa/swrast/s_texrender.c
index 47e458e..caa17f9 100644
--- a/src/mesa/swrast/s_texrender.c
+++ b/src/mesa/swrast/s_texrender.c
@@ -610,7 +610,7 @@ update_wrapper(struct gl_context *ctx, struct gl_renderbuffer_attachment *att)
       trb->Base.DataType = CHAN_TYPE;
       trb->Base._BaseFormat = GL_RGBA;
    }
-   trb->Base.Data = trb->TexImage->Base.Data;
+   trb->Base.Data = trb->TexImage->Data;
 }
 
 
diff --git a/src/mesa/swrast/s_texture.c b/src/mesa/swrast/s_texture.c
index 36b429c..df371c3 100644
--- a/src/mesa/swrast/s_texture.c
+++ b/src/mesa/swrast/s_texture.c
@@ -69,14 +69,32 @@ _swrast_alloc_texture_image_buffer(struct gl_context *ctx,
 {
    struct swrast_texture_image *swImg = swrast_texture_image(texImage);
    GLuint bytes = _mesa_format_image_size(format, width, height, depth);
+   GLuint i;
 
    /* This _should_ be true (revisit if these ever fail) */
    assert(texImage->Width == width);
    assert(texImage->Height == height);
    assert(texImage->Depth == depth);
 
-   assert(!texImage->Data);
-   texImage->Data = _mesa_align_malloc(bytes, 512);
+   assert(!swImg->Data);
+   swImg->Data = _mesa_align_malloc(bytes, 512);
+   if (!swImg->Data)
+      return GL_FALSE;
+
+   /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
+   swImg->RowStride = width;
+
+   /* Allocate the ImageOffsets array and initialize to typical values.
+    * We allocate the array for 1D/2D textures too in order to avoid special-
+    * case code in the texstore routines.
+    */
+   swImg->ImageOffsets = (GLuint *) malloc(depth * sizeof(GLuint));
+   if (!swImg->ImageOffsets)
+      return GL_FALSE;
+
+   for (i = 0; i < depth; i++) {
+      swImg->ImageOffsets[i] = i * width * height;
+   }
 
    if ((width == 1 || _mesa_is_pow_two(texImage->Width2)) &&
        (height == 1 || _mesa_is_pow_two(texImage->Height2)) &&
@@ -98,7 +116,7 @@ _swrast_alloc_texture_image_buffer(struct gl_context *ctx,
       swImg->DepthScale = (GLfloat) texImage->Depth;
    }
 
-   return texImage->Data != NULL;
+   return GL_TRUE;
 }
 
 
@@ -109,11 +127,16 @@ void
 _swrast_free_texture_image_buffer(struct gl_context *ctx,
                                   struct gl_texture_image *texImage)
 {
-   if (texImage->Data) {
-      _mesa_align_free(texImage->Data);
+   struct swrast_texture_image *swImage = swrast_texture_image(texImage);
+   if (swImage->Data) {
+      _mesa_align_free(swImage->Data);
+      swImage->Data = NULL;
    }
 
-   texImage->Data = NULL;
+   if (swImage->ImageOffsets) {
+      free(swImage->ImageOffsets);
+      swImage->ImageOffsets = NULL;
+   }
 }
 
 
@@ -155,6 +178,7 @@ _swrast_map_teximage(struct gl_context *ctx,
                      GLubyte **mapOut,
                      GLint *rowStrideOut)
 {
+   struct swrast_texture_image *swImage = swrast_texture_image(texImage);
    GLubyte *map;
    GLint stride, texelSize;
    GLuint bw, bh;
@@ -165,9 +189,9 @@ _swrast_map_teximage(struct gl_context *ctx,
    stride = _mesa_format_row_stride(texImage->TexFormat, texImage->Width);
    _mesa_get_format_block_size(texImage->TexFormat, &bw, &bh);
 
-   assert(texImage->Data);
+   assert(swImage->Data);
 
-   map = texImage->Data;
+   map = swImage->Data;
 
    if (texImage->TexObject->Target == GL_TEXTURE_3D ||
        texImage->TexObject->Target == GL_TEXTURE_2D_ARRAY) {
diff --git a/src/mesa/swrast/s_triangle.c b/src/mesa/swrast/s_triangle.c
index 839c4fd..b4f8e74 100644
--- a/src/mesa/swrast/s_triangle.c
+++ b/src/mesa/swrast/s_triangle.c
@@ -127,10 +127,12 @@ _swrast_culltriangle( struct gl_context *ctx,
       ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX];		\
    const struct gl_texture_image *texImg =				\
       obj->Image[0][obj->BaseLevel];					\
+   const struct swrast_texture_image *swImg =				\
+      swrast_texture_image_const(texImg);				\
    const GLfloat twidth = (GLfloat) texImg->Width;			\
    const GLfloat theight = (GLfloat) texImg->Height;			\
    const GLint twidth_log2 = texImg->WidthLog2;				\
-   const GLubyte *texture = (const GLubyte *) texImg->Data;		\
+   const GLubyte *texture = (const GLubyte *) swImg->Data;		\
    const GLint smask = texImg->Width - 1;				\
    const GLint tmask = texImg->Height - 1;				\
    ASSERT(texImg->TexFormat == MESA_FORMAT_RGB888);			\
@@ -181,10 +183,12 @@ _swrast_culltriangle( struct gl_context *ctx,
       ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX];		\
    const struct gl_texture_image *texImg = 				\
        obj->Image[0][obj->BaseLevel]; 					\
+   const struct swrast_texture_image *swImg =				\
+      swrast_texture_image_const(texImg);				\
    const GLfloat twidth = (GLfloat) texImg->Width;			\
    const GLfloat theight = (GLfloat) texImg->Height;			\
    const GLint twidth_log2 = texImg->WidthLog2;				\
-   const GLubyte *texture = (const GLubyte *) texImg->Data;		\
+   const GLubyte *texture = (const GLubyte *) swImg->Data;		\
    const GLint smask = texImg->Width - 1;				\
    const GLint tmask = texImg->Height - 1;				\
    ASSERT(texImg->TexFormat == MESA_FORMAT_RGB888);			\
@@ -533,9 +537,11 @@ affine_span(struct gl_context *ctx, SWspan *span,
       ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX];		\
    const struct gl_texture_image *texImg = 				\
       obj->Image[0][obj->BaseLevel]; 					\
+   const struct swrast_texture_image *swImg =				\
+      swrast_texture_image_const(texImg);				\
    const GLfloat twidth = (GLfloat) texImg->Width;			\
    const GLfloat theight = (GLfloat) texImg->Height;			\
-   info.texture = (const GLchan *) texImg->Data;			\
+   info.texture = (const GLchan *) swImg->Data;				\
    info.twidth_log2 = texImg->WidthLog2;				\
    info.smask = texImg->Width - 1;					\
    info.tmask = texImg->Height - 1;					\
@@ -800,7 +806,9 @@ fast_persp_span(struct gl_context *ctx, SWspan *span,
       ctx->Texture.Unit[0].CurrentTex[TEXTURE_2D_INDEX];		\
    const struct gl_texture_image *texImg = 				\
       obj->Image[0][obj->BaseLevel];			 		\
-   info.texture = (const GLchan *) texImg->Data;			\
+   const struct swrast_texture_image *swImg =				\
+      swrast_texture_image_const(texImg);				\
+   info.texture = (const GLchan *) swImg->Data;				\
    info.twidth_log2 = texImg->WidthLog2;				\
    info.smask = texImg->Width - 1;					\
    info.tmask = texImg->Height - 1;					\
@@ -1062,7 +1070,7 @@ _swrast_choose_triangle( struct gl_context *ctx )
              && texObj2D->_Swizzle == SWIZZLE_NOOP
              && swImg->_IsPowerOfTwo
              && texImg->Border == 0
-             && texImg->Width == texImg->RowStride
+             && texImg->Width == swImg->RowStride
              && (format == MESA_FORMAT_RGB888 || format == MESA_FORMAT_RGBA8888)
              && minFilter == magFilter
              && ctx->Light.Model.ColorControl == GL_SINGLE_COLOR
-- 
1.7.3.4



More information about the mesa-dev mailing list