mesa: add support for AlphaToCoverageDitherControlNV
[mesa.git] / src / mapi / glapi / gen / gl_marshal.py
index da71a1de787097047887167485ae33a547f35fc3..0572458fd974938e0a3766b74280dd717da55ee5 100644 (file)
@@ -46,6 +46,8 @@ static inline int safe_mul(int a, int b)
 """
 
 
+file_index = 0
+file_count = 1
 current_indent = 0
 
 
@@ -94,7 +96,7 @@ class PrintCode(gl_XML.gl_print_base):
 
     def print_sync_body(self, func):
         out('/* {0}: marshalled synchronously */'.format(func.name))
-        out('static {0} GLAPIENTRY'.format(func.return_type))
+        out('{0} GLAPIENTRY'.format(func.return_type))
         out('_mesa_marshal_{0}({1})'.format(func.name, func.get_parameter_string()))
         out('{')
         with indent():
@@ -172,7 +174,7 @@ class PrintCode(gl_XML.gl_print_base):
         out('};')
 
     def print_async_unmarshal(self, func):
-        out('static void')
+        out('void')
         out(('_mesa_unmarshal_{0}(struct gl_context *ctx, '
              'const struct marshal_cmd_{0} *cmd)').format(func.name))
         out('{')
@@ -240,7 +242,7 @@ class PrintCode(gl_XML.gl_print_base):
         out('}')
 
     def print_async_marshal(self, func):
-        out('static void GLAPIENTRY')
+        out('void GLAPIENTRY')
         out('_mesa_marshal_{0}({1})'.format(
                 func.name, func.get_parameter_string()))
         out('{')
@@ -261,14 +263,6 @@ class PrintCode(gl_XML.gl_print_base):
 
             self.validate_count_or_fallback(func)
 
-            if func.marshal_fail:
-                out('if ({0}) {{'.format(func.marshal_fail))
-                with indent():
-                    out('_mesa_glthread_disable(ctx, "{0}");'.format(func.name))
-                    self.print_sync_dispatch(func)
-                    out('return;')
-                out('}')
-
             if func.marshal_sync:
                 out('if ({0}) {{'.format(func.marshal_sync))
                 with indent():
@@ -302,6 +296,10 @@ class PrintCode(gl_XML.gl_print_base):
         out('')
 
     def print_create_marshal_table(self, api):
+        out('/* _mesa_create_marshal_table takes a long time to compile with -O2 */')
+        out('#ifdef __GNUC__')
+        out('__attribute__((optimize("O1")))')
+        out('#endif')
         out('struct _glapi_table *')
         out('_mesa_create_marshal_table(const struct gl_context *ctx)')
         out('{')
@@ -316,7 +314,11 @@ class PrintCode(gl_XML.gl_print_base):
             for func in api.functionIterateAll():
                 if func.marshal_flavor() == 'skip':
                     continue
-                out('SET_{0}(table, _mesa_marshal_{0});'.format(func.name))
+                # Don't use the SET_* functions, because they increase compile time
+                # by 20 seconds (on Ryzen 1700X).
+                out('if (_gloffset_{0} >= 0)'.format(func.name))
+                out('   ((_glapi_proc *)(table))[_gloffset_{0}] = (_glapi_proc)_mesa_marshal_{0};'
+                    .format(func.name))
             out('')
             out('return table;')
         out('}')
@@ -324,18 +326,27 @@ class PrintCode(gl_XML.gl_print_base):
         out('')
 
     def printBody(self, api):
-        async_funcs = []
+        # The first file only contains the dispatch tables
+        if file_index == 0:
+            self.print_unmarshal_dispatch_cmd(api)
+            self.print_create_marshal_table(api)
+            return
+
+        # The remaining files contain the marshal and unmarshal functions
+        func_per_file = (len(api.functionIterateAll()) // (file_count - 1)) + 1
+        i = -1
         for func in api.functionIterateAll():
+            i += 1
+            if i // func_per_file != (file_index - 1):
+                continue
+
             flavor = func.marshal_flavor()
             if flavor in ('skip', 'custom'):
                 continue
             elif flavor == 'async':
                 self.print_async_body(func)
-                async_funcs.append(func)
             elif flavor == 'sync':
                 self.print_sync_body(func)
-        self.print_unmarshal_dispatch_cmd(api)
-        self.print_create_marshal_table(api)
 
 
 def show_usage():
@@ -347,14 +358,19 @@ if __name__ == '__main__':
     file_name = 'gl_API.xml'
 
     try:
-        (args, trail) = getopt.getopt(sys.argv[1:], 'm:f:')
+        (args, trail) = getopt.getopt(sys.argv[1:], 'm:f:i:n:')
     except Exception:
         show_usage()
 
     for (arg,val) in args:
         if arg == '-f':
             file_name = val
+        elif arg == '-i':
+            file_index = int(val)
+        elif arg == '-n':
+            file_count = int(val)
 
+    assert file_index < file_count
     printer = PrintCode()
 
     api = gl_XML.parse_GL_API(file_name, marshal_XML.marshal_item_factory())