Mesa (master): glthread: sort variables in marshal structures to pack them optimally

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Apr 27 12:11:58 UTC 2020


Module: Mesa
Branch: master
Commit: 62154658426264c3f4dc5666ea04fc3fdd3d340a
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=62154658426264c3f4dc5666ea04fc3fdd3d340a

Author: Marek Olšák <marek.olsak at amd.com>
Date:   Mon Mar 23 19:39:40 2020 -0400

glthread: sort variables in marshal structures to pack them optimally

Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4758>

---

 src/mapi/glapi/gen/gl_marshal.py | 40 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/src/mapi/glapi/gen/gl_marshal.py b/src/mapi/glapi/gen/gl_marshal.py
index 16b3a6e04db..656381a0513 100644
--- a/src/mapi/glapi/gen/gl_marshal.py
+++ b/src/mapi/glapi/gen/gl_marshal.py
@@ -143,12 +143,50 @@ class PrintCode(gl_XML.gl_print_base):
         # Uncomment this if you want to call _mesa_glthread_finish for debugging
         #out('_mesa_glthread_finish(ctx);')
 
+    def get_type_size(self, str):
+        if str.find('*') != -1:
+            return 8;
+
+        mapping = {
+            'GLboolean': 1,
+            'GLbyte': 1,
+            'GLubyte': 1,
+            'GLenum': 2, # uses GLenum16
+            'GLshort': 2,
+            'GLushort': 2,
+            'GLint': 4,
+            'GLuint': 4,
+            'GLbitfield': 4,
+            'GLsizei': 4,
+            'GLfloat': 4,
+            'GLclampf': 4,
+            'GLfixed': 4,
+            'GLclampx': 4,
+            'GLhandleARB': 4,
+            'int': 4,
+            'float': 4,
+            'GLdouble': 8,
+            'GLclampd': 8,
+            'GLintptr': 8,
+            'GLsizeiptr': 8,
+            'GLint64': 8,
+            'GLuint64': 8,
+            'GLuint64EXT': 8,
+            'GLsync': 8,
+        }
+        val = mapping.get(str, 9999)
+        if val == 9999:
+            print('Unhandled type in gl_marshal.py.get_type_size: ' + str, file=sys.stderr)
+        return val
+
     def print_async_struct(self, func):
         out('struct marshal_cmd_{0}'.format(func.name))
         out('{')
         with indent():
             out('struct marshal_cmd_base cmd_base;')
-            for p in func.fixed_params:
+
+            # Sort the parameters according to their size to pack the structure optimally
+            for p in sorted(func.fixed_params, key=lambda p: self.get_type_size(p.type_string())):
                 if p.count:
                     out('{0} {1}[{2}];'.format(
                             p.get_base_type_string(), p.name, p.count))



More information about the mesa-commit mailing list