From 1388be4d39714c46f03af2d784272a0cde818690 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Mon, 8 Jan 2024 02:04:55 -0500 Subject: [PATCH] glthread: pack "size" in Pointer calls as 16 bits The only legal values are {1, 2, 3, 4, GL_BGRA}. We need GLpacked16i to be unsigned, not signed, because GL_BGRA is greater than 0x8000. This decreases the size of 1 frame by 10% in Viewperf2020/Catia1. It decreases the size of many Pointer calls by 8 bytes. Acked-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/mapi/glapi/gen/gl_marshal.py | 2 ++ src/mapi/glapi/gen/marshal_XML.py | 4 ++++ src/mesa/main/glthread_marshal.h | 6 ++++++ 3 files changed, 12 insertions(+) diff --git a/src/mapi/glapi/gen/gl_marshal.py b/src/mapi/glapi/gen/gl_marshal.py index 4aec2d438f5..1458c33fc76 100644 --- a/src/mapi/glapi/gen/gl_marshal.py +++ b/src/mapi/glapi/gen/gl_marshal.py @@ -229,6 +229,8 @@ class PrintCode(gl_XML.gl_print_base): out('cmd->{0} = MIN2({0}, 0xffff); /* clamped to 0xffff (invalid enum) */'.format(p.name)) elif type == 'GLclamped16i': out('cmd->{0} = CLAMP({0}, INT16_MIN, INT16_MAX);'.format(p.name)) + elif type == 'GLpacked16i': + 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: diff --git a/src/mapi/glapi/gen/marshal_XML.py b/src/mapi/glapi/gen/marshal_XML.py index 8c52df6a379..9aa99d19682 100644 --- a/src/mapi/glapi/gen/marshal_XML.py +++ b/src/mapi/glapi/gen/marshal_XML.py @@ -43,6 +43,9 @@ def get_marshal_type(func_name, param): if (type, param.name) == ('GLsizei', 'stride'): return 'GLclamped16i' + if (type, param.name) == ('GLint', 'size'): + return 'GLpacked16i' + return type def get_type_size(func_name, param): @@ -60,6 +63,7 @@ def get_type_size(func_name, param): 'GLushort': 2, 'GLhalfNV': 2, 'GLclamped16i': 2, # clamped by glthread + 'GLpacked16i': 2, # clamped by glthread 'GLint': 4, 'GLuint': 4, 'GLbitfield': 4, diff --git a/src/mesa/main/glthread_marshal.h b/src/mesa/main/glthread_marshal.h index d4ebfe090f9..3cc1853e890 100644 --- a/src/mesa/main/glthread_marshal.h +++ b/src/mesa/main/glthread_marshal.h @@ -35,6 +35,12 @@ #include "main/macros.h" #include "main/matrix.h" +/* 32-bit signed integer clamped to 0..UINT16_MAX to compress parameters + * for glthread. All values < 0 and >= UINT16_MAX are expected to throw + * GL_INVALID_VALUE. Negative values are mapped to UINT16_MAX. + */ +typedef uint16_t GLpacked16i; + /* 32-bit signed integer clamped to 16 bits. */ typedef int16_t GLclamped16i;