+ ext = supported_exts[ext_name]
+ ext.type = extension.attrib['type']
+
+ for command in extension.findall('./require/command'):
+ e = entrypoints[command.attrib['name']]
+ e.enabled = True
+ assert e.core_version is None
+ e.extensions.append(ext)
+
+ return [e for e in entrypoints.values() if e.enabled]
+
+
+def get_entrypoints_defines(doc):
+ """Maps entry points to extension defines."""
+ entrypoints_to_defines = {}
+
+ platform_define = {}
+ for platform in doc.findall('./platforms/platform'):
+ name = platform.attrib['name']
+ define = platform.attrib['protect']
+ platform_define[name] = define
+
+ for extension in doc.findall('./extensions/extension[@platform]'):
+ platform = extension.attrib['platform']
+ define = platform_define[platform]
+
+ for entrypoint in extension.findall('./require/command'):
+ fullname = entrypoint.attrib['name']
+ entrypoints_to_defines[fullname] = define
+
+ return entrypoints_to_defines
+
+
+def main():
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--outdir', help='Where to write the files.',
+ required=True)
+ parser.add_argument('--xml',
+ help='Vulkan API XML file.',
+ required=True,
+ action='append',
+ dest='xml_files')
+ args = parser.parse_args()
+
+ entrypoints = []
+
+ for filename in args.xml_files:
+ doc = et.parse(filename)
+ entrypoints += get_entrypoints(doc, get_entrypoints_defines(doc))
+
+ # Manually add CreateDmaBufImageINTEL for which we don't have an extension
+ # defined.
+ entrypoints.append(Entrypoint('vkCreateDmaBufImageINTEL', 'VkResult', [
+ EntrypointParam('VkDevice', 'device', 'VkDevice device'),
+ EntrypointParam('VkDmaBufImageCreateInfo', 'pCreateInfo',
+ 'const VkDmaBufImageCreateInfo* pCreateInfo'),
+ EntrypointParam('VkAllocationCallbacks', 'pAllocator',
+ 'const VkAllocationCallbacks* pAllocator'),
+ EntrypointParam('VkDeviceMemory', 'pMem', 'VkDeviceMemory* pMem'),
+ EntrypointParam('VkImage', 'pImage', 'VkImage* pImage')
+ ]))
+
+ device_entrypoints = []
+ instance_entrypoints = []
+ for e in entrypoints:
+ if e.is_device_entrypoint():
+ device_entrypoints.append(e)
+ else:
+ instance_entrypoints.append(e)
+
+ device_strmap = StringIntMap()
+ for num, e in enumerate(device_entrypoints):
+ device_strmap.add_string(e.name, num)
+ e.num = num
+ device_strmap.bake()
+
+ instance_strmap = StringIntMap()
+ for num, e in enumerate(instance_entrypoints):
+ instance_strmap.add_string(e.name, num)
+ e.num = num
+ instance_strmap.bake()
+
+ # For outputting entrypoints.h we generate a anv_EntryPoint() prototype
+ # per entry point.
+ try:
+ with open(os.path.join(args.outdir, 'anv_entrypoints.h'), 'wb') as f:
+ f.write(TEMPLATE_H.render(instance_entrypoints=instance_entrypoints,
+ device_entrypoints=device_entrypoints,
+ LAYERS=LAYERS,
+ filename=os.path.basename(__file__)))
+ with open(os.path.join(args.outdir, 'anv_entrypoints.c'), 'wb') as f:
+ f.write(TEMPLATE_C.render(instance_entrypoints=instance_entrypoints,
+ device_entrypoints=device_entrypoints,
+ LAYERS=LAYERS,
+ instance_strmap=instance_strmap,
+ device_strmap=device_strmap,
+ filename=os.path.basename(__file__)))
+ except Exception:
+ # In the event there's an error, this imports some helpers from mako
+ # to print a useful stack trace and prints it, then exits with
+ # status 1, if python is run with debug; otherwise it just raises
+ # the exception
+ if __debug__:
+ import sys
+ from mako import exceptions
+ sys.stderr.write(exceptions.text_error_template().render() + '\n')
+ sys.exit(1)
+ raise
+
+
+if __name__ == '__main__':
+ main()