Simplify the redundant meaning of format layout.
[mesa.git] / src / gallium / auxiliary / util / u_format_table.py
1 #!/usr/bin/env python
2
3 '''
4 /**************************************************************************
5 *
6 * Copyright 2009 VMware, Inc.
7 * All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the
11 * "Software"), to deal in the Software without restriction, including
12 * without limitation the rights to use, copy, modify, merge, publish,
13 * distribute, sub license, and/or sell copies of the Software, and to
14 * permit persons to whom the Software is furnished to do so, subject to
15 * the following conditions:
16 *
17 * The above copyright notice and this permission notice (including the
18 * next paragraph) shall be included in all copies or substantial portions
19 * of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
24 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
25 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 *
29 **************************************************************************/
30 '''
31
32
33 import sys
34
35 from u_format_parse import *
36
37
38 layout_map = {
39 'arith': 'UTIL_FORMAT_LAYOUT_PLAIN',
40 'array': 'UTIL_FORMAT_LAYOUT_PLAIN',
41 'yuv': 'UTIL_FORMAT_LAYOUT_PLAIN',
42 'dxt': 'UTIL_FORMAT_LAYOUT_DXT',
43 }
44
45
46 def colorspace_map(colorspace):
47 return 'UTIL_FORMAT_COLORSPACE_' + str(colorspace).upper()
48
49
50 colorspace_channels_map = {
51 'rgb': 'rgba',
52 'rgba': 'rgba',
53 'zs': 'zs',
54 'yuv': ['y1', 'y2', 'u', 'v'],
55 'dxt': []
56 }
57
58
59 kind_map = {
60 VOID: "UTIL_FORMAT_TYPE_VOID",
61 UNSIGNED: "UTIL_FORMAT_TYPE_UNSIGNED",
62 SIGNED: "UTIL_FORMAT_TYPE_SIGNED",
63 FIXED: "UTIL_FORMAT_TYPE_FIXED",
64 FLOAT: "UTIL_FORMAT_TYPE_FLOAT",
65 }
66
67
68 def bool_map(value):
69 if value:
70 return "TRUE"
71 else:
72 return "FALSE"
73
74
75 swizzle_map = {
76 SWIZZLE_X: "UTIL_FORMAT_SWIZZLE_X",
77 SWIZZLE_Y: "UTIL_FORMAT_SWIZZLE_Y",
78 SWIZZLE_Z: "UTIL_FORMAT_SWIZZLE_Z",
79 SWIZZLE_W: "UTIL_FORMAT_SWIZZLE_W",
80 SWIZZLE_0: "UTIL_FORMAT_SWIZZLE_0",
81 SWIZZLE_1: "UTIL_FORMAT_SWIZZLE_1",
82 SWIZZLE_NONE: "UTIL_FORMAT_SWIZZLE_NONE",
83 }
84
85
86 def write_format_table(formats):
87 print '/* This file is autogenerated by u_format_table.py from u_format.csv. Do not edit directly. */'
88 print
89 # This will print the copyright message on the top of this file
90 print __doc__.strip()
91 print
92 print '#include "u_format.h"'
93 print
94 print 'const struct util_format_description'
95 print 'util_format_description_table[] = '
96 print "{"
97 print " {"
98 print " PIPE_FORMAT_NONE,"
99 print " \"PIPE_FORMAT_NONE\","
100 print " {0, 0, 0},"
101 print " 0,"
102 print " {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}},"
103 print " {0, 0, 0, 0},"
104 print " 0"
105 print " },"
106 for format in formats:
107 print " {"
108 print " %s," % (format.name,)
109 print " \"%s\"," % (format.name,)
110 print " {%u, %u, %u}, /* block */" % (format.block_width, format.block_height, format.block_size())
111 print " %s," % (layout_map[format.layout],)
112 print " {"
113 for i in range(4):
114 type = format.in_types[i]
115 if i < 3:
116 sep = ","
117 else:
118 sep = ""
119 print " {%s, %s, %u}%s /* %s */" % (kind_map[type.kind], bool_map(type.norm), type.size, sep, "xyzw"[i])
120 print " },"
121 print " {"
122 for i in range(4):
123 swizzle = format.out_swizzle[i]
124 if i < 3:
125 sep = ","
126 else:
127 sep = ""
128 try:
129 comment = layout_channels_map[format.layout][i]
130 except:
131 comment = 'ignored'
132 print " %s%s /* %s */" % (swizzle_map[swizzle], sep, comment)
133 print " },"
134 print " %s," % (colorspace_map(format.colorspace),)
135 print " },"
136 print "};"
137
138
139 def main():
140
141 formats = []
142 for arg in sys.argv[1:]:
143 formats.extend(parse(arg))
144 write_format_table(formats)
145
146
147 if __name__ == '__main__':
148 main()