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

Author: Marek Olšák <[email protected]>
Date:   Thu Feb 11 20:40:05 2021 -0500

glthread: assume all parameters are fixed if marshal_sync is present

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, which will use marshal_sync to check whether
a PBO is bound.

Reviewed-by: Zoltán Böszörményi <[email protected]>
Reviewed-by: Pierre-Eric Pelloux-Prayer <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9029>

---

 src/mapi/glapi/gen/gl_marshal.py | 78 +++++++++++++++++++++++++++-------------
 1 file changed, 53 insertions(+), 25 deletions(-)

diff --git a/src/mapi/glapi/gen/gl_marshal.py b/src/mapi/glapi/gen/gl_marshal.py
index a759066cfa3..95a22bd9b1b 100644
--- a/src/mapi/glapi/gen/gl_marshal.py
+++ b/src/mapi/glapi/gen/gl_marshal.py
@@ -108,31 +108,44 @@ class PrintCode(gl_XML.gl_print_base):
     def print_async_dispatch(self, func):
         out('cmd = _mesa_glthread_allocate_command(ctx, '
             'DISPATCH_CMD_{0}, cmd_size);'.format(func.name))
-        for p in func.fixed_params:
+
+        # 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 func.marshal_sync:
+            fixed_params = func.fixed_params + func.variable_params
+            variable_params = []
+        else:
+            fixed_params = func.fixed_params
+            variable_params = func.variable_params
+
+        for p in fixed_params:
             if p.count:
                 out('memcpy(cmd->{0}, {0}, {1});'.format(
                         p.name, p.size_string()))
             else:
                 out('cmd->{0} = {0};'.format(p.name))
-        if func.variable_params:
+        if variable_params:
             out('char *variable_data = (char *) (cmd + 1);')
             i = 1
-            for p in func.variable_params:
+            for p in 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(func.variable_params):
+                        if i < len(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(func.variable_params):
+                    if i < len(variable_params):
                         out('variable_data += {0}_size;'.format(p.name))
                 i += 1
 
-        if not func.fixed_params and not func.variable_params:
+        if not fixed_params and not variable_params:
             out('(void) cmd;')
 
         if func.marshal_call_after:
@@ -179,25 +192,32 @@ class PrintCode(gl_XML.gl_print_base):
         return val
 
     def print_async_struct(self, func):
+        if func.marshal_sync:
+            fixed_params = func.fixed_params + func.variable_params
+            variable_params = []
+        else:
+            fixed_params = func.fixed_params
+            variable_params = func.variable_params
+
         out('struct marshal_cmd_{0}'.format(func.name))
         out('{')
         with indent():
             out('struct marshal_cmd_base cmd_base;')
 
             # 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())):
+            for p in sorted(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))
                 else:
                     out('{0} {1};'.format(p.type_string(), p.name))
 
-            for p in func.variable_params:
+            for p in variable_params:
                 if p.img_null_flag:
                     out('bool {0}_null; /* If set, no data follows '
                         'for "{0}" */'.format(p.name))
 
-            for p in func.variable_params:
+            for p in variable_params:
                 if p.count_scale != 1:
                     out(('/* Next {0} bytes are '
                          '{1} {2}[{3}][{4}] */').format(
@@ -211,12 +231,19 @@ class PrintCode(gl_XML.gl_print_base):
         out('};')
 
     def print_async_unmarshal(self, func):
+        if func.marshal_sync:
+            fixed_params = func.fixed_params + func.variable_params
+            variable_params = []
+        else:
+            fixed_params = func.fixed_params
+            variable_params = func.variable_params
+
         out('void')
         out(('_mesa_unmarshal_{0}(struct gl_context *ctx, '
              'const struct marshal_cmd_{0} *cmd)').format(func.name))
         out('{')
         with indent():
-            for p in func.fixed_params:
+            for p in fixed_params:
                 if p.count:
                     p_decl = '{0} * {1} = cmd->{1};'.format(
                             p.get_base_type_string(), p.name)
@@ -231,13 +258,13 @@ class PrintCode(gl_XML.gl_print_base):
 
                 out(p_decl)
 
-            if func.variable_params:
-                for p in func.variable_params:
+            if variable_params:
+                for p in 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 func.variable_params:
+                for p in variable_params:
                     out('{0} = ({1} *) variable_data;'.format(
                             p.name, p.get_base_type_string()))
 
@@ -245,11 +272,11 @@ 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(func.variable_params):
+                        if i < len(variable_params):
                             out('else')
                             with indent():
                                 out('variable_data += 
{0};'.format(p.size_string(False, marshal = 1)))
-                    elif i < len(func.variable_params):
+                    elif i < len(variable_params):
                         out('variable_data += 
{0};'.format(p.size_string(False, marshal = 1)))
                     i += 1
 
@@ -285,21 +312,21 @@ class PrintCode(gl_XML.gl_print_base):
         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(marshal 
= 1)))
+            if not func.marshal_sync:
+                for p in func.variable_params:
+                    out('int {0}_size = {1};'.format(p.name, 
p.size_string(marshal = 1)))
 
             struct = 'struct marshal_cmd_{0}'.format(func.name)
             size_terms = ['sizeof({0})'.format(struct)]
-            for p in func.variable_params:
-                if p.img_null_flag:
-                    size_terms.append('({0} ? {0}_size : 0)'.format(p.name))
-                else:
-                    size_terms.append('{0}_size'.format(p.name))
+            if not func.marshal_sync:
+                for p in func.variable_params:
+                    if p.img_null_flag:
+                        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))
 
-            self.validate_count_or_fallback(func)
-
             if func.marshal_sync:
                 out('if ({0}) {{'.format(func.marshal_sync))
                 with indent():
@@ -307,8 +334,9 @@ class PrintCode(gl_XML.gl_print_base):
                     self.print_sync_call(func)
                     out('return;')
                 out('}')
+            else:
+                self.validate_count_or_fallback(func)
 
-        with indent():
             self.print_async_dispatch(func)
         out('}')
 

_______________________________________________
mesa-commit mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to