• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python3
2#
3# Copyright (c) 2017-2020 The Khronos Group Inc.
4#
5# SPDX-License-Identifier: Apache-2.0
6
7# Construct an HTML fragment indexing extension appendices in vkspec.html.
8# This is run only when publishing an update spec, to update the Vulkan
9# registry.
10
11import argparse,io,os,re,string,sys,copy
12import xml.etree.ElementTree as etree
13
14def listExts(vendor, ext, tag):
15    prefix = '    <li> <b> '
16    suffix = ' </b> </li>'
17
18    if vendor in tag:
19        desc = vendor + ' Extensions (' + tag[vendor] + ')'
20    else:
21        desc = vendor + ' Extensions (full vendor description unavailable)'
22    print(prefix, desc, suffix)
23
24    # (OLD) Links to the extension appendix in the single-page HTML document.
25    # This is very slow to load.
26    # fmtString = '    <li> <a href="specs/1.2-extensions/html/vkspec.html#{0}"> {0} </a> </li>'
27
28    # This links to the individual per-extension refpages, which are a
29    # slightly modified version of the extension appendices, and far faster
30    # to load.
31    fmtString = '    <li> <a href="specs/1.2-extensions/man/html/{0}.html"> {0} </a> </li>'
32
33    for name in sorted(ext[vendor]):
34        print(fmtString.format(name))
35
36# -extension name - may be a single extension name, a a space-separated list
37# of names, or a regular expression.
38if __name__ == '__main__':
39    parser = argparse.ArgumentParser()
40
41    parser.add_argument('-registry', action='store',
42                        default='vk.xml',
43                        help='Use specified registry file instead of vk.xml')
44    parser.add_argument('-quiet', action='store_true', default=False,
45                        help='Suppress script output during normal execution.')
46
47    args = parser.parse_args()
48
49    tree = etree.parse(args.registry)
50
51    # Dictionary of vendor tags -> author name mappings
52    tag = {}
53
54    # Loop over all vendor tags, tracking the full corresponding author name
55    for elem in tree.findall('tags/tag'):
56        vendor = elem.get('name')
57        author = elem.get('author')
58
59        tag[vendor] = author
60
61    # Dictionary of supported extensions, indexed by vendor prefix
62    ext = {}
63
64    # Loop over all extensions, add supported names to the dictionary
65    for elem in tree.findall('extensions/extension'):
66        name = elem.get('name')
67        supported = elem.get('supported')
68
69        if supported == 'vulkan':
70            # Relies on name being in the form VK_<vendor>_stuff
71            (vk, vendor) = name.split('_')[0:2]
72
73            if not vendor in ext:
74                ext[vendor] = []
75            ext[vendor].append(name)
76
77    # Emit HTML fragment indexing the extensions
78
79    print('<ul>')
80
81    for vendor in ['KHR', 'EXT']:
82        if vendor in ext:
83            listExts(vendor, ext, tag)
84            del ext[vendor]
85
86    for vendor in sorted(ext.keys()):
87        listExts(vendor, ext, tag)
88        del ext[vendor]
89
90    print('</ul>')
91