3 * Copyright 2017 Intel Corporation
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:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
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.
30 def _bool_to_c_expr(b
):
38 def __init__(self
, name
, ext_version
, enable
):
40 self
.ext_version
= int(ext_version
)
41 self
.enable
= _bool_to_c_expr(enable
)
44 def __init__(self
, version
, enable
):
45 self
.version
= version
46 self
.enable
= _bool_to_c_expr(enable
)
48 API_PATCH_VERSION
= 102
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
55 ApiVersion('1.0', True),
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> ),
62 MAX_API_VERSION
= None # Computed later
65 #FIXME: for now we don't support additional extensions beyond 1.0. Revisit later
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
):
73 for substring
in re
.split('(KHR|EXT|[0-9]+)', ext
.name
):
74 if substring
== 'KHR':
76 if substring
== 'EXT':
78 elif substring
.isdigit():
79 order
.append(int(substring
))
81 order
.append(substring
)
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
)
89 def __init__(self
, string
):
90 split
= string
.split('.')
91 self
.major
= int(split
[0])
92 self
.minor
= int(split
[1])
94 assert len(split
) == 3
95 self
.patch
= int(split
[2])
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
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
)
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
) + ')'
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
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
128 return self
.__int
_ver
() > other
.__int
_ver
()
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