intel: Reserve less batchbuffer space.
[mesa.git] / src / mesa / drivers / dri / intel / intel_tex_image.c
index 63a1be03775e14004b56d589afa922ad3a8a0535..fba02c2b7d14f2b2793ef50005ab945ff1d243ff 100644 (file)
@@ -1,12 +1,12 @@
 
 #include "main/glheader.h"
 #include "main/macros.h"
-#include "main/mfeatures.h"
 #include "main/mtypes.h"
 #include "main/enums.h"
 #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"
@@ -22,7 +22,6 @@
 #include "intel_tex.h"
 #include "intel_blit.h"
 #include "intel_fbo.h"
-#include "intel_span.h"
 
 #ifndef I915
 #include "brw_context.h"
@@ -105,32 +104,9 @@ intel_miptree_create_for_teximage(struct intel_context *intel,
                               depth,
                               expect_accelerated_upload,
                                intelImage->base.Base.NumSamples,
-                               false /* force_y_tiling */);
+                               INTEL_MIPTREE_TILING_ANY);
 }
 
-/* There are actually quite a few combinations this will work for,
- * more than what I've listed here.
- */
-static bool
-check_pbo_format(GLenum format, GLenum type,
-                 gl_format mesa_format)
-{
-   switch (mesa_format) {
-   case MESA_FORMAT_ARGB8888:
-      return (format == GL_BGRA && (type == GL_UNSIGNED_BYTE ||
-                                   type == GL_UNSIGNED_INT_8_8_8_8_REV));
-   case MESA_FORMAT_RGB565:
-      return (format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5);
-   case MESA_FORMAT_L8:
-      return (format == GL_LUMINANCE && type == GL_UNSIGNED_BYTE);
-   case MESA_FORMAT_YCBCR:
-      return (type == GL_UNSIGNED_SHORT_8_8_MESA || type == GL_UNSIGNED_BYTE);
-   default:
-      return false;
-   }
-}
-
-
 /* XXX: Do this for TexSubImage also:
  */
 static bool
@@ -142,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;
@@ -157,13 +132,6 @@ try_pbo_upload(struct gl_context *ctx,
       return false;
    }
 
-   if (!check_pbo_format(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;
-   }
-
    ctx->Driver.AllocTextureImageBuffer(ctx, image);
 
    if (!intelImage->mt) {
@@ -171,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;
 }