summaryrefslogtreecommitdiffstats
path: root/src/mesa/main/format_parser.py
diff options
context:
space:
mode:
authorJason Ekstrand <jason.ekstrand@intel.com>2014-08-21 12:38:05 -0700
committerIago Toral Quiroga <itoral@igalia.com>2015-01-12 11:20:28 +0100
commite0439f750557bc6880a8a4eccb38256fafd63fae (patch)
tree3b12d414feba21ec08437adb376b47f5a3f2633d /src/mesa/main/format_parser.py
parent2b37bea010a9c9333a813cc77d28629e1382c0be (diff)
downloadexternal_mesa3d-e0439f750557bc6880a8a4eccb38256fafd63fae.zip
external_mesa3d-e0439f750557bc6880a8a4eccb38256fafd63fae.tar.gz
external_mesa3d-e0439f750557bc6880a8a4eccb38256fafd63fae.tar.bz2
mesa: Autogenerate most of format_pack.c
We were auto-generating it before. The problem was that the autogeneration tool we were using was called "copy, paste, and edit". Let's use a more sensible solution. Signed-off-by: Jason Ekstrand <jason.ekstrand@intel.com> v2 by Samuel Iglesias <siglesias@igalia.com> - Remove format_pack.c as it is now autogenerated - Add usage of INDENT_FLAGS in Makefile.am - Remove trailing blank line v3 by Samuel Iglesias <siglesias@igalia.com> - Merge format_convert.py into format_parser.py - Adapt pack_*_* function generations - Fix out-of-tree build v4 by Samuel Iglesias <siglesias@igalia.com> - _get_datatype() is now a helper function v5 by Samuel Iglesias <siglesias@igalia.com> - format_pack.c.mako is now format_pack.py, with the template code inlined. It now auto-generates format_pack.c - Simplify Makefile.am change. - Modify SConscript to build format_pack.c with scons. - Remove run_mako.py - Add format_pack.c to gitignore v6 by Samuel Iglesias <siglesias@igalia.com>: - Don't allow float to non-normalized integer format conversions. - Add non-normalized formats support for ubyte packing functions. Merge the previously separated patch. - Add clamping for non-normalized integer formats in pack_ubyte*() v7 by Samuel Iglesias <siglesias@igalia.com>: - Add assert to check that sRGB formats are 8-bit size. Signed-off-by: Samuel Iglesias Gonsalvez <siglesias@igalia.com> Reviewed-by: Jason Ekstrand <jason.ekstrand@intel.com>
Diffstat (limited to 'src/mesa/main/format_parser.py')
-rwxr-xr-xsrc/mesa/main/format_parser.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/mesa/main/format_parser.py b/src/mesa/main/format_parser.py
index 5e45c74..522bce3 100755
--- a/src/mesa/main/format_parser.py
+++ b/src/mesa/main/format_parser.py
@@ -102,6 +102,10 @@ class Channel:
"""Returns true if the size of this channel is a power of two."""
return is_power_of_two(self.size)
+ def datatype(self):
+ """Returns the datatype corresponding to a channel type and size"""
+ return _get_datatype(self.type, self.size)
+
class Swizzle:
"""Describes a swizzle operation.
@@ -469,6 +473,49 @@ class Format:
return channel
return None
+ def datatype(self):
+ """Returns the datatype corresponding to a format's channel type and size"""
+ if self.layout == PACKED:
+ if self.block_size() == 8:
+ return 'uint8_t'
+ if self.block_size() == 16:
+ return 'uint16_t'
+ if self.block_size() == 32:
+ return 'uint32_t'
+ else:
+ assert False
+ else:
+ return _get_datatype(self.channel_type(), self.channel_size())
+
+def _get_datatype(type, size):
+ if type == FLOAT:
+ if size == 32:
+ return 'float'
+ elif size == 16:
+ return 'uint16_t'
+ else:
+ assert False
+ elif type == UNSIGNED:
+ if size <= 8:
+ return 'uint8_t'
+ elif size <= 16:
+ return 'uint16_t'
+ elif size <= 32:
+ return 'uint32_t'
+ else:
+ assert False
+ elif type == SIGNED:
+ if size <= 8:
+ return 'int8_t'
+ elif size <= 16:
+ return 'int16_t'
+ elif size <= 32:
+ return 'int32_t'
+ else:
+ assert False
+ else:
+ assert False
+
def _parse_channels(fields, layout, colorspace, swizzle):
channels = []
for field in fields: