4 /**************************************************************************
6 * Copyright 2010 VMware, Inc.
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:
17 * The above copyright notice and this permission notice (including the
18 * next paragraph) shall be included in all copies or substantial portions
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.
29 **************************************************************************/
35 from vk_format_parse
import *
37 def layout_map(layout
):
38 return 'VK_FORMAT_LAYOUT_' + str(layout
).upper()
41 def colorspace_map(colorspace
):
42 return 'VK_FORMAT_COLORSPACE_' + str(colorspace
).upper()
45 colorspace_channels_map
= {
46 'rgb': ['r', 'g', 'b', 'a'],
47 'srgb': ['sr', 'sg', 'sb', 'a'],
49 'yuv': ['y', 'u', 'v'],
54 VOID
: "VK_FORMAT_TYPE_VOID",
55 UNSIGNED
: "VK_FORMAT_TYPE_UNSIGNED",
56 SIGNED
: "VK_FORMAT_TYPE_SIGNED",
57 FIXED
: "VK_FORMAT_TYPE_FIXED",
58 FLOAT
: "VK_FORMAT_TYPE_FLOAT",
70 SWIZZLE_X
: "VK_SWIZZLE_X",
71 SWIZZLE_Y
: "VK_SWIZZLE_Y",
72 SWIZZLE_Z
: "VK_SWIZZLE_Z",
73 SWIZZLE_W
: "VK_SWIZZLE_W",
74 SWIZZLE_0
: "VK_SWIZZLE_0",
75 SWIZZLE_1
: "VK_SWIZZLE_1",
76 SWIZZLE_NONE
: "VK_SWIZZLE_NONE",
79 def print_channels(format
, func
):
80 if format
.nr_channels() <= 1:
81 func(format
.le_channels
, format
.le_swizzles
)
83 print '#ifdef PIPE_ARCH_BIG_ENDIAN'
84 func(format
.be_channels
, format
.be_swizzles
)
86 func(format
.le_channels
, format
.le_swizzles
)
89 def write_format_table(formats
):
90 print '/* This file is autogenerated by u_format_table.py from u_format.csv. Do not edit directly. */'
92 # This will print the copyright message on the top of this file
93 print CopyRight
.strip()
95 print '#include "stdbool.h"'
96 print '#include "vk_format.h"'
99 def do_channel_array(channels
, swizzles
):
102 channel
= channels
[i
]
108 print " {%s, %s, %s, %s, %u, %u}%s\t/* %s = %s */" % (type_map
[channel
.type], bool_map(channel
.norm
), bool_map(channel
.pure
), bool_map(channel
.scaled
), channel
.size
, channel
.shift
, sep
, "xyzw"[i
], channel
.name
)
110 print " {0, 0, 0, 0, 0}%s" % (sep
,)
113 def do_swizzle_array(channels
, swizzles
):
116 swizzle
= swizzles
[i
]
122 comment
= colorspace_channels_map
[format
.colorspace
][i
]
123 except (KeyError, IndexError):
125 print " %s%s\t/* %s */" % (swizzle_map
[swizzle
], sep
, comment
)
128 for format
in formats
:
129 print 'const struct vk_format_description'
130 print 'vk_format_%s_description = {' % (format
.short_name(),)
131 print " %s," % (format
.name
,)
132 print " \"%s\"," % (format
.name
,)
133 print " \"%s\"," % (format
.short_name(),)
134 print " {%u, %u, %u},\t/* block */" % (format
.block_width
, format
.block_height
, format
.block_size())
135 print " %s," % (layout_map(format
.layout
),)
136 print " %u,\t/* nr_channels */" % (format
.nr_channels(),)
137 print " %s,\t/* is_array */" % (bool_map(format
.is_array()),)
138 print " %s,\t/* is_bitmask */" % (bool_map(format
.is_bitmask()),)
139 print " %s,\t/* is_mixed */" % (bool_map(format
.is_mixed()),)
140 print_channels(format
, do_channel_array
)
141 print_channels(format
, do_swizzle_array
)
142 print " %s," % (colorspace_map(format
.colorspace
),)
146 print "const struct vk_format_description *"
147 print "vk_format_description(VkFormat format)"
149 print " if (format > VK_FORMAT_END_RANGE) {"
150 print " return NULL;"
153 print " switch (format) {"
154 for format
in formats
:
155 print " case %s:" % format
.name
156 print " return &vk_format_%s_description;" % (format
.short_name(),)
158 print " return NULL;"
167 for arg
in sys
.argv
[1:]:
168 formats
.extend(parse(arg
))
169 write_format_table(formats
)
172 if __name__
== '__main__':