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),
56 ApiVersion('1.1', False),
60 MAX_API_VERSION
= None # Computed later
63 #Extension('VK_KHR_display', 23, 'VK_USE_PLATFORM_DISPLAY_KHR'),
64 #Extension('VK_KHR_external_memory', 1, True),
65 #TODO: enabling following extension creates compilation problem
66 #Extension('VK_KHR_external_memory_capabilities', 1, True),
67 #Extension('VK_KHR_external_memory_fd', 1, True),
68 Extension('VK_KHR_get_physical_device_properties2', 1, True),
69 #Extension('VK_KHR_get_surface_capabilities2', 1, 'LIBRESOC_HAS_SURFACE'),
70 Extension('VK_KHR_surface', 25, 'LIBRESOC_HAS_SURFACE'),
71 Extension('VK_KHR_swapchain', 68, 'LIBRESOC_HAS_SURFACE'),
72 # Extension('VK_KHR_wayland_surface', 6, 'VK_USE_PLATFORM_WAYLAND_KHR'),
73 Extension('VK_KHR_xcb_surface', 6, 'VK_USE_PLATFORM_XCB_KHR'),
74 Extension('VK_KHR_xlib_surface', 6, 'VK_USE_PLATFORM_XLIB_KHR'),
75 # Extension('VK_EXT_debug_report', 9, True),
76 # Extension('VK_EXT_external_memory_dma_buf', 1, True),
77 # Extension('VK_EXT_image_drm_format_modifier', 1, False),
81 # Sort the extension list the way we expect: KHR, then EXT, then vendors
82 # alphabetically. For digits, read them as a whole number sort that.
83 # eg.: VK_KHR_8bit_storage < VK_KHR_16bit_storage < VK_EXT_acquire_xlib_display
84 def extension_order(ext
):
86 for substring
in re
.split('(KHR|EXT|[0-9]+)', ext
.name
):
87 if substring
== 'KHR':
89 if substring
== 'EXT':
91 elif substring
.isdigit():
92 order
.append(int(substring
))
94 order
.append(substring
)
96 for i
in range(len(EXTENSIONS
) - 1):
97 if extension_order(EXTENSIONS
[i
+ 1]) < extension_order(EXTENSIONS
[i
]):
98 print(EXTENSIONS
[i
+ 1].name
+ ' should come before ' + EXTENSIONS
[i
].name
)
102 def __init__(self
, string
):
103 split
= string
.split('.')
104 self
.major
= int(split
[0])
105 self
.minor
= int(split
[1])
107 assert len(split
) == 3
108 self
.patch
= int(split
[2])
112 # Sanity check. The range bits are required by the definition of the
113 # VK_MAKE_VERSION macro
114 assert self
.major
< 1024 and self
.minor
< 1024
115 assert self
.patch
is None or self
.patch
< 4096
116 assert str(self
) == string
119 ver_list
= [str(self
.major
), str(self
.minor
)]
120 if self
.patch
is not None:
121 ver_list
.append(str(self
.patch
))
122 return '.'.join(ver_list
)
124 def c_vk_version(self
):
125 patch
= self
.patch
if self
.patch
is not None else 0
126 ver_list
= [str(self
.major
), str(self
.minor
), str(patch
)]
127 return 'VK_MAKE_VERSION(' + ', '.join(ver_list
) + ')'
130 # This is just an expansion of VK_VERSION
131 patch
= self
.patch
if self
.patch
is not None else 0
132 return (self
.major
<< 22) |
(self
.minor
<< 12) | patch
134 def __gt__(self
, other
):
135 # If only one of them has a patch version, "ignore" it by making
136 # other's patch version match self.
137 if (self
.patch
is None) != (other
.patch
is None):
138 other
= copy
.copy(other
)
139 other
.patch
= self
.patch
141 return self
.__int
_ver
() > other
.__int
_ver
()
145 MAX_API_VERSION
= VkVersion('0.0.0')
146 for version
in API_VERSIONS
:
147 version
.version
= VkVersion(version
.version
)
148 version
.version
.patch
= API_PATCH_VERSION
149 assert version
.version
> MAX_API_VERSION
150 MAX_API_VERSION
= version
.version