[Mesa-dev] [PATCH 3/9] i965: Drop a special case for guessing small miptree levels.

Eric Anholt eric at anholt.net
Wed Sep 18 12:59:22 PDT 2013


Let's say you started allocating your 2D texture with level 2 of a tree as
a 1x1 image.  The driver doesn't know if this means that level 0 is 4x4 or
4x1 or 1x4, so we would just allocate a single 1x1 and let it get copied
in to the real location at texture validate time later.

Since this is just a temporary allocation that *will* get copied, the
extra space allocation of just taking the normal path which will happen to
producing a 4x1 level 0, 2x1 level 1, and 1x1 level 2 is the right way to
go, to reduce complexity in the normal case.

No change in miptree copies over the course of a piglit run.
---
 src/mesa/drivers/dri/i965/intel_tex_image.c | 73 ++++++++++++-----------------
 1 file changed, 30 insertions(+), 43 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_tex_image.c b/src/mesa/drivers/dri/i965/intel_tex_image.c
index f270862..725d315 100644
--- a/src/mesa/drivers/dri/i965/intel_tex_image.c
+++ b/src/mesa/drivers/dri/i965/intel_tex_image.c
@@ -45,50 +45,37 @@ intel_miptree_create_for_teximage(struct brw_context *brw,
 
    DBG("%s\n", __FUNCTION__);
 
-   if (intelImage->base.Base.Level > intelObj->base.BaseLevel &&
-       (width == 1 ||
-        (intelObj->base.Target != GL_TEXTURE_1D && height == 1) ||
-        (intelObj->base.Target == GL_TEXTURE_3D && depth == 1))) {
-      /* For this combination, we're at some lower mipmap level and
-       * some important dimension is 1.  We can't extrapolate up to a
-       * likely base level width/height/depth for a full mipmap stack
-       * from this info, so just allocate this one level.
-       */
-      firstLevel = intelImage->base.Base.Level;
-      lastLevel = intelImage->base.Base.Level;
-   } else {
-      /* If this image disrespects BaseLevel, allocate from level zero.
-       * Usually BaseLevel == 0, so it's unlikely to happen.
-       */
-      if (intelImage->base.Base.Level < intelObj->base.BaseLevel)
-	 firstLevel = 0;
-      else
-	 firstLevel = intelObj->base.BaseLevel;
-
-      /* Figure out image dimensions at start level. */
-      for (i = intelImage->base.Base.Level; i > firstLevel; i--) {
-	 width <<= 1;
-	 if (height != 1)
-	    height <<= 1;
-	 if (depth != 1)
-	    depth <<= 1;
-      }
+   /* If this image disrespects BaseLevel, allocate from level zero.
+    * Usually BaseLevel == 0, so it's unlikely to happen.
+    */
+   if (intelImage->base.Base.Level < intelObj->base.BaseLevel)
+      firstLevel = 0;
+   else
+      firstLevel = intelObj->base.BaseLevel;
+
+   /* Figure out image dimensions at start level. */
+   for (i = intelImage->base.Base.Level; i > firstLevel; i--) {
+      width <<= 1;
+      if (height != 1)
+         height <<= 1;
+      if (depth != 1)
+         depth <<= 1;
+   }
 
-      /* Guess a reasonable value for lastLevel.  This is probably going
-       * to be wrong fairly often and might mean that we have to look at
-       * resizable buffers, or require that buffers implement lazy
-       * pagetable arrangements.
-       */
-      if ((intelObj->base.Sampler.MinFilter == GL_NEAREST ||
-	   intelObj->base.Sampler.MinFilter == GL_LINEAR) &&
-	  intelImage->base.Base.Level == firstLevel &&
-	  firstLevel == 0) {
-	 lastLevel = firstLevel;
-      } else {
-	 lastLevel = (firstLevel +
-                      _mesa_get_tex_max_num_levels(intelObj->base.Target,
-                                                   width, height, depth) - 1);
-      }
+   /* Guess a reasonable value for lastLevel.  This is probably going
+    * to be wrong fairly often and might mean that we have to look at
+    * resizable buffers, or require that buffers implement lazy
+    * pagetable arrangements.
+    */
+   if ((intelObj->base.Sampler.MinFilter == GL_NEAREST ||
+        intelObj->base.Sampler.MinFilter == GL_LINEAR) &&
+       intelImage->base.Base.Level == firstLevel &&
+       firstLevel == 0) {
+      lastLevel = firstLevel;
+   } else {
+      lastLevel = (firstLevel +
+                   _mesa_get_tex_max_num_levels(intelObj->base.Target,
+                                                width, height, depth) - 1);
    }
 
    return intel_miptree_create(brw,
-- 
1.8.4.rc3



More information about the mesa-dev mailing list