glthread: rename marshal.h/c to glthread_marshal.h and glthread_shaderobj.c
[mesa.git] / src / mapi / glapi / gen / gl_marshal.py
index 476f54d6aa6fca3b7b5d99a5f6dc88150fa8e3b4..da71a1de787097047887167485ae33a547f35fc3 100644 (file)
@@ -31,10 +31,18 @@ import sys
 
 header = """
 #include "api_exec.h"
-#include "context.h"
+#include "glthread_marshal.h"
 #include "dispatch.h"
-#include "glthread.h"
-#include "marshal.h"
+
+#define COMPAT (ctx->API != API_OPENGL_CORE)
+
+static inline int safe_mul(int a, int b)
+{
+    if (a < 0 || b < 0) return -1;
+    if (a == 0 || b == 0) return 0;
+    if (a > INT_MAX / b) return -1;
+    return a * b;
+}
 """
 
 
@@ -66,25 +74,20 @@ class PrintCode(gl_XML.gl_print_base):
 
     def printRealHeader(self):
         print(header)
-        print('static inline int safe_mul(int a, int b)')
-        print('{')
-        print('    if (a < 0 || b < 0) return -1;')
-        print('    if (a == 0 || b == 0) return 0;')
-        print('    if (a > INT_MAX / b) return -1;')
-        print('    return a * b;')
-        print('}')
-        print()
 
     def printRealFooter(self):
         pass
 
-    def print_sync_call(self, func):
+    def print_sync_call(self, func, unmarshal = 0):
         call = 'CALL_{0}(ctx->CurrentServerDispatch, ({1}))'.format(
             func.name, func.get_called_parameter_string())
         if func.return_type == 'void':
             out('{0};'.format(call))
+            if func.marshal_call_after and not unmarshal:
+                out(func.marshal_call_after);
         else:
             out('return {0};'.format(call))
+            assert not func.marshal_call_after
 
     def print_sync_dispatch(self, func):
         self.print_sync_call(func)
@@ -130,7 +133,10 @@ class PrintCode(gl_XML.gl_print_base):
                 i += 1
 
         if not func.fixed_params and not func.variable_params:
-            out('(void) cmd;\n')
+            out('(void) cmd;')
+
+        if func.marshal_call_after:
+            out(func.marshal_call_after);
 
         # Uncomment this if you want to call _mesa_glthread_finish for debugging
         #out('_mesa_glthread_finish(ctx);')
@@ -156,17 +162,17 @@ class PrintCode(gl_XML.gl_print_base):
                 if p.count_scale != 1:
                     out(('/* Next {0} bytes are '
                          '{1} {2}[{3}][{4}] */').format(
-                            p.size_string(), p.get_base_type_string(),
+                            p.size_string(marshal = 1), p.get_base_type_string(),
                             p.name, p.counter, p.count_scale))
                 else:
                     out(('/* Next {0} bytes are '
                          '{1} {2}[{3}] */').format(
-                            p.size_string(), p.get_base_type_string(),
+                            p.size_string(marshal = 1), p.get_base_type_string(),
                             p.name, p.counter))
         out('};')
 
     def print_async_unmarshal(self, func):
-        out('static inline void')
+        out('static void')
         out(('_mesa_unmarshal_{0}(struct gl_context *ctx, '
              'const struct marshal_cmd_{0} *cmd)').format(func.name))
         out('{')
@@ -203,12 +209,12 @@ class PrintCode(gl_XML.gl_print_base):
                         if i < len(func.variable_params):
                             out('else')
                             with indent():
-                                out('variable_data += {0};'.format(p.size_string(False)))
+                                out('variable_data += {0};'.format(p.size_string(False, marshal = 1)))
                     elif i < len(func.variable_params):
-                        out('variable_data += {0};'.format(p.size_string(False)))
+                        out('variable_data += {0};'.format(p.size_string(False, marshal = 1)))
                     i += 1
 
-            self.print_sync_call(func)
+            self.print_sync_call(func, unmarshal = 1)
         out('}')
 
     def validate_count_or_fallback(self, func):
@@ -219,6 +225,7 @@ class PrintCode(gl_XML.gl_print_base):
         for p in func.parameters:
             if p.is_variable_length():
                 list.append('{0}_size < 0'.format(p.name))
+                list.append('({0}_size > 0 && !{0})'.format(p.name))
 
         if len(list) == 0:
             return
@@ -240,7 +247,7 @@ class PrintCode(gl_XML.gl_print_base):
         with indent():
             out('GET_CURRENT_CONTEXT(ctx);')
             for p in func.variable_params:
-                out('int {0}_size = {1};'.format(p.name, p.size_string()))
+                out('int {0}_size = {1};'.format(p.name, p.size_string(marshal = 1)))
 
             struct = 'struct marshal_cmd_{0}'.format(func.name)
             size_terms = ['sizeof({0})'.format(struct)]
@@ -252,8 +259,6 @@ class PrintCode(gl_XML.gl_print_base):
             out('int cmd_size = {0};'.format(' + '.join(size_terms)))
             out('{0} *cmd;'.format(struct))
 
-            out('debug_print_marshal("{0}");'.format(func.name))
-
             self.validate_count_or_fallback(func)
 
             if func.marshal_fail:
@@ -264,6 +269,14 @@ class PrintCode(gl_XML.gl_print_base):
                     out('return;')
                 out('}')
 
+            if func.marshal_sync:
+                out('if ({0}) {{'.format(func.marshal_sync))
+                with indent():
+                    out('_mesa_glthread_finish_before(ctx, "{0}");'.format(func.name))
+                    self.print_sync_dispatch(func)
+                    out('return;')
+                out('}')
+
         with indent():
             self.print_async_dispatch(func)
         out('}')