From 5dce9b252b65102ed69956fdd47862d5cb1c4af1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Tue, 23 Feb 2010 19:51:42 +0000 Subject: [PATCH] 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(+) 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] -- 2.7.4