mesa: Statically allocate glthread command buffer in the batch struct.
authorEric Anholt <eric@anholt.net>
Sat, 16 Feb 2013 00:33:33 +0000 (16:33 -0800)
committerTimothy Arceri <tarceri@itsqueeze.com>
Thu, 16 Mar 2017 03:14:19 +0000 (14:14 +1100)
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 <tarceri@itsqueeze.com>
Acked-by: Marek Olšák <maraeo@gmail.com>
Tested-by: Dieter Nützel <Dieter@nuetzel-hh.de>
Tested-by: Mike Lothian <mike@fireburn.co.uk>
src/mesa/main/glthread.c
src/mesa/main/glthread.h

index c4d1031f4c67176f1dcd8ab4dbd47fcab2b128b5..8f300d46344e8110f8730ca75555200a4065908a 100644 (file)
@@ -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);
 }
 
index c38fef32fa01d4169bf2c55a8c3734145eaf4063..98ae11509a66061cec0e225125e2bfd4b8ab277b 100644 (file)
@@ -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);