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>

(cherry picked from commit 27769e54806dcfc1a12fdc4b07b054b8f2f4215b)
This commit is contained in:
Neil Roberts 2012-10-17 21:36:10 +01:00 committed by Robert Bragg
parent ec03357e88
commit 6db9427e8a
4 changed files with 28 additions and 9 deletions

View File

@ -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

View File

@ -261,6 +261,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

View File

@ -269,6 +269,7 @@ struct _CoglContext
data */
GByteArray *buffer_map_fallback_array;
CoglBool buffer_map_fallback_in_use;
size_t buffer_map_fallback_offset;
CoglWinsysRectangleState rectangle_state;

View File

@ -1079,7 +1079,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 */