gallium: remove shebang from python scripts
[mesa.git] / src / gallium / auxiliary / util / u_format_table.py
1
2 CopyRight = '''
3 /**************************************************************************
4 *
5 * Copyright 2010 VMware, Inc.
6 * All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sub license, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
15 *
16 * The above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial portions
18 * of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
23 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
24 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 *
28 **************************************************************************/
29 '''
30
31
32 import sys
33
34 from u_format_parse import *
35 import u_format_pack
36
37
38 def layout_map(layout):
39 return 'UTIL_FORMAT_LAYOUT_' + str(layout).upper()
40
41
42 def colorspace_map(colorspace):
43 return 'UTIL_FORMAT_COLORSPACE_' + str(colorspace).upper()
44
45
46 colorspace_channels_map = {
47 'rgb': ['r', 'g', 'b', 'a'],
48 'srgb': ['sr', 'sg', 'sb', 'a'],
49 'zs': ['z', 's'],
50 'yuv': ['y', 'u', 'v'],
51 }
52
53
54 type_map = {
55 VOID: "UTIL_FORMAT_TYPE_VOID",
56 UNSIGNED: "UTIL_FORMAT_TYPE_UNSIGNED",
57 SIGNED: "UTIL_FORMAT_TYPE_SIGNED",
58 FIXED: "UTIL_FORMAT_TYPE_FIXED",
59 FLOAT: "UTIL_FORMAT_TYPE_FLOAT",
60 }
61
62
63 def bool_map(value):
64 if value:
65 return "TRUE"
66 else:
67 return "FALSE"
68
69
70 swizzle_map = {
71 SWIZZLE_X: "PIPE_SWIZZLE_X",
72 SWIZZLE_Y: "PIPE_SWIZZLE_Y",
73 SWIZZLE_Z: "PIPE_SWIZZLE_Z",
74 SWIZZLE_W: "PIPE_SWIZZLE_W",
75 SWIZZLE_0: "PIPE_SWIZZLE_0",
76 SWIZZLE_1: "PIPE_SWIZZLE_1",
77 SWIZZLE_NONE: "PIPE_SWIZZLE_NONE",
78 }
79
80
81 def write_format_table(formats):
82 print '/* This file is autogenerated by u_format_table.py from u_format.csv. Do not edit directly. */'
83 print
84 # This will print the copyright message on the top of this file
85 print CopyRight.strip()
86 print
87 print '#include "u_format.h"'
88 print '#include "u_format_s3tc.h"'
89 print '#include "u_format_rgtc.h"'
90 print '#include "u_format_latc.h"'
91 print '#include "u_format_etc.h"'
92 print
93
94 u_format_pack.generate(formats)
95
96 def do_channel_array(channels, swizzles):
97 print " {"
98 for i in range(4):
99 channel = channels[i]
100 if i < 3:
101 sep = ","
102 else:
103 sep = ""
104 if channel.size:
105 print " {%s, %s, %s, %u, %u}%s\t/* %s = %s */" % (type_map[channel.type], bool_map(channel.norm), bool_map(channel.pure), channel.size, channel.shift, sep, "xyzw"[i], channel.name)
106 else:
107 print " {0, 0, 0, 0, 0}%s" % (sep,)
108 print " },"
109
110 def do_swizzle_array(channels, swizzles):
111 print " {"
112 for i in range(4):
113 swizzle = swizzles[i]
114 if i < 3:
115 sep = ","
116 else:
117 sep = ""
118 try:
119 comment = colorspace_channels_map[format.colorspace][i]
120 except (KeyError, IndexError):
121 comment = 'ignored'
122 print " %s%s\t/* %s */" % (swizzle_map[swizzle], sep, comment)
123 print " },"
124
125 for format in formats:
126 print 'const struct util_format_description'
127 print 'util_format_%s_description = {' % (format.short_name(),)
128 print " %s," % (format.name,)
129 print " \"%s\"," % (format.name,)
130 print " \"%s\"," % (format.short_name(),)
131 print " {%u, %u, %u},\t/* block */" % (format.block_width, format.block_height, format.block_size())
132 print " %s," % (layout_map(format.layout),)
133 print " %u,\t/* nr_channels */" % (format.nr_channels(),)
134 print " %s,\t/* is_array */" % (bool_map(format.is_array()),)
135 print " %s,\t/* is_bitmask */" % (bool_map(format.is_bitmask()),)
136 print " %s,\t/* is_mixed */" % (bool_map(format.is_mixed()),)
137 u_format_pack.print_channels(format, do_channel_array)
138 u_format_pack.print_channels(format, do_swizzle_array)
139 print " %s," % (colorspace_map(format.colorspace),)
140 access = True
141 if format.layout in ('bptc', 'astc'):
142 access = False
143 if format.layout == 'etc' and format.short_name() != 'etc1_rgb8':
144 access = False
145 if format.colorspace != ZS and not format.is_pure_color() and access:
146 print " &util_format_%s_unpack_rgba_8unorm," % format.short_name()
147 print " &util_format_%s_pack_rgba_8unorm," % format.short_name()
148 if format.layout == 's3tc' or format.layout == 'rgtc':
149 print " &util_format_%s_fetch_rgba_8unorm," % format.short_name()
150 else:
151 print " NULL, /* fetch_rgba_8unorm */"
152 print " &util_format_%s_unpack_rgba_float," % format.short_name()
153 print " &util_format_%s_pack_rgba_float," % format.short_name()
154 print " &util_format_%s_fetch_rgba_float," % format.short_name()
155 else:
156 print " NULL, /* unpack_rgba_8unorm */"
157 print " NULL, /* pack_rgba_8unorm */"
158 print " NULL, /* fetch_rgba_8unorm */"
159 print " NULL, /* unpack_rgba_float */"
160 print " NULL, /* pack_rgba_float */"
161 print " NULL, /* fetch_rgba_float */"
162 if format.has_depth():
163 print " &util_format_%s_unpack_z_32unorm," % format.short_name()
164 print " &util_format_%s_pack_z_32unorm," % format.short_name()
165 print " &util_format_%s_unpack_z_float," % format.short_name()
166 print " &util_format_%s_pack_z_float," % format.short_name()
167 else:
168 print " NULL, /* unpack_z_32unorm */"
169 print " NULL, /* pack_z_32unorm */"
170 print " NULL, /* unpack_z_float */"
171 print " NULL, /* pack_z_float */"
172 if format.has_stencil():
173 print " &util_format_%s_unpack_s_8uint," % format.short_name()
174 print " &util_format_%s_pack_s_8uint," % format.short_name()
175 else:
176 print " NULL, /* unpack_s_8uint */"
177 print " NULL, /* pack_s_8uint */"
178 if format.is_pure_unsigned():
179 print " &util_format_%s_unpack_unsigned, /* unpack_rgba_uint */" % format.short_name()
180 print " &util_format_%s_pack_unsigned, /* pack_rgba_uint */" % format.short_name()
181 print " &util_format_%s_unpack_signed, /* unpack_rgba_sint */" % format.short_name()
182 print " &util_format_%s_pack_signed, /* pack_rgba_sint */" % format.short_name()
183 print " &util_format_%s_fetch_unsigned, /* fetch_rgba_uint */" % format.short_name()
184 print " NULL /* fetch_rgba_sint */"
185 elif format.is_pure_signed():
186 print " &util_format_%s_unpack_unsigned, /* unpack_rgba_uint */" % format.short_name()
187 print " &util_format_%s_pack_unsigned, /* pack_rgba_uint */" % format.short_name()
188 print " &util_format_%s_unpack_signed, /* unpack_rgba_sint */" % format.short_name()
189 print " &util_format_%s_pack_signed, /* pack_rgba_sint */" % format.short_name()
190 print " NULL, /* fetch_rgba_uint */"
191 print " &util_format_%s_fetch_signed /* fetch_rgba_sint */" % format.short_name()
192 else:
193 print " NULL, /* unpack_rgba_uint */"
194 print " NULL, /* pack_rgba_uint */"
195 print " NULL, /* unpack_rgba_sint */"
196 print " NULL, /* pack_rgba_sint */"
197 print " NULL, /* fetch_rgba_uint */"
198 print " NULL /* fetch_rgba_sint */"
199 print "};"
200 print
201
202 print "const struct util_format_description *"
203 print "util_format_description(enum pipe_format format)"
204 print "{"
205 print " if (format >= PIPE_FORMAT_COUNT) {"
206 print " return NULL;"
207 print " }"
208 print
209 print " switch (format) {"
210 for format in formats:
211 print " case %s:" % format.name
212 print " return &util_format_%s_description;" % (format.short_name(),)
213 print " default:"
214 print " return NULL;"
215 print " }"
216 print "}"
217 print
218
219
220 def main():
221
222 formats = []
223 for arg in sys.argv[1:]:
224 formats.extend(parse(arg))
225 write_format_table(formats)
226
227
228 if __name__ == '__main__':
229 main()