Module: Mesa
Branch: main
Commit: 83ce647c1594bedfd1e8e07a0bb30a577db68616
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=83ce647c1594bedfd1e8e07a0bb30a577db68616

Author: Marek Olšák <[email protected]>
Date:   Sat Aug 13 01:49:35 2022 -0400

glthread: use a constant expression instead of cmd_size in custom functions

cmd_size is constant in these cases

Acked-By: Mike Blumenkrantz <[email protected]>
Reviewed-by: Pierre-Eric Pelloux-Prayer <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18199>

---

 src/mesa/main/glthread_draw.c | 12 +++++++++---
 src/mesa/main/glthread_list.c | 14 ++++++++++----
 2 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/src/mesa/main/glthread_draw.c b/src/mesa/main/glthread_draw.c
index 16eab75aa7c..bd411b54a83 100644
--- a/src/mesa/main/glthread_draw.c
+++ b/src/mesa/main/glthread_draw.c
@@ -292,7 +292,9 @@ _mesa_unmarshal_DrawArrays(struct gl_context *ctx,
    CALL_DrawArraysInstancedBaseInstance(ctx->CurrentServerDispatch,
                                         (mode, first, count, instance_count,
                                          baseinstance));
-   return cmd->cmd_base.cmd_size;
+   const unsigned cmd_size = align(sizeof(*cmd), 8) / 8;
+   assert(cmd_size == cmd->cmd_base.cmd_size);
+   return cmd_size;
 }
 
 static ALWAYS_INLINE void
@@ -609,7 +611,9 @@ _mesa_unmarshal_DrawElementsInstancedARB(struct gl_context 
*ctx,
                                                     (mode, count, type, 
indices,
                                                      instance_count, 
basevertex,
                                                      baseinstance));
-   return cmd->cmd_base.cmd_size;
+   const unsigned cmd_size = align(sizeof(*cmd), 8) / 8;
+   assert(cmd_size == cmd->cmd_base.cmd_size);
+   return cmd_size;
 }
 
 struct marshal_cmd_DrawRangeElementsBaseVertex
@@ -640,7 +644,9 @@ _mesa_unmarshal_DrawRangeElementsBaseVertex(struct 
gl_context *ctx,
    CALL_DrawRangeElementsBaseVertex(ctx->CurrentServerDispatch,
                                     (mode, min_index, max_index, count,
                                      type, indices, basevertex));
-   return cmd->cmd_base.cmd_size;
+   const unsigned cmd_size = align(sizeof(*cmd), 8) / 8;
+   assert(cmd_size == cmd->cmd_base.cmd_size);
+   return cmd_size;
 }
 
 static ALWAYS_INLINE void
diff --git a/src/mesa/main/glthread_list.c b/src/mesa/main/glthread_list.c
index 08a60d19e13..0eab38fad82 100644
--- a/src/mesa/main/glthread_list.c
+++ b/src/mesa/main/glthread_list.c
@@ -31,7 +31,10 @@ _mesa_unmarshal_CallList(struct gl_context *ctx, const 
struct marshal_cmd_CallLi
 {
    const GLuint list = cmd->list;
    uint64_t *ptr = (uint64_t *) cmd;
-   ptr += cmd->cmd_base.cmd_size;
+   const unsigned cmd_size = align(sizeof(*cmd), 8) / 8;
+
+   assert(cmd_size == cmd->cmd_base.cmd_size);
+   ptr += cmd_size;
 
    if (ptr < last) {
       const struct marshal_cmd_base *next =
@@ -50,13 +53,16 @@ _mesa_unmarshal_CallList(struct gl_context *ctx, const 
struct marshal_cmd_CallLi
 
          int count = 2;
 
-         ptr += next->cmd_size;
+         assert(cmd_size == next_callist->cmd_base.cmd_size);
+         ptr += cmd_size;
+
          while (ptr < last && count < max_list_count) {
             next = (const struct marshal_cmd_base *)ptr;
             if (next->cmd_id == DISPATCH_CMD_CallList) {
                next_callist = (struct marshal_cmd_CallList *) next;
                lists[count++] = next_callist->list;
-               ptr += next->cmd_size;
+               assert(cmd_size == next_callist->cmd_base.cmd_size);
+               ptr += cmd_size;
             } else {
                break;
             }
@@ -69,7 +75,7 @@ _mesa_unmarshal_CallList(struct gl_context *ctx, const struct 
marshal_cmd_CallLi
    }
 
    CALL_CallList(ctx->CurrentServerDispatch, (list));
-   return cmd->cmd_base.cmd_size;
+   return cmd_size;
 }
 
 void GLAPIENTRY

Reply via email to