summaryrefslogtreecommitdiffstats
path: root/src/mesa
diff options
context:
space:
mode:
authorChris Wilson <[email protected]>2011-02-08 22:22:36 +0000
committerChris Wilson <[email protected]>2011-02-21 12:59:34 +0000
commitabb37861d9f3310fe2d16194d893682092f41087 (patch)
treef0fe39e0ca39c83951eedb9086feaf3607cfeb30 /src/mesa
parente476e122207e6195a16a8c7d2cab90eeba227934 (diff)
i965: Combine vb upload buffer with the general upload buffer
Reuse the new common upload buffer for uploading temporary indices and rebuilt vertex arrays. Signed-off-by: Chris Wilson <[email protected]>
Diffstat (limited to 'src/mesa')
-rw-r--r--src/mesa/drivers/dri/i965/brw_context.h8
-rw-r--r--src/mesa/drivers/dri/i965/brw_draw.c5
-rw-r--r--src/mesa/drivers/dri/i965/brw_draw_upload.c67
-rw-r--r--src/mesa/drivers/dri/i965/brw_vtbl.c9
-rw-r--r--src/mesa/drivers/dri/intel/intel_buffer_objects.c67
-rw-r--r--src/mesa/drivers/dri/intel/intel_buffer_objects.h12
6 files changed, 71 insertions, 97 deletions
diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h
index ea74530be6c..4fbb554a39d 100644
--- a/src/mesa/drivers/dri/i965/brw_context.h
+++ b/src/mesa/drivers/dri/i965/brw_context.h
@@ -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:
*/
diff --git a/src/mesa/drivers/dri/i965/brw_draw.c b/src/mesa/drivers/dri/i965/brw_draw.c
index 7eb16b71f4a..57d1d7bbe07 100644
--- a/src/mesa/drivers/dri/i965/brw_draw.c
+++ b/src/mesa/drivers/dri/i965/brw_draw.c
@@ -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;
diff --git a/src/mesa/drivers/dri/i965/brw_draw_upload.c b/src/mesa/drivers/dri/i965/brw_draw_upload.c
index 7f93f1d5ede..427de55a9ce 100644
--- a/src/mesa/drivers/dri/i965/brw_draw_upload.c
+++ b/src/mesa/drivers/dri/i965/brw_draw_upload.c
@@ -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;
}
diff --git a/src/mesa/drivers/dri/i965/brw_vtbl.c b/src/mesa/drivers/dri/i965/brw_vtbl.c
index a7bed95732c..31964ee7dfb 100644
--- a/src/mesa/drivers/dri/i965/brw_vtbl.c
+++ b/src/mesa/drivers/dri/i965/brw_vtbl.c
@@ -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 )
diff --git a/src/mesa/drivers/dri/intel/intel_buffer_objects.c b/src/mesa/drivers/dri/intel/intel_buffer_objects.c
index f54fc1a12bc..79d9075daa4 100644
--- a/src/mesa/drivers/dri/intel/intel_buffer_objects.c
+++ b/src/mesa/drivers/dri/intel/intel_buffer_objects.c
@@ -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;
diff --git a/src/mesa/drivers/dri/intel/intel_buffer_objects.h b/src/mesa/drivers/dri/intel/intel_buffer_objects.h
index c845b70b52e..71f0c52fd8e 100644
--- a/src/mesa/drivers/dri/intel/intel_buffer_objects.h
+++ b/src/mesa/drivers/dri/intel/intel_buffer_objects.h
@@ -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);