intel: Assert that the linear blits succeed.
[mesa.git] / src / mesa / drivers / dri / intel / intel_blit.c
index f12a1c6fd392e04315ae85bdb9ae224c34546480..f4f93b5a13489af6e9399be36d565f9698a7e601 100644 (file)
@@ -89,6 +89,10 @@ intelEmitCopyBlit(struct intel_context *intel,
    dri_bo *aper_array[3];
    BATCH_LOCALS;
 
+   /* Blits are in a different ringbuffer so we don't use them. */
+   if (intel->gen >= 6)
+      return GL_FALSE;
+
    if (dst_tiling != I915_TILING_NONE) {
       if (dst_offset & 4095)
         return GL_FALSE;
@@ -115,22 +119,23 @@ intelEmitCopyBlit(struct intel_context *intel,
            break;
    } while (pass < 2);
 
+   intel_prepare_render(intel);
+
    if (pass >= 2) {
-       dri_bo_map(dst_buffer, GL_TRUE);
-       dri_bo_map(src_buffer, GL_FALSE);
-       _mesa_copy_rect((GLubyte *)dst_buffer->virtual + dst_offset,
-                       cpp,
-                       dst_pitch,
-                       dst_x, dst_y, 
-                       w, h, 
-                       (GLubyte *)src_buffer->virtual + src_offset, 
-                       src_pitch,
-                       src_x, src_y);
-       
-       dri_bo_unmap(src_buffer);
-       dri_bo_unmap(dst_buffer);
-
-       return GL_TRUE;
+      drm_intel_gem_bo_map_gtt(dst_buffer);
+      drm_intel_gem_bo_map_gtt(src_buffer);
+      _mesa_copy_rect((GLubyte *)dst_buffer->virtual + dst_offset,
+                     cpp,
+                     dst_pitch,
+                     dst_x, dst_y,
+                     w, h,
+                     (GLubyte *)src_buffer->virtual + src_offset,
+                     src_pitch,
+                     src_x, src_y);
+      drm_intel_gem_bo_unmap_gtt(src_buffer);
+      drm_intel_gem_bo_unmap_gtt(dst_buffer);
+
+      return GL_TRUE;
    }
 
    intel_batchbuffer_require_space(intel->batch, 8 * 4);
@@ -183,14 +188,14 @@ intelEmitCopyBlit(struct intel_context *intel,
    OUT_BATCH(BR13 | (uint16_t)dst_pitch);
    OUT_BATCH((dst_y << 16) | dst_x);
    OUT_BATCH((dst_y2 << 16) | dst_x2);
-   OUT_RELOC(dst_buffer,
-            I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
-            dst_offset);
+   OUT_RELOC_FENCED(dst_buffer,
+                   I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
+                   dst_offset);
    OUT_BATCH((src_y << 16) | src_x);
    OUT_BATCH((uint16_t)src_pitch);
-   OUT_RELOC(src_buffer,
-            I915_GEM_DOMAIN_RENDER, 0,
-            src_offset);
+   OUT_RELOC_FENCED(src_buffer,
+                   I915_GEM_DOMAIN_RENDER, 0,
+                   src_offset);
    ADVANCE_BATCH();
 
    intel_batchbuffer_emit_mi_flush(intel->batch);
@@ -216,6 +221,9 @@ intelClearWithBlit(GLcontext *ctx, GLbitfield mask)
    GLint cx, cy, cw, ch;
    BATCH_LOCALS;
 
+   /* Blits are in a different ringbuffer so we don't use them. */
+   assert(intel->gen < 6);
+
    /*
     * Compute values for clearing the buffers.
     */
@@ -229,9 +237,9 @@ intelClearWithBlit(GLcontext *ctx, GLbitfield mask)
 
    cx = fb->_Xmin;
    if (fb->Name == 0)
-      cy = fb->_Ymin;
-   else
       cy = ctx->DrawBuffer->Height - fb->_Ymax;
+   else
+      cy = fb->_Ymin;
    cw = fb->_Xmax - fb->_Xmin;
    ch = fb->_Ymax - fb->_Ymin;
 
@@ -241,6 +249,8 @@ intelClearWithBlit(GLcontext *ctx, GLbitfield mask)
    GLuint buf;
    all = (cw == fb->Width && ch == fb->Height);
 
+   intel_prepare_render(intel);
+
    /* Loop over all renderbuffers */
    for (buf = 0; buf < BUFFER_COUNT && mask; buf++) {
       const GLbitfield bufBit = 1 << buf;
@@ -250,6 +260,7 @@ intelClearWithBlit(GLcontext *ctx, GLbitfield mask)
       uint32_t clear_val;
       uint32_t BR13, CMD;
       int pitch, cpp;
+      drm_intel_bo *aper_array[2];
 
       if (!(mask & bufBit))
         continue;
@@ -340,14 +351,23 @@ intelClearWithBlit(GLcontext *ctx, GLbitfield mask)
       assert(x1 < x2);
       assert(y1 < y2);
 
+      /* do space check before going any further */
+      aper_array[0] = intel->batch->buf;
+      aper_array[1] = write_buffer;
+
+      if (drm_intel_bufmgr_check_aperture_space(aper_array,
+                                               ARRAY_SIZE(aper_array)) != 0) {
+        intel_batchbuffer_flush(intel->batch);
+      }
+
       BEGIN_BATCH(6);
       OUT_BATCH(CMD);
       OUT_BATCH(BR13);
       OUT_BATCH((y1 << 16) | x1);
       OUT_BATCH((y2 << 16) | x2);
-      OUT_RELOC(write_buffer,
-               I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
-               0);
+      OUT_RELOC_FENCED(write_buffer,
+                      I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
+                      0);
       OUT_BATCH(clear_val);
       ADVANCE_BATCH();
 
@@ -374,6 +394,10 @@ intelEmitImmediateColorExpandBlit(struct intel_context *intel,
    int dwords = ALIGN(src_size, 8) / 4;
    uint32_t opcode, br13, blit_cmd;
 
+   /* Blits are in a different ringbuffer so we don't use them. */
+   if (intel->gen >= 6)
+      return GL_FALSE;
+
    if (dst_tiling != I915_TILING_NONE) {
       if (dst_offset & 4095)
         return GL_FALSE;
@@ -424,9 +448,9 @@ intelEmitImmediateColorExpandBlit(struct intel_context *intel,
    OUT_BATCH(br13);
    OUT_BATCH((0 << 16) | 0); /* clip x1, y1 */
    OUT_BATCH((100 << 16) | 100); /* clip x2, y2 */
-   OUT_RELOC(dst_buffer,
-            I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
-            dst_offset);
+   OUT_RELOC_FENCED(dst_buffer,
+                   I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
+                   dst_offset);
    OUT_BATCH(0); /* bg */
    OUT_BATCH(fg_color); /* fg */
    OUT_BATCH(0); /* pattern base addr */
@@ -458,29 +482,35 @@ intel_emit_linear_blit(struct intel_context *intel,
                       unsigned int size)
 {
    GLuint pitch, height;
+   GLboolean ok;
+
+   /* Blits are in a different ringbuffer so we don't use them. */
+   assert(intel->gen < 6);
 
    /* The pitch is a signed value. */
    pitch = MIN2(size, (1 << 15) - 1);
    height = size / pitch;
-   intelEmitCopyBlit(intel, 1,
-                    pitch, src_bo, src_offset, I915_TILING_NONE,
-                    pitch, dst_bo, dst_offset, I915_TILING_NONE,
-                    0, 0, /* src x/y */
-                    0, 0, /* dst x/y */
-                    pitch, height, /* w, h */
-                    GL_COPY);
+   ok = intelEmitCopyBlit(intel, 1,
+                         pitch, src_bo, src_offset, I915_TILING_NONE,
+                         pitch, dst_bo, dst_offset, I915_TILING_NONE,
+                         0, 0, /* src x/y */
+                         0, 0, /* dst x/y */
+                         pitch, height, /* w, h */
+                         GL_COPY);
+   assert(ok);
 
    src_offset += pitch * height;
    dst_offset += pitch * height;
    size -= pitch * height;
    assert (size < (1 << 15));
    if (size != 0) {
-      intelEmitCopyBlit(intel, 1,
-                       size, src_bo, src_offset, I915_TILING_NONE,
-                       size, dst_bo, dst_offset, I915_TILING_NONE,
-                       0, 0, /* src x/y */
-                       0, 0, /* dst x/y */
-                       size, 1, /* w, h */
-                       GL_COPY);
+      ok = intelEmitCopyBlit(intel, 1,
+                            size, src_bo, src_offset, I915_TILING_NONE,
+                            size, dst_bo, dst_offset, I915_TILING_NONE,
+                            0, 0, /* src x/y */
+                            0, 0, /* dst x/y */
+                            size, 1, /* w, h */
+                            GL_COPY);
+      assert(ok);
    }
 }