glthread: reduce dereferences of the next batch
authorMarek Olšák <marek.olsak@amd.com>
Fri, 27 Mar 2020 10:06:31 +0000 (06:06 -0400)
committerMarge Bot <eric+marge@anholt.net>
Mon, 27 Apr 2020 11:56:06 +0000 (11:56 +0000)
Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4758>

src/mesa/main/glthread.c
src/mesa/main/glthread.h
src/mesa/main/glthread_marshal.h

index 5d50e138150dd6fe87d2475f2a0247d046c7dbe8..b8e04c9f771893f415bced0c4cf8fe717d8edc37 100644 (file)
@@ -102,6 +102,7 @@ _mesa_glthread_init(struct gl_context *ctx)
       glthread->batches[i].ctx = ctx;
       util_queue_fence_init(&glthread->batches[i].fence);
    }
+   glthread->next_batch = &glthread->batches[glthread->next];
 
    glthread->enabled = true;
    glthread->stats.queue = &glthread->queue;
@@ -176,7 +177,7 @@ _mesa_glthread_flush_batch(struct gl_context *ctx)
    if (!glthread->enabled)
       return;
 
-   struct glthread_batch *next = &glthread->batches[glthread->next];
+   struct glthread_batch *next = glthread->next_batch;
    if (!next->used)
       return;
 
@@ -197,6 +198,7 @@ _mesa_glthread_flush_batch(struct gl_context *ctx)
                       glthread_unmarshal_batch, NULL, 0);
    glthread->last = glthread->next;
    glthread->next = (glthread->next + 1) % MARSHAL_MAX_BATCHES;
+   glthread->next_batch = &glthread->batches[glthread->next];
 }
 
 /**
@@ -221,7 +223,7 @@ _mesa_glthread_finish(struct gl_context *ctx)
       return;
 
    struct glthread_batch *last = &glthread->batches[glthread->last];
-   struct glthread_batch *next = &glthread->batches[glthread->next];
+   struct glthread_batch *next = glthread->next_batch;
    bool synced = false;
 
    if (!util_queue_fence_is_signalled(&last->fence)) {
index 9c1742eb2b4134a5e8215f806b0f0c2841e34ae2..a50b2f87ceb4e3d97021e6b02386106591e1345e 100644 (file)
@@ -94,6 +94,9 @@ struct glthread_state
    /** The ring of batches in memory. */
    struct glthread_batch batches[MARSHAL_MAX_BATCHES];
 
+   /** Pointer to the batch currently being filled. */
+   struct glthread_batch *next_batch;
+
    /** Index of the last submitted batch. */
    unsigned last;
 
index f464f2bd56577c587ed96033da9cce540aefd382..a519ff0c5cf9d3f5b3d1e6bc9a8cc0575545cecc 100644 (file)
@@ -57,12 +57,12 @@ _mesa_glthread_allocate_command(struct gl_context *ctx,
                                 int size)
 {
    struct glthread_state *glthread = &ctx->GLThread;
-   struct glthread_batch *next = &glthread->batches[glthread->next];
+   struct glthread_batch *next = glthread->next_batch;
    struct marshal_cmd_base *cmd_base;
 
    if (unlikely(next->used + size > MARSHAL_MAX_CMD_SIZE)) {
       _mesa_glthread_flush_batch(ctx);
-      next = &glthread->batches[glthread->next];
+      next = glthread->next_batch;
    }
 
    const int aligned_size = align(size, 8);