• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
13import difflib
14import os
15import sys
16import xml.etree.ElementTree as etree
17
18from enum import Enum
19
20xml_inputs = [
21    'cl.xml',
22    'gl.xml',
23    'gl_angle_ext.xml',
24    'egl.xml',
25    'egl_angle_ext.xml',
26    'wgl.xml',
27    'registry_xml.py',
28]
29
30# Notes on categories of extensions:
31# 'Requestable' extensions are extensions that can be enabled with ANGLE_request_extension
32# 'ES-Only' extensions are always implicitly enabled.
33# 'Toggleable' extensions are like 'Requestable' except they can be also disabled.
34# 'ANGLE' extensions are extensions that are not yet officially upstreamed to Khronos.
35# We document those extensions in gl_angle_ext.xml instead of the canonical gl.xml.
36
37angle_toggleable_extensions = [
38    "GL_ANGLE_texture_rectangle",
39]
40
41angle_requestable_extensions = [
42    "GL_ANGLE_base_vertex_base_instance",
43    "GL_ANGLE_base_vertex_base_instance_shader_builtin",
44    "GL_ANGLE_compressed_texture_etc",
45    "GL_ANGLE_copy_texture_3d",
46    "GL_ANGLE_framebuffer_multisample",
47    "GL_ANGLE_get_image",
48    "GL_ANGLE_get_tex_level_parameter",
49    "GL_ANGLE_lossy_etc_decode",
50    "GL_ANGLE_memory_object_flags",
51    "GL_ANGLE_memory_object_fuchsia",
52    "GL_ANGLE_memory_size",
53    "GL_ANGLE_multi_draw",
54    "GL_ANGLE_multiview_multisample",
55    "GL_ANGLE_provoking_vertex",
56    "GL_ANGLE_robust_fragment_shader_output",
57    "GL_ANGLE_semaphore_fuchsia",
58    "GL_ANGLE_texture_compression_dxt3",
59    "GL_ANGLE_texture_compression_dxt5",
60    "GL_ANGLE_texture_external_update",
61    "GL_ANGLE_texture_multisample",
62    "GL_ANGLE_vulkan_image",
63    "GL_ANGLE_yuv_internal_format",
64    "GL_CHROMIUM_color_buffer_float_rgb",
65    "GL_CHROMIUM_color_buffer_float_rgba",
66    "GL_CHROMIUM_lose_context",
67    "GL_CHROMIUM_sync_query",
68    "GL_CHROMIUM_texture_filtering_hint",
69]
70
71gles_requestable_extensions = [
72    "GL_ANGLE_framebuffer_blit",
73    "GL_ANGLE_instanced_arrays",
74    "GL_ANGLE_pack_reverse_row_order",
75    "GL_ANGLE_texture_usage",
76    "GL_APPLE_clip_distance",
77    "GL_ARB_sync",
78    "GL_EXT_blend_func_extended",
79    "GL_EXT_blend_minmax",
80    "GL_EXT_buffer_storage",
81    "GL_EXT_clip_control",
82    "GL_EXT_clip_cull_distance",
83    "GL_EXT_color_buffer_float",
84    "GL_EXT_color_buffer_half_float",
85    "GL_EXT_compressed_ETC1_RGB8_sub_texture",
86    "GL_EXT_copy_image",
87    "GL_EXT_disjoint_timer_query",
88    "GL_EXT_draw_buffers",
89    "GL_EXT_draw_buffers_indexed",
90    "GL_EXT_draw_elements_base_vertex",
91    "GL_EXT_EGL_image_array",
92    "GL_EXT_EGL_image_external_wrap_modes",
93    "GL_EXT_EGL_image_storage",
94    "GL_EXT_external_buffer",
95    "GL_EXT_float_blend",
96    "GL_EXT_frag_depth",
97    "GL_EXT_geometry_shader",
98    "GL_EXT_gpu_shader5",
99    "GL_EXT_instanced_arrays",
100    "GL_EXT_map_buffer_range",
101    "GL_EXT_memory_object",
102    "GL_EXT_memory_object_fd",
103    "GL_EXT_multi_draw_indirect",
104    "GL_EXT_multisampled_render_to_texture",
105    "GL_EXT_multisampled_render_to_texture2",
106    "GL_EXT_occlusion_query_boolean",
107    "GL_EXT_protected_textures",
108    "GL_EXT_pvrtc_sRGB",
109    "GL_EXT_read_format_bgra",
110    "GL_EXT_semaphore",
111    "GL_EXT_semaphore_fd",
112    "GL_EXT_separate_shader_objects",
113    "GL_EXT_shader_framebuffer_fetch_non_coherent",
114    "GL_EXT_shader_io_blocks",
115    "GL_EXT_shader_non_constant_global_initializers",
116    "GL_EXT_shader_texture_lod",
117    "GL_EXT_shadow_samplers",
118    "GL_EXT_sRGB",
119    "GL_EXT_tessellation_shader",
120    "GL_EXT_texture_border_clamp",
121    "GL_EXT_texture_buffer",
122    "GL_EXT_texture_compression_bptc",
123    "GL_EXT_texture_compression_dxt1",
124    "GL_EXT_texture_compression_rgtc",
125    "GL_EXT_texture_compression_s3tc",
126    "GL_EXT_texture_compression_s3tc_srgb",
127    "GL_EXT_texture_cube_map_array",
128    "GL_EXT_texture_filter_anisotropic",
129    "GL_EXT_texture_format_BGRA8888",
130    "GL_EXT_texture_norm16",
131    "GL_EXT_texture_rg",
132    "GL_EXT_texture_sRGB_R8",
133    "GL_EXT_texture_sRGB_RG8",
134    "GL_EXT_texture_storage",
135    "GL_EXT_texture_type_2_10_10_10_REV",
136    "GL_EXT_unpack_subimage",
137    "GL_EXT_YUV_target",
138    "GL_IMG_texture_compression_pvrtc",
139    "GL_IMG_texture_compression_pvrtc2",
140    "GL_KHR_parallel_shader_compile",
141    "GL_KHR_texture_compression_astc_hdr",
142    "GL_KHR_texture_compression_astc_ldr",
143    "GL_KHR_texture_compression_astc_sliced_3d",
144    "GL_NV_depth_buffer_float2",
145    "GL_NV_EGL_stream_consumer_external",
146    "GL_NV_framebuffer_blit",
147    "GL_NV_pack_subimage",
148    "GL_NV_pixel_buffer_object",
149    "GL_NV_read_depth",
150    "GL_NV_read_stencil",
151    "GL_NV_shader_noperspective_interpolation",
152    "GL_OES_compressed_EAC_R11_signed_texture",
153    "GL_OES_compressed_EAC_R11_unsigned_texture",
154    "GL_OES_compressed_EAC_RG11_signed_texture",
155    "GL_OES_compressed_EAC_RG11_unsigned_texture",
156    "GL_OES_compressed_ETC1_RGB8_texture",
157    "GL_OES_compressed_ETC2_punchthroughA_RGBA8_texture",
158    "GL_OES_compressed_ETC2_punchthroughA_sRGB8_alpha_texture",
159    "GL_OES_compressed_ETC2_RGB8_texture",
160    "GL_OES_compressed_ETC2_RGBA8_texture",
161    "GL_OES_compressed_ETC2_sRGB8_alpha8_texture",
162    "GL_OES_compressed_ETC2_sRGB8_texture",
163    "GL_OES_copy_image",
164    "GL_OES_depth_texture_cube_map",
165    "GL_OES_draw_buffers_indexed",
166    "GL_OES_draw_elements_base_vertex",
167    "GL_OES_EGL_image",
168    "GL_OES_EGL_image_external",
169    "GL_OES_EGL_image_external_essl3",
170    "GL_OES_element_index_uint",
171    "GL_OES_fbo_render_mipmap",
172    "GL_OES_geometry_shader",
173    "GL_OES_get_program_binary",
174    "GL_OES_mapbuffer",
175    "GL_OES_rgb8_rgba8",
176    "GL_OES_sample_shading",
177    "GL_OES_sample_variables",
178    "GL_OES_shader_image_atomic",
179    "GL_OES_shader_io_blocks",
180    "GL_OES_shader_multisample_interpolation",
181    "GL_OES_standard_derivatives",
182    "GL_OES_texture_3D",
183    "GL_OES_texture_border_clamp",
184    "GL_OES_texture_buffer",
185    "GL_OES_texture_compression_astc",
186    "GL_OES_texture_cube_map_array",
187    "GL_OES_texture_float",
188    "GL_OES_texture_float_linear",
189    "GL_OES_texture_half_float",
190    "GL_OES_texture_half_float_linear",
191    "GL_OES_texture_npot",
192    "GL_OES_texture_stencil8",
193    "GL_OES_texture_storage_multisample_2d_array",
194    "GL_OES_vertex_array_object",
195    "GL_OES_vertex_half_float",
196    "GL_OES_vertex_type_10_10_10_2",
197    "GL_OVR_multiview",
198    "GL_OVR_multiview2",
199    "GL_WEBGL_video_texture",
200]
201
202angle_es_only_extensions = [
203    "GL_ANGLE_client_arrays",
204    "GL_ANGLE_get_serialized_context_string",
205    "GL_ANGLE_program_binary",
206    "GL_ANGLE_program_cache_control",
207    "GL_ANGLE_relaxed_vertex_attribute_type",
208    "GL_ANGLE_request_extension",
209    "GL_ANGLE_rgbx_internal_format",
210    "GL_ANGLE_robust_client_memory",
211    "GL_ANGLE_robust_resource_initialization",
212    "GL_ANGLE_webgl_compatibility",
213    "GL_CHROMIUM_bind_generates_resource",
214    "GL_CHROMIUM_bind_uniform_location",
215    "GL_CHROMIUM_copy_compressed_texture",
216    "GL_CHROMIUM_copy_texture",
217    "GL_CHROMIUM_framebuffer_mixed_samples",
218]
219
220gles_es_only_extensions = [
221    "GL_ANGLE_depth_texture",
222    "GL_ANGLE_translated_shader_source",
223    "GL_EXT_debug_label",
224    "GL_EXT_debug_marker",
225    "GL_EXT_discard_framebuffer",
226    "GL_EXT_multisample_compatibility",
227    "GL_EXT_primitive_bounding_box",
228    "GL_EXT_robustness",
229    "GL_EXT_sRGB_write_control",
230    "GL_EXT_texture_format_sRGB_override",
231    "GL_EXT_texture_sRGB_decode",
232    "GL_KHR_blend_equation_advanced",
233    "GL_KHR_debug",
234    "GL_KHR_no_error",
235    "GL_KHR_robust_buffer_access_behavior",
236    "GL_NV_fence",
237    "GL_NV_robustness_video_memory_purge",
238    "GL_OES_depth24",
239    "GL_OES_depth32",
240    "GL_OES_depth_texture",
241    "GL_OES_EGL_sync",
242    "GL_OES_packed_depth_stencil",
243    "GL_OES_surfaceless_context",
244]
245
246# ES1 (Possibly the min set of extensions needed by Android)
247gles1_extensions = [
248    "GL_OES_draw_texture",
249    "GL_OES_framebuffer_object",
250    "GL_OES_matrix_palette",
251    "GL_OES_point_size_array",
252    "GL_OES_point_sprite",
253    "GL_OES_query_matrix",
254    "GL_OES_texture_cube_map",
255]
256
257
258def check_sorted(name, l):
259    unidiff = difflib.unified_diff(l, sorted(l, key=str.casefold), 'unsorted', 'sorted')
260    diff_lines = list(unidiff)
261    assert not diff_lines, '\n\nPlease sort "%s":\n%s' % (name, '\n'.join(diff_lines))
262
263
264angle_extensions = angle_requestable_extensions + angle_es_only_extensions + angle_toggleable_extensions
265gles_extensions = gles_requestable_extensions + gles_es_only_extensions
266supported_extensions = sorted(angle_extensions + gles1_extensions + gles_extensions)
267
268assert len(supported_extensions) == len(set(supported_extensions)), 'Duplicates in extension list'
269check_sorted('angle_requestable_extensions', angle_requestable_extensions)
270check_sorted('angle_es_only_extensions', angle_es_only_extensions)
271check_sorted('angle_toggleable_extensions', angle_toggleable_extensions)
272check_sorted('gles_requestable_extensions', gles_requestable_extensions)
273check_sorted('gles_es_only_extensions', gles_es_only_extensions)
274check_sorted('gles_extensions', gles1_extensions)
275
276supported_egl_extensions = [
277    "EGL_ANDROID_blob_cache",
278    "EGL_ANDROID_create_native_client_buffer",
279    "EGL_ANDROID_framebuffer_target",
280    "EGL_ANDROID_get_frame_timestamps",
281    "EGL_ANDROID_get_native_client_buffer",
282    "EGL_ANDROID_native_fence_sync",
283    "EGL_ANDROID_presentation_time",
284    "EGL_ANGLE_create_surface_swap_interval",
285    "EGL_ANGLE_d3d_share_handle_client_buffer",
286    "EGL_ANGLE_device_creation",
287    "EGL_ANGLE_device_d3d",
288    "EGL_ANGLE_display_semaphore_share_group",
289    "EGL_ANGLE_display_texture_share_group",
290    "EGL_ANGLE_feature_control",
291    "EGL_ANGLE_ggp_stream_descriptor",
292    "EGL_ANGLE_power_preference",
293    "EGL_ANGLE_program_cache_control",
294    "EGL_ANGLE_query_surface_pointer",
295    "EGL_ANGLE_stream_producer_d3d_texture",
296    "EGL_ANGLE_surface_d3d_texture_2d_share_handle",
297    "EGL_ANGLE_swap_with_frame_token",
298    "EGL_ANGLE_sync_control_rate",
299    "EGL_ANGLE_vulkan_image",
300    "EGL_ANGLE_window_fixed_size",
301    "EGL_CHROMIUM_sync_control",
302    "EGL_EXT_create_context_robustness",
303    "EGL_EXT_device_query",
304    "EGL_EXT_gl_colorspace_display_p3",
305    "EGL_EXT_gl_colorspace_display_p3_linear",
306    "EGL_EXT_gl_colorspace_display_p3_passthrough",
307    "EGL_EXT_gl_colorspace_scrgb",
308    "EGL_EXT_gl_colorspace_scrgb_linear",
309    "EGL_EXT_image_gl_colorspace",
310    "EGL_EXT_pixel_format_float",
311    "EGL_EXT_platform_base",
312    "EGL_EXT_platform_device",
313    "EGL_EXT_protected_content",
314    "EGL_IMG_context_priority",
315    "EGL_KHR_debug",
316    "EGL_KHR_fence_sync",
317    "EGL_KHR_gl_colorspace",
318    "EGL_KHR_image",
319    "EGL_KHR_lock_surface3",
320    "EGL_KHR_mutable_render_buffer",
321    "EGL_KHR_no_config_context",
322    "EGL_KHR_reusable_sync",
323    "EGL_KHR_stream",
324    "EGL_KHR_stream_consumer_gltexture",
325    "EGL_KHR_surfaceless_context",
326    "EGL_KHR_swap_buffers_with_damage",
327    "EGL_KHR_wait_sync",
328    "EGL_NV_post_sub_buffer",
329    "EGL_NV_stream_consumer_gltexture_yuv",
330]
331
332check_sorted('supported_egl_extensions', supported_egl_extensions)
333
334supported_cl_extensions = [
335    # Since OpenCL 1.1
336    "cl_khr_byte_addressable_store",
337    "cl_khr_global_int32_base_atomics",
338    "cl_khr_global_int32_extended_atomics",
339    "cl_khr_local_int32_base_atomics",
340    "cl_khr_local_int32_extended_atomics",
341
342    # OpenCL 2.0 - 2.2
343    "cl_khr_3d_image_writes",
344    "cl_khr_depth_images",
345    "cl_khr_image2d_from_buffer",
346
347    # Optional
348    "cl_khr_extended_versioning",
349    "cl_khr_fp64",
350    "cl_khr_icd",
351    "cl_khr_int64_base_atomics",
352    "cl_khr_int64_extended_atomics",
353]
354
355# Strip these suffixes from Context entry point names. NV is excluded (for now).
356strip_suffixes = ["ANGLE", "EXT", "KHR", "OES", "CHROMIUM"]
357
358# The EGL_ANGLE_explicit_context extension is generated differently from other extensions.
359# Toggle generation here.
360support_EGL_ANGLE_explicit_context = True
361
362# For ungrouped GLenum types
363default_enum_group_name = "DefaultGroup"
364
365# Group names that appear in command/param, but not present in groups/group
366unsupported_enum_group_names = {
367    'GetMultisamplePNameNV',
368    'BufferPNameARB',
369    'BufferPointerNameARB',
370    'VertexAttribPointerPropertyARB',
371    'VertexAttribPropertyARB',
372    'FenceParameterNameNV',
373    'FenceConditionNV',
374    'BufferPointerNameARB',
375    'MatrixIndexPointerTypeARB',
376    'PointParameterNameARB',
377    'ClampColorTargetARB',
378    'ClampColorModeARB',
379}
380
381# Versions (major, minor). Note that GLES intentionally places 1.0 last.
382DESKTOP_GL_VERSIONS = [(1, 0), (1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (2, 0), (2, 1), (3, 0),
383                       (3, 1), (3, 2), (3, 3), (4, 0), (4, 1), (4, 2), (4, 3), (4, 4), (4, 5),
384                       (4, 6)]
385GLES_VERSIONS = [(2, 0), (3, 0), (3, 1), (3, 2), (1, 0)]
386EGL_VERSIONS = [(1, 0), (1, 1), (1, 2), (1, 3), (1, 4), (1, 5)]
387WGL_VERSIONS = [(1, 0)]
388CL_VERSIONS = [(1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2), (3, 0)]
389
390
391# API types
392class apis:
393    GL = 'GL'
394    GLES = 'GLES'
395    WGL = 'WGL'
396    EGL = 'EGL'
397    CL = 'CL'
398
399
400def script_relative(path):
401    return os.path.join(os.path.dirname(sys.argv[0]), path)
402
403
404def path_to(folder, file):
405    return os.path.join(script_relative(".."), "src", folder, file)
406
407
408def strip_api_prefix(cmd_name):
409    return cmd_name.lstrip("cwegl")
410
411
412def get_cmd_name(command_node):
413    proto = command_node.find('proto')
414    cmd_name = proto.find('name').text
415    return cmd_name
416
417
418class CommandNames:
419
420    def __init__(self):
421        self.command_names = {}
422
423    def get_commands(self, version):
424        return self.command_names[version]
425
426    def get_all_commands(self):
427        cmd_names = []
428        # Combine all the version lists into a single list
429        for version, version_cmd_names in sorted(self.command_names.items()):
430            cmd_names += version_cmd_names
431
432        return cmd_names
433
434    def add_commands(self, version, commands):
435        # Add key if it doesn't exist
436        if version not in self.command_names:
437            self.command_names[version] = []
438        # Add the commands that aren't duplicates
439        self.command_names[version] += commands
440
441
442class RegistryXML:
443
444    def __init__(self, xml_file, ext_file=None):
445        tree = etree.parse(script_relative(xml_file))
446        self.root = tree.getroot()
447        if (ext_file):
448            self._AppendANGLEExts(ext_file)
449        self.all_commands = self.root.findall('commands/command')
450        self.all_cmd_names = CommandNames()
451        self.commands = {}
452
453    def _AppendANGLEExts(self, ext_file):
454        angle_ext_tree = etree.parse(script_relative(ext_file))
455        angle_ext_root = angle_ext_tree.getroot()
456
457        insertion_point = self.root.findall("./commands")[0]
458        for command in angle_ext_root.iter('commands'):
459            insertion_point.extend(command)
460
461        insertion_point = self.root.findall("./extensions")[0]
462        for extension in angle_ext_root.iter('extensions'):
463            insertion_point.extend(extension)
464
465        insertion_point = self.root
466        for enums in angle_ext_root.iter('enums'):
467            insertion_point.append(enums)
468
469    def AddCommands(self, feature_name, annotation):
470        xpath = ".//feature[@name='%s']//command" % feature_name
471        commands = [cmd.attrib['name'] for cmd in self.root.findall(xpath)]
472
473        # Remove commands that have already been processed
474        current_cmds = self.all_cmd_names.get_all_commands()
475        commands = [cmd for cmd in commands if cmd not in current_cmds]
476
477        self.all_cmd_names.add_commands(annotation, commands)
478        self.commands[annotation] = commands
479
480    def _ClassifySupport(self, extension):
481        supported = extension.attrib['supported']
482        if 'gles2' in supported:
483            return 'gl2ext'
484        elif 'gles1' in supported:
485            return 'glext'
486        elif 'egl' in supported:
487            return 'eglext'
488        elif 'wgl' in supported:
489            return 'wglext'
490        elif 'cl' in supported:
491            return 'clext'
492        else:
493            assert False, 'Cannot classify support for %s: %s' % (extension.attrib['name'],
494                                                                  supported)
495            return 'unknown'
496
497    def AddExtensionCommands(self, supported_extensions, apis):
498        # Use a first step to run through the extensions so we can generate them
499        # in sorted order.
500        self.ext_data = {}
501        self.ext_dupes = {}
502        ext_annotations = {}
503
504        for extension in self.root.findall("extensions/extension"):
505            extension_name = extension.attrib['name']
506            if not extension_name in supported_extensions:
507                continue
508
509            ext_annotations[extension_name] = self._ClassifySupport(extension)
510
511            ext_cmd_names = []
512
513            # There's an extra step here to filter out 'api=gl' extensions. This
514            # is necessary for handling KHR extensions, which have separate entry
515            # point signatures (without the suffix) for desktop GL. Note that this
516            # extra step is necessary because of Etree's limited Xpath support.
517            for require in extension.findall('require'):
518                if 'api' in require.attrib and require.attrib['api'] not in apis:
519                    continue
520
521                # A special case for EXT_texture_storage
522                filter_out_comment = "Supported only if GL_EXT_direct_state_access is supported"
523                if 'comment' in require.attrib and require.attrib['comment'] == filter_out_comment:
524                    continue
525
526                extension_commands = require.findall('command')
527                ext_cmd_names += [command.attrib['name'] for command in extension_commands]
528
529            self.ext_data[extension_name] = sorted(ext_cmd_names)
530
531        for extension_name, ext_cmd_names in sorted(self.ext_data.items()):
532
533            # Detect and filter duplicate extensions.
534            dupes = []
535            for ext_cmd in ext_cmd_names:
536                if ext_cmd in self.all_cmd_names.get_all_commands():
537                    dupes.append(ext_cmd)
538
539            for dupe in dupes:
540                ext_cmd_names.remove(dupe)
541
542            self.ext_data[extension_name] = sorted(ext_cmd_names)
543            self.ext_dupes[extension_name] = dupes
544            self.all_cmd_names.add_commands(ext_annotations[extension_name], ext_cmd_names)
545
546
547class EntryPoints:
548
549    def __init__(self, api, xml, commands):
550        self.api = api
551        self._cmd_info = []
552
553        for command_node in xml.all_commands:
554            cmd_name = get_cmd_name(command_node)
555
556            if api == apis.WGL:
557                cmd_name = cmd_name if cmd_name[:3] == 'wgl' else 'wgl' + cmd_name
558
559            if cmd_name not in commands:
560                continue
561
562            param_text = ["".join(param.itertext()) for param in command_node.findall('param')]
563
564            # Treat (void) as ()
565            if len(param_text) == 1 and param_text[0].strip() == 'void':
566                param_text = []
567
568            proto = command_node.find('proto')
569            proto_text = "".join(proto.itertext())
570
571            self._cmd_info.append((cmd_name, command_node, param_text, proto_text))
572
573    def get_infos(self):
574        return self._cmd_info
575