Mesa (master): glthread: count batch space in units of uint64_t elements

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Dec 8 18:06:43 UTC 2020


Module: Mesa
Branch: master
Commit: 1b6b31bd1acbd1080e59c94c0ada9b89ef714d75
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=1b6b31bd1acbd1080e59c94c0ada9b89ef714d75

Author: Marek Olšák <marek.olsak at amd.com>
Date:   Sat Oct 10 05:09:53 2020 -0400

glthread: count batch space in units of uint64_t elements

This removes one x86 shr instruction from _mesa_glthread_allocate_command.

Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7719>

---

 src/mesa/main/glthread.c         |  2 +-
 src/mesa/main/glthread.h         |  4 ++--
 src/mesa/main/glthread_marshal.h | 12 ++++++------
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/mesa/main/glthread.c b/src/mesa/main/glthread.c
index 456722ac044..15714283025 100644
--- a/src/mesa/main/glthread.c
+++ b/src/mesa/main/glthread.c
@@ -59,7 +59,7 @@ glthread_unmarshal_batch(void *job, int thread_index)
 
    while (pos < used) {
       const struct marshal_cmd_base *cmd =
-         (const struct marshal_cmd_base *)&buffer[pos / 8];
+         (const struct marshal_cmd_base *)&buffer[pos];
 
       _mesa_unmarshal_dispatch[cmd->cmd_id](ctx, cmd);
       pos += cmd->cmd_size;
diff --git a/src/mesa/main/glthread.h b/src/mesa/main/glthread.h
index 9abc4045815..177737f5be2 100644
--- a/src/mesa/main/glthread.h
+++ b/src/mesa/main/glthread.h
@@ -101,7 +101,7 @@ struct glthread_batch
    struct gl_context *ctx;
 
    /**
-    * Amount of data used by batch commands, in bytes.
+    * Number of uint64_t elements filled already.
     * This is 0 when it's being filled because glthread::used holds the real
     * value temporarily, and glthread::used is copied to this variable when
     * the batch is submitted.
@@ -153,7 +153,7 @@ struct glthread_state
    /** Index of the batch being filled and about to be submitted. */
    unsigned next;
 
-   /** Amount of data filled in next_batch, in bytes. */
+   /** Number of uint64_t elements filled already. */
    unsigned used;
 
    /** Upload buffer. */
diff --git a/src/mesa/main/glthread_marshal.h b/src/mesa/main/glthread_marshal.h
index cd303f62d9d..94bfff1e3cb 100644
--- a/src/mesa/main/glthread_marshal.h
+++ b/src/mesa/main/glthread_marshal.h
@@ -43,7 +43,7 @@ struct marshal_cmd_base
    uint16_t cmd_id;
 
    /**
-    * Size of command, in multiples of 4 bytes, including cmd_base.
+    * Number of uint64_t elements used by the command.
     */
    uint16_t cmd_size;
 };
@@ -57,17 +57,17 @@ _mesa_glthread_allocate_command(struct gl_context *ctx,
                                 unsigned size)
 {
    struct glthread_state *glthread = &ctx->GLThread;
+   const unsigned num_elements = align(size, 8) / 8;
 
-   if (unlikely(glthread->used + size > MARSHAL_MAX_CMD_SIZE))
+   if (unlikely(glthread->used + num_elements > MARSHAL_MAX_CMD_SIZE / 8))
       _mesa_glthread_flush_batch(ctx);
 
    struct glthread_batch *next = glthread->next_batch;
-   const unsigned aligned_size = align(size, 8);
    struct marshal_cmd_base *cmd_base =
-      (struct marshal_cmd_base *)&next->buffer[glthread->used / 8];
-   glthread->used += aligned_size;
+      (struct marshal_cmd_base *)&next->buffer[glthread->used];
+   glthread->used += num_elements;
    cmd_base->cmd_id = cmd_id;
-   cmd_base->cmd_size = aligned_size;
+   cmd_base->cmd_size = num_elements;
    return cmd_base;
 }
 



More information about the mesa-commit mailing list