[Intel-gfx] [PATCH v2 2/2] i965: Add calls to nonblocking maps

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


When mapping a range of a buffer that has the UNSYNCHRONIZED_BIT, and is
only writable, we can take some shortcuts and let people shoot their
feet.

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 |   35 ++++++++++++++------
 src/mesa/drivers/dri/intel/intel_buffer_objects.h |    8 ++++-
 2 files changed, 31 insertions(+), 12 deletions(-)

diff --git a/src/mesa/drivers/dri/intel/intel_buffer_objects.c b/src/mesa/drivers/dri/intel/intel_buffer_objects.c
index d475355..3a540fa 100644
--- a/src/mesa/drivers/dri/intel/intel_buffer_objects.c
+++ b/src/mesa/drivers/dri/intel/intel_buffer_objects.c
@@ -354,24 +354,29 @@ intel_bufferobj_map_range(struct gl_context * ctx,
 						   length, 64);
 
       drm_intel_gem_bo_map_gtt(intel_obj->range_map_bo);
-      intel_obj->mapped_gtt = GL_TRUE;
+      intel_obj->mapped_type = BO_MAP_TYPE_GTT;
       obj->Pointer = intel_obj->range_map_bo->virtual;
       goto out;
    }
 
    if (!(access & GL_MAP_READ_BIT)) {
-      drm_intel_gem_bo_map_gtt(intel_obj->buffer);
-      intel_obj->mapped_gtt = GL_TRUE;
+      if (access & GL_MAP_UNSYNCHRONIZED_BIT) {
+	 drm_intel_gem_bo_map_nonblocking(intel_obj->buffer);
+	 intel_obj->mapped_type = BO_MAP_TYPE_NONBLOCKING;
+      } else {
+	 drm_intel_gem_bo_map_gtt(intel_obj->buffer);
+	 intel_obj->mapped_type = BO_MAP_TYPE_GTT;
+      }
    } else {
       drm_intel_bo_map(intel_obj->buffer, (access & GL_MAP_WRITE_BIT) != 0);
-      intel_obj->mapped_gtt = GL_FALSE;
+      intel_obj->mapped_type = BO_MAP_TYPE_CPU;
    }
 
    obj->Pointer = intel_obj->buffer->virtual + offset;
 
 out:
    if (!(access & GL_MAP_FLUSH_EXPLICIT_BIT))
-      intel_obj->needs_flush_at_unmap;
+      intel_obj->needs_flush_at_unmap = true;
    return obj->Pointer;
 
 error_out:
@@ -418,10 +423,12 @@ intel_bufferobj_unmap(struct gl_context * ctx, struct gl_buffer_object *obj)
    if (intel_obj->sys_buffer != NULL) {
       /* always keep the mapping around. */
    } else if (intel_obj->range_map_bo != NULL) {
-      if (intel_obj->mapped_gtt) {
+      switch (intel_obj->mapped_type) {
+      case BO_MAP_TYPE_GTT:
 	 drm_intel_gem_bo_unmap_gtt(intel_obj->range_map_bo);
-      } else {
-	 drm_intel_bo_unmap(intel_obj->range_map_bo);
+	 break;
+      default:
+	 return GL_FALSE;
       }
 
       if (intel_obj->needs_flush_at_unmap) {
@@ -430,7 +437,6 @@ intel_bufferobj_unmap(struct gl_context * ctx, struct gl_buffer_object *obj)
 				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
@@ -441,13 +447,20 @@ intel_bufferobj_unmap(struct gl_context * ctx, struct gl_buffer_object *obj)
       intel_batchbuffer_emit_mi_flush(intel);
       intel_obj->range_map_bo = NULL;
    } else if (intel_obj->buffer != NULL) {
-      if (intel_obj->mapped_gtt) {
+      switch (intel_obj->mapped_type) {
+      case BO_MAP_TYPE_GTT:
 	 drm_intel_gem_bo_unmap_gtt(intel_obj->buffer);
-      } else {
+	 break;
+      case BO_MAP_TYPE_CPU:
 	 drm_intel_bo_unmap(intel_obj->buffer);
+	 break;
+      case BO_MAP_TYPE_NONBLOCKING:
+	 drm_intel_gem_bo_unmap_nonblocking(intel_obj->buffer);
+	 break;
       }
    }
 
+   intel_obj->needs_flush_at_unmap = false;
    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 24a1636..fd43bd5 100644
--- a/src/mesa/drivers/dri/intel/intel_buffer_objects.h
+++ b/src/mesa/drivers/dri/intel/intel_buffer_objects.h
@@ -33,6 +33,12 @@
 struct intel_context;
 struct gl_buffer_object;
 
+enum {
+   BO_MAP_TYPE_NONE=0,
+   BO_MAP_TYPE_GTT,
+   BO_MAP_TYPE_CPU,
+   BO_MAP_TYPE_NONBLOCKING
+};
 
 /**
  * Intel vertex/pixel buffer object, derived from Mesa's gl_buffer_object.
@@ -48,8 +54,8 @@ struct intel_buffer_object
 
    drm_intel_bo *range_map_bo;
    bool needs_flush_at_unmap;
+   int mapped_type;
 
-   GLboolean mapped_gtt;
    GLboolean source;
 };
 
-- 
1.7.6.3




More information about the Intel-gfx mailing list