From e9819744b32542b3070e83ef68f38cf9bd7929fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Mon, 8 Jan 2024 18:54:34 -0500 Subject: [PATCH] glthread: precompute fixed_params and variable_params lists This removes functions get_fixed_params and get_variable_params. No functional change. Acked-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/mapi/glapi/gen/gl_marshal.py | 31 ++++++++++------------ src/mapi/glapi/gen/marshal_XML.py | 44 +++++++++++++------------------ 2 files changed, 32 insertions(+), 43 deletions(-) diff --git a/src/mapi/glapi/gen/gl_marshal.py b/src/mapi/glapi/gen/gl_marshal.py index cef84e6175b..0d652eac7db 100644 --- a/src/mapi/glapi/gen/gl_marshal.py +++ b/src/mapi/glapi/gen/gl_marshal.py @@ -104,9 +104,6 @@ class PrintCode(gl_XML.gl_print_base): out('') def print_async_body(self, func): - fixed_params = func.get_fixed_params() - variable_params = func.get_variable_params() - out('/* {0}: marshalled asynchronously */'.format(func.name)) func.print_struct() @@ -115,7 +112,7 @@ class PrintCode(gl_XML.gl_print_base): 'const struct marshal_cmd_{0} *restrict cmd)').format(func.name)) out('{') with indent(): - for p in fixed_params: + for p in func.fixed_params: if p.count: p_decl = '{0} *{1} = cmd->{1};'.format( p.get_base_type_string(), p.name) @@ -130,13 +127,13 @@ class PrintCode(gl_XML.gl_print_base): out(p_decl) - if variable_params: - for p in variable_params: + if func.variable_params: + for p in func.variable_params: 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 variable_params: + for p in func.variable_params: out('{0} = ({1} *) variable_data;'.format( p.name, p.get_base_type_string())) @@ -144,16 +141,16 @@ class PrintCode(gl_XML.gl_print_base): out('if (cmd->{0}_null)'.format(p.name)) with indent(): out('{0} = NULL;'.format(p.name)) - if i < len(variable_params): + if i < len(func.variable_params): out('else') with indent(): out('variable_data += {0};'.format(p.size_string(False, marshal=1))) - elif i < len(variable_params): + elif i < len(func.variable_params): out('variable_data += {0};'.format(p.size_string(False, marshal=1))) i += 1 self.print_call(func, unmarshal=1) - if variable_params: + if func.variable_params: out('return cmd->num_slots;') else: struct = 'struct marshal_cmd_{0}'.format(func.name) @@ -216,10 +213,10 @@ class PrintCode(gl_XML.gl_print_base): # Add the call into the batch. out('cmd = _mesa_glthread_allocate_command(ctx, ' 'DISPATCH_CMD_{0}, cmd_size);'.format(func.name)) - if variable_params: + if func.variable_params: out('cmd->num_slots = align(cmd_size, 8) / 8;') - for p in fixed_params: + for p in func.fixed_params: type = func.get_marshal_type(p) if p.count: @@ -235,25 +232,25 @@ class PrintCode(gl_XML.gl_print_base): out('cmd->{0} = {0} < 0 ? UINT16_MAX : MIN2({0}, UINT16_MAX);'.format(p.name)) else: out('cmd->{0} = {0};'.format(p.name)) - if variable_params: + if func.variable_params: out('char *variable_data = (char *) (cmd + 1);') i = 1 - for p in variable_params: + 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}, {0}_size);').format(p.name)) - if i < len(variable_params): + if i < len(func.variable_params): out('variable_data += {0}_size;'.format(p.name)) out('}') else: out(('memcpy(variable_data, {0}, {0}_size);').format(p.name)) - if i < len(variable_params): + if i < len(func.variable_params): out('variable_data += {0}_size;'.format(p.name)) i += 1 - if not fixed_params and not variable_params: + if not func.fixed_params and not func.variable_params: out('(void) cmd;') if func.marshal_call_after: diff --git a/src/mapi/glapi/gen/marshal_XML.py b/src/mapi/glapi/gen/marshal_XML.py index 8837d84e119..11c3715601d 100644 --- a/src/mapi/glapi/gen/marshal_XML.py +++ b/src/mapi/glapi/gen/marshal_XML.py @@ -143,6 +143,20 @@ class marshal_function(gl_XML.gl_function): self.name.endswith('PointerOES') or self.name.endswith('OffsetEXT')) + # marshal_sync means whether a function should be called to determine + # whether we should sync. + if self.marshal_sync: + # This is a case of a pointer with an unknown size. Move + # variable-sized pointer parameters to fixed parameters because + # they will be passed as-is if the marshal_sync function evaluates + # to true. + self.fixed_params = self.fixed_params + self.variable_params + self.variable_params = [] + + # Sort the parameters, so that the marshal structure fields are sorted + # from smallest to biggest. + self.fixed_params = sorted(self.fixed_params, key=lambda p: self.get_type_size(p)) + def marshal_flavor(self): """Find out how this function should be marshalled between client and server threads.""" @@ -174,49 +188,27 @@ class marshal_function(gl_XML.gl_function): self.name[0:8] != 'Internal' and self.exec_flavor != 'beginend') - def get_fixed_params(self): - # We want glthread to ignore variable-sized parameters if the only thing - # we want is to pass the pointer parameter as-is, e.g. when a PBO is bound. - # Making it conditional on marshal_sync is kinda hacky, but it's the easiest - # path towards handling PBOs in glthread, which use marshal_sync to check whether - # a PBO is bound. - if self.marshal_sync: - list = self.fixed_params + self.variable_params - else: - list = self.fixed_params - - return sorted(list, key=lambda p: self.get_type_size(p)) - - def get_variable_params(self): - if self.marshal_sync: - return [] - else: - return self.variable_params - def print_struct(self, is_header=False): - fixed_params = self.get_fixed_params() - variable_params = self.get_variable_params() - if (self.marshal_struct == 'public') == is_header: print('struct marshal_cmd_{0}'.format(self.name)) print('{') print(' struct marshal_cmd_base cmd_base;') - if variable_params: + if self.variable_params: print(' uint16_t num_slots;') - for p in fixed_params: + for p in self.fixed_params: if p.count: print(' {0} {1}[{2}];'.format( p.get_base_type_string(), p.name, p.count)) else: print(' {0} {1};'.format(self.get_marshal_type(p), p.name)) - for p in variable_params: + for p in self.variable_params: if p.img_null_flag: print(' bool {0}_null; /* If set, no data follows ' 'for "{0}" */'.format(p.name)) - for p in variable_params: + for p in self.variable_params: if p.count_scale != 1: print((' /* Next {0} bytes are ' '{1} {2}[{3}][{4}] */').format(