At this commit driver skeleton is able to dump spirv and nir
[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 ApiVersion('1.1', False),
57
58 ]
59
60 MAX_API_VERSION = None # Computed later
61
62 EXTENSIONS = [
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),
78
79 ]
80
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):
85 order = []
86 for substring in re.split('(KHR|EXT|[0-9]+)', ext.name):
87 if substring == 'KHR':
88 order.append(1)
89 if substring == 'EXT':
90 order.append(2)
91 elif substring.isdigit():
92 order.append(int(substring))
93 else:
94 order.append(substring)
95 return order
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)
99 exit(1)
100
101 class VkVersion:
102 def __init__(self, string):
103 split = string.split('.')
104 self.major = int(split[0])
105 self.minor = int(split[1])
106 if len(split) > 2:
107 assert len(split) == 3
108 self.patch = int(split[2])
109 else:
110 self.patch = None
111
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
117
118 def __str__(self):
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)
123
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) + ')'
128
129 def __int_ver(self):
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
133
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
140
141 return self.__int_ver() > other.__int_ver()
142
143
144
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