Module: Mesa Branch: main Commit: 666d53214aff75da8cd907ad50f7fa11fddb7424 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=666d53214aff75da8cd907ad50f7fa11fddb7424
Author: Marek Olšák <[email protected]> Date: Thu Nov 30 15:55:01 2023 -0500 glthread: rework type reduction and reduce vertex stride params to 16 bits - add get_marshal_type(), which reduces type sizes - rework all places to use the result of get_marshal_type() Reviewed-by: Timothy Arceri <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26548> --- src/mapi/glapi/gen/gl_marshal.py | 8 ++++++-- src/mapi/glapi/gen/marshal_XML.py | 35 +++++++++++++++++++++++++---------- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/mapi/glapi/gen/gl_marshal.py b/src/mapi/glapi/gen/gl_marshal.py index a4bb2d0bb01..d571f047532 100644 --- a/src/mapi/glapi/gen/gl_marshal.py +++ b/src/mapi/glapi/gen/gl_marshal.py @@ -121,7 +121,7 @@ class PrintCode(gl_XML.gl_print_base): p.get_base_type_string(), p.name) else: p_decl = '{0} {1} = cmd->{1};'.format( - p.type_string(), p.name) + marshal_XML.get_marshal_type(func.name, p), p.name) if not p_decl.startswith('const ') and p.count: # Declare all local function variables as const, even if @@ -220,11 +220,15 @@ class PrintCode(gl_XML.gl_print_base): 'DISPATCH_CMD_{0}, cmd_size);'.format(func.name)) for p in fixed_params: + type = marshal_XML.get_marshal_type(func.name, p) + if p.count: out('memcpy(cmd->{0}, {0}, {1});'.format( p.name, p.size_string())) - elif p.type_string() == 'GLenum': + elif type == 'GLenum16': out('cmd->{0} = MIN2({0}, 0xffff); /* clamped to 0xffff (invalid enum) */'.format(p.name)) + elif type == 'int16_t': + out('cmd->{0} = CLAMP({0}, INT16_MIN, INT16_MAX);'.format(p.name)) else: out('cmd->{0} = {0};'.format(p.name)) if variable_params: diff --git a/src/mapi/glapi/gen/marshal_XML.py b/src/mapi/glapi/gen/marshal_XML.py index 01ec84502ab..49314fd14bb 100644 --- a/src/mapi/glapi/gen/marshal_XML.py +++ b/src/mapi/glapi/gen/marshal_XML.py @@ -25,18 +25,36 @@ import gl_XML -def get_type_size(str): - if str.find('*') != -1: +# We decrease the type size when it's safe, such as when the maximum value +# and all greater values are invalid. +def get_marshal_type(func_name, param): + type = param.type_string() + + if type == 'GLenum': + return 'GLenum16' # clamped to 0xffff (always invalid enum) + + # Use int16_t for the vertex stride, the max value is usually 2048. + if ((type, param.name) == ('GLsizei', 'stride') and + ('Vertex' in func_name or 'Pointer' in func_name or 'Interleaved' in func_name)): + return 'int16_t' # clamped to INT16_MAX (always invalid value) + + return type + +def get_type_size(func_name, param): + type = get_marshal_type(func_name, param) + + if type.find('*') != -1: return 8; mapping = { 'GLboolean': 1, 'GLbyte': 1, 'GLubyte': 1, - 'GLenum': 2, # uses GLenum16, clamped to 0xffff (invalid enum) + 'GLenum16': 2, # clamped by glthread 'GLshort': 2, 'GLushort': 2, 'GLhalfNV': 2, + 'int16_t': 2, # clamped by glthread 'GLint': 4, 'GLuint': 4, 'GLbitfield': 4, @@ -57,9 +75,9 @@ def get_type_size(str): 'GLuint64EXT': 8, 'GLsync': 8, } - val = mapping.get(str, 9999) + val = mapping.get(type, 9999) if val == 9999: - print('Unhandled type in marshal_XML.get_type_size: ' + str, file=sys.stderr) + print('Unhandled type in marshal_XML.get_type_size: ' + type, file=sys.stderr) assert False return val @@ -157,15 +175,12 @@ class marshal_function(gl_XML.gl_function): print(' struct marshal_cmd_base cmd_base;') # Sort the parameters according to their size to pack the structure optimally - for p in sorted(fixed_params, key=lambda p: get_type_size(p.type_string())): + for p in sorted(fixed_params, key=lambda p: get_type_size(self.name, p)): if p.count: print(' {0} {1}[{2}];'.format( p.get_base_type_string(), p.name, p.count)) else: - type = p.type_string() - if type == 'GLenum': - type = 'GLenum16' - print(' {0} {1};'.format(type, p.name)) + print(' {0} {1};'.format(get_marshal_type(self.name, p), p.name)) for p in variable_params: if p.img_null_flag:
