intel: Add an AllocTextureImageBuffer() implementation using miptrees.
authorEric Anholt <eric@anholt.net>
Wed, 21 Sep 2011 21:43:20 +0000 (14:43 -0700)
committerEric Anholt <eric@anholt.net>
Mon, 3 Oct 2011 20:29:37 +0000 (13:29 -0700)
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
src/mesa/drivers/dri/intel/intel_tex.h
src/mesa/drivers/dri/intel/intel_tex_image.c

index bc7b1f64b3e8c7658ef4d609c056cdb2bc8ba115..c7d57f7caf9073f85c37b32a4b589259ee50c322 100644 (file)
@@ -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;
index 895c6348e856393de3fa6c8a257632117e64aee6..d0757b7d746c2350f91ba49aa05d5404471d544e 100644 (file)
@@ -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,
index fb91e40a6d61f1da4dd8f9bb86e178f558b3fe92..7c2831e9d22bce680a3d8628e31b6ca1701184ef 100644 (file)
@@ -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,