[Intel-gfx] [PATCH v2 1/2] i965: Cleanup MapRangeBuffer

Ben Widawsky ben at bwidawsk.net
Sat Sep 24 02:36:16 CEST 2011


Clean the code up, and always use a BO when creating a new buffer. I've
not seen any regressions but haven't yet tried this on < Gen6.

Cc: Chad Versace <chad at chad-versace.us>
Cc: Eric Anholt <eric at anholt.net>
Cc: Mesa Devs <mesa-dev at lists.freedesktop.org>
Signed-off-by: Ben Widawsky <ben at bwidawsk.net>
---
 src/mesa/drivers/dri/intel/intel_buffer_objects.c |   86 +++++++++------------
 src/mesa/drivers/dri/intel/intel_buffer_objects.h |    4 +-
 2 files changed, 37 insertions(+), 53 deletions(-)

diff --git a/src/mesa/drivers/dri/intel/intel_buffer_objects.c b/src/mesa/drivers/dri/intel/intel_buffer_objects.c
index 4df2d76..d475355 100644
--- a/src/mesa/drivers/dri/intel/intel_buffer_objects.c
+++ b/src/mesa/drivers/dri/intel/intel_buffer_objects.c
@@ -291,6 +291,12 @@ intel_bufferobj_map_range(struct gl_context * ctx,
 
    assert(intel_obj);
 
+   if (access & GL_MAP_FLUSH_EXPLICIT_BIT)
+      goto error_out;
+
+   if (access & GL_MAP_INVALIDATE_RANGE_BIT)
+      goto error_out;
+
    /* _mesa_MapBufferRange (GL entrypoint) sets these, but the vbo module also
     * internally uses our functions directly.
     */
@@ -322,10 +328,8 @@ intel_bufferobj_map_range(struct gl_context * ctx,
        drm_intel_bo_references(intel->batch.bo, intel_obj->buffer))
       intel_flush(ctx);
 
-   if (intel_obj->buffer == NULL) {
-      obj->Pointer = NULL;
-      return NULL;
-   }
+   if (intel_obj->buffer == NULL)
+      goto error_out; 
 
    /* If the user doesn't care about existing buffer contents and mapping
     * would cause us to block, then throw out the old buffer.
@@ -344,24 +348,15 @@ intel_bufferobj_map_range(struct gl_context * ctx,
     */
    if ((access & GL_MAP_INVALIDATE_RANGE_BIT) &&
        drm_intel_bo_busy(intel_obj->buffer)) {
-      if (access & GL_MAP_FLUSH_EXPLICIT_BIT) {
-	 intel_obj->range_map_buffer = malloc(length);
-	 obj->Pointer = intel_obj->range_map_buffer;
-      } else {
-	 intel_obj->range_map_bo = drm_intel_bo_alloc(intel->bufmgr,
-						      "range map",
-						      length, 64);
-	 if (!(access & GL_MAP_READ_BIT)) {
-	    drm_intel_gem_bo_map_gtt(intel_obj->range_map_bo);
-	    intel_obj->mapped_gtt = GL_TRUE;
-	 } else {
-	    drm_intel_bo_map(intel_obj->range_map_bo,
-			     (access & GL_MAP_WRITE_BIT) != 0);
-	    intel_obj->mapped_gtt = GL_FALSE;
-	 }
-	 obj->Pointer = intel_obj->range_map_bo->virtual;
-      }
-      return obj->Pointer;
+
+      intel_obj->range_map_bo = drm_intel_bo_alloc(intel->bufmgr,
+						   "range map",
+						   length, 64);
+
+      drm_intel_gem_bo_map_gtt(intel_obj->range_map_bo);
+      intel_obj->mapped_gtt = GL_TRUE;
+      obj->Pointer = intel_obj->range_map_bo->virtual;
+      goto out;
    }
 
    if (!(access & GL_MAP_READ_BIT)) {
@@ -373,7 +368,15 @@ intel_bufferobj_map_range(struct gl_context * ctx,
    }
 
    obj->Pointer = intel_obj->buffer->virtual + offset;
+
+out:
+   if (!(access & GL_MAP_FLUSH_EXPLICIT_BIT))
+      intel_obj->needs_flush_at_unmap;
    return obj->Pointer;
+
+error_out:
+      obj->Pointer = NULL;
+      return NULL;
 }
 
 /* Ideally we'd use a BO to avoid taking up cache space for the temporary
@@ -388,27 +391,16 @@ intel_bufferobj_flush_mapped_range(struct gl_context *ctx,
 {
    struct intel_context *intel = intel_context(ctx);
    struct intel_buffer_object *intel_obj = intel_buffer_object(obj);
-   drm_intel_bo *temp_bo;
-
-   /* Unless we're in the range map using a temporary system buffer,
-    * there's no work to do.
-    */
-   if (intel_obj->range_map_buffer == NULL)
-      return;
 
    if (length == 0)
       return;
 
-   temp_bo = drm_intel_bo_alloc(intel->bufmgr, "range map flush", length, 64);
-
-   drm_intel_bo_subdata(temp_bo, 0, length, intel_obj->range_map_buffer);
-
    intel_emit_linear_blit(intel,
 			  intel_obj->buffer, obj->Offset + offset,
-			  temp_bo, 0,
+			  intel_obj->range_map_bo, 0,
 			  length);
 
-   drm_intel_bo_unreference(temp_bo);
+   drm_intel_bo_unreference(intel_obj->range_map_bo);
 }
 
 
@@ -425,15 +417,6 @@ intel_bufferobj_unmap(struct gl_context * ctx, struct gl_buffer_object *obj)
    assert(obj->Pointer);
    if (intel_obj->sys_buffer != NULL) {
       /* always keep the mapping around. */
-   } else if (intel_obj->range_map_buffer != NULL) {
-      /* Since we've emitted some blits to buffers that will (likely) be used
-       * in rendering operations in other cache domains in this batch, emit a
-       * flush.  Once again, we wish for a domain tracker in libdrm to cover
-       * usage inside of a batchbuffer.
-       */
-      intel_batchbuffer_emit_mi_flush(intel);
-      free(intel_obj->range_map_buffer);
-      intel_obj->range_map_buffer = NULL;
    } else if (intel_obj->range_map_bo != NULL) {
       if (intel_obj->mapped_gtt) {
 	 drm_intel_gem_bo_unmap_gtt(intel_obj->range_map_bo);
@@ -441,10 +424,14 @@ intel_bufferobj_unmap(struct gl_context * ctx, struct gl_buffer_object *obj)
 	 drm_intel_bo_unmap(intel_obj->range_map_bo);
       }
 
-      intel_emit_linear_blit(intel,
-			     intel_obj->buffer, obj->Offset,
-			     intel_obj->range_map_bo, 0,
-			     obj->Length);
+      if (intel_obj->needs_flush_at_unmap) {
+	 intel_emit_linear_blit(intel,
+				intel_obj->buffer, obj->Offset,
+				intel_obj->range_map_bo, 0,
+				obj->Length);
+	 drm_intel_bo_unreference(intel_obj->range_map_bo);
+	 intel_obj->needs_flush_at_unmap = false;
+      }
 
       /* Since we've emitted some blits to buffers that will (likely) be used
        * in rendering operations in other cache domains in this batch, emit a
@@ -452,8 +439,6 @@ intel_bufferobj_unmap(struct gl_context * ctx, struct gl_buffer_object *obj)
        * usage inside of a batchbuffer.
        */
       intel_batchbuffer_emit_mi_flush(intel);
-
-      drm_intel_bo_unreference(intel_obj->range_map_bo);
       intel_obj->range_map_bo = NULL;
    } else if (intel_obj->buffer != NULL) {
       if (intel_obj->mapped_gtt) {
@@ -462,6 +447,7 @@ intel_bufferobj_unmap(struct gl_context * ctx, struct gl_buffer_object *obj)
 	 drm_intel_bo_unmap(intel_obj->buffer);
       }
    }
+
    obj->Pointer = NULL;
    obj->Offset = 0;
    obj->Length = 0;
diff --git a/src/mesa/drivers/dri/intel/intel_buffer_objects.h b/src/mesa/drivers/dri/intel/intel_buffer_objects.h
index e74d061..24a1636 100644
--- a/src/mesa/drivers/dri/intel/intel_buffer_objects.h
+++ b/src/mesa/drivers/dri/intel/intel_buffer_objects.h
@@ -47,9 +47,7 @@ struct intel_buffer_object
    void *sys_buffer;
 
    drm_intel_bo *range_map_bo;
-   void *range_map_buffer;
-   unsigned int range_map_offset;
-   GLsizei range_map_size;
+   bool needs_flush_at_unmap;
 
    GLboolean mapped_gtt;
    GLboolean source;
-- 
1.7.6.3




More information about the Intel-gfx mailing list