summaryrefslogtreecommitdiff
path: root/src/gallium/auxiliary/util/u_format_parse.py
diff options
context:
space:
mode:
authorRichard Sandiford <rsandifo@linux.vnet.ibm.com>2014-03-19 17:08:44 +0000
committerJosé Fonseca <jfonseca@vmware.com>2014-04-28 13:16:20 +0100
commit227d7a6a3ca0e32df2c87cf50112c5d7f02b2aae (patch)
tree6711561d4c0170b46213e536e560434a3f6973ff /src/gallium/auxiliary/util/u_format_parse.py
parent136c437cea3ebc9541735bb40951128e1210f06b (diff)
util: Add more query methods to u_format_parse.Format
The main aim is to reduce the number of places that access channels[0], swizzles[0] and swizzles[1] directly. There is no change to the generated u_format_table.c. Signed-off-by: Richard Sandiford <rsandifo@linux.vnet.ibm.com> Signed-off-by: José Fonseca <jfonseca@vmware.com>
Diffstat (limited to 'src/gallium/auxiliary/util/u_format_parse.py')
-rwxr-xr-xsrc/gallium/auxiliary/util/u_format_parse.py50
1 files changed, 43 insertions, 7 deletions
diff --git a/src/gallium/auxiliary/util/u_format_parse.py b/src/gallium/auxiliary/util/u_format_parse.py
index e202099b9ef..6b7b0f6941b 100755
--- a/src/gallium/auxiliary/util/u_format_parse.py
+++ b/src/gallium/auxiliary/util/u_format_parse.py
@@ -145,23 +145,26 @@ class Format:
nr_channels += 1
return nr_channels
- def is_array(self):
+ def array_element(self):
if self.layout != PLAIN:
- return False
+ return None
ref_channel = self.channels[0]
if ref_channel.type == VOID:
ref_channel = self.channels[1]
for channel in self.channels:
if channel.size and (channel.size != ref_channel.size or channel.size % 8):
- return False
+ return None
if channel.type != VOID:
if channel.type != ref_channel.type:
- return False
+ return None
if channel.norm != ref_channel.norm:
- return False
+ return None
if channel.pure != ref_channel.pure:
- return False
- return True
+ return None
+ return ref_channel
+
+ def is_array(self):
+ return self.array_element() != None
def is_mixed(self):
if self.layout != PLAIN:
@@ -208,6 +211,39 @@ class Format:
return False
return True
+ def is_pure_color(self):
+ if self.layout != PLAIN or self.colorspace == ZS:
+ return False
+ pures = [channel.pure
+ for channel in self.channels
+ if channel.type != VOID]
+ for x in pures:
+ assert x == pures[0]
+ return pures[0]
+
+ def channel_type(self):
+ types = [channel.type
+ for channel in self.channels
+ if channel.type != VOID]
+ for x in types:
+ assert x == types[0]
+ return types[0]
+
+ def is_pure_signed(self):
+ return self.is_pure_color() and self.channel_type() == SIGNED
+
+ def is_pure_unsigned(self):
+ return self.is_pure_color() and self.channel_type() == UNSIGNED
+
+ def has_channel(self, id):
+ return self.swizzles[id] != SWIZZLE_NONE
+
+ def has_depth(self):
+ return self.colorspace == ZS and self.has_channel(0)
+
+ def has_stencil(self):
+ return self.colorspace == ZS and self.has_channel(1)
+
def inv_swizzles(self):
'''Return an array[4] of inverse swizzle terms'''
'''Only pick the first matching value to avoid l8 getting blue and i8 getting alpha'''