i965: Combine vb upload buffer with the general upload buffer
authorChris Wilson <chris@chris-wilson.co.uk>
Tue, 8 Feb 2011 22:22:36 +0000 (22:22 +0000)
committerChris Wilson <chris@chris-wilson.co.uk>
Mon, 21 Feb 2011 12:59:34 +0000 (12:59 +0000)
Reuse the new common upload buffer for uploading temporary indices and
rebuilt vertex arrays.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
src/mesa/drivers/dri/i965/brw_context.h
src/mesa/drivers/dri/i965/brw_draw.c
src/mesa/drivers/dri/i965/brw_draw_upload.c
src/mesa/drivers/dri/i965/brw_vtbl.c
src/mesa/drivers/dri/intel/intel_buffer_objects.c
src/mesa/drivers/dri/intel/intel_buffer_objects.h

index ea74530be6cdd3d7f5827d3a0e7eadf9c423414a..4fbb554a39dc840d04167d26db89c68bc3c337e7 100644 (file)
@@ -487,14 +487,6 @@ struct brw_context
       struct brw_vertex_element *enabled[VERT_ATTRIB_MAX];
       GLuint nr_enabled;
 
-#define BRW_NR_UPLOAD_BUFS 17
-#define BRW_UPLOAD_INIT_SIZE (128*1024)
-
-      struct {
-        drm_intel_bo *bo;
-        GLuint offset;
-      } upload;
-
       /* Summary of size and varying of active arrays, so we can check
        * for changes to this state:
        */
index 7eb16b71f4af1623ca2abc670e21352bb714ff63..57d1d7bbe076eac4f7a2a53af8168f1887b9b560 100644 (file)
@@ -471,11 +471,6 @@ void brw_draw_destroy( struct brw_context *brw )
 {
    int i;
 
-   if (brw->vb.upload.bo != NULL) {
-      drm_intel_bo_unreference(brw->vb.upload.bo);
-      brw->vb.upload.bo = NULL;
-   }
-
    for (i = 0; i < VERT_ATTRIB_MAX; i++) {
       drm_intel_bo_unreference(brw->vb.inputs[i].bo);
       brw->vb.inputs[i].bo = NULL;
index 7f93f1d5ede040932294adf16957ce4591ad63c1..427de55a9cea4c86ffbe0b70fd15398637e8ca35 100644 (file)
@@ -238,39 +238,6 @@ static GLuint get_index_type(GLenum type)
    }
 }
 
-static void wrap_buffers( struct brw_context *brw,
-                         GLuint size )
-{
-   if (size < BRW_UPLOAD_INIT_SIZE)
-      size = BRW_UPLOAD_INIT_SIZE;
-
-   brw->vb.upload.offset = 0;
-
-   if (brw->vb.upload.bo != NULL)
-      drm_intel_bo_unreference(brw->vb.upload.bo);
-   brw->vb.upload.bo = drm_intel_bo_alloc(brw->intel.bufmgr, "temporary VBO",
-                                         size, 1);
-}
-
-static void get_space( struct brw_context *brw,
-                      GLuint size,
-                      drm_intel_bo **bo_return,
-                      GLuint *offset_return )
-{
-   size = ALIGN(size, 64);
-
-   if (brw->vb.upload.bo == NULL ||
-       brw->vb.upload.offset + size > brw->vb.upload.bo->size) {
-      wrap_buffers(brw, size);
-   }
-
-   assert(*bo_return == NULL);
-   drm_intel_bo_reference(brw->vb.upload.bo);
-   *bo_return = brw->vb.upload.bo;
-   *offset_return = brw->vb.upload.offset;
-   brw->vb.upload.offset += size;
-}
-
 static void
 copy_array_to_vbo_array( struct brw_context *brw,
                         struct brw_vertex_element *element,
@@ -278,8 +245,6 @@ copy_array_to_vbo_array( struct brw_context *brw,
 {
    GLuint size = element->count * dst_stride;
 
-   get_space(brw, size, &element->bo, &element->offset);
-
    if (element->glarray->StrideB == 0) {
       assert(element->count == 1);
       element->stride = 0;
@@ -288,26 +253,19 @@ copy_array_to_vbo_array( struct brw_context *brw,
    }
 
    if (dst_stride == element->glarray->StrideB) {
-      drm_intel_gem_bo_map_gtt(element->bo);
-      memcpy((char *)element->bo->virtual + element->offset,
-            element->glarray->Ptr, size);
-      drm_intel_gem_bo_unmap_gtt(element->bo);
+      intel_upload_data(&brw->intel, element->glarray->Ptr, size,
+                       &element->bo, &element->offset);
    } else {
-      char *dest;
       const unsigned char *src = element->glarray->Ptr;
+      char *dst = intel_upload_map(&brw->intel, size,
+                                  &element->bo, &element->offset);
       int i;
 
-      drm_intel_gem_bo_map_gtt(element->bo);
-      dest = element->bo->virtual;
-      dest += element->offset;
-
       for (i = 0; i < element->count; i++) {
-        memcpy(dest, src, dst_stride);
+        memcpy(dst, src, dst_stride);
         src += element->glarray->StrideB;
-        dest += dst_stride;
+        dst += dst_stride;
       }
-
-      drm_intel_gem_bo_unmap_gtt(element->bo);
    }
 }
 
@@ -606,13 +564,7 @@ static void brw_prepare_indices(struct brw_context *brw)
 
       /* Get new bufferobj, offset:
        */
-      get_space(brw, ib_size, &bo, &offset);
-
-      /* Straight upload
-       */
-      drm_intel_gem_bo_map_gtt(bo);
-      memcpy((char *)bo->virtual + offset, index_buffer->ptr, ib_size);
-      drm_intel_gem_bo_unmap_gtt(bo);
+      intel_upload_data(&brw->intel, index_buffer->ptr, ib_size, &bo, &offset);
    } else {
       offset = (GLuint) (unsigned long) index_buffer->ptr;
       brw->ib.start_vertex_offset = 0;
@@ -627,9 +579,7 @@ static void brw_prepare_indices(struct brw_context *brw)
                                                 bufferobj);
            map += offset;
 
-          get_space(brw, ib_size, &bo, &offset);
-
-          drm_intel_bo_subdata(bo, offset, ib_size, map);
+          intel_upload_data(&brw->intel, map, ib_size, &bo, &offset);
 
            ctx->Driver.UnmapBuffer(ctx, GL_ELEMENT_ARRAY_BUFFER_ARB, bufferobj);
        } else {
@@ -641,7 +591,6 @@ static void brw_prepare_indices(struct brw_context *brw)
 
          bo = intel_bufferobj_source(intel, intel_buffer_object(bufferobj),
                                      &offset);
-         drm_intel_bo_reference(bo);
 
          ib_size = bo->size;
        }
index a7bed95732c21f78f4dab81ddf91eba5858a8e28..31964ee7dfbb5e15162791663bd1dea04be42e76 100644 (file)
@@ -163,15 +163,6 @@ static void brw_new_batch( struct intel_context *intel )
    brw->state.dirty.mesa |= ~0;
    brw->state.dirty.brw |= ~0;
    brw->state.dirty.cache |= ~0;
-
-   /* Move to the end of the current upload buffer so that we'll force choosing
-    * a new buffer next time.
-    */
-   if (brw->vb.upload.bo != NULL) {
-      drm_intel_bo_unreference(brw->vb.upload.bo);
-      brw->vb.upload.bo = NULL;
-      brw->vb.upload.offset = 0;
-   }
 }
 
 static void brw_invalidate_state( struct intel_context *intel, GLuint new_state )
index f54fc1a12bc5267f85bc72f8ed8fcb1453ebecdd..79d9075daa4a264f541e97c57ba5e53864077f3d 100644 (file)
@@ -157,6 +157,7 @@ intel_bufferobj_data(struct gl_context * ctx,
    if (intel_obj->buffer != NULL) {
       drm_intel_bo_unreference(intel_obj->buffer);
       intel_obj->buffer = NULL;
+      intel_obj->source = 0;
    }
    free(intel_obj->sys_buffer);
    intel_obj->sys_buffer = NULL;
@@ -218,6 +219,7 @@ intel_bufferobj_subdata(struct gl_context * ctx,
       if (intel_obj->buffer) {
         drm_intel_bo_unreference(intel_obj->buffer);
         intel_obj->buffer = NULL;
+        intel_obj->source = 0;
       }
       memcpy((char *)intel_obj->sys_buffer + offset, data, size);
    } else {
@@ -290,6 +292,7 @@ intel_bufferobj_map(struct gl_context * ctx,
       if (!read_only && intel_obj->buffer) {
         drm_intel_bo_unreference(intel_obj->buffer);
         intel_obj->buffer = NULL;
+        intel_obj->source = 0;
       }
       obj->Pointer = intel_obj->sys_buffer;
       obj->Length = obj->Size;
@@ -361,6 +364,7 @@ intel_bufferobj_map_range(struct gl_context * ctx,
       if (access != GL_READ_ONLY_ARB && intel_obj->buffer) {
         drm_intel_bo_unreference(intel_obj->buffer);
         intel_obj->buffer = NULL;
+        intel_obj->source = 0;
       }
       obj->Pointer = intel_obj->sys_buffer + offset;
       return obj->Pointer;
@@ -574,28 +578,61 @@ static void wrap_buffers(struct intel_context *intel, GLuint size)
    intel->upload.offset = 0;
 }
 
+void intel_upload_data(struct intel_context *intel,
+                      const void *ptr, GLuint size,
+                      drm_intel_bo **return_bo,
+                      GLuint *return_offset)
+{
+   if (intel->upload.bo == NULL ||
+       intel->upload.offset + size > intel->upload.bo->size) {
+      wrap_buffers(intel, size);
+   }
+
+   drm_intel_bo_reference(intel->upload.bo);
+   *return_bo = intel->upload.bo;
+   *return_offset = intel->upload.offset;
+
+   drm_intel_bo_subdata(intel->upload.bo,
+                       intel->upload.offset,
+                       size, ptr);
+
+   intel->upload.offset += ALIGN(size, 64);
+}
+
+void *intel_upload_map(struct intel_context *intel,
+                      GLuint size,
+                      drm_intel_bo **return_bo,
+                      GLuint *return_offset)
+{
+   char *ptr;
+
+   if (intel->upload.bo == NULL ||
+       intel->upload.offset + size > intel->upload.bo->size) {
+      wrap_buffers(intel, size);
+   }
+
+   drm_intel_bo_reference(intel->upload.bo);
+   *return_bo = intel->upload.bo;
+   *return_offset = intel->upload.offset;
+
+   drm_intel_gem_bo_map_gtt(intel->upload.bo);
+   ptr = intel->upload.bo->virtual;
+   ptr += intel->upload.offset;
+   intel->upload.offset += ALIGN(size, 64);
+
+   return ptr;
+}
+
 drm_intel_bo *
 intel_bufferobj_source(struct intel_context *intel,
                        struct intel_buffer_object *intel_obj,
                       GLuint *offset)
 {
    if (intel_obj->buffer == NULL) {
-      GLuint size = ALIGN(intel_obj->Base.Size, 64);
-
-      if (intel->upload.bo == NULL ||
-         intel->upload.offset + size > intel->upload.bo->size) {
-        wrap_buffers(intel, size);
-      }
-
-      drm_intel_bo_reference(intel->upload.bo);
-      intel_obj->buffer = intel->upload.bo;
-      intel_obj->offset = intel->upload.offset;
+      intel_upload_data(intel,
+                       intel_obj->sys_buffer, intel_obj->Base.Size,
+                       &intel_obj->buffer, &intel_obj->offset);
       intel_obj->source = 1;
-      intel->upload.offset += size;
-
-      drm_intel_bo_subdata(intel_obj->buffer,
-                          intel_obj->offset, intel_obj->Base.Size,
-                          intel_obj->sys_buffer);
    }
 
    *offset = intel_obj->offset;
index c845b70b52e060a7767015ecf536d9ccef9126fd..71f0c52fd8e9aeee8dc4789d6db7de4a584b3f36 100644 (file)
@@ -70,7 +70,17 @@ drm_intel_bo *intel_bufferobj_source(struct intel_context *intel,
                                     struct intel_buffer_object *obj,
                                     GLuint *offset);
 
-/* Hook the bufferobject implementation into mesa: 
+void intel_upload_data(struct intel_context *intel,
+                      const void *ptr, GLuint size,
+                      drm_intel_bo **return_bo,
+                      GLuint *return_offset);
+
+void *intel_upload_map(struct intel_context *intel,
+                      GLuint size,
+                      drm_intel_bo **return_bo,
+                      GLuint *return_offset);
+
+/* Hook the bufferobject implementation into mesa:
  */
 void intelInitBufferObjectFuncs(struct dd_function_table *functions);