X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmapi%2Fglapi%2Fgen%2Fgl_marshal.py;h=476f54d6aa6fca3b7b5d99a5f6dc88150fa8e3b4;hb=88b5fb18b35e68edf2b187251df9a290f386d91c;hp=9d5d5ad9e2718fe1efc38a5d849648991aaf0ec1;hpb=245f9593b7967521bd6661d7059096c528cc7f0d;p=mesa.git diff --git a/src/mapi/glapi/gen/gl_marshal.py b/src/mapi/glapi/gen/gl_marshal.py index 9d5d5ad9e27..476f54d6aa6 100644 --- a/src/mapi/glapi/gen/gl_marshal.py +++ b/src/mapi/glapi/gen/gl_marshal.py @@ -35,7 +35,6 @@ header = """ #include "dispatch.h" #include "glthread.h" #include "marshal.h" -#include "marshal_generated.h" """ @@ -88,7 +87,6 @@ class PrintCode(gl_XML.gl_print_base): out('return {0};'.format(call)) def print_sync_dispatch(self, func): - out('debug_print_sync_fallback("{0}");'.format(func.name)) self.print_sync_call(func) def print_sync_body(self, func): @@ -98,8 +96,7 @@ class PrintCode(gl_XML.gl_print_base): out('{') with indent(): out('GET_CURRENT_CONTEXT(ctx);') - out('_mesa_glthread_finish(ctx);') - out('debug_print_sync("{0}");'.format(func.name)) + out('_mesa_glthread_finish_before(ctx, "{0}");'.format(func.name)) self.print_sync_call(func) out('}') out('') @@ -116,25 +113,27 @@ class PrintCode(gl_XML.gl_print_base): out('cmd->{0} = {0};'.format(p.name)) if func.variable_params: out('char *variable_data = (char *) (cmd + 1);') + i = 1 for p in func.variable_params: if p.img_null_flag: out('cmd->{0}_null = !{0};'.format(p.name)) out('if (!cmd->{0}_null) {{'.format(p.name)) with indent(): - out(('memcpy(variable_data, {0}, {1});').format( - p.name, p.size_string(False))) - out('variable_data += {0};'.format( - p.size_string(False))) + out(('memcpy(variable_data, {0}, {0}_size);').format(p.name)) + if i < len(func.variable_params): + out('variable_data += {0}_size;'.format(p.name)) out('}') else: - out(('memcpy(variable_data, {0}, {1});').format( - p.name, p.size_string(False))) - out('variable_data += {0};'.format( - p.size_string(False))) + out(('memcpy(variable_data, {0}, {0}_size);').format(p.name)) + if i < len(func.variable_params): + out('variable_data += {0}_size;'.format(p.name)) + i += 1 if not func.fixed_params and not func.variable_params: out('(void) cmd;\n') - out('_mesa_post_marshal_hook(ctx);') + + # Uncomment this if you want to call _mesa_glthread_finish for debugging + #out('_mesa_glthread_finish(ctx);') def print_async_struct(self, func): out('struct marshal_cmd_{0}'.format(func.name)) @@ -192,6 +191,7 @@ class PrintCode(gl_XML.gl_print_base): out('{0} * {1};'.format( p.get_base_type_string(), p.name)) out('const char *variable_data = (const char *) (cmd + 1);') + i = 1 for p in func.variable_params: out('{0} = ({1} *) variable_data;'.format( p.name, p.get_base_type_string())) @@ -200,11 +200,13 @@ class PrintCode(gl_XML.gl_print_base): out('if (cmd->{0}_null)'.format(p.name)) with indent(): out('{0} = NULL;'.format(p.name)) - out('else') - with indent(): - out('variable_data += {0};'.format(p.size_string(False))) - else: + if i < len(func.variable_params): + out('else') + with indent(): + out('variable_data += {0};'.format(p.size_string(False))) + elif i < len(func.variable_params): out('variable_data += {0};'.format(p.size_string(False))) + i += 1 self.print_sync_call(func) out('}') @@ -213,64 +215,57 @@ 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. + list = [] for p in func.parameters: if p.is_variable_length(): - out('if (unlikely({0} < 0)) {{'.format(p.size_string())) - 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): - need_fallback_sync = False out('static void GLAPIENTRY') out('_mesa_marshal_{0}({1})'.format( func.name, func.get_parameter_string())) out('{') with indent(): out('GET_CURRENT_CONTEXT(ctx);') + for p in func.variable_params: + out('int {0}_size = {1};'.format(p.name, p.size_string())) + struct = 'struct marshal_cmd_{0}'.format(func.name) size_terms = ['sizeof({0})'.format(struct)] for p in func.variable_params: - size = p.size_string() if p.img_null_flag: - size = '({0} ? {1} : 0)'.format(p.name, size) - size_terms.append(size) - out('size_t cmd_size = {0};'.format(' + '.join(size_terms))) + size_terms.append('({0} ? {0}_size : 0)'.format(p.name)) + else: + size_terms.append('{0}_size'.format(p.name)) + out('int cmd_size = {0};'.format(' + '.join(size_terms))) out('{0} *cmd;'.format(struct)) 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)) with indent(): - out('_mesa_glthread_finish(ctx);') - out('_mesa_glthread_restore_dispatch(ctx, __func__);') + out('_mesa_glthread_disable(ctx, "{0}");'.format(func.name)) self.print_sync_dispatch(func) 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(ctx);') - 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): @@ -282,31 +277,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('')