[Mesa-dev] [PATCH 12/17] swrast: Always use MapTextureImage for mapping textures for swrast.

Eric Anholt eric at anholt.net
Mon Apr 22 09:14:53 PDT 2013


Now that everything goes through ImageSlices[], we can rely on the
driver's existing texture mapping function.

A big block of code goes away on Radeon that looks like it was to deal with
the validate that happened at SpanRenderStart, which no longer occurs since we
don't need validation for the MapTextureImage hook.
---
 src/mesa/drivers/dri/i915/intel_tris.c           |    2 -
 src/mesa/drivers/dri/intel/intel_span.c          |   80 ++-----------------
 src/mesa/drivers/dri/intel/intel_span.h          |    2 -
 src/mesa/drivers/dri/intel/intel_tex.h           |    6 --
 src/mesa/drivers/dri/intel/intel_tex_validate.c  |   90 ----------------------
 src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c |   21 -----
 src/mesa/drivers/dri/radeon/radeon_span.c        |   18 +----
 src/mesa/drivers/dri/radeon/radeon_texture.c     |   74 ------------------
 src/mesa/drivers/dri/radeon/radeon_texture.h     |    3 -
 src/mesa/swrast/s_texture.c                      |   61 ++++++++++++---
 10 files changed, 59 insertions(+), 298 deletions(-)

diff --git a/src/mesa/drivers/dri/i915/intel_tris.c b/src/mesa/drivers/dri/i915/intel_tris.c
index 4516db6..30eb6ac 100644
--- a/src/mesa/drivers/dri/i915/intel_tris.c
+++ b/src/mesa/drivers/dri/i915/intel_tris.c
@@ -1096,11 +1096,9 @@ intelRunPipeline(struct gl_context * ctx)
       intel->NewGLState = 0;
    }
 
-   intel_map_vertex_shader_textures(ctx);
    intel->tnl_pipeline_running = true;
    _tnl_run_pipeline(ctx);
    intel->tnl_pipeline_running = false;
-   intel_unmap_vertex_shader_textures(ctx);
 
    _mesa_unlock_context_textures(ctx);
 }
diff --git a/src/mesa/drivers/dri/intel/intel_span.c b/src/mesa/drivers/dri/intel/intel_span.c
index d7eaa41..e74398d 100644
--- a/src/mesa/drivers/dri/intel/intel_span.c
+++ b/src/mesa/drivers/dri/intel/intel_span.c
@@ -105,31 +105,8 @@ intel_offset_S8(uint32_t stride, uint32_t x, uint32_t y, bool swizzled)
 }
 
 /**
- * Map the regions needed by intelSpanRenderStart().
- */
-static void
-intel_span_map_buffers(struct intel_context *intel)
-{
-   struct gl_context *ctx = &intel->ctx;
-   struct intel_texture_object *tex_obj;
-
-   for (int i = 0; i < ctx->Const.MaxTextureImageUnits; i++) {
-      if (!ctx->Texture.Unit[i]._ReallyEnabled)
-	 continue;
-      tex_obj = intel_texture_object(ctx->Texture.Unit[i]._Current);
-      intel_finalize_mipmap_tree(intel, i);
-      intel_tex_map_images(intel, tex_obj,
-			   GL_MAP_READ_BIT | GL_MAP_WRITE_BIT);
-   }
-
-   _swrast_map_renderbuffers(ctx);
-}
-
-/**
  * Prepare for software rendering.  Map current read/draw framebuffers'
- * renderbuffes and all currently bound texture objects.
- *
- * Old note: Moved locking out to get reasonable span performance.
+ * renderbuffers and all currently bound texture objects.
  */
 void
 intelSpanRenderStart(struct gl_context * ctx)
@@ -139,7 +116,9 @@ intelSpanRenderStart(struct gl_context * ctx)
    intel_flush(ctx);
    intel_prepare_render(intel);
    intel_flush(ctx);
-   intel_span_map_buffers(intel);
+
+   _swrast_map_textures(ctx);
+   _swrast_map_renderbuffers(ctx);
 }
 
 /**
@@ -149,18 +128,8 @@ intelSpanRenderStart(struct gl_context * ctx)
 void
 intelSpanRenderFinish(struct gl_context * ctx)
 {
-   struct intel_context *intel = intel_context(ctx);
-   GLuint i;
-
    _swrast_flush(ctx);
-
-   for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) {
-      if (ctx->Texture.Unit[i]._ReallyEnabled) {
-         struct gl_texture_object *texObj = ctx->Texture.Unit[i]._Current;
-         intel_tex_unmap_images(intel, intel_texture_object(texObj));
-      }
-   }
-
+   _swrast_unmap_textures(ctx);
    _swrast_unmap_renderbuffers(ctx);
 }
 
@@ -174,42 +143,3 @@ intelInitSpanFuncs(struct gl_context * ctx)
       swdd->SpanRenderFinish = intelSpanRenderFinish;
    }
 }
-
-void
-intel_map_vertex_shader_textures(struct gl_context *ctx)
-{
-   struct intel_context *intel = intel_context(ctx);
-   int i;
-
-   if (ctx->VertexProgram._Current == NULL)
-      return;
-
-   for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) {
-      if (ctx->Texture.Unit[i]._ReallyEnabled &&
-	  ctx->VertexProgram._Current->Base.TexturesUsed[i] != 0) {
-         struct gl_texture_object *texObj = ctx->Texture.Unit[i]._Current;
-
-         intel_tex_map_images(intel, intel_texture_object(texObj),
-                              GL_MAP_READ_BIT | GL_MAP_WRITE_BIT);
-      }
-   }
-}
-
-void
-intel_unmap_vertex_shader_textures(struct gl_context *ctx)
-{
-   struct intel_context *intel = intel_context(ctx);
-   int i;
-
-   if (ctx->VertexProgram._Current == NULL)
-      return;
-
-   for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) {
-      if (ctx->Texture.Unit[i]._ReallyEnabled &&
-	  ctx->VertexProgram._Current->Base.TexturesUsed[i] != 0) {
-         struct gl_texture_object *texObj = ctx->Texture.Unit[i]._Current;
-
-         intel_tex_unmap_images(intel, intel_texture_object(texObj));
-      }
-   }
-}
diff --git a/src/mesa/drivers/dri/intel/intel_span.h b/src/mesa/drivers/dri/intel/intel_span.h
index e521869..412f244 100644
--- a/src/mesa/drivers/dri/intel/intel_span.h
+++ b/src/mesa/drivers/dri/intel/intel_span.h
@@ -36,8 +36,6 @@ extern void intelInitSpanFuncs(struct gl_context * ctx);
 extern void intelSpanRenderFinish(struct gl_context * ctx);
 extern void intelSpanRenderStart(struct gl_context * ctx);
 
-void intel_map_vertex_shader_textures(struct gl_context *ctx);
-void intel_unmap_vertex_shader_textures(struct gl_context *ctx);
 intptr_t intel_offset_S8(uint32_t stride, uint32_t x, uint32_t y, bool swizzled);
 
 #endif
diff --git a/src/mesa/drivers/dri/intel/intel_tex.h b/src/mesa/drivers/dri/intel/intel_tex.h
index 6fa5b40..4785507 100644
--- a/src/mesa/drivers/dri/intel/intel_tex.h
+++ b/src/mesa/drivers/dri/intel/intel_tex.h
@@ -64,12 +64,6 @@ void intel_tex_unmap_level_images(struct intel_context *intel,
 				  struct intel_texture_object *intelObj,
 				  int level);
 
-void intel_tex_map_images(struct intel_context *intel,
-                          struct intel_texture_object *intelObj,
-                          GLbitfield mode);
-
-void intel_tex_unmap_images(struct intel_context *intel,
-                            struct intel_texture_object *intelObj);
 bool
 intel_tex_image_s8z24_create_renderbuffers(struct intel_context *intel,
 					   struct intel_texture_image *image);
diff --git a/src/mesa/drivers/dri/intel/intel_tex_validate.c b/src/mesa/drivers/dri/intel/intel_tex_validate.c
index 6068733..eaa2561 100644
--- a/src/mesa/drivers/dri/intel/intel_tex_validate.c
+++ b/src/mesa/drivers/dri/intel/intel_tex_validate.c
@@ -139,93 +139,3 @@ intel_finalize_mipmap_tree(struct intel_context *intel, GLuint unit)
 
    return true;
 }
-
-/**
- * \param mode  bitmask of GL_MAP_READ_BIT, GL_MAP_WRITE_BIT
- */
-static void
-intel_tex_map_image_for_swrast(struct intel_context *intel,
-			       struct intel_texture_image *intel_image,
-			       GLbitfield mode)
-{
-   int level;
-   int face;
-   struct intel_mipmap_tree *mt;
-   unsigned int x, y;
-
-   if (!intel_image || !intel_image->mt)
-      return;
-
-   level = intel_image->base.Base.Level;
-   face = intel_image->base.Base.Face;
-   mt = intel_image->mt;
-
-   for (int i = 0; i < mt->level[level].depth; i++)
-      intel_miptree_slice_resolve_depth(intel, mt, level, i);
-
-   void *map = intel_miptree_map_raw(intel, mt);
-
-   for (int i = 0; i < mt->level[level].depth; i++) {
-      intel_miptree_get_image_offset(mt, level, i, &x, &y);
-      intel_image->base.ImageSlices[i] = (map +
-                                          y * mt->region->pitch +
-                                          x * mt->cpp);
-      DBG("%s: (%d,%d,%d) -> (%d, %d)/%d\n",
-	  __FUNCTION__, face, level, i, x, y, mt->region->pitch);
-   }
-
-   intel_image->base.Map = intel_image->base.ImageSlices[0];
-
-   assert(mt->region->pitch % mt->region->cpp == 0);
-   intel_image->base.RowStride = mt->region->pitch / mt->region->cpp;
-}
-
-static void
-intel_tex_unmap_image_for_swrast(struct intel_context *intel,
-				 struct intel_texture_image *intel_image)
-{
-   if (intel_image && intel_image->mt) {
-      intel_miptree_unmap_raw(intel, intel_image->mt);
-      intel_image->base.Map = NULL;
-   }
-}
-
-/**
- * \param mode  bitmask of GL_MAP_READ_BIT, GL_MAP_WRITE_BIT
- */
-void
-intel_tex_map_images(struct intel_context *intel,
-		     struct intel_texture_object *intelObj,
-		     GLbitfield mode)
-{
-   GLuint nr_faces = _mesa_num_tex_faces(intelObj->base.Target);
-   int i, face;
-
-   DBG("%s\n", __FUNCTION__);
-
-   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, mode);
-      }
-   }
-}
-
-void
-intel_tex_unmap_images(struct intel_context *intel,
-		       struct intel_texture_object *intelObj)
-{
-   GLuint nr_faces = _mesa_num_tex_faces(intelObj->base.Target);
-   int i, face;
-
-   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);
-      }
-   }
-}
diff --git a/src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c b/src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c
index ebf6a19..4cb1838 100644
--- a/src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c
+++ b/src/mesa/drivers/dri/radeon/radeon_mipmap_tree.c
@@ -431,27 +431,6 @@ 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.Map) {
-		/* This condition should be removed, it's here to workaround
-		 * a segfault when mapping textures during software fallbacks.
-		 */
-		radeon_print(RADEON_FALLBACKS, RADEON_IMPORTANT,
-				"%s Trying to map texture in software fallback.\n",
-				__func__);
-		const uint32_t srcrowstride = _mesa_format_row_stride(image->base.Base.TexFormat, image->base.Base.Width);
-		uint32_t rows = image->base.Base.Height * image->base.Base.Depth;
-
-		if (_mesa_is_format_compressed(image->base.Base.TexFormat)) {
-			uint32_t blockWidth, blockHeight;
-			_mesa_get_format_block_size(image->base.Base.TexFormat, &blockWidth, &blockHeight);
-			rows = (rows + blockHeight - 1) / blockHeight;
-		}
-
-		copy_rows(dest, dstlvl->rowstride, image->base.Map, srcrowstride,
-				  rows, srcrowstride);
-
-		_mesa_align_free(image->base.Map);
-		image->base.Map = 0;
 	}
 
 	radeon_bo_unmap(mt->bo);
diff --git a/src/mesa/drivers/dri/radeon/radeon_span.c b/src/mesa/drivers/dri/radeon/radeon_span.c
index 0617adc..6a7df73 100644
--- a/src/mesa/drivers/dri/radeon/radeon_span.c
+++ b/src/mesa/drivers/dri/radeon/radeon_span.c
@@ -119,18 +119,11 @@ radeon_unmap_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb)
 static void radeonSpanRenderStart(struct gl_context * ctx)
 {
 	radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
-	int i;
 
 	radeon_firevertices(rmesa);
 
-	for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) {
-		if (ctx->Texture.Unit[i]._ReallyEnabled) {
-			radeon_validate_texture_miptree(ctx, _mesa_get_samplerobj(ctx, i),
-							ctx->Texture.Unit[i]._Current);
-			radeon_swrast_map_texture_images(ctx, ctx->Texture.Unit[i]._Current);
-		}
-	}
-	
+	_swrast_map_textures(ctx);
+
 	radeon_map_framebuffer(ctx, ctx->DrawBuffer);
 	if (ctx->ReadBuffer != ctx->DrawBuffer)
 		radeon_map_framebuffer(ctx, ctx->ReadBuffer);
@@ -138,13 +131,8 @@ static void radeonSpanRenderStart(struct gl_context * ctx)
 
 static void radeonSpanRenderFinish(struct gl_context * ctx)
 {
-	int i;
-
 	_swrast_flush(ctx);
-
-	for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++)
-		if (ctx->Texture.Unit[i]._ReallyEnabled)
-			radeon_swrast_unmap_texture_images(ctx, ctx->Texture.Unit[i]._Current);
+	_swrast_unmap_textures(ctx);
 
 	radeon_unmap_framebuffer(ctx, ctx->DrawBuffer);
 	if (ctx->ReadBuffer != ctx->DrawBuffer)
diff --git a/src/mesa/drivers/dri/radeon/radeon_texture.c b/src/mesa/drivers/dri/radeon/radeon_texture.c
index aa2f734..52cf95d 100644
--- a/src/mesa/drivers/dri/radeon/radeon_texture.c
+++ b/src/mesa/drivers/dri/radeon/radeon_texture.c
@@ -630,80 +630,6 @@ radeon_init_common_texture_funcs(radeonContextPtr radeon,
 	radeonInitTextureFormats();
 }
 
-static void
-radeon_swrast_map_image(radeonContextPtr rmesa,
-			radeon_texture_image *image)
-{
-	GLuint level, face;
-	radeon_mipmap_tree *mt;
-	GLuint texel_size;
-	radeon_mipmap_level *lvl;
-
-	if (!image || !image->mt)
-		return;
-
-	texel_size = _mesa_get_format_bytes(image->base.Base.TexFormat);
-	level = image->base.Base.Level;
-	face = image->base.Base.Face;
-	mt = image->mt;
-
-	lvl = &image->mt->levels[level];
-
-	radeon_bo_map(mt->bo, 1);
-	
-	image->base.Map = mt->bo->ptr + lvl->faces[face].offset;
-
-	for (int i = 0; i < mt->levels[level].depth; i++) {
-		image->base.ImageSlices[i] =
-			image->base.Map + (lvl->rowstride * lvl->height * i);
-	}
-
-	image->base.RowStride = lvl->rowstride / texel_size;
-}
-
-static void
-radeon_swrast_unmap_image(radeonContextPtr rmesa,
-			  radeon_texture_image *image)
-{
-	if (image && image->mt) {
-		image->base.Map = NULL;
-		radeon_bo_unmap(image->mt->bo);
-	}
-}
-
-void
-radeon_swrast_map_texture_images(struct gl_context *ctx,
-				 struct gl_texture_object *texObj)
-{
-	radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
-	GLuint nr_faces = _mesa_num_tex_faces(texObj->Target);
-	int i, face;
-
-	for (i = texObj->BaseLevel; i <= texObj->_MaxLevel; i++) {
-		for (face = 0; face < nr_faces; face++) {
-			radeon_texture_image *image = get_radeon_texture_image(texObj->Image[face][i]);
-			radeon_swrast_map_image(rmesa, image);
-		}
-	}
-}
-
-void
-radeon_swrast_unmap_texture_images(struct gl_context *ctx,
-				   struct gl_texture_object *texObj)
-{
-	radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
-	GLuint nr_faces = _mesa_num_tex_faces(texObj->Target);
-	int i, face;
-
-	for (i = texObj->BaseLevel; i <= texObj->_MaxLevel; i++) {
-		for (face = 0; face < nr_faces; face++) {
-			radeon_texture_image *image = get_radeon_texture_image(texObj->Image[face][i]);
-			radeon_swrast_unmap_image(rmesa, image);
-		}
-	}
-	
-}
-
 static radeon_mipmap_tree *radeon_miptree_create_for_teximage(radeonContextPtr rmesa,
 						       struct gl_texture_object *texObj,
 						       struct gl_texture_image *texImage)
diff --git a/src/mesa/drivers/dri/radeon/radeon_texture.h b/src/mesa/drivers/dri/radeon/radeon_texture.h
index 343c171..6ef640c 100644
--- a/src/mesa/drivers/dri/radeon/radeon_texture.h
+++ b/src/mesa/drivers/dri/radeon/radeon_texture.h
@@ -51,9 +51,6 @@ int radeon_validate_texture_miptree(struct gl_context * ctx,
 				    struct gl_texture_object *texObj);
 
 
-void radeon_swrast_map_texture_images(struct gl_context *ctx, struct gl_texture_object *texObj);
-void radeon_swrast_unmap_texture_images(struct gl_context *ctx, struct gl_texture_object *texObj);
-
 gl_format radeonChooseTextureFormat_mesa(struct gl_context * ctx,
                                          GLenum target,
                                          GLint internalFormat,
diff --git a/src/mesa/swrast/s_texture.c b/src/mesa/swrast/s_texture.c
index bfc2e9d..d56e91d 100644
--- a/src/mesa/swrast/s_texture.c
+++ b/src/mesa/swrast/s_texture.c
@@ -257,12 +257,43 @@ _swrast_map_texture(struct gl_context *ctx, struct gl_texture_object *texObj)
    for (face = 0; face < faces; face++) {
       for (level = texObj->BaseLevel; level < MAX_TEXTURE_LEVELS; level++) {
          struct gl_texture_image *texImage = texObj->Image[face][level];
-         if (texImage) {
-            struct swrast_texture_image *swImage =
-               swrast_texture_image(texImage);
+         struct swrast_texture_image *swImage =
+            swImage = swrast_texture_image(texImage);
+         unsigned int i;
+
+         if (!texImage)
+            continue;
+
+         /* In the case of a swrast-allocated texture buffer, the ImageSlices
+          * and RowStride are always available.
+          */
+         if (swImage->Buffer) {
+            assert(swImage->ImageSlices[0] == swImage->Buffer);
+            continue;
+         }
 
-            /* XXX we'll eventually call _swrast_map_teximage() here */
-            swImage->Map = swImage->Buffer;
+         for (i = 0; i < texture_slices(texImage); i++) {
+            GLubyte *map;
+            GLint rowStride;
+
+            if (swImage->ImageSlices[i])
+               continue;
+
+            ctx->Driver.MapTextureImage(ctx, texImage, i,
+                                        0, 0,
+                                        texImage->Width, texImage->Height,
+                                        GL_MAP_READ_BIT | GL_MAP_WRITE_BIT,
+                                        &map, &rowStride);
+
+            swImage->ImageSlices[i] = map;
+            /* A swrast-using driver has to return the same rowstride for
+             * every slice of the same texture, since we don't track them
+             * separately.
+             */
+            if (i == 0)
+               swImage->RowStride = rowStride;
+            else
+               assert(swImage->RowStride == rowStride);
          }
       }
    }
@@ -278,12 +309,22 @@ _swrast_unmap_texture(struct gl_context *ctx, struct gl_texture_object *texObj)
    for (face = 0; face < faces; face++) {
       for (level = texObj->BaseLevel; level < MAX_TEXTURE_LEVELS; level++) {
          struct gl_texture_image *texImage = texObj->Image[face][level];
-         if (texImage) {
-            struct swrast_texture_image *swImage
-               = swrast_texture_image(texImage);
+         struct swrast_texture_image *swImage =
+            swImage = swrast_texture_image(texImage);
+         unsigned int i;
+
+         if (!texImage)
+            continue;
+
+         if (swImage->Buffer)
+            return;
+
+         for (i = 0; i < texture_slices(texImage); i++) {
+            if (!swImage->ImageSlices[i])
+               continue;
 
-            /* XXX we'll eventually call _swrast_unmap_teximage() here */
-            swImage->Map = NULL;
+            ctx->Driver.UnmapTextureImage(ctx, texImage, i);
+            swImage->ImageSlices[i] = 0;
          }
       }
    }
-- 
1.7.10.4



More information about the mesa-dev mailing list