Add implementation for libresoc_CreatePipelineCache().
[mesa.git] / src / libre-soc / vulkan / libresoc_extensions.py
1 COPYRIGHT = """\
2 /*
3 * Copyright 2017 Intel Corporation
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
15 * of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25 """
26
27 import copy
28 import re
29
30 def _bool_to_c_expr(b):
31 if b is True:
32 return 'true'
33 if b is False:
34 return 'false'
35 return b
36
37 class Extension:
38 def __init__(self, name, ext_version, enable):
39 self.name = name
40 self.ext_version = int(ext_version)
41 self.enable = _bool_to_c_expr(enable)
42
43 class ApiVersion:
44 def __init__(self, version, enable):
45 self.version = version
46 self.enable = _bool_to_c_expr(enable)
47
48 API_PATCH_VERSION = 102
49
50 # Supported API versions. Each one is the maximum patch version for the given
51 # version. Version come in increasing order and each version is available if
52 # it's provided "enable" condition is true and all previous versions are
53 # available.
54 API_VERSIONS = [
55 ApiVersion('1.0', True),
56
57 # FIXME: for now we only support 1.0. We maintain this support from anv just in case in
58 # the future we support more that one version supported.
59 # ApiVersion('1.1', <condition> ),
60 ]
61
62 MAX_API_VERSION = None # Computed later
63
64 EXTENSIONS = [
65 #FIXME: for now we don't support additional extensions beyond 1.0. Revisit later
66 ]
67
68 # Sort the extension list the way we expect: KHR, then EXT, then vendors
69 # alphabetically. For digits, read them as a whole number sort that.
70 # eg.: VK_KHR_8bit_storage < VK_KHR_16bit_storage < VK_EXT_acquire_xlib_display
71 def extension_order(ext):
72 order = []
73 for substring in re.split('(KHR|EXT|[0-9]+)', ext.name):
74 if substring == 'KHR':
75 order.append(1)
76 if substring == 'EXT':
77 order.append(2)
78 elif substring.isdigit():
79 order.append(int(substring))
80 else:
81 order.append(substring)
82 return order
83 for i in range(len(EXTENSIONS) - 1):
84 if extension_order(EXTENSIONS[i + 1]) < extension_order(EXTENSIONS[i]):
85 print(EXTENSIONS[i + 1].name + ' should come before ' + EXTENSIONS[i].name)
86 exit(1)
87
88 class VkVersion:
89 def __init__(self, string):
90 split = string.split('.')
91 self.major = int(split[0])
92 self.minor = int(split[1])
93 if len(split) > 2:
94 assert len(split) == 3
95 self.patch = int(split[2])
96 else:
97 self.patch = None
98
99 # Sanity check. The range bits are required by the definition of the
100 # VK_MAKE_VERSION macro
101 assert self.major < 1024 and self.minor < 1024
102 assert self.patch is None or self.patch < 4096
103 assert str(self) == string
104
105 def __str__(self):
106 ver_list = [str(self.major), str(self.minor)]
107 if self.patch is not None:
108 ver_list.append(str(self.patch))
109 return '.'.join(ver_list)
110
111 def c_vk_version(self):
112 patch = self.patch if self.patch is not None else 0
113 ver_list = [str(self.major), str(self.minor), str(patch)]
114 return 'VK_MAKE_VERSION(' + ', '.join(ver_list) + ')'
115
116 def __int_ver(self):
117 # This is just an expansion of VK_VERSION
118 patch = self.patch if self.patch is not None else 0
119 return (self.major << 22) | (self.minor << 12) | patch
120
121 def __gt__(self, other):
122 # If only one of them has a patch version, "ignore" it by making
123 # other's patch version match self.
124 if (self.patch is None) != (other.patch is None):
125 other = copy.copy(other)
126 other.patch = self.patch
127
128 return self.__int_ver() > other.__int_ver()
129
130
131
132 MAX_API_VERSION = VkVersion('0.0.0')
133 for version in API_VERSIONS:
134 version.version = VkVersion(version.version)
135 version.version.patch = API_PATCH_VERSION
136 assert version.version > MAX_API_VERSION
137 MAX_API_VERSION = version.version