summaryrefslogtreecommitdiff
path: root/src/mesa/state_tracker/st_cb_clear.c
diff options
context:
space:
mode:
authorKeith Whitwell <keith@tungstengraphics.com>2008-12-12 16:46:34 +0000
committerKeith Whitwell <keith@tungstengraphics.com>2008-12-12 16:57:39 +0000
commitd2c2e9316d043ab584794a3524f22776deb4c777 (patch)
tree1d6045093cd7c935ceb26a3afb6c57b177c0ac62 /src/mesa/state_tracker/st_cb_clear.c
parenteb20e2984e51e632ef1a51620db7aca3eb89dafa (diff)
gallium: avoid mapping same vertex buffer in subsequent frames
Quite a few util modules were maintaining a single vertex buffer over multiple frames, and potentially reusing it in subsequent frames. Unfortunately that would force us into syncrhonous rendering as the buffer manager would be forced to wait for the previous rendering to complete prior to allowing the map. This resolves that issue, but requires the state tracker to issue a few new flush() calls at the end of each frame.
Diffstat (limited to 'src/mesa/state_tracker/st_cb_clear.c')
-rw-r--r--src/mesa/state_tracker/st_cb_clear.c31
1 files changed, 28 insertions, 3 deletions
diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c
index bc3055c3fd..b6cea16163 100644
--- a/src/mesa/state_tracker/st_cb_clear.c
+++ b/src/mesa/state_tracker/st_cb_clear.c
@@ -148,12 +148,18 @@ draw_quad(GLcontext *ctx,
{
struct st_context *st = ctx->st;
struct pipe_context *pipe = st->pipe;
+ const GLuint max_slots = 1024 / sizeof(st->clear.vertices);
GLuint i;
void *buf;
+ if (st->clear.vbuf_slot >= max_slots) {
+ pipe_buffer_reference(pipe->screen, &st->clear.vbuf, NULL);
+ st->clear.vbuf_slot = 0;
+ }
+
if (!st->clear.vbuf) {
st->clear.vbuf = pipe_buffer_create(pipe->screen, 32, PIPE_BUFFER_USAGE_VERTEX,
- sizeof(st->clear.vertices));
+ max_slots * sizeof(st->clear.vertices));
}
/* positions */
@@ -181,14 +187,23 @@ draw_quad(GLcontext *ctx,
/* put vertex data into vbuf */
buf = pipe_buffer_map(pipe->screen, st->clear.vbuf, PIPE_BUFFER_USAGE_CPU_WRITE);
- memcpy(buf, st->clear.vertices, sizeof(st->clear.vertices));
+
+ memcpy((char *)buf + st->clear.vbuf_slot * sizeof(st->clear.vertices),
+ st->clear.vertices,
+ sizeof(st->clear.vertices));
+
pipe_buffer_unmap(pipe->screen, st->clear.vbuf);
/* draw */
- util_draw_vertex_buffer(pipe, st->clear.vbuf,
+ util_draw_vertex_buffer(pipe,
+ st->clear.vbuf,
+ st->clear.vbuf_slot * sizeof(st->clear.vertices),
PIPE_PRIM_TRIANGLE_FAN,
4, /* verts */
2); /* attribs/vert */
+
+ /* Increment slot */
+ st->clear.vbuf_slot++;
}
@@ -508,6 +523,16 @@ clear_depth_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
}
+void st_flush_clear( struct st_context *st )
+{
+ /* Release vertex buffer to avoid synchronous rendering if we were
+ * to map it in the next frame.
+ */
+ pipe_buffer_reference(st->pipe->screen, &st->clear.vbuf, NULL);
+ st->clear.vbuf_slot = 0;
+}
+
+
/**
* Called via ctx->Driver.Clear()