[Mesa-dev] [PATCH 02/16] intel: Add an AllocTextureImageBuffer() implementation using miptrees.

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


Now we can rely on Mesa core for uploads of data without introducing
an extra copy at validate time.
---
 src/mesa/drivers/dri/intel/intel_tex.c       |   43 ++++++++++++++++++++++++++
 src/mesa/drivers/dri/intel/intel_tex.h       |    6 +++
 src/mesa/drivers/dri/intel/intel_tex_image.c |    2 +-
 3 files changed, 50 insertions(+), 1 deletions(-)

diff --git a/src/mesa/drivers/dri/intel/intel_tex.c b/src/mesa/drivers/dri/intel/intel_tex.c
index bc7b1f6..c7d57f7 100644
--- a/src/mesa/drivers/dri/intel/intel_tex.c
+++ b/src/mesa/drivers/dri/intel/intel_tex.c
@@ -49,6 +49,48 @@ intelDeleteTextureObject(struct gl_context *ctx,
    _mesa_delete_texture_object(ctx, texObj);
 }
 
+static GLboolean
+intel_alloc_texture_image_buffer(struct gl_context *ctx,
+				 struct gl_texture_image *image,
+				 gl_format format, GLsizei width,
+				 GLsizei height, GLsizei depth)
+{
+   struct intel_context *intel = intel_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);
+
+   if (intel_texobj->mt &&
+       intel_miptree_match_image(intel_texobj->mt, image)) {
+      intel_miptree_reference(&intel_image->mt, intel_texobj->mt);
+      DBG("%s: alloc obj %p level %d %dx%dx%d using object's miptree %p\n",
+          __FUNCTION__, texobj, image->Level,
+          width, height, depth, intel_texobj->mt);
+      return true;
+   } else if (image->Border == 0) {
+      intel_image->mt = intel_miptree_create_for_teximage(intel, intel_texobj,
+                                                          intel_image,
+                                                          false);
+
+      /* Even if the object currently has a mipmap tree associated
+       * with it, this one is a more likely candidate to represent the
+       * whole object since our level didn't fit what was there
+       * before, and any lower levels would fit into our miptree.
+       */
+      intel_miptree_reference(&intel_texobj->mt, intel_image->mt);
+
+      DBG("%s: alloc obj %p level %d %dx%dx%d using new miptree %p\n",
+          __FUNCTION__, texobj, image->Level,
+          width, height, depth, intel_image->mt);
+      return true;
+   }
+
+   DBG("%s: alloc obj %p level %d %dx%dx%d using swrast\n",
+       __FUNCTION__, texobj, image->Level, width, height, depth);
+
+   return _swrast_alloc_texture_image_buffer(ctx, image, format,
+					     width, height, depth);
+}
 
 static void
 intel_free_texture_image_buffer(struct gl_context * ctx,
@@ -182,6 +224,7 @@ intelInitTextureFuncs(struct dd_function_table *functions)
    functions->NewTextureImage = intelNewTextureImage;
    functions->DeleteTextureImage = intelDeleteTextureImage;
    functions->DeleteTexture = intelDeleteTextureObject;
+   functions->AllocTextureImageBuffer = intel_alloc_texture_image_buffer;
    functions->FreeTextureImageBuffer = intel_free_texture_image_buffer;
    functions->MapTextureImage = intel_map_texture_image;
    functions->UnmapTextureImage = intel_unmap_texture_image;
diff --git a/src/mesa/drivers/dri/intel/intel_tex.h b/src/mesa/drivers/dri/intel/intel_tex.h
index 895c634..d0757b7 100644
--- a/src/mesa/drivers/dri/intel/intel_tex.h
+++ b/src/mesa/drivers/dri/intel/intel_tex.h
@@ -47,6 +47,12 @@ void intelSetTexBuffer(__DRIcontext *pDRICtx,
 void intelSetTexBuffer2(__DRIcontext *pDRICtx,
 			GLint target, GLint format, __DRIdrawable *pDraw);
 
+struct intel_mipmap_tree *
+intel_miptree_create_for_teximage(struct intel_context *intel,
+				  struct intel_texture_object *intelObj,
+				  struct intel_texture_image *intelImage,
+				  GLboolean expect_accelerated_upload);
+
 GLuint intel_finalize_mipmap_tree(struct intel_context *intel, GLuint unit);
 
 void intel_tex_map_level_images(struct intel_context *intel,
diff --git a/src/mesa/drivers/dri/intel/intel_tex_image.c b/src/mesa/drivers/dri/intel/intel_tex_image.c
index fb91e40..7c2831e 100644
--- a/src/mesa/drivers/dri/intel/intel_tex_image.c
+++ b/src/mesa/drivers/dri/intel/intel_tex_image.c
@@ -45,7 +45,7 @@
  * 0)..(1x1).  Consider pruning this tree at a validation if the
  * saving is worth it.
  */
-static struct intel_mipmap_tree *
+struct intel_mipmap_tree *
 intel_miptree_create_for_teximage(struct intel_context *intel,
 				  struct intel_texture_object *intelObj,
 				  struct intel_texture_image *intelImage,
-- 
1.7.6.3



More information about the mesa-dev mailing list