util: Store more derived data in the the format description.
authorJosé Fonseca <jfonseca@vmware.com>
Tue, 23 Feb 2010 19:51:42 +0000 (19:51 +0000)
committerJosé Fonseca <jfonseca@vmware.com>
Wed, 24 Feb 2010 12:15:13 +0000 (12:15 +0000)
src/gallium/auxiliary/util/u_format.h
src/gallium/auxiliary/util/u_format_parse.py
src/gallium/auxiliary/util/u_format_table.py

index 2fbbb83..7054a07 100644 (file)
@@ -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;
 };
 
index 493aff7..5d49fc7 100755 (executable)
@@ -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
 
index 571cab5..05e176d 100755 (executable)
@@ -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]