intel: Move more of the PBO blit upload logic into that function.
authorEric Anholt <eric@anholt.net>
Wed, 21 Sep 2011 16:32:57 +0000 (09:32 -0700)
committerEric Anholt <eric@anholt.net>
Thu, 22 Sep 2011 18:03:20 +0000 (11:03 -0700)
This also improves the debugging output in the failure paths so you
get more than just "failed", and don't get spammed with "failed" when
you didn't even have a PBO to try.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/mesa/drivers/dri/intel/intel_tex_image.c

index 6db27bca8512c5eaa4ca00f95405147d618f2ff3..9a1249548d763a9939c8286119e8e7ea3bbdd33d 100644 (file)
@@ -156,26 +156,43 @@ check_pbo_format(GLint internalFormat,
 
 /* XXX: Do this for TexSubImage also:
  */
-static GLboolean
+static bool
 try_pbo_upload(struct intel_context *intel,
                struct intel_texture_image *intelImage,
                const struct gl_pixelstore_attrib *unpack,
+              GLenum format, GLenum type,
                GLint width, GLint height, const void *pixels)
 {
    struct intel_buffer_object *pbo = intel_buffer_object(unpack->BufferObj);
    GLuint src_offset, src_stride;
    GLuint dst_x, dst_y, dst_stride;
-   drm_intel_bo *dst_buffer = intel_region_buffer(intel,
-                                                 intelImage->mt->region,
-                                                 INTEL_WRITE_FULL);
+   drm_intel_bo *dst_buffer, *src_buffer;
+
+   if (!_mesa_is_bufferobj(unpack->BufferObj))
+      return false;
+
+   DBG("trying pbo upload\n");
 
-   if (!_mesa_is_bufferobj(unpack->BufferObj) ||
-       intel->ctx._ImageTransferState ||
+   if (!intelImage->mt) {
+      DBG("%s: no miptree\n", __FUNCTION__);
+      return false;
+   }
+
+   if (intel->ctx._ImageTransferState ||
        unpack->SkipPixels || unpack->SkipRows) {
-      DBG("%s: failure 1\n", __FUNCTION__);
-      return GL_FALSE;
+      DBG("%s: image transfer\n", __FUNCTION__);
+      return false;
    }
 
+   if (!check_pbo_format(intelImage->base.Base.InternalFormat, format,
+                        type, intelImage->base.Base.TexFormat)) {
+      DBG("%s: format mismatch (upload to %s with format 0x%x, type 0x%x)\n",
+         __FUNCTION__, _mesa_get_format_name(intelImage->base.Base.TexFormat),
+         format, type);
+      return false;
+   }
+
+   dst_buffer = intel_region_buffer(intel, intelImage->mt->region, INTEL_WRITE_FULL);
    /* note: potential 64-bit ptr to 32-bit int cast */
    src_offset = (GLuint) (unsigned long) pixels;
 
@@ -206,11 +223,13 @@ try_pbo_upload(struct intel_context *intel,
                             intelImage->mt->region->tiling,
                             0, 0, dst_x, dst_y, width, height,
                             GL_COPY)) {
-        return GL_FALSE;
+        DBG("%s: blit failed\n", __FUNCTION__);
+        return false;
       }
    }
 
-   return GL_TRUE;
+   DBG("%s: success\n", __FUNCTION__);
+   return true;
 }
 
 /**
@@ -398,24 +417,12 @@ intelTexImage(struct gl_context * ctx,
       }
    }
 
-   /* PBO fastpaths:
+   /* Attempt to use the blitter for PBO image uploads.
     */
    if (dims <= 2 &&
-       intelImage->mt &&
-       _mesa_is_bufferobj(unpack->BufferObj) &&
-       check_pbo_format(internalFormat, format,
-                        type, intelImage->base.Base.TexFormat)) {
-
-      DBG("trying pbo upload\n");
-
-      /* Otherwise, attempt to use the blitter for PBO image uploads.
-       */
-      if (try_pbo_upload(intel, intelImage, unpack, width, height, pixels)) {
-         DBG("pbo upload succeeded\n");
-         return;
-      }
-
-      DBG("pbo upload failed\n");
+       try_pbo_upload(intel, intelImage, unpack, format, type,
+                     width, height, pixels)) {
+      return;
    }
 
    /* intelCopyTexImage calls this function with pixels == NULL, with