[Mesa-dev] [PATCH 06/16] intel: Clean up the function chain for mapping texture images for swrast.

Eric Anholt eric at anholt.net
Thu Sep 29 15:39:57 PDT 2011


Too many separate functions each called from one location (in
different files).  This code should all die soon when swrast starts
using MapTextureImage.
---
 src/mesa/drivers/dri/intel/intel_mipmap_tree.c  |   57 ------------
 src/mesa/drivers/dri/intel/intel_mipmap_tree.h  |   12 ---
 src/mesa/drivers/dri/intel/intel_tex_validate.c |  109 ++++++++++++++---------
 3 files changed, 65 insertions(+), 113 deletions(-)

diff --git a/src/mesa/drivers/dri/intel/intel_mipmap_tree.c b/src/mesa/drivers/dri/intel/intel_mipmap_tree.c
index 8289c39..c25df35 100644
--- a/src/mesa/drivers/dri/intel/intel_mipmap_tree.c
+++ b/src/mesa/drivers/dri/intel/intel_mipmap_tree.c
@@ -310,63 +310,6 @@ intel_miptree_get_image_offset(struct intel_mipmap_tree *mt,
 }
 
 /**
- * Map a teximage in a mipmap tree.
- * \param row_stride  returns row stride in bytes
- * \param image_stride  returns image stride in bytes (for 3D textures).
- * \param image_offsets pointer to array of pixel offsets from the returned
- *	  pointer to each depth image
- * \return address of mapping
- */
-GLubyte *
-intel_miptree_image_map(struct intel_context * intel,
-                        struct intel_mipmap_tree * mt,
-                        GLuint face,
-                        GLuint level,
-                        GLuint * row_stride, GLuint * image_offsets)
-{
-   GLuint x, y;
-
-   if (row_stride)
-      *row_stride = mt->region->pitch * mt->cpp;
-
-   if (mt->target == GL_TEXTURE_3D) {
-      int i;
-
-      for (i = 0; i < mt->level[level].depth; i++) {
-
-	 intel_miptree_get_image_offset(mt, level, face, i,
-					&x, &y);
-	 image_offsets[i] = x + y * mt->region->pitch;
-      }
-
-      DBG("%s \n", __FUNCTION__);
-
-      return intel_region_map(intel, mt->region);
-   } else {
-      assert(mt->level[level].depth == 1);
-      intel_miptree_get_image_offset(mt, level, face, 0,
-				     &x, &y);
-      image_offsets[0] = 0;
-
-      DBG("%s: (%d,%d) -> (%d, %d)/%d\n",
-	  __FUNCTION__, face, level, x, y, mt->region->pitch * mt->cpp);
-
-      return intel_region_map(intel, mt->region) +
-	 (x + y * mt->region->pitch) * mt->cpp;
-   }
-}
-
-
-void
-intel_miptree_image_unmap(struct intel_context *intel,
-                          struct intel_mipmap_tree *mt)
-{
-   DBG("%s\n", __FUNCTION__);
-   intel_region_unmap(intel, mt->region);
-}
-
-
-/**
  * Upload data for a particular image.
  */
 void
diff --git a/src/mesa/drivers/dri/intel/intel_mipmap_tree.h b/src/mesa/drivers/dri/intel/intel_mipmap_tree.h
index 0d4d2f9..7ca24f9 100644
--- a/src/mesa/drivers/dri/intel/intel_mipmap_tree.h
+++ b/src/mesa/drivers/dri/intel/intel_mipmap_tree.h
@@ -165,18 +165,6 @@ void intel_miptree_release(struct intel_mipmap_tree **mt);
 GLboolean intel_miptree_match_image(struct intel_mipmap_tree *mt,
                                     struct gl_texture_image *image);
 
-/* Return a pointer to an image within a tree.  Return image stride as
- * well.
- */
-GLubyte *intel_miptree_image_map(struct intel_context *intel,
-                                 struct intel_mipmap_tree *mt,
-                                 GLuint face,
-                                 GLuint level,
-                                 GLuint * row_stride, GLuint * image_stride);
-
-void intel_miptree_image_unmap(struct intel_context *intel,
-                               struct intel_mipmap_tree *mt);
-
 void
 intel_miptree_get_image_offset(struct intel_mipmap_tree *mt,
 			       GLuint level, GLuint face, GLuint depth,
diff --git a/src/mesa/drivers/dri/intel/intel_tex_validate.c b/src/mesa/drivers/dri/intel/intel_tex_validate.c
index 1379108..f227ab8 100644
--- a/src/mesa/drivers/dri/intel/intel_tex_validate.c
+++ b/src/mesa/drivers/dri/intel/intel_tex_validate.c
@@ -156,70 +156,91 @@ intel_finalize_mipmap_tree(struct intel_context *intel, GLuint unit)
    return GL_TRUE;
 }
 
-void
-intel_tex_map_level_images(struct intel_context *intel,
-			   struct intel_texture_object *intelObj,
-			   int level)
+static void
+intel_tex_map_image_for_swrast(struct intel_context *intel,
+			       struct intel_texture_image *intel_image)
 {
-   GLuint nr_faces = (intelObj->base.Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1;
-   GLuint face;
+   int level = intel_image->base.Base.Level;
+   int face = intel_image->base.Base.Face;
+   struct intel_mipmap_tree *mt;
+   unsigned int x, y;
 
-   for (face = 0; face < nr_faces; face++) {
-      struct intel_texture_image *intelImage =
-	 intel_texture_image(intelObj->base.Image[face][level]);
-
-      if (intelImage && intelImage->mt) {
-	 intelImage->base.Base.Data =
-	    intel_miptree_image_map(intel,
-				    intelImage->mt,
-				    intelImage->base.Base.Face,
-				    intelImage->base.Base.Level,
-				    &intelImage->base.Base.RowStride,
-				    intelImage->base.Base.ImageOffsets);
-	 /* convert stride to texels, not bytes */
-	 intelImage->base.Base.RowStride /= intelImage->mt->cpp;
-	 /* intelImage->base.ImageStride /= intelImage->mt->cpp; */
+   if (!intel_image || !intel_image->mt)
+      return;
+
+   mt = intel_image->mt;
+
+   if (mt->target == GL_TEXTURE_3D) {
+      int i;
+
+      /* 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;
       }
+
+      DBG("%s \n", __FUNCTION__);
+
+      intel_image->base.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) +
+	 (x + y * mt->region->pitch) * mt->cpp;
    }
+
+   intel_image->base.Base.RowStride = mt->region->pitch;
 }
 
-void
-intel_tex_unmap_level_images(struct intel_context *intel,
-			     struct intel_texture_object *intelObj,
-			     int level)
+static void
+intel_tex_unmap_image_for_swrast(struct intel_context *intel,
+				 struct intel_texture_image *intel_image)
 {
-   GLuint nr_faces = (intelObj->base.Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1;
-   GLuint face;
-
-   for (face = 0; face < nr_faces; face++) {
-      struct intel_texture_image *intelImage =
-	 intel_texture_image(intelObj->base.Image[face][level]);
-
-      if (intelImage && intelImage->mt) {
-	 intel_miptree_image_unmap(intel, intelImage->mt);
-	 intelImage->base.Base.Data = NULL;
-      }
+   if (intel_image && intel_image->mt) {
+      intel_region_unmap(intel, intel_image->mt->region);
+      intel_image->base.Base.Data = NULL;
    }
 }
 
 void
 intel_tex_map_images(struct intel_context *intel,
-                     struct intel_texture_object *intelObj)
+		     struct intel_texture_object *intelObj)
 {
-   int i;
+   GLuint nr_faces = (intelObj->base.Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1;
+   int i, face;
 
    DBG("%s\n", __FUNCTION__);
 
-   for (i = intelObj->base.BaseLevel; i <= intelObj->_MaxLevel; i++)
-      intel_tex_map_level_images(intel, intelObj, i);
+   for (i = intelObj->base.BaseLevel; i <= intelObj->_MaxLevel; i++) {
+      for (face = 0; face < nr_faces; face++) {
+	 struct intel_texture_image *intel_image =
+	    intel_texture_image(intelObj->base.Image[face][i]);
+
+	 intel_tex_map_image_for_swrast(intel, intel_image);
+      }
+   }
 }
 
 void
 intel_tex_unmap_images(struct intel_context *intel,
-                       struct intel_texture_object *intelObj)
+		       struct intel_texture_object *intelObj)
 {
-   int i;
+   GLuint nr_faces = (intelObj->base.Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1;
+   int i, face;
 
-   for (i = intelObj->base.BaseLevel; i <= intelObj->_MaxLevel; i++)
-      intel_tex_unmap_level_images(intel, intelObj, i);
+   for (i = intelObj->base.BaseLevel; i <= intelObj->_MaxLevel; i++) {
+      for (face = 0; face < nr_faces; face++) {
+	 struct intel_texture_image *intel_image =
+	    intel_texture_image(intelObj->base.Image[face][i]);
+
+	 intel_tex_unmap_image_for_swrast(intel, intel_image);
+      }
+   }
 }
-- 
1.7.6.3



More information about the mesa-dev mailing list