diff --git a/src/mapi/glapi/gen/gl_marshal.py b/src/mapi/glapi/gen/gl_marshal.py index 3dbfa6c19a7..74bd57beb32 100644 --- a/src/mapi/glapi/gen/gl_marshal.py +++ b/src/mapi/glapi/gen/gl_marshal.py @@ -26,6 +26,8 @@ import gl_XML import license import marshal_XML import sys +import collections +import apiexec header = """ #include "context.h" @@ -377,30 +379,48 @@ class PrintCode(gl_XML.gl_print_base): out('#if defined(__GNUC__) && !defined(__clang__)') out('__attribute__((optimize("O1")))') out('#endif') - out('struct _glapi_table *') - out('_mesa_create_marshal_table(const struct gl_context *ctx)') + out('bool') + out('_mesa_create_marshal_tables(struct gl_context *ctx)') out('{') with indent(): - out('struct _glapi_table *table;') - out('') - out('table = _mesa_alloc_dispatch_table(true);') - out('if (table == NULL)') + out('ctx->MarshalExec = _mesa_alloc_dispatch_table(true);') + out('if (!ctx->MarshalExec)') with indent(): - out('return NULL;') + out('return false;') out('') + + # Collect SET_* calls by the condition under which they should + # be called. + settings_by_condition = collections.defaultdict(lambda: []) + for func in api.functionIterateAll(): if func.marshal_flavor() == 'skip': continue + + condition = apiexec.get_api_condition(func) + if not condition: + continue + # 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;') + settings_by_condition[condition].append( + ('if (_gloffset_{0} >= 0)\n' + + ' ((_glapi_proc *)(ctx->MarshalExec))[_gloffset_{0}] =' + + ' (_glapi_proc)_mesa_marshal_{0};').format(func.name)) + + # Print out an if statement for each unique condition, with + # the SET_* calls nested inside it. + for condition in sorted(settings_by_condition.keys()): + out('if ({0}) {{'.format(condition)) + with indent(): + for setting in sorted(settings_by_condition[condition]): + for line in setting.split('\n'): + out(line) + out('}') + + out('') + out(' return true;') out('}') - out('') - out('') def printBody(self, api): # The first file only contains the dispatch tables diff --git a/src/mesa/main/glthread.c b/src/mesa/main/glthread.c index 9738e74a441..8e7b518defc 100644 --- a/src/mesa/main/glthread.c +++ b/src/mesa/main/glthread.c @@ -110,8 +110,7 @@ _mesa_glthread_init(struct gl_context *ctx) _mesa_glthread_reset_vao(&glthread->DefaultVAO); glthread->CurrentVAO = &glthread->DefaultVAO; - ctx->MarshalExec = _mesa_create_marshal_table(ctx); - if (!ctx->MarshalExec) { + if (!_mesa_create_marshal_tables(ctx)) { _mesa_DeleteHashTable(glthread->VAOs); util_queue_destroy(&glthread->queue); return; diff --git a/src/mesa/main/glthread_marshal.h b/src/mesa/main/glthread_marshal.h index 300d975a6e9..2edb6ecf3cd 100644 --- a/src/mesa/main/glthread_marshal.h +++ b/src/mesa/main/glthread_marshal.h @@ -132,8 +132,8 @@ _mesa_glthread_has_non_vbo_vertices_or_indices_or_indirect(const struct gl_conte } -struct _glapi_table * -_mesa_create_marshal_table(const struct gl_context *ctx); +bool +_mesa_create_marshal_tables(struct gl_context *ctx); static inline unsigned _mesa_buffer_enum_to_count(GLenum buffer)