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:
*/
{
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;
}
}
-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,
{
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;
}
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);
}
}
/* 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;
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 {
bo = intel_bufferobj_source(intel, intel_buffer_object(bufferobj),
&offset);
- drm_intel_bo_reference(bo);
ib_size = bo->size;
}
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 )
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;
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 {
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;
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;
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;
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);