panfrost: gen_pack: Move the group get_length() logic to its own method
authorBoris Brezillon <boris.brezillon@collabora.com>
Sat, 5 Sep 2020 09:53:06 +0000 (11:53 +0200)
committerAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Mon, 21 Sep 2020 11:34:48 +0000 (07:34 -0400)
So we can re-use it elsewhere.

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6797>

src/panfrost/lib/gen_pack.py

index ffa8e01..1877f27 100644 (file)
@@ -290,6 +290,16 @@ class Group(object):
         self.length = 0
         self.fields = []
 
+    def get_length(self):
+        # Determine number of bytes in this group.
+        calculated = max(field.end // 8 for field in self.fields) + 1
+        if self.length > 0:
+            assert(self.length >= calculated)
+        else:
+            self.length = calculated
+        return self.length
+
+
     def emit_template_struct(self, dim, opaque_structs):
         if self.count == 0:
             print("   /* variable length fields follow */")
@@ -320,13 +330,7 @@ class Group(object):
                 words[b].fields.append(field)
 
     def emit_pack_function(self, opaque_structs):
-        # Determine number of bytes in this group.
-        calculated = max(field.end // 8 for field in self.fields) + 1
-
-        if self.length > 0:
-            assert(self.length >= calculated)
-        else:
-            self.length = calculated
+        self.get_length()
 
         words = {}
         self.collect_words(words)