| 1 |
#!/usr/bin/env python3 |
| 2 |
|
| 3 |
import argparse |
| 4 |
import base64 |
| 5 |
import pathlib |
| 6 |
import requests |
| 7 |
import subprocess |
| 8 |
import typing |
| 9 |
|
| 10 |
|
| 11 |
def error(msg: str) -> None: |
| 12 |
print('\033[31m' + msg + '\033[0m') |
| 13 |
|
| 14 |
|
| 15 |
class Source: |
| 16 |
def __init__(self, filename: str, url: typing.Optional[str], |
| 17 |
template: typing.Optional[str] = None, remove: |
| 18 |
typing.Optional[str] = None): |
| 19 |
self.file = pathlib.Path(filename) |
| 20 |
self.url = url |
| 21 |
self.template = template |
| 22 |
self.remove = remove |
| 23 |
|
| 24 |
def sync(self) -> None: |
| 25 |
if self.url is None: |
| 26 |
return |
| 27 |
|
| 28 |
print('Syncing {}...'.format(self.file), end=' ', flush=True) |
| 29 |
req = requests.get(self.url) |
| 30 |
|
| 31 |
if not req.ok: |
| 32 |
error('Failed to retrieve file: {} {}'.format(req.status_code, req.reason)) |
| 33 |
return |
| 34 |
|
| 35 |
# Gitiles returns base64-encoded strings. |
| 36 |
# Google has been resisting for years to the idea of allowing plain text: https://github.com/google/gitiles/issues/7 |
| 37 |
if 'format=TEXT' in self.url: |
| 38 |
content = base64.b64decode(req.content) |
| 39 |
else: |
| 40 |
content = req.content |
| 41 |
|
| 42 |
content = str(content, encoding='utf-8') |
| 43 |
if self.remove is not None: |
| 44 |
content = content.replace(self.remove, '') |
| 45 |
if self.template is not None: |
| 46 |
content = self.template % content |
| 47 |
|
| 48 |
with open(self.file, 'w') as f: |
| 49 |
f.write(content) |
| 50 |
|
| 51 |
print('Done') |
| 52 |
|
| 53 |
|
| 54 |
VK_ANDROID_NATIVE_BUFFER_TEMPLATE = """\ |
| 55 |
/* |
| 56 |
* MESA: buffer_handle_t is defined by all Mesa builds, even if |
| 57 |
* one is building for a non-Android target. This avoids unnecessary |
| 58 |
* conditionals in driver code. |
| 59 |
* |
| 60 |
* We don't need to define buffer_handle_t locally when (__ANDROID__) |
| 61 |
* or ANDROID are set. Here's the distinction between the two: |
| 62 |
* |
| 63 |
* - AOSP always defines ANDROID, since it just means one is using the |
| 64 |
* AOSP tree. It means the build environment is Android, roughly. |
| 65 |
* - __ANDROID__ is defined by the toolchain. This typically means the |
| 66 |
* build target is Android. |
| 67 |
* |
| 68 |
* If the build environment is Android, AOSP can provide common Android |
| 69 |
* headers, such as <cutils/native_handle.h>. This allows one to build |
| 70 |
* and test certain aspects of Android window system code, on the host |
| 71 |
* system rather the build target. |
| 72 |
*/ |
| 73 |
|
| 74 |
#if defined(__ANDROID__) || defined(ANDROID) |
| 75 |
|
| 76 |
#include <cutils/native_handle.h> |
| 77 |
#if ANDROID_API_LEVEL < 28 |
| 78 |
/* buffer_handle_t was defined in the deprecated system/window.h */ |
| 79 |
typedef const native_handle_t *buffer_handle_t; |
| 80 |
#endif |
| 81 |
|
| 82 |
#else |
| 83 |
|
| 84 |
typedef void *buffer_handle_t; |
| 85 |
|
| 86 |
#endif |
| 87 |
|
| 88 |
%s\ |
| 89 |
""" |
| 90 |
|
| 91 |
# a URL of `None` means there is no upstream, because *we* are the upstream |
| 92 |
SOURCES = [ |
| 93 |
{ |
| 94 |
'api': 'khr', |
| 95 |
'inc_folder': 'KHR', |
| 96 |
'sources': [ |
| 97 |
Source('include/KHR/khrplatform.h', 'https://github.com/KhronosGroup/EGL-Registry/raw/main/api/KHR/khrplatform.h'), |
| 98 |
], |
| 99 |
}, |
| 100 |
|
| 101 |
{ |
| 102 |
'api': 'egl', |
| 103 |
'inc_folder': 'EGL', |
| 104 |
'sources': [ |
| 105 |
Source('src/egl/generate/egl.xml', 'https://github.com/KhronosGroup/EGL-Registry/raw/main/api/egl.xml'), |
| 106 |
Source('include/EGL/egl.h', 'https://github.com/KhronosGroup/EGL-Registry/raw/main/api/EGL/egl.h'), |
| 107 |
Source('include/EGL/eglplatform.h', 'https://github.com/KhronosGroup/EGL-Registry/raw/main/api/EGL/eglplatform.h'), |
| 108 |
Source('include/EGL/eglext.h', 'https://github.com/KhronosGroup/EGL-Registry/raw/main/api/EGL/eglext.h'), |
| 109 |
Source('include/EGL/eglext_angle.h', 'https://chromium.googlesource.com/angle/angle/+/refs/heads/main/include/EGL/eglext_angle.h?format=TEXT'), |
| 110 |
Source('include/EGL/eglmesaext.h', None), |
| 111 |
], |
| 112 |
}, |
| 113 |
|
| 114 |
{ |
| 115 |
'api': 'gl', |
| 116 |
'inc_folder': 'GL', |
| 117 |
'sources': [ |
| 118 |
Source('src/mesa/glapi/glapi/registry/gl.xml', 'https://github.com/KhronosGroup/OpenGL-Registry/raw/main/xml/gl.xml'), |
| 119 |
Source('include/GL/glcorearb.h', 'https://github.com/KhronosGroup/OpenGL-Registry/raw/main/api/GL/glcorearb.h'), |
| 120 |
Source('include/GL/glext.h', 'https://github.com/KhronosGroup/OpenGL-Registry/raw/main/api/GL/glext.h'), |
| 121 |
Source('include/GL/glxext.h', 'https://github.com/KhronosGroup/OpenGL-Registry/raw/main/api/GL/glxext.h'), |
| 122 |
Source('include/GL/wglext.h', 'https://github.com/KhronosGroup/OpenGL-Registry/raw/main/api/GL/wglext.h'), |
| 123 |
Source('include/GL/gl.h', None), # FIXME: I don't know what the canonical source is |
| 124 |
Source('include/GL/glx.h', None), # FIXME: I don't know what the canonical source is |
| 125 |
Source('include/GL/internal/', None), |
| 126 |
Source('include/GL/mesa_glinterop.h', None), |
| 127 |
], |
| 128 |
}, |
| 129 |
|
| 130 |
{ |
| 131 |
'api': 'gles1', |
| 132 |
'inc_folder': 'GLES', |
| 133 |
'sources': [ |
| 134 |
Source('include/GLES/gl.h', 'https://github.com/KhronosGroup/OpenGL-Registry/raw/main/api/GLES/gl.h'), |
| 135 |
Source('include/GLES/glplatform.h', 'https://github.com/KhronosGroup/OpenGL-Registry/raw/main/api/GLES/glplatform.h'), |
| 136 |
Source('include/GLES/glext.h', 'https://github.com/KhronosGroup/OpenGL-Registry/raw/main/api/GLES/glext.h'), |
| 137 |
Source('include/GLES/egl.h', 'https://github.com/KhronosGroup/OpenGL-Registry/raw/main/api/GLES/egl.h'), |
| 138 |
], |
| 139 |
}, |
| 140 |
|
| 141 |
{ |
| 142 |
'api': 'gles2', |
| 143 |
'inc_folder': 'GLES2', |
| 144 |
'sources': [ |
| 145 |
Source('include/GLES2/gl2.h', 'https://github.com/KhronosGroup/OpenGL-Registry/raw/main/api/GLES2/gl2.h'), |
| 146 |
Source('include/GLES2/gl2platform.h', 'https://github.com/KhronosGroup/OpenGL-Registry/raw/main/api/GLES2/gl2platform.h'), |
| 147 |
Source('include/GLES2/gl2ext.h', 'https://github.com/KhronosGroup/OpenGL-Registry/raw/main/api/GLES2/gl2ext.h'), |
| 148 |
], |
| 149 |
}, |
| 150 |
|
| 151 |
{ |
| 152 |
'api': 'gles3', |
| 153 |
'inc_folder': 'GLES3', |
| 154 |
'sources': [ |
| 155 |
Source('include/GLES3/gl3.h', 'https://github.com/KhronosGroup/OpenGL-Registry/raw/main/api/GLES3/gl3.h'), |
| 156 |
Source('include/GLES3/gl31.h', 'https://github.com/KhronosGroup/OpenGL-Registry/raw/main/api/GLES3/gl31.h'), |
| 157 |
Source('include/GLES3/gl32.h', 'https://github.com/KhronosGroup/OpenGL-Registry/raw/main/api/GLES3/gl32.h'), |
| 158 |
Source('include/GLES3/gl3platform.h', 'https://github.com/KhronosGroup/OpenGL-Registry/raw/main/api/GLES3/gl3platform.h'), |
| 159 |
Source('include/GLES3/gl3ext.h', None), # FIXME: I don't know what the canonical source is |
| 160 |
], |
| 161 |
}, |
| 162 |
|
| 163 |
{ |
| 164 |
'api': 'opencl', |
| 165 |
'inc_folder': 'CL', |
| 166 |
'sources': [ |
| 167 |
Source('include/CL/cl.h', 'https://github.com/KhronosGroup/OpenCL-Headers/raw/main/CL/cl.h'), |
| 168 |
Source('include/CL/cl_d3d10.h', 'https://github.com/KhronosGroup/OpenCL-Headers/raw/main/CL/cl_d3d10.h'), |
| 169 |
Source('include/CL/cl_d3d11.h', 'https://github.com/KhronosGroup/OpenCL-Headers/raw/main/CL/cl_d3d11.h'), |
| 170 |
Source('include/CL/cl_dx9_media_sharing.h', 'https://github.com/KhronosGroup/OpenCL-Headers/raw/main/CL/cl_dx9_media_sharing.h'), |
| 171 |
Source('include/CL/cl_dx9_media_sharing_intel.h', 'https://github.com/KhronosGroup/OpenCL-Headers/raw/main/CL/cl_dx9_media_sharing_intel.h'), |
| 172 |
Source('include/CL/cl_egl.h', 'https://github.com/KhronosGroup/OpenCL-Headers/raw/main/CL/cl_egl.h'), |
| 173 |
Source('include/CL/cl_ext.h', 'https://github.com/KhronosGroup/OpenCL-Headers/raw/main/CL/cl_ext.h'), |
| 174 |
Source('include/CL/cl_ext_intel.h', 'https://github.com/KhronosGroup/OpenCL-Headers/raw/main/CL/cl_ext_intel.h'), |
| 175 |
Source('include/CL/cl_function_types.h', 'https://github.com/KhronosGroup/OpenCL-Headers/raw/main/CL/cl_function_types.h'), |
| 176 |
Source('include/CL/cl_gl.h', 'https://github.com/KhronosGroup/OpenCL-Headers/raw/main/CL/cl_gl.h'), |
| 177 |
Source('include/CL/cl_gl_ext.h', 'https://github.com/KhronosGroup/OpenCL-Headers/raw/main/CL/cl_gl_ext.h'), |
| 178 |
Source('include/CL/cl_half.h', 'https://github.com/KhronosGroup/OpenCL-Headers/raw/main/CL/cl_half.h'), |
| 179 |
Source('include/CL/cl_icd.h', 'https://github.com/KhronosGroup/OpenCL-Headers/raw/main/CL/cl_icd.h'), |
| 180 |
Source('include/CL/cl_layer.h', 'https://github.com/KhronosGroup/OpenCL-Headers/raw/main/CL/cl_layer.h'), |
| 181 |
Source('include/CL/cl_platform.h', 'https://github.com/KhronosGroup/OpenCL-Headers/raw/main/CL/cl_platform.h'), |
| 182 |
Source('include/CL/cl_va_api_media_sharing_intel.h', 'https://github.com/KhronosGroup/OpenCL-Headers/raw/main/CL/cl_va_api_media_sharing_intel.h'), |
| 183 |
Source('include/CL/cl_version.h', 'https://github.com/KhronosGroup/OpenCL-Headers/raw/main/CL/cl_version.h'), |
| 184 |
Source('include/CL/opencl.h', 'https://github.com/KhronosGroup/OpenCL-Headers/raw/main/CL/opencl.h'), |
| 185 |
], |
| 186 |
}, |
| 187 |
|
| 188 |
{ |
| 189 |
'api': 'opencl_intel', |
| 190 |
'inc_folder': 'CL_intel', |
| 191 |
'sources': [ |
| 192 |
Source('include/CL_intel/cl_ext_private.h', 'https://github.com/intel/compute-runtime/raw/master/opencl/extensions/public/cl_ext_private.h'), |
| 193 |
], |
| 194 |
}, |
| 195 |
|
| 196 |
{ |
| 197 |
'api': 'spirv', |
| 198 |
'sources': [ |
| 199 |
Source('src/compiler/spirv/NonSemanticShaderDebugInfo100.h', 'https://github.com/KhronosGroup/SPIRV-Headers/raw/main/include/spirv/unified1/NonSemanticShaderDebugInfo100.h'), |
| 200 |
Source('src/compiler/spirv/spirv.h', 'https://github.com/KhronosGroup/SPIRV-Headers/raw/main/include/spirv/unified1/spirv.h'), |
| 201 |
Source('src/compiler/spirv/spirv.core.grammar.json', 'https://github.com/KhronosGroup/SPIRV-Headers/raw/main/include/spirv/unified1/spirv.core.grammar.json'), |
| 202 |
Source('src/compiler/spirv/OpenCL.std.h', 'https://github.com/KhronosGroup/SPIRV-Headers/raw/main/include/spirv/unified1/OpenCL.std.h'), |
| 203 |
Source('src/compiler/spirv/GLSL.std.450.h', 'https://github.com/KhronosGroup/SPIRV-Headers/raw/main/include/spirv/unified1/GLSL.std.450.h'), |
| 204 |
Source('src/compiler/spirv/GLSL.ext.AMD.h', 'https://github.com/KhronosGroup/glslang/raw/main/SPIRV/GLSL.ext.AMD.h'), # FIXME: is this the canonical source? |
| 205 |
], |
| 206 |
}, |
| 207 |
|
| 208 |
{ |
| 209 |
'api': 'vulkan', |
| 210 |
'inc_folder': 'vulkan', |
| 211 |
'sources': [ |
| 212 |
Source('src/vulkan/registry/vk.xml', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/main/registry/vk.xml'), |
| 213 |
Source('include/vulkan/vulkan.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/main/include/vulkan/vulkan.h'), |
| 214 |
Source('include/vulkan/vulkan_core.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/main/include/vulkan/vulkan_core.h'), |
| 215 |
Source('include/vulkan/vulkan_beta.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/main/include/vulkan/vulkan_beta.h'), |
| 216 |
Source('include/vulkan/vk_icd.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/main/include/vulkan/vk_icd.h'), |
| 217 |
Source('include/vulkan/vk_layer.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/main/include/vulkan/vk_layer.h'), |
| 218 |
Source('include/vulkan/vk_platform.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/main/include/vulkan/vk_platform.h'), |
| 219 |
Source('include/vulkan/vulkan_android.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/main/include/vulkan/vulkan_android.h'), |
| 220 |
Source('include/vulkan/vulkan_directfb.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/main/include/vulkan/vulkan_directfb.h'), |
| 221 |
Source('include/vulkan/vulkan_fuchsia.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/main/include/vulkan/vulkan_fuchsia.h'), |
| 222 |
Source('include/vulkan/vulkan_ggp.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/main/include/vulkan/vulkan_ggp.h'), |
| 223 |
Source('include/vulkan/vulkan_ios.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/main/include/vulkan/vulkan_ios.h'), |
| 224 |
Source('include/vulkan/vulkan_macos.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/main/include/vulkan/vulkan_macos.h'), |
| 225 |
Source('include/vulkan/vulkan_metal.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/main/include/vulkan/vulkan_metal.h'), |
| 226 |
Source('include/vulkan/vulkan_ohos.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/main/include/vulkan/vulkan_ohos.h'), |
| 227 |
Source('include/vulkan/vulkan_screen.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/main/include/vulkan/vulkan_screen.h'), |
| 228 |
Source('include/vulkan/vulkan_vi.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/main/include/vulkan/vulkan_vi.h'), |
| 229 |
Source('include/vulkan/vulkan_wayland.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/main/include/vulkan/vulkan_wayland.h'), |
| 230 |
Source('include/vulkan/vulkan_win32.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/main/include/vulkan/vulkan_win32.h'), |
| 231 |
Source('include/vulkan/vulkan_xcb.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/main/include/vulkan/vulkan_xcb.h'), |
| 232 |
Source('include/vulkan/vulkan_xlib.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/main/include/vulkan/vulkan_xlib.h'), |
| 233 |
Source('include/vulkan/vulkan_xlib_xrandr.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/main/include/vulkan/vulkan_xlib_xrandr.h'), |
| 234 |
Source('include/vulkan/vk_android_native_buffer.h', 'https://android.googlesource.com/platform/frameworks/native/+/master/vulkan/include/vulkan/vk_android_native_buffer.h?format=TEXT', |
| 235 |
template=VK_ANDROID_NATIVE_BUFFER_TEMPLATE, remove='#include <cutils/native_handle.h>\n'), |
| 236 |
Source('include/vk_video/vulkan_video_codec_av1std.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/main/include/vk_video/vulkan_video_codec_av1std.h'), |
| 237 |
Source('include/vk_video/vulkan_video_codec_av1std_decode.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/main/include/vk_video/vulkan_video_codec_av1std_decode.h'), |
| 238 |
Source('include/vk_video/vulkan_video_codec_av1std_encode.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/main/include/vk_video/vulkan_video_codec_av1std_encode.h'), |
| 239 |
Source('include/vk_video/vulkan_video_codec_h264std.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/main/include/vk_video/vulkan_video_codec_h264std.h'), |
| 240 |
Source('include/vk_video/vulkan_video_codec_h264std_decode.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/main/include/vk_video/vulkan_video_codec_h264std_decode.h'), |
| 241 |
Source('include/vk_video/vulkan_video_codec_h264std_encode.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/main/include/vk_video/vulkan_video_codec_h264std_encode.h'), |
| 242 |
Source('include/vk_video/vulkan_video_codec_h265std.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/main/include/vk_video/vulkan_video_codec_h265std.h'), |
| 243 |
Source('include/vk_video/vulkan_video_codec_h265std_decode.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/main/include/vk_video/vulkan_video_codec_h265std_decode.h'), |
| 244 |
Source('include/vk_video/vulkan_video_codec_h265std_encode.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/main/include/vk_video/vulkan_video_codec_h265std_encode.h'), |
| 245 |
Source('include/vk_video/vulkan_video_codec_vp9std.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/main/include/vk_video/vulkan_video_codec_vp9std.h'), |
| 246 |
Source('include/vk_video/vulkan_video_codec_vp9std_decode.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/main/include/vk_video/vulkan_video_codec_vp9std_decode.h'), |
| 247 |
Source('include/vk_video/vulkan_video_codecs_common.h', 'https://github.com/KhronosGroup/Vulkan-Headers/raw/main/include/vk_video/vulkan_video_codecs_common.h'), |
| 248 |
Source('include/vulkan/.editorconfig', None), |
| 249 |
], |
| 250 |
}, |
| 251 |
] |
| 252 |
|
| 253 |
|
| 254 |
if __name__ == '__main__': |
| 255 |
git_toplevel = subprocess.check_output(['git', 'rev-parse', '--show-toplevel'], |
| 256 |
stderr=subprocess.DEVNULL).decode("ascii").strip() |
| 257 |
if not pathlib.Path(git_toplevel).resolve() == pathlib.Path('.').resolve(): |
| 258 |
error('Please run this script from the root folder ({})'.format(git_toplevel)) |
| 259 |
exit(1) |
| 260 |
|
| 261 |
parser = argparse.ArgumentParser() |
| 262 |
parser.add_argument('apis', nargs='*', |
| 263 |
# the `[[]]` here is a workaround for python bug 9625 |
| 264 |
# where having `choices` breaks `nargs='*'`: |
| 265 |
# https://bugs.python.org/issue9625 |
| 266 |
choices=[group['api'] for group in SOURCES] + [[]], |
| 267 |
help='Only update the APIs specified.') |
| 268 |
args = parser.parse_args() |
| 269 |
|
| 270 |
# These APIs all depend on the KHR header |
| 271 |
depend_on_khr = set(['egl', 'gl', 'gles', 'gles2', 'gles3']) |
| 272 |
if args.apis and 'khr' not in args.apis and depend_on_khr.intersection(set(args.apis)): |
| 273 |
args.apis = ['khr'] + args.apis |
| 274 |
|
| 275 |
for group in SOURCES: |
| 276 |
if args.apis and group['api'] not in args.apis: |
| 277 |
continue |
| 278 |
|
| 279 |
for source in group['sources']: |
| 280 |
source.sync() |
| 281 |
|
| 282 |
# Make sure all the API files are handled by this script |
| 283 |
if 'inc_folder' in group: |
| 284 |
for file in pathlib.Path('include/' + group['inc_folder']).iterdir(): |
| 285 |
if file not in [source.file for source in group['sources']]: |
| 286 |
error('{} is unknown, please add it to SOURCES'.format(file)) |