From 8c655f499cf61211146a3d38f77532541f88aa88 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Tue, 24 Apr 2012 17:04:18 +0200 Subject: [PATCH] st/mesa: make user index buffers optional v2: use a separate upload buffer for indices --- src/mesa/state_tracker/st_context.c | 10 ++++++++++ src/mesa/state_tracker/st_context.h | 2 +- src/mesa/state_tracker/st_draw.c | 5 +++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index 19d9da131f3..d50c6be6c4d 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -138,6 +138,7 @@ static void st_init_vbuf(struct st_context *st) static struct st_context * st_create_context_priv( struct gl_context *ctx, struct pipe_context *pipe ) { + struct pipe_screen *screen = pipe->screen; uint i; struct st_context *st = ST_CALLOC_STRUCT( st_context ); @@ -156,6 +157,12 @@ st_create_context_priv( struct gl_context *ctx, struct pipe_context *pipe ) st->dirty.st = ~0; st->uploader = u_upload_create(st->pipe, 65536, 4, PIPE_BIND_VERTEX_BUFFER); + + if (!screen->get_param(screen, PIPE_CAP_USER_INDEX_BUFFERS)) { + st->indexbuf_uploader = u_upload_create(st->pipe, 128 * 1024, 4, + PIPE_BIND_INDEX_BUFFER); + } + st->cso_context = cso_create_context(pipe); st_init_vbuf(st); @@ -263,6 +270,9 @@ static void st_destroy_context_priv( struct st_context *st ) } u_upload_destroy(st->uploader); + if (st->indexbuf_uploader) { + u_upload_destroy(st->indexbuf_uploader); + } free( st ); } diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 3ec98ada196..8f557e81a7c 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -73,7 +73,7 @@ struct st_context struct pipe_context *pipe; - struct u_upload_mgr *uploader; + struct u_upload_mgr *uploader, *indexbuf_uploader; struct u_vbuf *vbuf; struct draw_context *draw; /**< For selection/feedback/rastpos only */ diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c index c24ae75a2a9..fa7c18895c7 100644 --- a/src/mesa/state_tracker/st_draw.c +++ b/src/mesa/state_tracker/st_draw.c @@ -61,6 +61,7 @@ #include "util/u_format.h" #include "util/u_prim.h" #include "util/u_draw_quad.h" +#include "util/u_upload_mgr.h" #include "draw/draw_context.h" #include "cso_cache/cso_context.h" @@ -645,6 +646,10 @@ setup_index_buffer(struct st_context *st, pipe_resource_reference(&ibuffer->buffer, stobj->buffer); ibuffer->offset = pointer_to_offset(ib->ptr); } + else if (st->indexbuf_uploader) { + u_upload_data(st->indexbuf_uploader, 0, ib->count * ibuffer->index_size, + ib->ptr, &ibuffer->offset, &ibuffer->buffer); + } else { /* indices are in user space memory */ ibuffer->buffer = -- 2.30.2