diff options
author | Eric Anholt <eric@anholt.net> | 2014-02-28 13:02:19 -0500 |
---|---|---|
committer | Zhigang Gong <zhigang.gong@gmail.com> | 2014-03-13 21:52:28 +0800 |
commit | 7ed9221f08157afa82af33980682dc637f3d0f0a (patch) | |
tree | 24b637d38e39c5891c938da61ce5c8df4d47cb01 | |
parent | 3eb7ba02f337806a613f2afd0cbe724435dd9308 (diff) |
glamor: Use streamed vertex data for solid fills.
No difference on performance in x11perf -f8text (n=15), but if we ever
get GL_ARB_buffer_storage support, it should be worth a few percent
CPU overhead on Intel.
Ported from Eric's xserver glamor tree.
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
-rw-r--r-- | src/glamor_fill.c | 47 | ||||
-rw-r--r-- | src/glamor_vbo.c | 1 |
2 files changed, 19 insertions, 29 deletions
diff --git a/src/glamor_fill.c b/src/glamor_fill.c index 6d8d9c5..356bddc 100644 --- a/src/glamor_fill.c +++ b/src/glamor_fill.c @@ -193,9 +193,6 @@ _glamor_solid_boxes(PixmapPtr pixmap, BoxPtr box, int nbox, float *color) glamor_get_pixmap_private(pixmap); glamor_gl_dispatch *dispatch; GLfloat xscale, yscale; - float stack_vertices[32]; - float *vertices = stack_vertices; - int valid_nbox = ARRAY_SIZE(stack_vertices) / (4 * 2); glamor_set_destination_pixmap_priv_nc(pixmap_priv); @@ -207,35 +204,27 @@ _glamor_solid_boxes(PixmapPtr pixmap, BoxPtr box, int nbox, float *color) pixmap_priv_get_dest_scale(pixmap_priv, &xscale, &yscale); - if (nbox > valid_nbox) { - int allocated_nbox; - float *new_vertices; + dispatch->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, glamor_priv->ebo); - if (nbox > GLAMOR_COMPOSITE_VBO_VERT_CNT / 6) - allocated_nbox = GLAMOR_COMPOSITE_VBO_VERT_CNT / 6; - else - allocated_nbox = nbox; - new_vertices = malloc(allocated_nbox * 4 * 2 * sizeof(float)); - if (new_vertices) { - vertices = new_vertices; - valid_nbox = allocated_nbox; - } - } - - if (unlikely(nbox > 1)) - dispatch->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, glamor_priv->ebo); - - dispatch->glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT, - GL_FALSE, 2 * sizeof(float), - vertices); dispatch->glEnableVertexAttribArray(GLAMOR_VERTEX_POS); while(nbox) { - int box_cnt, i; + /* We can only use a limited number of verts up to the size of + * the precomputed index buffer. + */ + int index_buffer_box_count = GLAMOR_COMPOSITE_VBO_VERT_CNT / 6; + int box_cnt = MIN(index_buffer_box_count, nbox); + int i; float *next_box; + char *vbo_offset; + + next_box = glamor_get_vbo_space(screen, box_cnt * 4 * 2 * sizeof(float), + &vbo_offset); + + dispatch->glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT, + GL_FALSE, 2 * sizeof(float), + vbo_offset); - next_box = vertices; - box_cnt = nbox > valid_nbox ? valid_nbox : nbox; for (i = 0; i < box_cnt; i++) { glamor_set_normalize_vcoords(pixmap_priv, xscale, yscale, box[i].x1, box[i].y1, @@ -244,6 +233,8 @@ _glamor_solid_boxes(PixmapPtr pixmap, BoxPtr box, int nbox, float *color) next_box); next_box += 4 * 2; } + glamor_put_vbo_space(screen); + if (box_cnt == 1) dispatch->glDrawArrays(GL_TRIANGLE_FAN, 0, box_cnt * 4); else @@ -264,9 +255,7 @@ _glamor_solid_boxes(PixmapPtr pixmap, BoxPtr box, int nbox, float *color) box += box_cnt; } - if (vertices != stack_vertices) - free(vertices); - + dispatch->glBindBuffer(GL_ARRAY_BUFFER, 0); dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_POS); dispatch->glUseProgram(0); glamor_put_dispatch(glamor_priv); diff --git a/src/glamor_vbo.c b/src/glamor_vbo.c index 3689379..8b1d99a 100644 --- a/src/glamor_vbo.c +++ b/src/glamor_vbo.c @@ -55,6 +55,7 @@ glamor_get_vbo_space(ScreenPtr screen, int size, char **vbo_offset) GL_MAP_INVALIDATE_RANGE_BIT); assert(glamor_priv->vb != NULL); *vbo_offset = (void *)(uintptr_t)glamor_priv->vbo_offset; + glamor_priv->vbo_offset += size; glamor_priv->vbo_mapped = TRUE; } else { /* Return a pointer to the statically allocated non-VBO |