glthread: check the size of all variable params and clean up the code
authorMarek Olšák <marek.olsak@amd.com>
Fri, 21 Feb 2020 01:21:45 +0000 (20:21 -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

index f21d0f65ff877f79253facb4ca32fe2b979dae6d..476f54d6aa6fca3b7b5d99a5f6dc88150fa8e3b4 100644 (file)
@@ -215,18 +215,24 @@ class PrintCode(gl_XML.gl_print_base):
         # Check that any counts for variable-length arguments might be < 0, in
         # which case the command alloc or the memcpy would blow up before we
         # get to the validation in Mesa core.
         # Check that any counts for variable-length arguments might be < 0, in
         # which case the command alloc or the memcpy would blow up before we
         # get to the validation in Mesa core.
+        list = []
         for p in func.parameters:
             if p.is_variable_length():
         for p in func.parameters:
             if p.is_variable_length():
-                out('if (unlikely({0}_size < 0)) {{'.format(p.name))
-                with indent():
-                    out('goto fallback_to_sync;')
-                out('}')
-                return True
-        return False
+                list.append('{0}_size < 0'.format(p.name))
+
+        if len(list) == 0:
+            return
+
+        list.append('(unsigned)cmd_size > MARSHAL_MAX_CMD_SIZE')
 
 
+        out('if (unlikely({0})) {{'.format(' || '.join(list)))
+        with indent():
+            out('_mesa_glthread_finish_before(ctx, "{0}");'.format(func.name))
+            self.print_sync_dispatch(func)
+            out('return;')
+        out('}')
 
     def print_async_marshal(self, func):
 
     def print_async_marshal(self, func):
-        need_fallback_sync = False
         out('static void GLAPIENTRY')
         out('_mesa_marshal_{0}({1})'.format(
                 func.name, func.get_parameter_string()))
         out('static void GLAPIENTRY')
         out('_mesa_marshal_{0}({1})'.format(
                 func.name, func.get_parameter_string()))
@@ -248,7 +254,7 @@ class PrintCode(gl_XML.gl_print_base):
 
             out('debug_print_marshal("{0}");'.format(func.name))
 
 
             out('debug_print_marshal("{0}");'.format(func.name))
 
-            need_fallback_sync = self.validate_count_or_fallback(func)
+            self.validate_count_or_fallback(func)
 
             if func.marshal_fail:
                 out('if ({0}) {{'.format(func.marshal_fail))
 
             if func.marshal_fail:
                 out('if ({0}) {{'.format(func.marshal_fail))
@@ -258,23 +264,8 @@ class PrintCode(gl_XML.gl_print_base):
                     out('return;')
                 out('}')
 
                     out('return;')
                 out('}')
 
-        if len(func.variable_params) > 0:
-            with indent():
-                out('if (cmd_size <= MARSHAL_MAX_CMD_SIZE) {')
-                with indent():
-                    self.print_async_dispatch(func)
-                    out('return;')
-                out('}')
-            out('')
-            if need_fallback_sync:
-                out('fallback_to_sync:')
-            with indent():
-                out('_mesa_glthread_finish_before(ctx, "{0}");'.format(func.name))
-                self.print_sync_dispatch(func)
-        else:
-            with indent():
-                self.print_async_dispatch(func)
-                assert not need_fallback_sync
+        with indent():
+            self.print_async_dispatch(func)
         out('}')
 
     def print_async_body(self, func):
         out('}')
 
     def print_async_body(self, func):