Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/angle
Path: blob/main_old/scripts/registry_xml.py
1693 views
1
#!/usr/bin/python3
2
#
3
# Copyright 2018 The ANGLE Project Authors. All rights reserved.
4
# Use of this source code is governed by a BSD-style license that can be
5
# found in the LICENSE file.
6
#
7
# registry_xml.py:
8
# Parses information from Khronos registry files..
9
10
# List of supported extensions. Add to this list to enable new extensions
11
# available in gl.xml.
12
13
import os
14
import sys
15
import xml.etree.ElementTree as etree
16
17
from enum import Enum
18
19
xml_inputs = [
20
'cl.xml',
21
'gl.xml',
22
'gl_angle_ext.xml',
23
'egl.xml',
24
'egl_angle_ext.xml',
25
'wgl.xml',
26
'registry_xml.py',
27
]
28
29
angle_extensions = [
30
# ANGLE extensions
31
"GL_CHROMIUM_bind_uniform_location",
32
"GL_CHROMIUM_framebuffer_mixed_samples",
33
"GL_CHROMIUM_path_rendering",
34
"GL_CHROMIUM_copy_texture",
35
"GL_CHROMIUM_copy_compressed_texture",
36
"GL_CHROMIUM_lose_context",
37
"GL_ANGLE_copy_texture_3d",
38
"GL_ANGLE_get_image",
39
"GL_ANGLE_get_serialized_context_string",
40
"GL_ANGLE_get_tex_level_parameter",
41
"GL_ANGLE_program_binary",
42
"GL_ANGLE_request_extension",
43
"GL_ANGLE_robust_client_memory",
44
"GL_ANGLE_texture_external_update",
45
]
46
47
gles1_extensions = [
48
# ES1 (Possibly the min set of extensions needed by Android)
49
"GL_OES_draw_texture",
50
"GL_OES_framebuffer_object",
51
"GL_OES_matrix_palette",
52
"GL_OES_point_size_array",
53
"GL_OES_query_matrix",
54
"GL_OES_texture_cube_map",
55
]
56
57
gles_extensions = [
58
# ES2+
59
"GL_ANGLE_base_vertex_base_instance",
60
"GL_ANGLE_framebuffer_blit",
61
"GL_ANGLE_framebuffer_multisample",
62
"GL_ANGLE_instanced_arrays",
63
"GL_ANGLE_memory_object_flags",
64
"GL_ANGLE_memory_object_fuchsia",
65
"GL_ANGLE_multi_draw",
66
"GL_ANGLE_provoking_vertex",
67
"GL_ANGLE_semaphore_fuchsia",
68
"GL_ANGLE_texture_multisample",
69
"GL_ANGLE_translated_shader_source",
70
"GL_KHR_blend_equation_advanced",
71
"GL_EXT_blend_func_extended",
72
"GL_EXT_buffer_storage",
73
"GL_EXT_copy_image",
74
"GL_EXT_clip_control",
75
"GL_EXT_debug_label",
76
"GL_EXT_debug_marker",
77
"GL_EXT_discard_framebuffer",
78
"GL_EXT_disjoint_timer_query",
79
"GL_EXT_draw_buffers",
80
"GL_EXT_draw_buffers_indexed",
81
"GL_EXT_draw_elements_base_vertex",
82
"GL_EXT_EGL_image_array",
83
"GL_EXT_external_buffer",
84
"GL_EXT_geometry_shader",
85
"GL_EXT_instanced_arrays",
86
"GL_EXT_map_buffer_range",
87
"GL_EXT_memory_object",
88
"GL_EXT_memory_object_fd",
89
"GL_EXT_multisampled_render_to_texture",
90
"GL_EXT_multisampled_render_to_texture2",
91
"GL_EXT_occlusion_query_boolean",
92
"GL_EXT_primitive_bounding_box",
93
"GL_EXT_protected_textures",
94
"GL_EXT_pvrtc_sRGB",
95
"GL_EXT_read_format_bgra",
96
"GL_EXT_robustness",
97
"GL_EXT_semaphore",
98
"GL_EXT_semaphore_fd",
99
"GL_EXT_separate_shader_objects",
100
"GL_EXT_shader_framebuffer_fetch_non_coherent",
101
"GL_EXT_shader_io_blocks",
102
"GL_EXT_sRGB",
103
"GL_EXT_sRGB_write_control",
104
"GL_EXT_tessellation_shader",
105
"GL_EXT_texture_border_clamp",
106
"GL_EXT_texture_buffer",
107
"GL_EXT_texture_compression_bptc",
108
"GL_EXT_texture_compression_dxt1",
109
"GL_EXT_texture_compression_rgtc",
110
"GL_EXT_texture_compression_s3tc",
111
"GL_EXT_texture_compression_s3tc_srgb",
112
"GL_EXT_texture_cube_map_array",
113
"GL_EXT_texture_filter_anisotropic",
114
"GL_EXT_texture_format_BGRA8888",
115
"GL_EXT_texture_storage",
116
"GL_EXT_texture_sRGB_R8",
117
"GL_EXT_texture_sRGB_RG8",
118
"GL_EXT_YUV_target",
119
"GL_IMG_texture_compression_pvrtc",
120
"GL_IMG_texture_compression_pvrtc2",
121
"GL_KHR_debug",
122
"GL_KHR_parallel_shader_compile",
123
"GL_KHR_texture_compression_astc_ldr",
124
"GL_KHR_texture_compression_astc_hdr",
125
"GL_KHR_texture_compression_astc_sliced_3d",
126
"GL_NV_fence",
127
"GL_NV_framebuffer_blit",
128
"GL_OES_compressed_ETC1_RGB8_texture",
129
"GL_EXT_compressed_ETC1_RGB8_sub_texture",
130
"GL_OES_copy_image",
131
"GL_OES_depth32",
132
"GL_OES_draw_buffers_indexed",
133
"GL_OES_draw_elements_base_vertex",
134
"GL_OES_EGL_image",
135
"GL_OES_geometry_shader",
136
"GL_OES_get_program_binary",
137
"GL_OES_mapbuffer",
138
"GL_OES_sample_shading",
139
"GL_OES_shader_io_blocks",
140
"GL_OES_texture_3D",
141
"GL_OES_texture_border_clamp",
142
"GL_OES_texture_buffer",
143
"GL_OES_texture_cube_map_array",
144
"GL_OES_texture_half_float",
145
"GL_OES_texture_stencil8",
146
"GL_OES_texture_storage_multisample_2d_array",
147
"GL_OES_vertex_array_object",
148
"GL_OVR_multiview",
149
"GL_OVR_multiview2",
150
]
151
152
supported_extensions = sorted(angle_extensions + gles1_extensions + gles_extensions)
153
154
supported_egl_extensions = [
155
"EGL_ANDROID_blob_cache",
156
"EGL_ANDROID_create_native_client_buffer",
157
"EGL_ANDROID_framebuffer_target",
158
"EGL_ANDROID_get_frame_timestamps",
159
"EGL_ANDROID_get_native_client_buffer",
160
"EGL_ANDROID_native_fence_sync",
161
"EGL_ANDROID_presentation_time",
162
"EGL_ANGLE_create_surface_swap_interval",
163
"EGL_ANGLE_d3d_share_handle_client_buffer",
164
"EGL_ANGLE_device_creation",
165
"EGL_ANGLE_device_d3d",
166
"EGL_ANGLE_display_semaphore_share_group",
167
"EGL_ANGLE_display_texture_share_group",
168
"EGL_ANGLE_feature_control",
169
"EGL_ANGLE_ggp_stream_descriptor",
170
"EGL_ANGLE_power_preference",
171
"EGL_ANGLE_program_cache_control",
172
"EGL_ANGLE_query_surface_pointer",
173
"EGL_ANGLE_stream_producer_d3d_texture",
174
"EGL_ANGLE_surface_d3d_texture_2d_share_handle",
175
"EGL_ANGLE_swap_with_frame_token",
176
"EGL_ANGLE_sync_control_rate",
177
"EGL_ANGLE_window_fixed_size",
178
"EGL_CHROMIUM_sync_control",
179
"EGL_EXT_create_context_robustness",
180
"EGL_EXT_device_query",
181
"EGL_EXT_gl_colorspace_display_p3",
182
"EGL_EXT_gl_colorspace_display_p3_linear",
183
"EGL_EXT_gl_colorspace_display_p3_passthrough",
184
"EGL_EXT_gl_colorspace_scrgb",
185
"EGL_EXT_gl_colorspace_scrgb_linear",
186
"EGL_EXT_image_gl_colorspace",
187
"EGL_EXT_pixel_format_float",
188
"EGL_EXT_platform_base",
189
"EGL_EXT_platform_device",
190
"EGL_EXT_protected_content",
191
"EGL_IMG_context_priority",
192
"EGL_KHR_debug",
193
"EGL_KHR_fence_sync",
194
"EGL_KHR_gl_colorspace",
195
"EGL_KHR_image",
196
"EGL_KHR_mutable_render_buffer",
197
"EGL_KHR_no_config_context",
198
"EGL_KHR_reusable_sync",
199
"EGL_KHR_stream",
200
"EGL_KHR_stream_consumer_gltexture",
201
"EGL_KHR_surfaceless_context",
202
"EGL_KHR_swap_buffers_with_damage",
203
"EGL_KHR_wait_sync",
204
"EGL_NV_post_sub_buffer",
205
"EGL_NV_stream_consumer_gltexture_yuv",
206
]
207
208
supported_cl_extensions = [
209
# Since OpenCL 1.1
210
"cl_khr_byte_addressable_store",
211
"cl_khr_global_int32_base_atomics",
212
"cl_khr_global_int32_extended_atomics",
213
"cl_khr_local_int32_base_atomics",
214
"cl_khr_local_int32_extended_atomics",
215
216
# OpenCL 2.0 - 2.2
217
"cl_khr_3d_image_writes",
218
"cl_khr_depth_images",
219
"cl_khr_image2d_from_buffer",
220
221
# Optional
222
"cl_khr_extended_versioning",
223
"cl_khr_fp64",
224
"cl_khr_icd",
225
"cl_khr_int64_base_atomics",
226
"cl_khr_int64_extended_atomics",
227
]
228
229
# Strip these suffixes from Context entry point names. NV is excluded (for now).
230
strip_suffixes = ["ANGLE", "EXT", "KHR", "OES", "CHROMIUM"]
231
232
# The EGL_ANGLE_explicit_context extension is generated differently from other extensions.
233
# Toggle generation here.
234
support_EGL_ANGLE_explicit_context = True
235
236
# For ungrouped GLenum types
237
default_enum_group_name = "DefaultGroup"
238
239
# Group names that appear in command/param, but not present in groups/group
240
unsupported_enum_group_names = {
241
'GetMultisamplePNameNV',
242
'BufferPNameARB',
243
'BufferPointerNameARB',
244
'VertexAttribPointerPropertyARB',
245
'VertexAttribPropertyARB',
246
'FenceParameterNameNV',
247
'FenceConditionNV',
248
'BufferPointerNameARB',
249
'MatrixIndexPointerTypeARB',
250
'PointParameterNameARB',
251
'ClampColorTargetARB',
252
'ClampColorModeARB',
253
}
254
255
# Versions (major, minor). Note that GLES intentionally places 1.0 last.
256
DESKTOP_GL_VERSIONS = [(1, 0), (1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (2, 0), (2, 1), (3, 0),
257
(3, 1), (3, 2), (3, 3), (4, 0), (4, 1), (4, 2), (4, 3), (4, 4), (4, 5),
258
(4, 6)]
259
GLES_VERSIONS = [(2, 0), (3, 0), (3, 1), (3, 2), (1, 0)]
260
EGL_VERSIONS = [(1, 0), (1, 1), (1, 2), (1, 3), (1, 4), (1, 5)]
261
WGL_VERSIONS = [(1, 0)]
262
CL_VERSIONS = [(1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2), (3, 0)]
263
264
265
# API types
266
class apis:
267
GL = 'GL'
268
GLES = 'GLES'
269
WGL = 'WGL'
270
EGL = 'EGL'
271
CL = 'CL'
272
273
274
def script_relative(path):
275
return os.path.join(os.path.dirname(sys.argv[0]), path)
276
277
278
def path_to(folder, file):
279
return os.path.join(script_relative(".."), "src", folder, file)
280
281
282
def strip_api_prefix(cmd_name):
283
return cmd_name.lstrip("cwegl")
284
285
286
def get_cmd_name(command_node):
287
proto = command_node.find('proto')
288
cmd_name = proto.find('name').text
289
return cmd_name
290
291
292
class CommandNames:
293
294
def __init__(self):
295
self.command_names = {}
296
297
def get_commands(self, version):
298
return self.command_names[version]
299
300
def get_all_commands(self):
301
cmd_names = []
302
# Combine all the version lists into a single list
303
for version, version_cmd_names in sorted(self.command_names.items()):
304
cmd_names += version_cmd_names
305
306
return cmd_names
307
308
def add_commands(self, version, commands):
309
# Add key if it doesn't exist
310
if version not in self.command_names:
311
self.command_names[version] = []
312
# Add the commands that aren't duplicates
313
self.command_names[version] += commands
314
315
316
class RegistryXML:
317
318
def __init__(self, xml_file, ext_file=None):
319
tree = etree.parse(script_relative(xml_file))
320
self.root = tree.getroot()
321
if (ext_file):
322
self._AppendANGLEExts(ext_file)
323
self.all_commands = self.root.findall('commands/command')
324
self.all_cmd_names = CommandNames()
325
self.commands = {}
326
327
def _AppendANGLEExts(self, ext_file):
328
angle_ext_tree = etree.parse(script_relative(ext_file))
329
angle_ext_root = angle_ext_tree.getroot()
330
331
insertion_point = self.root.findall("./commands")[0]
332
for command in angle_ext_root.iter('commands'):
333
insertion_point.extend(command)
334
335
insertion_point = self.root.findall("./extensions")[0]
336
for extension in angle_ext_root.iter('extensions'):
337
insertion_point.extend(extension)
338
339
insertion_point = self.root
340
for enums in angle_ext_root.iter('enums'):
341
insertion_point.append(enums)
342
343
def AddCommands(self, feature_name, annotation):
344
xpath = ".//feature[@name='%s']//command" % feature_name
345
commands = [cmd.attrib['name'] for cmd in self.root.findall(xpath)]
346
347
# Remove commands that have already been processed
348
current_cmds = self.all_cmd_names.get_all_commands()
349
commands = [cmd for cmd in commands if cmd not in current_cmds]
350
351
self.all_cmd_names.add_commands(annotation, commands)
352
self.commands[annotation] = commands
353
354
def _ClassifySupport(self, supported):
355
if 'gles2' in supported:
356
return 'gl2ext'
357
elif 'gles1' in supported:
358
return 'glext'
359
elif 'egl' in supported:
360
return 'eglext'
361
elif 'wgl' in supported:
362
return 'wglext'
363
elif 'cl' in supported:
364
return 'clext'
365
else:
366
assert False
367
return 'unknown'
368
369
def AddExtensionCommands(self, supported_extensions, apis):
370
# Use a first step to run through the extensions so we can generate them
371
# in sorted order.
372
self.ext_data = {}
373
self.ext_dupes = {}
374
ext_annotations = {}
375
376
for extension in self.root.findall("extensions/extension"):
377
extension_name = extension.attrib['name']
378
if not extension_name in supported_extensions:
379
continue
380
381
ext_annotations[extension_name] = self._ClassifySupport(extension.attrib['supported'])
382
383
ext_cmd_names = []
384
385
# There's an extra step here to filter out 'api=gl' extensions. This
386
# is necessary for handling KHR extensions, which have separate entry
387
# point signatures (without the suffix) for desktop GL. Note that this
388
# extra step is necessary because of Etree's limited Xpath support.
389
for require in extension.findall('require'):
390
if 'api' in require.attrib and require.attrib['api'] not in apis:
391
continue
392
393
# A special case for EXT_texture_storage
394
filter_out_comment = "Supported only if GL_EXT_direct_state_access is supported"
395
if 'comment' in require.attrib and require.attrib['comment'] == filter_out_comment:
396
continue
397
398
extension_commands = require.findall('command')
399
ext_cmd_names += [command.attrib['name'] for command in extension_commands]
400
401
self.ext_data[extension_name] = sorted(ext_cmd_names)
402
403
for extension_name, ext_cmd_names in sorted(self.ext_data.items()):
404
405
# Detect and filter duplicate extensions.
406
dupes = []
407
for ext_cmd in ext_cmd_names:
408
if ext_cmd in self.all_cmd_names.get_all_commands():
409
dupes.append(ext_cmd)
410
411
for dupe in dupes:
412
ext_cmd_names.remove(dupe)
413
414
self.ext_data[extension_name] = sorted(ext_cmd_names)
415
self.ext_dupes[extension_name] = dupes
416
self.all_cmd_names.add_commands(ext_annotations[extension_name], ext_cmd_names)
417
418
419
class EntryPoints:
420
421
def __init__(self, api, xml, commands):
422
self.api = api
423
self._cmd_info = []
424
425
for command_node in xml.all_commands:
426
cmd_name = get_cmd_name(command_node)
427
428
if api == apis.WGL:
429
cmd_name = cmd_name if cmd_name[:3] == 'wgl' else 'wgl' + cmd_name
430
431
if cmd_name not in commands:
432
continue
433
434
param_text = ["".join(param.itertext()) for param in command_node.findall('param')]
435
436
# Treat (void) as ()
437
if len(param_text) == 1 and param_text[0].strip() == 'void':
438
param_text = []
439
440
proto = command_node.find('proto')
441
proto_text = "".join(proto.itertext())
442
443
self._cmd_info.append((cmd_name, command_node, param_text, proto_text))
444
445
def get_infos(self):
446
return self._cmd_info
447
448