vulkan: enum generator: generate extension number defines
New extensions can introduce additional enums. Most of the new enums will have disjoint numbers from the initial enums. For example new formats introduced by VK_IMG_format_pvrtc : VK_FORMAT_ASTC_10x8_UNORM_BLOCK = 177, VK_FORMAT_ASTC_10x8_SRGB_BLOCK = 178, VK_FORMAT_ASTC_10x10_UNORM_BLOCK = 179, VK_FORMAT_ASTC_10x10_SRGB_BLOCK = 180, VK_FORMAT_ASTC_12x10_UNORM_BLOCK = 181, VK_FORMAT_ASTC_12x10_SRGB_BLOCK = 182, VK_FORMAT_ASTC_12x12_UNORM_BLOCK = 183, VK_FORMAT_ASTC_12x12_SRGB_BLOCK = 184, VK_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG = 1000054000, VK_FORMAT_PVRTC1_4BPP_UNORM_BLOCK_IMG = 1000054001, VK_FORMAT_PVRTC2_2BPP_UNORM_BLOCK_IMG = 1000054002, VK_FORMAT_PVRTC2_4BPP_UNORM_BLOCK_IMG = 1000054003, VK_FORMAT_PVRTC1_2BPP_SRGB_BLOCK_IMG = 1000054004, VK_FORMAT_PVRTC1_4BPP_SRGB_BLOCK_IMG = 1000054005, VK_FORMAT_PVRTC2_2BPP_SRGB_BLOCK_IMG = 1000054006, VK_FORMAT_PVRTC2_4BPP_SRGB_BLOCK_IMG = 1000054007, It's obvious we can't have a single table for handling those anymore. Fortunately the enum values actually contain the number of the extension that introduced the new enums. So we can build an indirection table off the extension number and then index by subtracting the first enum of the the format enum value. This change makes the extension number available in the generated enum code. Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> Reviewed-by: Jason Ekstrand <jason@jlekstrand.net> Reviewed-by: Dylan Baker <dylan@pnwbakers.com>
This commit is contained in:
parent
7e90fc54e5
commit
0ee868c1f6
|
@ -101,6 +101,10 @@ H_TEMPLATE = Template(textwrap.dedent(u"""\
|
||||||
#include <vulkan/vulkan.h>
|
#include <vulkan/vulkan.h>
|
||||||
#include <vulkan/vk_android_native_buffer.h>
|
#include <vulkan/vk_android_native_buffer.h>
|
||||||
|
|
||||||
|
% for ext in extensions:
|
||||||
|
#define _${ext.name}_number (${ext.number})
|
||||||
|
% endfor
|
||||||
|
|
||||||
% for enum in enums:
|
% for enum in enums:
|
||||||
const char * vk_${enum.name[2:]}_to_str(${enum.name} input);
|
const char * vk_${enum.name[2:]}_to_str(${enum.name} input);
|
||||||
% endfor
|
% endfor
|
||||||
|
@ -130,6 +134,14 @@ class NamedFactory(object):
|
||||||
return n
|
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):
|
class VkEnum(object):
|
||||||
"""Simple struct-like class representing a single Vulkan Enum."""
|
"""Simple struct-like class representing a single Vulkan Enum."""
|
||||||
|
|
||||||
|
@ -138,8 +150,8 @@ class VkEnum(object):
|
||||||
self.values = values or []
|
self.values = values or []
|
||||||
|
|
||||||
|
|
||||||
def parse_xml(enum_factory, filename):
|
def parse_xml(enum_factory, ext_factory, filename):
|
||||||
"""Parse the XML file. Accumulate results into the efactory.
|
"""Parse the XML file. Accumulate results into the factories.
|
||||||
|
|
||||||
This parser is a memory efficient iterative XML parser that returns a list
|
This parser is a memory efficient iterative XML parser that returns a list
|
||||||
of VkEnum objects.
|
of VkEnum objects.
|
||||||
|
@ -160,6 +172,9 @@ def parse_xml(enum_factory, filename):
|
||||||
enum = enum_factory(elem.attrib['name'])
|
enum = enum_factory(elem.attrib['name'])
|
||||||
enum.values.extend([e.attrib['name'] for e in elem
|
enum.values.extend([e.attrib['name'] for e in elem
|
||||||
if e.tag == 'enum'])
|
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':
|
elif event == 'end' and elem.tag == 'extension':
|
||||||
if elem.attrib['supported'] != 'vulkan':
|
if elem.attrib['supported'] != 'vulkan':
|
||||||
continue
|
continue
|
||||||
|
@ -169,7 +184,6 @@ def parse_xml(enum_factory, filename):
|
||||||
|
|
||||||
root.clear()
|
root.clear()
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('--xml', required=True,
|
parser.add_argument('--xml', required=True,
|
||||||
|
@ -183,9 +197,11 @@ def main():
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
enum_factory = NamedFactory(VkEnum)
|
enum_factory = NamedFactory(VkEnum)
|
||||||
|
ext_factory = NamedFactory(VkExtension)
|
||||||
for filename in args.xml_files:
|
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)
|
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')),
|
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'))]:
|
(H_TEMPLATE, os.path.join(args.outdir, 'vk_enum_to_str.h'))]:
|
||||||
|
@ -193,6 +209,7 @@ def main():
|
||||||
f.write(template.render(
|
f.write(template.render(
|
||||||
file=os.path.basename(__file__),
|
file=os.path.basename(__file__),
|
||||||
enums=enums,
|
enums=enums,
|
||||||
|
extensions=extensions,
|
||||||
copyright=COPYRIGHT,
|
copyright=COPYRIGHT,
|
||||||
FOREIGN_ENUM_VALUES=FOREIGN_ENUM_VALUES))
|
FOREIGN_ENUM_VALUES=FOREIGN_ENUM_VALUES))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue