Mesa (master): anv: Make anv_icd.py more generic and independent

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Feb 4 20:15:26 UTC 2021


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

Author: Jason Ekstrand <jason.ekstrand at intel.com>
Date:   Sat Jan 30 09:57:27 2021 -0600

anv: Make anv_icd.py more generic and independent

Instead of depending on anv_extensions.py, fetch the patch version from
the XML ourselves.  This way it can be moved to common code and used by
other ICDs going forward.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
Reviewed-by: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>
Tested-by: Tapani Pälli <tapani.palli at intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8792>

---

 src/intel/vulkan/anv_icd.py  | 52 ++++++++++++++++++++++++++++++++++----------
 src/intel/vulkan/meson.build |  9 ++++----
 2 files changed, 46 insertions(+), 15 deletions(-)

diff --git a/src/intel/vulkan/anv_icd.py b/src/intel/vulkan/anv_icd.py
index 70e8c7af75b..d5401e80156 100644
--- a/src/intel/vulkan/anv_icd.py
+++ b/src/intel/vulkan/anv_icd.py
@@ -20,29 +20,59 @@
 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
+import argparse
 import json
 import os.path
-import argparse
+import re
+import xml.etree.ElementTree as et
+
+def get_xml_patch_version(xml_file):
+    xml = et.parse(xml_file)
+    for d in xml.findall('.types/type'):
+        if d.get('category', None) != 'define':
+            continue
 
-from anv_extensions import MAX_API_VERSION
+        name = d.find('.name')
+        if name.text != 'VK_HEADER_VERSION':
+            continue;
+
+        return name.tail.strip()
 
 if __name__ == '__main__':
     parser = argparse.ArgumentParser()
-    parser.add_argument('--out', help='Output json file.', required=True)
-    parser.add_argument('--lib-path', help='Path to libvulkan_intel.so')
+    parser.add_argument('--api-version', required=True,
+                        help='Vulkan API version.')
+    parser.add_argument('--xml', required=False,
+                        help='Vulkan registry XML for patch version')
+    parser.add_argument('--lib-path', required=True,
+                        help='Path to installed library')
+    parser.add_argument('--out', required=False,
+                        help='Output json file.')
     args = parser.parse_args()
 
-    path = 'libvulkan_intel.so'
-    if args.lib_path:
-        path = os.path.join(args.lib_path, path)
+    version = args.api_version
+    if args.xml:
+        re.match(r'\d+\.\d+', version)
+        version = version + '.' + get_xml_patch_version(args.xml)
+    else:
+        re.match(r'\d+\.\d+\.\d+', version)
 
     json_data = {
         'file_format_version': '1.0.0',
         'ICD': {
-            'library_path': path,
-            'api_version': str(MAX_API_VERSION),
+            'library_path': args.lib_path,
+            'api_version': version,
         },
     }
 
-    with open(args.out, 'w') as f:
-        json.dump(json_data, f, indent=4, sort_keys=True, separators=(',', ': '))
+    json_params = {
+        'indent': 4,
+        'sort_keys': True,
+        'separators': (',', ': '),
+    }
+
+    if args.out:
+        with open(args.out, 'w') as f:
+            json.dump(json_data, f, **json_params)
+    else:
+        print(json.dumps(json_data, **json_params))
diff --git a/src/intel/vulkan/meson.build b/src/intel/vulkan/meson.build
index 4c0e132c45f..686438064e3 100644
--- a/src/intel/vulkan/meson.build
+++ b/src/intel/vulkan/meson.build
@@ -58,14 +58,15 @@ anv_extensions_h = custom_target(
 
 intel_icd = custom_target(
   'intel_icd',
-  input : 'anv_icd.py',
+  input : ['anv_icd.py', vk_api_xml],
   output : 'intel_icd. at 0@.json'.format(host_machine.cpu()),
   command : [
-    prog_python, '@INPUT@',
-    '--lib-path', join_paths(get_option('prefix'), get_option('libdir')),
+    prog_python, '@INPUT0@',
+    '--api-version', '1.2', '--xml', '@INPUT1@',
+    '--lib-path', join_paths(get_option('prefix'), get_option('libdir'),
+                             'libvulkan_intel.so'),
     '--out', '@OUTPUT@',
   ],
-  depend_files : anv_extensions_py,
   build_by_default : true,
   install_dir : with_vulkan_icd_dir,
   install : true,



More information about the mesa-commit mailing list