Mesa (master): zink/codegen: find promotion version using vulkan registry

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sun Jan 17 15:31:08 UTC 2021


Module: Mesa
Branch: master
Commit: c85902d60d4e21c12c5b0a22de4855fe4de2263d
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=c85902d60d4e21c12c5b0a22de4855fe4de2263d

Author: Hoe Hao Cheng <haochengho12907 at gmail.com>
Date:   Sat Jan 16 01:48:33 2021 +0800

zink/codegen: find promotion version using vulkan registry

Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8521>

---

 src/gallium/drivers/zink/meson.build      |  2 +-
 src/gallium/drivers/zink/zink_instance.py | 50 ++++++++++++++++++++++++++-----
 2 files changed, 44 insertions(+), 8 deletions(-)

diff --git a/src/gallium/drivers/zink/meson.build b/src/gallium/drivers/zink/meson.build
index f341ff9fbd9..293d2aacc7b 100644
--- a/src/gallium/drivers/zink/meson.build
+++ b/src/gallium/drivers/zink/meson.build
@@ -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')
   ]
 )
 
diff --git a/src/gallium/drivers/zink/zink_instance.py b/src/gallium/drivers/zink/zink_instance.py
index 4302c64db14..8758331a0be 100644
--- a/src/gallium/drivers/zink/zink_instance.py
+++ b/src/gallium/drivers/zink/zink_instance.py
@@ -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)



More information about the mesa-commit mailing list