[Mesa-dev] [PATCH 2/5] anv: Add MAX_API_VERSION to anv_extensions.py

Jason Ekstrand jason at jlekstrand.net
Tue Aug 1 18:54:04 UTC 2017


The VkVersion class is probably overkill but it makes it really easy to
compare versions in a way that's safe without the caller having to think
about patch vs. no patch.
---
 src/intel/vulkan/anv_entrypoints_gen.py |  4 +--
 src/intel/vulkan/anv_extensions.py      | 43 +++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 3 deletions(-)

diff --git a/src/intel/vulkan/anv_entrypoints_gen.py b/src/intel/vulkan/anv_entrypoints_gen.py
index 9177a94..f5c527e 100644
--- a/src/intel/vulkan/anv_entrypoints_gen.py
+++ b/src/intel/vulkan/anv_entrypoints_gen.py
@@ -32,8 +32,6 @@ from mako.template import Template
 
 from anv_extensions import *
 
-MAX_API_VERSION = 1.0
-
 # We generate a static hash table for entry point lookup
 # (vkGetProcAddress). We use a linear congruential generator for our hash
 # function and a power-of-two size table. The prime numbers are determined
@@ -262,7 +260,7 @@ def get_entrypoints(doc, entrypoints_to_defines):
     enabled_commands = set()
     for feature in doc.findall('./feature'):
         assert feature.attrib['api'] == 'vulkan'
-        if float(feature.attrib['number']) > MAX_API_VERSION:
+        if VkVersion(feature.attrib['number']) > MAX_API_VERSION:
             continue
 
         for command in feature.findall('./require/command'):
diff --git a/src/intel/vulkan/anv_extensions.py b/src/intel/vulkan/anv_extensions.py
index 0d243c6..7307cac 100644
--- a/src/intel/vulkan/anv_extensions.py
+++ b/src/intel/vulkan/anv_extensions.py
@@ -25,10 +25,14 @@ COPYRIGHT = """\
 """
 
 import argparse
+import copy
+import re
 import xml.etree.cElementTree as et
 
 from mako.template import Template
 
+MAX_API_VERSION = '1.0.54'
+
 class Extension:
     def __init__(self, name, ext_version, enable):
         self.name = name
@@ -64,6 +68,45 @@ EXTENSIONS = [
     Extension('VK_KHX_multiview',                         1, True),
 ]
 
+class VkVersion:
+    def __init__(self, string):
+        split = string.split('.')
+        self.major = int(split[0])
+        self.minor = int(split[1])
+        if len(split) > 2:
+            assert len(split) == 3
+            self.patch = int(split[2])
+        else:
+            self.patch = None
+
+        # Sanity check.  The range bits are required by the definition of the
+        # VK_MAKE_VERSION macro
+        assert self.major < 1024 and self.minor < 1024
+        assert self.patch is None or self.patch < 4096
+        assert(str(self) == string)
+
+    def __str__(self):
+        ver_list = [str(self.major), str(self.minor)]
+        if self.patch is not None:
+            ver_list.append(str(self.patch))
+        return '.'.join(ver_list)
+
+    def __int_ver(self):
+        # This is just an expansion of VK_VERSION
+        patch = self.patch if self.patch is not None else 0
+        return (self.major << 22) | (self.minor << 12) | patch
+
+    def __cmp__(self, other):
+        # If only one of them has a patch version, "ignore" it by making
+        # other's patch version match self.
+        if (self.patch is None) != (other.patch is None):
+            other = copy.copy(other)
+            other.patch = self.patch
+
+        return self.__int_ver().__cmp__(other.__int_ver())
+
+MAX_API_VERSION = VkVersion(MAX_API_VERSION)
+
 def _init_exts_from_xml(xml):
     """ Walk the Vulkan XML and fill out extra extension information. """
 
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list