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++) {
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);
}
}
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;
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++;
/* 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 {
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;
}
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,
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,
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 *
{
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;
}