u_format: Sanity check that BE swizzles are appropriately mapped from LE.
authorEric Anholt <eric@anholt.net>
Wed, 28 Apr 2021 21:10:08 +0000 (14:10 -0700)
committerMarge Bot <eric+marge@anholt.net>
Thu, 3 Jun 2021 00:12:39 +0000 (00:12 +0000)
Once you read enough of them, there's an obvious pattern that we can just
write a little code for instead of making every dev write it out each time.

Acked-by: Adam Jackson <ajax@redhat.com>
Acked-by: Ilia Mirkin <imirkin@alum.mit.edu>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10505>

src/util/format/u_format_parse.py

index 0094d57..f921626 100644 (file)
@@ -159,6 +159,20 @@ class Format:
                     print("{}: {} != {}".format(
                         self.name, be_channels, packed_be_channels))
                     exit(1)
+
+                xyzw = [SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_W]
+                chan_map = {SWIZZLE_X: xyzw[chans - 1] if chans >= 1 else SWIZZLE_X,
+                            SWIZZLE_Y: xyzw[chans - 2] if chans >= 2 else SWIZZLE_X,
+                            SWIZZLE_Z: xyzw[chans - 3] if chans >= 3 else SWIZZLE_X,
+                            SWIZZLE_W: xyzw[chans - 4] if chans >= 4 else SWIZZLE_X,
+                            SWIZZLE_1: SWIZZLE_1,
+                            SWIZZLE_0: SWIZZLE_0,
+                            SWIZZLE_NONE: SWIZZLE_NONE}
+                be_swizzles = [chan_map[s] for s in self.le_swizzles]
+                if be_swizzles != self.be_swizzles:
+                    print("{}: LE {}, computed BE {} != {}".format(
+                        self.name, self.le_swizzles, be_swizzles, self.be_swizzles))
+                    exit(1)
         else:
             self.be_channels = copy.deepcopy(le_channels)
             self.be_swizzles = le_swizzles