diff options
author | Chris Wilson <[email protected]> | 2011-02-18 12:30:37 +0000 |
---|---|---|
committer | Chris Wilson <[email protected]> | 2011-02-21 12:59:36 +0000 |
commit | a07e4811794051dc65187d17b7f85e340e61854e (patch) | |
tree | b743fcc67cfb1cb0834b4f59f5d8440436ec62a7 /src/mesa/drivers/dri | |
parent | d9e591391d490c83ce301aa568a2e0afe4cc3c0a (diff) |
intel: Use specified alignment for writes into the upload buffer
Signed-off-by: Chris Wilson <[email protected]>
Diffstat (limited to 'src/mesa/drivers/dri')
-rw-r--r-- | src/mesa/drivers/dri/i965/brw_draw_upload.c | 16 | ||||
-rw-r--r-- | src/mesa/drivers/dri/intel/intel_buffer_objects.c | 65 | ||||
-rw-r--r-- | src/mesa/drivers/dri/intel/intel_buffer_objects.h | 6 |
3 files changed, 57 insertions, 30 deletions
diff --git a/src/mesa/drivers/dri/i965/brw_draw_upload.c b/src/mesa/drivers/dri/i965/brw_draw_upload.c index daae136a143..d4841226bfa 100644 --- a/src/mesa/drivers/dri/i965/brw_draw_upload.c +++ b/src/mesa/drivers/dri/i965/brw_draw_upload.c @@ -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; diff --git a/src/mesa/drivers/dri/intel/intel_buffer_objects.c b/src/mesa/drivers/dri/intel/intel_buffer_objects.c index 9d54f47fead..81afe170c1b 100644 --- a/src/mesa/drivers/dri/intel/intel_buffer_objects.c +++ b/src/mesa/drivers/dri/intel/intel_buffer_objects.c @@ -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; } diff --git a/src/mesa/drivers/dri/intel/intel_buffer_objects.h b/src/mesa/drivers/dri/intel/intel_buffer_objects.h index 2d86becdf3e..3ec3a521382 100644 --- a/src/mesa/drivers/dri/intel/intel_buffer_objects.h +++ b/src/mesa/drivers/dri/intel/intel_buffer_objects.h @@ -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); |