intel: Make a temporary miptree when doing blit uploads for glTexSubImage().
authorEric Anholt <eric@anholt.net>
Thu, 23 May 2013 21:16:15 +0000 (14:16 -0700)
committerEric Anholt <eric@anholt.net>
Tue, 28 May 2013 20:06:56 +0000 (13:06 -0700)
While this is a bit more CPU work, it also is less code to handle this
path, and fixes problems with 32k-pitch textures and missing resolves.

v2: Add error checking in new code.

Reviewed-and-tested-by: Ian Romanick <ian.d.romanick@intel.com> (v1)
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> (v1)
Acked-by: Paul Berry <stereotype441@gmail.com>
src/mesa/drivers/dri/intel/intel_tex_subimage.c

index 42cc739292727904dc2b9c98eb7415fba16a5e35..834288ba2b1094cdbcc6ae501ba2a45ec4b09760 100644 (file)
@@ -53,12 +53,6 @@ intel_blit_texsubimage(struct gl_context * ctx,
 {
    struct intel_context *intel = intel_context(ctx);
    struct intel_texture_image *intelImage = intel_texture_image(texImage);
-   GLuint dstRowStride = 0;
-   drm_intel_bo *temp_bo = NULL;
-   unsigned int blit_x = 0, blit_y = 0;
-   unsigned long pitch;
-   uint32_t tiling_mode = I915_TILING_NONE;
-   GLubyte *dstMap;
 
    /* Try to do a blit upload of the subimage if the texture is
     * currently busy.
@@ -93,60 +87,50 @@ intel_blit_texsubimage(struct gl_context * ctx,
    if (!pixels)
       return false;
 
-   temp_bo = drm_intel_bo_alloc_tiled(intel->bufmgr,
-                                     "subimage blit bo",
-                                     width, height,
-                                     intelImage->mt->cpp,
-                                     &tiling_mode,
-                                     &pitch,
-                                     0);
-   if (temp_bo == NULL) {
-      _mesa_error(ctx, GL_OUT_OF_MEMORY, "intelTexSubImage");
-      return false;
-   }
+   struct intel_mipmap_tree *temp_mt =
+      intel_miptree_create(intel, GL_TEXTURE_2D, texImage->TexFormat,
+                           0, 0,
+                           width, height, 1,
+                           false, 0,
+                           (1 << I915_TILING_NONE) /* force_tiling_mask */);
+   if (!temp_mt)
+      goto err;
 
-   if (drm_intel_gem_bo_map_gtt(temp_bo)) {
-      _mesa_error(ctx, GL_OUT_OF_MEMORY, "intelTexSubImage");
-      return false;
-   }
-
-   dstMap = temp_bo->virtual;
-   dstRowStride = pitch;
-
-   intel_miptree_get_image_offset(intelImage->mt, texImage->Level,
-                                 intelImage->base.Base.Face,
-                                 &blit_x, &blit_y);
-   blit_x += xoffset;
-   blit_y += yoffset;
+   GLubyte *dst = intel_miptree_map_raw(intel, temp_mt);
+   if (!dst)
+      goto err;
 
    if (!_mesa_texstore(ctx, 2, texImage->_BaseFormat,
                       texImage->TexFormat,
-                      dstRowStride,
-                      &dstMap,
+                      temp_mt->region->pitch,
+                      &dst,
                       width, height, 1,
                       format, type, pixels, packing)) {
       _mesa_error(ctx, GL_OUT_OF_MEMORY, "intelTexSubImage");
    }
 
+   intel_miptree_unmap_raw(intel, temp_mt);
+
    bool ret;
 
-   drm_intel_gem_bo_unmap_gtt(temp_bo);
-
-   ret = intelEmitCopyBlit(intel,
-                          intelImage->mt->cpp,
-                          dstRowStride,
-                          temp_bo, 0, false,
-                          intelImage->mt->region->pitch,
-                          intelImage->mt->region->bo, 0,
-                          intelImage->mt->region->tiling,
-                          0, 0, blit_x, blit_y, width, height,
-                          GL_COPY);
+   ret = intel_miptree_blit(intel,
+                            temp_mt, 0, 0,
+                            0, 0, false,
+                            intelImage->mt, texImage->Level, texImage->Face,
+                            xoffset, yoffset, false,
+                            width, height, GL_COPY);
    assert(ret);
 
-   drm_intel_bo_unreference(temp_bo);
+   intel_miptree_release(&temp_mt);
    _mesa_unmap_teximage_pbo(ctx, packing);
 
    return ret;
+
+err:
+   _mesa_error(ctx, GL_OUT_OF_MEMORY, "intelTexSubImage");
+   intel_miptree_release(&temp_mt);
+   _mesa_unmap_teximage_pbo(ctx, packing);
+   return false;
 }
 
 /**