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 <lionel.g.landwerlin@intel.com>
This commit is contained in:
Jason Ekstrand 2017-08-01 11:09:50 -07:00
parent a25267654b
commit 7382d8a416
2 changed files with 44 additions and 3 deletions

View file

@ -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'):

View file

@ -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. """