[Mesa-dev] [PATCH 18/26] mesa: Statically allocate glthread command buffer in the batch struct.

Marek Olšák maraeo at gmail.com
Wed Feb 8 18:03:32 UTC 2017


From: Eric Anholt <eric at anholt.net>

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.
---
 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 01ca78c..3a7c753 100644
--- a/src/mesa/main/glthread.c
+++ b/src/mesa/main/glthread.c
@@ -38,40 +38,39 @@
 #include "main/marshal_generated.h"
 
 #ifdef HAVE_PTHREAD
 
 static void
 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
 glthread_unmarshal_batch(struct gl_context *ctx, struct glthread_batch *batch)
 {
    size_t pos = 0;
 
    _glapi_set_dispatch(ctx->CurrentServerDispatch);
 
    while (pos < batch->used) {
       pos += _mesa_unmarshal_dispatch_cmd(ctx, &batch->buffer[pos]);
    }
 
    assert(pos == batch->used);
 
-   free(batch->buffer);
    free(batch);
 }
 
 static void *
 glthread_worker(void *data)
 {
    struct gl_context *ctx = data;
    struct glthread_state *glthread = ctx->GLThread;
 
    ctx->Driver.SetBackgroundContext(ctx);
diff --git a/src/mesa/main/glthread.h b/src/mesa/main/glthread.h
index c38fef3..98ae115 100644
--- a/src/mesa/main/glthread.h
+++ b/src/mesa/main/glthread.h
@@ -87,28 +87,28 @@ struct glthread_state
  */
 struct glthread_batch
 {
    /**
     * Next batch of commands to execute after this batch, or NULL if this is
     * the last set of commands queued.  Protected by ctx->Marshal.Mutex.
     */
    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);
 void _mesa_glthread_destroy(struct gl_context *ctx);
 
 void _mesa_glthread_flush_batch(struct gl_context *ctx);
 void _mesa_glthread_finish(struct gl_context *ctx);
 
 #else /* HAVE_PTHREAD */
 
-- 
2.7.4



More information about the mesa-dev mailing list