diff options
author | Neil Roberts <neil@linux.intel.com> | 2012-10-17 21:36:10 +0100 |
---|---|---|
committer | Neil Roberts <neil@linux.intel.com> | 2012-10-17 21:47:42 +0100 |
commit | 27769e54806dcfc1a12fdc4b07b054b8f2f4215b (patch) | |
tree | 9576125a045de62d282a09977308bb3ccb63eea5 | |
parent | 55ca02b5ca9cafc750251ec974e0d6a536cb80b8 (diff) | |
download | cogl-27769e54806dcfc1a12fdc4b07b054b8f2f4215b.tar.gz |
Use cogl_buffer_map_range from the journal
The journal maintains a cache of attribute buffers to upload the
vertices for the rectangles. The buffers are mapped to fill in the
data. However, if the previous journal was larger than the one being
flushed now then the buffers may be larger than is actually needed. In
that case we might as well only map the range that is actually used so
that the driver can potentially avoid having to set up a mapping for
the entire buffer. The COGL_BUFFER_MAP_HINT_DISCARD flag is still set
so that the driver is free to discard the entire buffer, not just the
subrange.
The _cogl_buffer_map_for_fill_or_fallback has been replaced with
_cogl_buffer_map_range_for_fill_or_fallback so that the range
parameters can be passed. The original function is now just a wrapper
around the latter.
Reviewed-by: Robert Bragg <robert@linux.intel.com>
-rw-r--r-- | cogl/cogl-buffer-private.h | 8 | ||||
-rw-r--r-- | cogl/cogl-buffer.c | 24 | ||||
-rw-r--r-- | cogl/cogl-context-private.h | 1 | ||||
-rw-r--r-- | cogl/cogl-journal.c | 4 |
4 files changed, 28 insertions, 9 deletions
diff --git a/cogl/cogl-buffer-private.h b/cogl/cogl-buffer-private.h index cf2d9b92..4b21fa38 100644 --- a/cogl/cogl-buffer-private.h +++ b/cogl/cogl-buffer-private.h @@ -137,13 +137,17 @@ _cogl_buffer_immutable_ref (CoglBuffer *buffer); void _cogl_buffer_immutable_unref (CoglBuffer *buffer); -/* This is a wrapper around cogl_buffer_map for internal use when we - want to map the buffer for write only to replace the entire +/* This is a wrapper around cogl_buffer_map_range for internal use + when we want to map the buffer for write only to replace the entire contents. If the map fails then it will fallback to writing to a temporary buffer. When _cogl_buffer_unmap_for_fill_or_fallback is called the temporary buffer will be copied into the array. Note that these calls share a global array so they can not be nested. */ void * +_cogl_buffer_map_range_for_fill_or_fallback (CoglBuffer *buffer, + size_t offset, + size_t size); +void * _cogl_buffer_map_for_fill_or_fallback (CoglBuffer *buffer); void diff --git a/cogl/cogl-buffer.c b/cogl/cogl-buffer.c index 7a1a0846..72fd3f85 100644 --- a/cogl/cogl-buffer.c +++ b/cogl/cogl-buffer.c @@ -262,6 +262,14 @@ cogl_buffer_unmap (CoglBuffer *buffer) void * _cogl_buffer_map_for_fill_or_fallback (CoglBuffer *buffer) { + return _cogl_buffer_map_range_for_fill_or_fallback (buffer, 0, buffer->size); +} + +void * +_cogl_buffer_map_range_for_fill_or_fallback (CoglBuffer *buffer, + size_t offset, + size_t size) +{ CoglContext *ctx = buffer->context; void *ret; @@ -269,9 +277,11 @@ _cogl_buffer_map_for_fill_or_fallback (CoglBuffer *buffer) ctx->buffer_map_fallback_in_use = TRUE; - ret = cogl_buffer_map (buffer, - COGL_BUFFER_ACCESS_WRITE, - COGL_BUFFER_MAP_HINT_DISCARD); + ret = cogl_buffer_map_range (buffer, + offset, + size, + COGL_BUFFER_ACCESS_WRITE, + COGL_BUFFER_MAP_HINT_DISCARD); if (ret) return ret; @@ -281,7 +291,8 @@ _cogl_buffer_map_for_fill_or_fallback (CoglBuffer *buffer) the data and then upload it using cogl_buffer_set_data when the buffer is unmapped. The temporary buffer is shared to avoid reallocating it every time */ - g_byte_array_set_size (ctx->buffer_map_fallback_array, buffer->size); + g_byte_array_set_size (ctx->buffer_map_fallback_array, size); + ctx->buffer_map_fallback_offset = offset; buffer->flags |= COGL_BUFFER_FLAG_MAPPED_FALLBACK; @@ -300,9 +311,10 @@ _cogl_buffer_unmap_for_fill_or_fallback (CoglBuffer *buffer) if ((buffer->flags & COGL_BUFFER_FLAG_MAPPED_FALLBACK)) { - cogl_buffer_set_data (buffer, 0, + cogl_buffer_set_data (buffer, + ctx->buffer_map_fallback_offset, ctx->buffer_map_fallback_array->data, - buffer->size); + ctx->buffer_map_fallback_array->len); buffer->flags &= ~COGL_BUFFER_FLAG_MAPPED_FALLBACK; } else diff --git a/cogl/cogl-context-private.h b/cogl/cogl-context-private.h index 4ea66874..0f5bdd81 100644 --- a/cogl/cogl-context-private.h +++ b/cogl/cogl-context-private.h @@ -254,6 +254,7 @@ struct _CoglContext data */ GByteArray *buffer_map_fallback_array; CoglBool buffer_map_fallback_in_use; + size_t buffer_map_fallback_offset; CoglWinsysRectangleState rectangle_state; diff --git a/cogl/cogl-journal.c b/cogl/cogl-journal.c index 4faed167..79fc016e 100644 --- a/cogl/cogl-journal.c +++ b/cogl/cogl-journal.c @@ -1095,7 +1095,9 @@ upload_vertices (CoglJournal *journal, buffer = COGL_BUFFER (attribute_buffer); cogl_buffer_set_update_hint (buffer, COGL_BUFFER_UPDATE_HINT_STATIC); - vout = _cogl_buffer_map_for_fill_or_fallback (buffer); + vout = _cogl_buffer_map_range_for_fill_or_fallback (buffer, + 0, /* offset */ + needed_vbo_len * 4); vin = &g_array_index (vertices, float, 0); /* Expand the number of vertices from 2 to 4 while uploading */ |