From 47f819d3cb89ab90914181e3c61744ac1f16e056 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Fri, 15 Feb 2013 16:33:33 -0800 Subject: [PATCH] mesa: Statically allocate glthread command buffer in the batch struct. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This avoids an extra pointer dereference in the marshalling functions, which, with the instruction count doing in the low 30s, could actually matter for main-thread performance. Acked-by: Timothy Arceri Acked-by: Marek Olšák Tested-by: Dieter Nützel Tested-by: Mike Lothian --- src/mesa/main/glthread.c | 5 ++--- src/mesa/main/glthread.h | 8 ++++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/mesa/main/glthread.c b/src/mesa/main/glthread.c index c4d1031f4c6..8f300d46344 100644 --- a/src/mesa/main/glthread.c +++ b/src/mesa/main/glthread.c @@ -45,10 +45,10 @@ glthread_allocate_batch(struct gl_context *ctx) struct glthread_state *glthread = ctx->GLThread; /* TODO: handle memory allocation failure. */ - glthread->batch = calloc(1, sizeof(*glthread->batch)); + glthread->batch = malloc(sizeof(*glthread->batch)); if (!glthread->batch) return; - glthread->batch->buffer = malloc(MARSHAL_MAX_CMD_SIZE); + memset(glthread->batch, 0, offsetof(struct glthread_batch, buffer)); } static void @@ -63,7 +63,6 @@ glthread_unmarshal_batch(struct gl_context *ctx, struct glthread_batch *batch) assert(pos == batch->used); - free(batch->buffer); free(batch); } diff --git a/src/mesa/main/glthread.h b/src/mesa/main/glthread.h index c38fef32fa0..98ae11509a6 100644 --- a/src/mesa/main/glthread.h +++ b/src/mesa/main/glthread.h @@ -94,14 +94,14 @@ struct glthread_batch struct glthread_batch *next; /** - * Points to the first command in the batch. + * Amount of data used by batch commands, in bytes. */ - uint8_t *buffer; + size_t used; /** - * Amount of data used by batch commands, in bytes. + * Data contained in the command buffer. */ - size_t used; + uint8_t buffer[MARSHAL_MAX_CMD_SIZE]; }; void _mesa_glthread_init(struct gl_context *ctx); -- 2.30.2