Mesa (main): u_format: Sanity check the BE channels for all bitmask formats.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Jun 3 00:44:43 UTC 2021


Module: Mesa
Branch: main
Commit: 36569b9f8cbcaea1dbfeed7a7f0c6d4b33dd99a6
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=36569b9f8cbcaea1dbfeed7a7f0c6d4b33dd99a6

Author: Eric Anholt <eric at anholt.net>
Date:   Tue Apr 27 15:17:39 2021 -0700

u_format: Sanity check the BE channels for all bitmask formats.

Just check against the CSV (which has its codegen now tested with
u_format_test in CI) for now, so we know that our computed channels are
correct.

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

---

 src/util/format/u_format_parse.py | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/src/util/format/u_format_parse.py b/src/util/format/u_format_parse.py
index aba4e29ee36..0094d576cf5 100644
--- a/src/util/format/u_format_parse.py
+++ b/src/util/format/u_format_parse.py
@@ -71,6 +71,9 @@ class Channel:
         s += str(self.size)
         return s
 
+    def __repr__(self):
+        return "Channel({})".format(self.__str__())
+
     def __eq__(self, other):
         if other is None:
             return False
@@ -135,6 +138,27 @@ class Format:
                 exit(1)
             self.be_channels = be_channels
             self.be_swizzles = be_swizzles
+
+            if self.is_bitmask():
+                # Bitmask formats are "load a word the size of the block and
+                # bitshift channels out of it." However, the channel shifts
+                # defined in u_format_table.c are numbered right-to-left on BE
+                # for some historical reason (see below), which is hard to
+                # change due to llvmpipe, so we also have to flip the channel
+                # order and the channel-to-rgba swizzle values to read
+                # right-to-left from the defined (non-VOID) channels so that the
+                # correct shifts happen.
+                #
+                # This is nonsense, but it's the nonsense that makes
+                # u_format_test pass and you get the right colors in softpipe at
+                # least.
+                chans = self.nr_channels()
+                packed_be_channels = self.le_channels[chans -
+                                                    1::-1] + self.le_channels[chans:4]
+                if packed_be_channels != be_channels:
+                    print("{}: {} != {}".format(
+                        self.name, be_channels, packed_be_channels))
+                    exit(1)
         else:
             self.be_channels = copy.deepcopy(le_channels)
             self.be_swizzles = le_swizzles



More information about the mesa-commit mailing list