#include <vulkan/vulkan.h>
#include <vulkan/vk_android_native_buffer.h>
+ % for ext in extensions:
+ #define _${ext.name}_number (${ext.number})
+ % endfor
+
% for enum in enums:
const char * vk_${enum.name[2:]}_to_str(${enum.name} input);
% endfor
return n
+class VkExtension(object):
+ """Simple struct-like class representing extensions"""
+
+ def __init__(self, name, number=None):
+ self.name = name
+ self.number = number
+
+
class VkEnum(object):
"""Simple struct-like class representing a single Vulkan Enum."""
self.values = values or []
-def parse_xml(enum_factory, filename):
- """Parse the XML file. Accumulate results into the efactory.
+def parse_xml(enum_factory, ext_factory, filename):
+ """Parse the XML file. Accumulate results into the factories.
This parser is a memory efficient iterative XML parser that returns a list
of VkEnum objects.
enum = enum_factory(elem.attrib['name'])
enum.values.extend([e.attrib['name'] for e in elem
if e.tag == 'enum'])
+ elif event == 'start' and elem.tag == 'extension':
+ ext_factory(elem.attrib['name'],
+ number=int(elem.attrib['number']))
elif event == 'end' and elem.tag == 'extension':
if elem.attrib['supported'] != 'vulkan':
continue
root.clear()
-
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--xml', required=True,
args = parser.parse_args()
enum_factory = NamedFactory(VkEnum)
+ ext_factory = NamedFactory(VkExtension)
for filename in args.xml_files:
- parse_xml(enum_factory, filename)
+ parse_xml(enum_factory, ext_factory, filename)
enums = sorted(enum_factory.registry.values(), key=lambda e: e.name)
+ extensions = sorted(ext_factory.registry.values(), key=lambda e: e.name)
for template, file_ in [(C_TEMPLATE, os.path.join(args.outdir, 'vk_enum_to_str.c')),
(H_TEMPLATE, os.path.join(args.outdir, 'vk_enum_to_str.h'))]:
f.write(template.render(
file=os.path.basename(__file__),
enums=enums,
+ extensions=extensions,
copyright=COPYRIGHT,
FOREIGN_ENUM_VALUES=FOREIGN_ENUM_VALUES))