glthread: inline _mesa_unmarshal_dispatch_cmd and convert the switch to a table
authorMarek Olšák <marek.olsak@amd.com>
Wed, 19 Feb 2020 20:58:34 +0000 (15:58 -0500)
committerMarge Bot <eric+marge@anholt.net>
Fri, 6 Mar 2020 01:06:14 +0000 (01:06 +0000)
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3948>

src/mapi/glapi/gen/gl_marshal.py
src/mapi/glapi/gen/gl_marshal_h.py
src/mesa/main/glthread.c
src/mesa/main/marshal.c
src/mesa/main/marshal.h

index 9d5d5ad9e2718fe1efc38a5d849648991aaf0ec1..1e5f75da399404c02ec51a940117a3bef4680bf4 100644 (file)
@@ -35,7 +35,6 @@ header = """
 #include "dispatch.h"
 #include "glthread.h"
 #include "marshal.h"
-#include "marshal_generated.h"
 """
 
 
@@ -282,31 +281,14 @@ class PrintCode(gl_XML.gl_print_base):
         out('')
 
     def print_unmarshal_dispatch_cmd(self, api):
-        out('size_t')
-        out('_mesa_unmarshal_dispatch_cmd(struct gl_context *ctx, '
-            'const void *cmd)')
-        out('{')
+        out('const _mesa_unmarshal_func _mesa_unmarshal_dispatch[NUM_DISPATCH_CMD] = {')
         with indent():
-            out('const struct marshal_cmd_base *cmd_base = cmd;')
-            out('switch (cmd_base->cmd_id) {')
             for func in api.functionIterateAll():
                 flavor = func.marshal_flavor()
                 if flavor in ('skip', 'sync'):
                     continue
-                out('case DISPATCH_CMD_{0}:'.format(func.name))
-                with indent():
-                    out('debug_print_unmarshal("{0}");'.format(func.name))
-                    out(('_mesa_unmarshal_{0}(ctx, (const struct marshal_cmd_{0} *)'
-                         ' cmd);').format(func.name))
-                    out('break;')
-            out('default:')
-            with indent():
-                out('assert(!"Unrecognized command ID");')
-                out('break;')
-            out('}')
-            out('')
-            out('return cmd_base->cmd_size;')
-        out('}')
+                out('[DISPATCH_CMD_{0}] = (_mesa_unmarshal_func)_mesa_unmarshal_{0},'.format(func.name))
+        out('};')
         out('')
         out('')
 
index a7a9eda5731340a29072ec638e34d0dbd772d242..94926b99a0f7cd5064152c76d799c924430c2a46 100644 (file)
@@ -61,6 +61,7 @@ class PrintCode(gl_XML.gl_print_base):
             if flavor in ('skip', 'sync'):
                 continue
             print('   DISPATCH_CMD_{0},'.format(func.name))
+        print('   NUM_DISPATCH_CMD,')
         print('};')
 
 
index 82baad597f92168f9c1ec09d8092ff82644fd5e8..3b6051834834128cb238b59878d0a1de78d3f03e 100644 (file)
@@ -35,7 +35,6 @@
 #include "main/mtypes.h"
 #include "main/glthread.h"
 #include "main/marshal.h"
-#include "main/marshal_generated.h"
 #include "util/u_atomic.h"
 #include "util/u_thread.h"
 
@@ -49,8 +48,13 @@ glthread_unmarshal_batch(void *job, int thread_index)
 
    _glapi_set_dispatch(ctx->CurrentServerDispatch);
 
-   while (pos < batch->used)
-      pos += _mesa_unmarshal_dispatch_cmd(ctx, &batch->buffer[pos]);
+   while (pos < batch->used) {
+      const struct marshal_cmd_base *cmd =
+         (const struct marshal_cmd_base *)&batch->buffer[pos];
+
+      _mesa_unmarshal_dispatch[cmd->cmd_id](ctx, cmd);
+      pos += cmd->cmd_size;
+   }
 
    assert(pos == batch->used);
    batch->used = 0;
index 43deafb2c80a74014a4acf1d4d15a7b944a3c48d..b2428e5e7cdab99fa27c567c2c527788f4bf26ea 100644 (file)
@@ -31,7 +31,6 @@
 #include "main/macros.h"
 #include "marshal.h"
 #include "dispatch.h"
-#include "marshal_generated.h"
 
 struct marshal_cmd_Flush
 {
index 63e0295576ef04fde2b5f44704873492404a9cbe..b2556ca98415ea9a4e0c135e7801a10fa3717a6a 100644 (file)
@@ -33,6 +33,7 @@
 #include "main/glthread.h"
 #include "main/context.h"
 #include "main/macros.h"
+#include "marshal_generated.h"
 
 struct marshal_cmd_base
 {
@@ -47,6 +48,9 @@ struct marshal_cmd_base
    uint16_t cmd_size;
 };
 
+typedef void (*_mesa_unmarshal_func)(struct gl_context *ctx, const void *cmd);
+extern const _mesa_unmarshal_func _mesa_unmarshal_dispatch[NUM_DISPATCH_CMD];
+
 static inline void *
 _mesa_glthread_allocate_command(struct gl_context *ctx,
                                 uint16_t cmd_id,
@@ -125,20 +129,9 @@ debug_print_marshal(const char *func)
 #endif
 }
 
-static inline void
-debug_print_unmarshal(const char *func)
-{
-#if DEBUG_MARSHAL_PRINT_CALLS
-   printf("unmarshal: %s\n", func);
-#endif
-}
-
 struct _glapi_table *
 _mesa_create_marshal_table(const struct gl_context *ctx);
 
-size_t
-_mesa_unmarshal_dispatch_cmd(struct gl_context *ctx, const void *cmd);
-
 static inline void
 _mesa_post_marshal_hook(struct gl_context *ctx)
 {