[Mesa-dev] [PATCH 14/17] intel: Rebuild PBO blit glTexImage() on top of miptrees.

Eric Anholt eric at anholt.net
Fri May 24 13:56:52 PDT 2013


This will ensure that we have resolves if we ever extend this to
glTexSubImage(), and fixes missing image start offset handling.

The texture buffer alloc ended up getting moved up, because we want to
look at the format of the image's actual mt to see if we'll end up
blitting the right thing, in the case of packed depth/stencil uploads.

This is the last caller of intelEmitCopyBlit() on a miptree-wrapped BO.
---
 src/mesa/drivers/dri/intel/intel_tex_image.c | 62 ++++++++++++++--------------
 1 file changed, 32 insertions(+), 30 deletions(-)

diff --git a/src/mesa/drivers/dri/intel/intel_tex_image.c b/src/mesa/drivers/dri/intel/intel_tex_image.c
index a3928bb..4ad5ccc 100644
--- a/src/mesa/drivers/dri/intel/intel_tex_image.c
+++ b/src/mesa/drivers/dri/intel/intel_tex_image.c
@@ -6,6 +6,7 @@
 #include "main/bufferobj.h"
 #include "main/context.h"
 #include "main/formats.h"
+#include "main/image.h"
 #include "main/pbo.h"
 #include "main/renderbuffer.h"
 #include "main/texcompress.h"
@@ -117,9 +118,8 @@ try_pbo_upload(struct gl_context *ctx,
    struct intel_texture_image *intelImage = intel_texture_image(image);
    struct intel_context *intel = intel_context(ctx);
    struct intel_buffer_object *pbo = intel_buffer_object(unpack->BufferObj);
-   GLuint src_offset, src_stride;
-   GLuint dst_x, dst_y;
-   drm_intel_bo *dst_buffer, *src_buffer;
+   GLuint src_offset;
+   drm_intel_bo *src_buffer;
 
    if (!_mesa_is_bufferobj(unpack->BufferObj))
       return false;
@@ -132,14 +132,6 @@ try_pbo_upload(struct gl_context *ctx,
       return false;
    }
 
-   if (!_mesa_format_matches_format_and_type(image->TexFormat,
-                                             format, type, false)) {
-      DBG("%s: format mismatch (upload to %s with format 0x%x, type 0x%x)\n",
-	  __FUNCTION__, _mesa_get_format_name(image->TexFormat),
-	  format, type);
-      return false;
-   }
-
    ctx->Driver.AllocTextureImageBuffer(ctx, image);
 
    if (!intelImage->mt) {
@@ -147,39 +139,49 @@ try_pbo_upload(struct gl_context *ctx,
       return false;
    }
 
+   if (!_mesa_format_matches_format_and_type(intelImage->mt->format,
+                                             format, type, false)) {
+      DBG("%s: format mismatch (upload to %s with format 0x%x, type 0x%x)\n",
+	  __FUNCTION__, _mesa_get_format_name(intelImage->mt->format),
+	  format, type);
+      return false;
+   }
+
    if (image->TexObject->Target == GL_TEXTURE_1D_ARRAY ||
        image->TexObject->Target == GL_TEXTURE_2D_ARRAY) {
       DBG("%s: no support for array textures\n", __FUNCTION__);
       return false;
    }
 
-   dst_buffer = intelImage->mt->region->bo;
    src_buffer = intel_bufferobj_source(intel, pbo, 64, &src_offset);
    /* note: potential 64-bit ptr to 32-bit int cast */
    src_offset += (GLuint) (unsigned long) pixels;
 
-   if (unpack->RowLength > 0)
-      src_stride = unpack->RowLength;
-   else
-      src_stride = image->Width;
-   src_stride *= intelImage->mt->region->cpp;
-
-   intel_miptree_get_image_offset(intelImage->mt, intelImage->base.Base.Level,
-				  intelImage->base.Base.Face,
-				  &dst_x, &dst_y);
-
-   if (!intelEmitCopyBlit(intel,
-			  intelImage->mt->cpp,
-			  src_stride, src_buffer,
-			  src_offset, false,
-			  intelImage->mt->region->pitch, dst_buffer, 0,
-			  intelImage->mt->region->tiling,
-			  0, 0, dst_x, dst_y, image->Width, image->Height,
-			  GL_COPY)) {
+   int src_stride =
+      _mesa_image_row_stride(unpack, image->Width, format, type);
+
+   struct intel_mipmap_tree *pbo_mt =
+      intel_miptree_create_for_bo(intel,
+                                  src_buffer,
+                                  intelImage->mt->format,
+                                  src_offset,
+                                  image->Width, image->Height,
+                                  src_stride, I915_TILING_NONE);
+   if (!pbo_mt)
+      return false;
+
+   if (!intel_miptree_blit(intel,
+                           pbo_mt, 0, 0,
+                           0, 0, false,
+                           intelImage->mt, image->Level, image->Face,
+                           0, 0, false,
+                           image->Width, image->Height, GL_COPY)) {
       DBG("%s: blit failed\n", __FUNCTION__);
       return false;
    }
 
+   intel_miptree_release(&pbo_mt);
+
    DBG("%s: success\n", __FUNCTION__);
    return true;
 }
-- 
1.8.3.rc0



More information about the mesa-dev mailing list