From: Jason Ekstrand Date: Tue, 1 Aug 2017 18:09:50 +0000 (-0700) Subject: anv: Add MAX_API_VERSION to anv_extensions.py X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=7382d8a41684e6f7cd7a558469fcd2724c844982;p=mesa.git anv: Add MAX_API_VERSION to anv_extensions.py 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. Reviewed-by: Lionel Landwerlin --- diff --git a/src/intel/vulkan/anv_entrypoints_gen.py b/src/intel/vulkan/anv_entrypoints_gen.py index 9177a94cb98..f5c527ed92c 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 0d243c6f138..7307cacbcac 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. """