Commit 7fb86fb5 authored by Jason Ekstrand's avatar Jason Ekstrand

vulkan/enum_to_str: Add support for aliases and new Vulkan versions

Reviewed-by: Samuel Iglesias Gonsálvez's avatarSamuel Iglesias Gonsálvez <>
parent 539a0aec
...@@ -152,28 +152,38 @@ class VkEnum(object): ...@@ -152,28 +152,38 @@ class VkEnum(object): = name = name
# Maps numbers to names # Maps numbers to names
self.values = values or dict() self.values = values or dict()
self.name_to_value = dict()
def add_value(self, name, value=None, def add_value(self, name, value=None,
extension=None, offset=None, extnum=None, offset=None,
error=False): error=False):
assert value is not None or extension is not None assert value is not None or extnum is not None
if value is None: if value is None:
value = 1000000000 + (extension.number - 1) * 1000 + offset value = 1000000000 + (extnum - 1) * 1000 + offset
if error: if error:
value = -value value = -value
self.name_to_value[name] = value
if value not in self.values: if value not in self.values:
self.values[value] = name self.values[value] = name
elif len(self.values[value]) > len(name):
self.values[value] = name
def add_value_from_xml(self, elem, extension=None): def add_value_from_xml(self, elem, extension=None):
if 'value' in elem.attrib: if 'value' in elem.attrib:
self.add_value(elem.attrib['name'], self.add_value(elem.attrib['name'],
value=int(elem.attrib['value'])) value=int(elem.attrib['value']))
elif 'alias' in elem.attrib:
else: else:
error = 'dir' in elem.attrib and elem.attrib['dir'] == '-' error = 'dir' in elem.attrib and elem.attrib['dir'] == '-'
print(elem.attrib['name']) if 'extnumber' in elem.attrib:
extnum = int(elem.attrib['extnumber'])
extnum = extension.number
self.add_value(elem.attrib['name'], self.add_value(elem.attrib['name'],
extension=extension, extnum=extnum,
offset=int(elem.attrib['offset']), offset=int(elem.attrib['offset']),
error=error) error=error)
...@@ -192,6 +202,11 @@ def parse_xml(enum_factory, ext_factory, filename): ...@@ -192,6 +202,11 @@ def parse_xml(enum_factory, ext_factory, filename):
for value in enum_type.findall('./enum'): for value in enum_type.findall('./enum'):
enum.add_value_from_xml(value) enum.add_value_from_xml(value)
for value in xml.findall('./feature/require/enum[@extends]'):
enum = enum_factory.get(value.attrib['extends'])
if enum is not None:
for ext_elem in xml.findall('./extensions/extension[@supported="vulkan"]'): for ext_elem in xml.findall('./extensions/extension[@supported="vulkan"]'):
extension = ext_factory(ext_elem.attrib['name'], extension = ext_factory(ext_elem.attrib['name'],
number=int(ext_elem.attrib['number'])) number=int(ext_elem.attrib['number']))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment