Vulkan-Docs/scripts/make_ext_dependency.py
Jon Leech 194a7f4d0d Change log for September 8, 2019 Vulkan 1.1.122 spec update:
* Update release number to 122.

Internal Issues:

  * Add style guide language on not using standalone `+` signs (internal
    issue 736); not using leading whitespace for markup (internal issue
    747); and on keeping descriptions of a single API in a contiguous block
    of markup (internal issue 949), and apply them to the specification.
  * Add a glossary definition of "`constant integral expression`", pointing
    to the SPIR-V "`constant instruction`" definition (internal issue 1225).
  * Many minor edits to improve writing style consistency and capture
    additional style guidelines (internal issue 1553).
  * Clarify that <<fragops-depth-write, depth writes are not performed>> if
    there is no depth framebuffer attachment (internal issue 1771).
  * Allow implementations to use rectangular line style of interpolation for
    <<primsrast-lines-bresenham, wide Bresenham lines>>, though replicating
    attributes is still preferred. Clarify that code:FragCoord is not
    replicated (internal issue 1772).
  * Resolve a contradiction in valid usage statements for
    slink:VkImageCreateInfo and slink:VkImageStencilUsageCreateInfoEXT
    (internal issue 1773).
  * Add style guide discussion of markup for indented equations, and use
    markup workaround for asciidoctor 2 compatibility (internal issue 1793).
  * Deprecate the `<<VK_EXT_validation_flags>>` extension in `vk.xml` and
    the extension appendix (internal issue 1801).
  * Add a new checker script `scripts/xml_consistency.py`. This is not
    currently run as part of internal CI (internal merge request 3285).
  * Correct "`an`" -> "`a`" prepositions where needed (internal merge
    request 3334).
  * Clarify that the <<features-uniformBufferStandardLayout,
    pname:uniformBufferStandardLayout>> feature is only required when the
    extension defining it is supported (internal merge request 3341).
  * Bring scripts into closer sync with OpenXR, mainly through conversion of
    comments to docstrings where appropriate, and add gen-scripts-docs.sh
    (internal merge request 3324).
  * Correct pname:maxDrawMeshTasksCount to 2^16^-1 in the <<limits-required,
    Required Limits>> table (internal merge requests 3361).

New Extensions

  * `<<VK_IMG_format_pvrtc>>` (public issue 512).
2019-09-08 20:41:02 -07:00

255 lines
7.9 KiB
Python
Executable File

#!/usr/bin/env python3
#
# Copyright (c) 2017-2019 The Khronos Group Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Generate a mapping of extension name -> all required extension names for that extension.
This script generates a list of all extensions, and of just KHR
extensions, that are placed into a Bash script and/or Python script. This
script can then be sources or executed to set a variable (e.g. khrExts),
Frontend scripts such as 'makeAllExts' and 'makeKHR' use this information
to set the EXTENSIONS Makefile variable when building the spec.
Sample Usage:
python3 scripts/make_ext_dependency.py -outscript=temp.sh
source temp.sh
make EXTENSIONS="$khrExts" html
rm temp.sh
"""
import argparse
import errno
import xml.etree.ElementTree as etree
from pathlib import Path
from vkconventions import VulkanConventions as APIConventions
def enQuote(key):
return "'" + str(key) + "'"
def shList(names):
"""Return a sortable (list or set) of names as a string encoding
of a Bash or Python list, sorted on the names."""
s = ('"' +
' '.join(str(key) for key in sorted(names)) +
'"')
return s
def pyList(names):
s = ('[ ' +
', '.join(enQuote(key) for key in sorted(names)) +
' ]')
return s
class DiGraph:
"""A directed graph.
The implementation and API mimic that of networkx.DiGraph in networkx-1.11.
networkx implements graphs as nested dicts; it's dicts all the way down, no
lists.
Some major differences between this implementation and that of
networkx-1.11 are:
* This omits edge and node attribute data, because we never use them
yet they add additional code complexity.
* This returns iterator objects when possible instead of collection
objects, because it simplifies the implementation and should provide
better performance.
"""
def __init__(self):
self.__nodes = {}
def add_node(self, node):
if node not in self.__nodes:
self.__nodes[node] = DiGraphNode()
def add_edge(self, src, dest):
self.add_node(src)
self.add_node(dest)
self.__nodes[src].adj.add(dest)
def nodes(self):
"""Iterate over the nodes in the graph."""
return self.__nodes.keys()
def descendants(self, node):
"""
Iterate over the nodes reachable from the given start node, excluding
the start node itself. Each node in the graph is yielded at most once.
"""
# Implementation detail: Do a breadth-first traversal because it's
# easier than depth-first.
# All nodes seen during traversal.
seen = set()
# The stack of nodes that need visiting.
visit_me = []
# Bootstrap the traversal.
seen.add(node)
for x in self.__nodes[node].adj:
if x not in seen:
seen.add(x)
visit_me.append(x)
while visit_me:
x = visit_me.pop()
assert x in seen
yield x
for y in self.__nodes[x].adj:
if y not in seen:
seen.add(y)
visit_me.append(y)
class DiGraphNode:
def __init__(self):
# Set of adjacent of nodes.
self.adj = set()
def make_dir(fn):
outdir = Path(fn).parent
try:
outdir.mkdir(parents=True)
except OSError as e:
if e.errno != errno.EEXIST:
raise
# API conventions object
conventions = APIConventions()
# -extension name - may be a single extension name, a space-separated list
# of names, or a regular expression.
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-registry', action='store',
default=conventions.registry_path,
help='Use specified registry file instead of ' + conventions.registry_path)
parser.add_argument('-outscript', action='store',
default=None,
help='Shell script to create')
parser.add_argument('-outpy', action='store',
default=None,
help='Python script to create')
parser.add_argument('-test', action='store',
default=None,
help='Specify extension to find dependencies of')
parser.add_argument('-quiet', action='store_true', default=False,
help='Suppress script output during normal execution.')
args = parser.parse_args()
tree = etree.parse(args.registry)
# Loop over all supported extensions, creating a digraph of the
# extension dependencies in the 'requires' attribute, which is a
# comma-separated list of extension names. Also track lists of
# all extensions and all KHR extensions.
allExts = set()
khrExts = set()
g = DiGraph()
for elem in tree.findall('extensions/extension'):
name = elem.get('name')
supported = elem.get('supported')
if supported == conventions.xml_api_name:
allExts.add(name)
if 'KHR' in name:
khrExts.add(name)
deps = elem.get('requires')
if deps:
deps = deps.split(',')
for dep in deps:
g.add_edge(name, dep)
else:
g.add_node(name)
else:
# Skip unsupported extensions
pass
if args.outscript:
make_dir(args.outscript)
fp = open(args.outscript, 'w', encoding='utf-8')
print('#!/bin/bash', file=fp)
print('# Generated from make_ext_dependency.py', file=fp)
print('# Specify maps of all extensions required by an enabled extension', file=fp)
print('', file=fp)
print('declare -A extensions', file=fp)
# When printing lists of extensions, sort them so that the output script
# remains as stable as possible as extensions are added to the API XML.
for ext in sorted(g.nodes()):
children = list(g.descendants(ext))
# Only emit an ifdef block if an extension has dependencies
if children:
print('extensions[' + ext + ']=' + shList(children), file=fp)
print('', file=fp)
print('# Define lists of all extensions and KHR extensions', file=fp)
print('allExts=' + shList(allExts), file=fp)
print('khrExts=' + shList(khrExts), file=fp)
fp.close()
if args.outpy:
make_dir(args.outpy)
fp = open(args.outpy, 'w', encoding='utf-8')
print('#!/usr/bin/env python', file=fp)
print('# Generated from make_ext_dependency.py', file=fp)
print('# Specify maps of all extensions required by an enabled extension', file=fp)
print('', file=fp)
print('extensions = {}', file=fp)
# When printing lists of extensions, sort them so that the output script
# remains as stable as possible as extensions are added to the API XML.
for ext in sorted(g.nodes()):
children = list(g.descendants(ext))
# Only emit an ifdef block if an extension has dependencies
if children:
print("extensions['" + ext + "'] = " +
pyList(children), file=fp)
print('', file=fp)
print('# Define lists of all extensions and KHR extensions', file=fp)
print('allExts = ' + pyList(allExts), file=fp)
print('khrExts = ' + pyList(khrExts), file=fp)
fp.close()