zink/codegen: find promotion version using vulkan registry

Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8521>
This commit is contained in:
Hoe Hao Cheng 2021-01-16 01:48:33 +08:00 committed by Marge Bot
parent 833b6ab443
commit c85902d60d
2 changed files with 44 additions and 8 deletions

View File

@ -55,7 +55,7 @@ zink_instance = custom_target(
input : ['zink_instance.py'],
output : ['zink_instance.h', 'zink_instance.c'],
command : [
prog_python, '@INPUT@', '@OUTPUT@'
prog_python, '@INPUT@', '@OUTPUT@', join_paths(meson.source_root(), 'src/vulkan/registry/vk.xml')
]
)

View File

@ -25,6 +25,7 @@
from mako.template import Template
from os import path
from xml.etree import ElementTree
from zink_extensions import Extension,Layer,Version
import sys
@ -41,16 +42,12 @@ import sys
# will be added by the codegen accordingly.
EXTENSIONS = [
Extension("VK_EXT_debug_utils"),
Extension("VK_KHR_maintenance2",
core_since=Version((1, 1, 0))),
Extension("VK_KHR_maintenance2"),
Extension("VK_KHR_get_physical_device_properties2",
core_since=Version((1, 1, 0)),
functions=["GetPhysicalDeviceFeatures2", "GetPhysicalDeviceProperties2"]),
Extension("VK_KHR_draw_indirect_count",
core_since=Version((1, 2, 0)),
functions=["CmdDrawIndexedIndirectCount", "CmdDrawIndirectCount"]),
Extension("VK_KHR_external_memory_capabilities",
core_since=Version((1, 1, 0))),
Extension("VK_KHR_external_memory_capabilities"),
Extension("VK_MVK_moltenvk"),
]
@ -277,21 +274,60 @@ def replace_code(code: str, replacement: dict):
return code
# Parses e.g. "VK_VERSION_x_y" to integer tuple (x, y)
# For any erroneous inputs, None is returned
def parse_promotedto(promotedto: str):
result = None
if promotedto and promotedto.startswith("VK_VERSION_"):
(major, minor) = promotedto.split('_')[-2:]
result = (int(major), int(minor))
return result
def parse_vkxml(path: str):
vkxml = ElementTree.parse(path)
all_extensions = dict()
for ext in vkxml.findall("extensions/extension"):
name = ext.get("name")
promotedto = parse_promotedto(ext.get("promotedto"))
if not name:
print("found malformed extension entry in vk.xml")
exit(1)
all_extensions[name] = promotedto
return all_extensions
if __name__ == "__main__":
try:
header_path = sys.argv[1]
impl_path = sys.argv[2]
vkxml_path = sys.argv[3]
header_path = path.abspath(header_path)
impl_path = path.abspath(impl_path)
vkxml_path = path.abspath(vkxml_path)
except:
print("usage: %s <path to .h> <path to .c>" % sys.argv[0])
print("usage: %s <path to .h> <path to .c> <path to vk.xml>" % sys.argv[0])
exit(1)
all_extensions = parse_vkxml(vkxml_path)
extensions = EXTENSIONS
layers = LAYERS
replacement = REPLACEMENTS
for ext in extensions:
if ext.name not in all_extensions:
print("the extension {} is not registered in vk.xml - a typo?".format(ext.name))
exit(1)
if all_extensions[ext.name] is not None:
ext.core_since = Version((*all_extensions[ext.name], 0))
with open(header_path, "w") as header_file:
header = Template(header_code).render(extensions=extensions, layers=layers).strip()
header = replace_code(header, replacement)