Mesa (master): util: Store more derived data in the the format description.

Jose Fonseca jrfonseca at kemper.freedesktop.org
Wed Feb 24 12:15:55 UTC 2010


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

Author: José Fonseca <jfonseca at vmware.com>
Date:   Tue Feb 23 19:51:42 2010 +0000

util: Store more derived data in the the format description.

---

 src/gallium/auxiliary/util/u_format.h        |   18 ++++++++++++++++++
 src/gallium/auxiliary/util/u_format_parse.py |   24 ++++++++++++++++++++++++
 src/gallium/auxiliary/util/u_format_table.py |    6 ++++++
 3 files changed, 48 insertions(+), 0 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_format.h b/src/gallium/auxiliary/util/u_format.h
index 2fbbb83..7054a07 100644
--- a/src/gallium/auxiliary/util/u_format.h
+++ b/src/gallium/auxiliary/util/u_format.h
@@ -138,8 +138,26 @@ struct util_format_description
    const char *name;
    struct util_format_block block;
    enum util_format_layout layout;
+
+   /**
+    * The number of channels.
+    */
+   unsigned nr_channels:3;
+
+   /**
+    * Whether all channels have the same number of whole bytes.
+    */
+   unsigned is_array:1;
+
+   /**
+    * Whether channels have mixed types (ignoring UTIL_FORMAT_TYPE_VOID).
+    */
+   unsigned is_mixed:1;
+
    struct util_format_channel_description channel[4];
+
    unsigned char swizzle[4];
+
    enum util_format_colorspace colorspace;
 };
 
diff --git a/src/gallium/auxiliary/util/u_format_parse.py b/src/gallium/auxiliary/util/u_format_parse.py
index 493aff7..5d49fc7 100755
--- a/src/gallium/auxiliary/util/u_format_parse.py
+++ b/src/gallium/auxiliary/util/u_format_parse.py
@@ -83,6 +83,30 @@ class Format:
             size += type.size
         return size
 
+    def nr_channels(self):
+        nr_channels = 0
+        for type in self.in_types:
+            if type.size:
+                nr_channels += 1
+        return nr_channels
+
+    def is_array(self):
+        ref_type = self.in_types[0]
+        for type in self.in_types[1:]:
+            if type.size and (type.size != ref_type.size or type.size % 8):
+                return False
+        return True
+
+    def is_mixed(self):
+        ref_type = self.in_types[0]
+        for type in self.in_types[1:]:
+            if type.kind != VOID:
+                if type.kind != ref_type.kind:
+                    return True
+                if type.norm != ref_type.norm:
+                    return True
+        return False
+
     def stride(self):
         return self.block_size()/8
 
diff --git a/src/gallium/auxiliary/util/u_format_table.py b/src/gallium/auxiliary/util/u_format_table.py
index 571cab5..05e176d 100755
--- a/src/gallium/auxiliary/util/u_format_table.py
+++ b/src/gallium/auxiliary/util/u_format_table.py
@@ -94,6 +94,9 @@ def write_format_table(formats):
     print "      \"PIPE_FORMAT_NONE\","
     print "      {0, 0, 0},"
     print "      0,"
+    print "      0,"
+    print "      0,"
+    print "      0,"
     print "      {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}},"
     print "      {0, 0, 0, 0},"
     print "      0"
@@ -104,6 +107,9 @@ def write_format_table(formats):
         print "      \"%s\"," % (format.name,)
         print "      {%u, %u, %u},\t/* block */" % (format.block_width, format.block_height, format.block_size())
         print "      %s," % (layout_map(format.layout),)
+        print "      %u,\t/* nr_channels */" % (format.nr_channels(),)
+        print "      %s,\t/* is_array */" % (bool_map(format.is_array()),)
+        print "      %s,\t/* is_mixed */" % (bool_map(format.is_mixed()),)
         print "      {"
         for i in range(4):
             type = format.in_types[i]




More information about the mesa-commit mailing list