3 /**************************************************************************
5 * Copyright 2010 VMware, Inc.
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:
16 * The above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial portions
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.
28 **************************************************************************/
34 from vk_format_parse
import *
36 def layout_map(layout
):
37 return 'VK_FORMAT_LAYOUT_' + str(layout
).upper()
40 def colorspace_map(colorspace
):
41 return 'VK_FORMAT_COLORSPACE_' + str(colorspace
).upper()
44 colorspace_channels_map
= {
45 'rgb': ['r', 'g', 'b', 'a'],
46 'srgb': ['sr', 'sg', 'sb', 'a'],
48 'yuv': ['y', 'u', 'v'],
53 VOID
: "VK_FORMAT_TYPE_VOID",
54 UNSIGNED
: "VK_FORMAT_TYPE_UNSIGNED",
55 SIGNED
: "VK_FORMAT_TYPE_SIGNED",
56 FIXED
: "VK_FORMAT_TYPE_FIXED",
57 FLOAT
: "VK_FORMAT_TYPE_FLOAT",
69 SWIZZLE_X
: "VK_SWIZZLE_X",
70 SWIZZLE_Y
: "VK_SWIZZLE_Y",
71 SWIZZLE_Z
: "VK_SWIZZLE_Z",
72 SWIZZLE_W
: "VK_SWIZZLE_W",
73 SWIZZLE_0
: "VK_SWIZZLE_0",
74 SWIZZLE_1
: "VK_SWIZZLE_1",
75 SWIZZLE_NONE
: "VK_SWIZZLE_NONE",
78 def print_channels(format
, func
):
79 if format
.nr_channels() <= 1:
80 func(format
.le_channels
, format
.le_swizzles
)
82 print '#ifdef PIPE_ARCH_BIG_ENDIAN'
83 func(format
.be_channels
, format
.be_swizzles
)
85 func(format
.le_channels
, format
.le_swizzles
)
88 def write_format_table(formats
):
89 print '/* This file is autogenerated by u_format_table.py from u_format.csv. Do not edit directly. */'
91 # This will print the copyright message on the top of this file
92 print CopyRight
.strip()
94 print '#include "stdbool.h"'
95 print '#include "vk_format.h"'
98 def do_channel_array(channels
, swizzles
):
101 channel
= channels
[i
]
107 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
)
109 print " {0, 0, 0, 0, 0}%s" % (sep
,)
112 def do_swizzle_array(channels
, swizzles
):
115 swizzle
= swizzles
[i
]
121 comment
= colorspace_channels_map
[format
.colorspace
][i
]
122 except (KeyError, IndexError):
124 print " %s%s\t/* %s */" % (swizzle_map
[swizzle
], sep
, comment
)
127 for format
in formats
:
128 print 'const struct vk_format_description'
129 print 'vk_format_%s_description = {' % (format
.short_name(),)
130 print " %s," % (format
.name
,)
131 print " \"%s\"," % (format
.name
,)
132 print " \"%s\"," % (format
.short_name(),)
133 print " {%u, %u, %u},\t/* block */" % (format
.block_width
, format
.block_height
, format
.block_size())
134 print " %s," % (layout_map(format
.layout
),)
135 print " %u,\t/* nr_channels */" % (format
.nr_channels(),)
136 print " %s,\t/* is_array */" % (bool_map(format
.is_array()),)
137 print " %s,\t/* is_bitmask */" % (bool_map(format
.is_bitmask()),)
138 print " %s,\t/* is_mixed */" % (bool_map(format
.is_mixed()),)
139 print_channels(format
, do_channel_array
)
140 print_channels(format
, do_swizzle_array
)
141 print " %s," % (colorspace_map(format
.colorspace
),)
145 print "const struct vk_format_description *"
146 print "vk_format_description(VkFormat format)"
148 print " if (format > VK_FORMAT_END_RANGE) {"
149 print " return NULL;"
152 print " switch (format) {"
153 for format
in formats
:
154 print " case %s:" % format
.name
155 print " return &vk_format_%s_description;" % (format
.short_name(),)
157 print " return NULL;"
166 for arg
in sys
.argv
[1:]:
167 formats
.extend(parse(arg
))
168 write_format_table(formats
)
171 if __name__
== '__main__':