intel: Use specified alignment for writes into the upload buffer
authorChris Wilson <chris@chris-wilson.co.uk>
Fri, 18 Feb 2011 12:30:37 +0000 (12:30 +0000)
committerChris Wilson <chris@chris-wilson.co.uk>
Mon, 21 Feb 2011 12:59:36 +0000 (12:59 +0000)
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
src/mesa/drivers/dri/i965/brw_draw_upload.c
src/mesa/drivers/dri/intel/intel_buffer_objects.c
src/mesa/drivers/dri/intel/intel_buffer_objects.h

index daae136a143fd7083d2abd64789b39d3f95aeae3..d4841226bfa3ef3aad4ae86ae8177bc5b1f3a9d1 100644 (file)
@@ -249,11 +249,11 @@ copy_array_to_vbo_array( struct brw_context *brw,
 
    buffer->stride = dst_stride;
    if (dst_stride == element->glarray->StrideB) {
-      intel_upload_data(&brw->intel, element->glarray->Ptr, size,
+      intel_upload_data(&brw->intel, element->glarray->Ptr, size, dst_stride,
                        &buffer->bo, &buffer->offset);
    } else {
       const unsigned char *src = element->glarray->Ptr;
-      char *dst = intel_upload_map(&brw->intel, size);
+      char *dst = intel_upload_map(&brw->intel, size, dst_stride);
       int i;
 
       for (i = 0; i < element->count; i++) {
@@ -261,7 +261,7 @@ copy_array_to_vbo_array( struct brw_context *brw,
         src += element->glarray->StrideB;
         dst += dst_stride;
       }
-      intel_upload_unmap(&brw->intel, dst, size,
+      intel_upload_unmap(&brw->intel, dst, size, dst_stride,
                         &buffer->bo, &buffer->offset);
    }
 }
@@ -421,7 +421,7 @@ static void brw_prepare_vertices(struct brw_context *brw)
         int count = upload[0]->count, offset;
         char *map;
 
-        map = intel_upload_map(&brw->intel, total_size * count);
+        map = intel_upload_map(&brw->intel, total_size * count, total_size);
         for (i = offset = 0; i < nr_uploads; i++) {
            const unsigned char *src = upload[i]->glarray->Ptr;
            int size = upload[i]->element_size;
@@ -440,7 +440,7 @@ static void brw_prepare_vertices(struct brw_context *brw)
 
            offset += size;
         }
-        intel_upload_unmap(&brw->intel, map, total_size * count,
+        intel_upload_unmap(&brw->intel, map, total_size * count, total_size,
                            &buffer->bo, &buffer->offset);
         buffer->stride = offset;
         j++;
@@ -608,7 +608,8 @@ static void brw_prepare_indices(struct brw_context *brw)
 
       /* Get new bufferobj, offset:
        */
-      intel_upload_data(&brw->intel, index_buffer->ptr, ib_size, &bo, &offset);
+      intel_upload_data(&brw->intel, index_buffer->ptr, ib_size, ib_type_size,
+                       &bo, &offset);
       brw->ib.start_vertex_offset = offset / ib_type_size;
       offset = 0;
    } else {
@@ -624,7 +625,8 @@ static void brw_prepare_indices(struct brw_context *brw)
                                                 bufferobj);
            map += offset;
 
-          intel_upload_data(&brw->intel, map, ib_size, &bo, &offset);
+          intel_upload_data(&brw->intel, map, ib_size, ib_type_size,
+                            &bo, &offset);
           brw->ib.start_vertex_offset = offset / ib_type_size;
           offset = 0;
 
index 9d54f47fead5b5d6e195b51bad43a3d7995ccc86..81afe170c1bfe87f54dd3dd23deab84266ba3732 100644 (file)
@@ -603,23 +603,25 @@ static void wrap_buffers(struct intel_context *intel, GLuint size)
 }
 
 void intel_upload_data(struct intel_context *intel,
-                      const void *ptr, GLuint size,
+                      const void *ptr, GLuint size, GLuint align,
                       drm_intel_bo **return_bo,
                       GLuint *return_offset)
 {
-   GLuint asize = ALIGN(size, 64);
+   GLuint base, delta;
 
-   if (intel->upload.bo == NULL ||
-       intel->upload.offset + size > intel->upload.bo->size) {
+   base = (intel->upload.offset + align - 1) / align * align;
+   if (intel->upload.bo == NULL || base + size > intel->upload.bo->size) {
       wrap_buffers(intel, size);
+      base = 0;
    }
 
    drm_intel_bo_reference(intel->upload.bo);
    *return_bo = intel->upload.bo;
-   *return_offset = intel->upload.offset;
+   *return_offset = base;
 
+   delta = base - intel->upload.offset;
    if (intel->upload.buffer_len &&
-       intel->upload.buffer_len + size > sizeof(intel->upload.buffer))
+       intel->upload.buffer_len + delta + size > sizeof(intel->upload.buffer))
    {
       drm_intel_bo_subdata(intel->upload.bo,
                           intel->upload.buffer_offset,
@@ -631,27 +633,35 @@ void intel_upload_data(struct intel_context *intel,
    if (size < sizeof(intel->upload.buffer))
    {
       if (intel->upload.buffer_len == 0)
-        intel->upload.buffer_offset = intel->upload.offset;
+        intel->upload.buffer_offset = base;
+      else
+        intel->upload.buffer_len += delta;
 
       memcpy(intel->upload.buffer + intel->upload.buffer_len, ptr, size);
-      intel->upload.buffer_len += asize;
+      intel->upload.buffer_len += size;
    }
    else
    {
-      drm_intel_bo_subdata(intel->upload.bo,
-                          intel->upload.offset,
-                          size, ptr);
+      drm_intel_bo_subdata(intel->upload.bo, base, size, ptr);
    }
 
-   intel->upload.offset += asize;
+   intel->upload.offset = base + size;
 }
 
-void *intel_upload_map(struct intel_context *intel, GLuint size)
+void *intel_upload_map(struct intel_context *intel, GLuint size, GLuint align)
 {
+   GLuint base, delta;
    char *ptr;
 
+   base = (intel->upload.offset + align - 1) / align * align;
+   if (intel->upload.bo == NULL || base + size > intel->upload.bo->size) {
+      wrap_buffers(intel, size);
+      base = 0;
+   }
+
+   delta = base - intel->upload.offset;
    if (intel->upload.buffer_len &&
-       intel->upload.buffer_len + size > sizeof(intel->upload.buffer))
+       intel->upload.buffer_len + delta + size > sizeof(intel->upload.buffer))
    {
       drm_intel_bo_subdata(intel->upload.bo,
                           intel->upload.buffer_offset,
@@ -660,23 +670,38 @@ void *intel_upload_map(struct intel_context *intel, GLuint size)
       intel->upload.buffer_len = 0;
    }
 
-   if (size <= sizeof(intel->upload.buffer))
+   if (size <= sizeof(intel->upload.buffer)) {
+      if (intel->upload.buffer_len == 0)
+        intel->upload.buffer_offset = base;
+      else
+        intel->upload.buffer_len += delta;
+
       ptr = intel->upload.buffer + intel->upload.buffer_len;
-   else
+      intel->upload.buffer_len += size;
+   } else
       ptr = malloc(size);
 
    return ptr;
 }
 
 void intel_upload_unmap(struct intel_context *intel,
-                       const void *ptr, GLuint size,
+                       const void *ptr, GLuint size, GLuint align,
                        drm_intel_bo **return_bo,
                        GLuint *return_offset)
 {
-   intel_upload_data(intel, ptr, size, return_bo, return_offset);
+   GLuint base;
 
-   if (size > sizeof(intel->upload.buffer))
+   base = (intel->upload.offset + align - 1) / align * align;
+   if (size > sizeof(intel->upload.buffer)) {
+      drm_intel_bo_subdata(intel->upload.bo, base, size, ptr);
       free((void*)ptr);
+   }
+
+   drm_intel_bo_reference(intel->upload.bo);
+   *return_bo = intel->upload.bo;
+   *return_offset = base;
+
+   intel->upload.offset = base + size;
 }
 
 drm_intel_bo *
@@ -686,7 +711,7 @@ intel_bufferobj_source(struct intel_context *intel,
 {
    if (intel_obj->buffer == NULL) {
       intel_upload_data(intel,
-                       intel_obj->sys_buffer, intel_obj->Base.Size,
+                       intel_obj->sys_buffer, intel_obj->Base.Size, 64,
                        &intel_obj->buffer, &intel_obj->offset);
       intel_obj->source = 1;
    }
index 2d86becdf3e72d4eef3b1d835023848710671792..3ec3a521382d1c4546a7e12216c7ac2e8c6955d9 100644 (file)
@@ -71,14 +71,14 @@ drm_intel_bo *intel_bufferobj_source(struct intel_context *intel,
                                     GLuint *offset);
 
 void intel_upload_data(struct intel_context *intel,
-                      const void *ptr, GLuint size,
+                      const void *ptr, GLuint size, GLuint align,
                       drm_intel_bo **return_bo,
                       GLuint *return_offset);
 
 void *intel_upload_map(struct intel_context *intel,
-                      GLuint size);
+                      GLuint size, GLuint align);
 void intel_upload_unmap(struct intel_context *intel,
-                       const void *ptr, GLuint size,
+                       const void *ptr, GLuint size, GLuint align,
                        drm_intel_bo **return_bo,
                        GLuint *return_offset);