• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python2
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 sys
14import os
15import xml.etree.ElementTree as etree
16
17xml_inputs = [
18    'gl.xml',
19    'gl_angle_ext.xml',
20    'egl.xml',
21    'egl_angle_ext.xml',
22    'wgl.xml',
23    'registry_xml.py',
24]
25
26angle_extensions = [
27    # ANGLE extensions
28    "GL_CHROMIUM_bind_uniform_location",
29    "GL_CHROMIUM_framebuffer_mixed_samples",
30    "GL_CHROMIUM_path_rendering",
31    "GL_CHROMIUM_copy_texture",
32    "GL_CHROMIUM_copy_compressed_texture",
33    "GL_CHROMIUM_lose_context",
34    "GL_ANGLE_copy_texture_3d",
35    "GL_ANGLE_get_image",
36    "GL_ANGLE_program_binary",
37    "GL_ANGLE_request_extension",
38    "GL_ANGLE_robust_client_memory",
39    "GL_ANGLE_texture_external_update",
40]
41
42gles1_extensions = [
43    # ES1 (Possibly the min set of extensions needed by Android)
44    "GL_OES_draw_texture",
45    "GL_OES_framebuffer_object",
46    "GL_OES_matrix_palette",
47    "GL_OES_point_size_array",
48    "GL_OES_query_matrix",
49    "GL_OES_texture_cube_map",
50]
51
52gles_extensions = [
53    # ES2+
54    "GL_ANGLE_base_vertex_base_instance",
55    "GL_ANGLE_framebuffer_blit",
56    "GL_ANGLE_framebuffer_multisample",
57    "GL_ANGLE_instanced_arrays",
58    "GL_ANGLE_memory_object_fuchsia",
59    "GL_ANGLE_multi_draw",
60    "GL_ANGLE_provoking_vertex",
61    "GL_ANGLE_semaphore_fuchsia",
62    "GL_ANGLE_texture_multisample",
63    "GL_ANGLE_translated_shader_source",
64    "GL_EXT_blend_func_extended",
65    "GL_EXT_debug_marker",
66    "GL_EXT_discard_framebuffer",
67    "GL_EXT_disjoint_timer_query",
68    "GL_EXT_draw_buffers",
69    "GL_EXT_draw_buffers_indexed",
70    "GL_EXT_draw_elements_base_vertex",
71    "GL_EXT_EGL_image_array",
72    "GL_EXT_geometry_shader",
73    "GL_EXT_instanced_arrays",
74    "GL_EXT_map_buffer_range",
75    "GL_EXT_memory_object",
76    "GL_EXT_memory_object_fd",
77    "GL_EXT_multisampled_render_to_texture",
78    "GL_EXT_occlusion_query_boolean",
79    "GL_EXT_read_format_bgra",
80    "GL_EXT_robustness",
81    "GL_EXT_semaphore",
82    "GL_EXT_semaphore_fd",
83    "GL_EXT_sRGB",
84    "GL_EXT_texture_compression_bptc",
85    "GL_EXT_texture_compression_dxt1",
86    "GL_EXT_texture_compression_rgtc",
87    "GL_EXT_texture_compression_s3tc",
88    "GL_EXT_texture_compression_s3tc_srgb",
89    "GL_EXT_texture_cube_map_array",
90    "GL_EXT_texture_filter_anisotropic",
91    "GL_EXT_texture_format_BGRA8888",
92    "GL_EXT_texture_storage",
93    "GL_EXT_texture_sRGB_R8",
94    "GL_KHR_debug",
95    "GL_KHR_parallel_shader_compile",
96    "GL_NV_fence",
97    "GL_OES_compressed_ETC1_RGB8_texture",
98    "GL_EXT_compressed_ETC1_RGB8_sub_texture",
99    "GL_OES_depth32",
100    "GL_OES_draw_buffers_indexed",
101    "GL_OES_draw_elements_base_vertex",
102    "GL_OES_EGL_image",
103    "GL_OES_get_program_binary",
104    "GL_OES_mapbuffer",
105    "GL_OES_texture_3D",
106    "GL_OES_texture_border_clamp",
107    "GL_OES_texture_cube_map_array",
108    "GL_OES_texture_half_float",
109    "GL_OES_texture_storage_multisample_2d_array",
110    "GL_OES_vertex_array_object",
111    "GL_OVR_multiview",
112    "GL_OVR_multiview2",
113]
114
115supported_extensions = sorted(angle_extensions + gles1_extensions + gles_extensions)
116
117supported_egl_extensions = [
118    "EGL_ANDROID_blob_cache",
119    "EGL_ANDROID_framebuffer_target",
120    "EGL_ANDROID_get_frame_timestamps",
121    "EGL_ANDROID_get_native_client_buffer",
122    "EGL_ANDROID_native_fence_sync",
123    "EGL_ANDROID_presentation_time",
124    "EGL_ANGLE_d3d_share_handle_client_buffer",
125    "EGL_ANGLE_device_creation",
126    "EGL_ANGLE_device_d3d",
127    "EGL_ANGLE_feature_control",
128    "EGL_ANGLE_ggp_stream_descriptor",
129    "EGL_ANGLE_program_cache_control",
130    "EGL_ANGLE_query_surface_pointer",
131    "EGL_ANGLE_stream_producer_d3d_texture",
132    "EGL_ANGLE_surface_d3d_texture_2d_share_handle",
133    "EGL_ANGLE_swap_with_frame_token",
134    "EGL_ANGLE_window_fixed_size",
135    "EGL_CHROMIUM_sync_control",
136    "EGL_ANGLE_sync_control_rate",
137    "EGL_EXT_create_context_robustness",
138    "EGL_EXT_device_query",
139    "EGL_EXT_image_gl_colorspace",
140    "EGL_EXT_pixel_format_float",
141    "EGL_EXT_platform_base",
142    "EGL_EXT_platform_device",
143    "EGL_IMG_context_priority",
144    "EGL_KHR_debug",
145    "EGL_KHR_fence_sync",
146    "EGL_KHR_gl_colorspace",
147    "EGL_EXT_gl_colorspace_display_p3",
148    "EGL_EXT_gl_colorspace_display_p3_linear",
149    "EGL_EXT_gl_colorspace_display_p3_passthrough",
150    "EGL_EXT_gl_colorspace_scrgb",
151    "EGL_EXT_gl_colorspace_scrgb_linear",
152    "EGL_KHR_image",
153    "EGL_KHR_no_config_context",
154    "EGL_KHR_stream",
155    "EGL_KHR_stream_consumer_gltexture",
156    "EGL_KHR_surfaceless_context",
157    "EGL_KHR_swap_buffers_with_damage",
158    "EGL_KHR_wait_sync",
159    "EGL_NV_post_sub_buffer",
160    "EGL_NV_stream_consumer_gltexture_yuv",
161]
162
163# Strip these suffixes from Context entry point names. NV is excluded (for now).
164strip_suffixes = ["ANGLE", "EXT", "KHR", "OES", "CHROMIUM"]
165
166# The EGL_ANGLE_explicit_context extension is generated differently from other extensions.
167# Toggle generation here.
168support_EGL_ANGLE_explicit_context = True
169
170# For ungrouped GLenum types
171default_enum_group_name = "DefaultGroup"
172
173# Group names that appear in command/param, but not present in groups/group
174unsupported_enum_group_names = {
175    'GetMultisamplePNameNV',
176    'BufferPNameARB',
177    'BufferPointerNameARB',
178    'VertexAttribPointerPropertyARB',
179    'VertexAttribPropertyARB',
180    'FenceParameterNameNV',
181    'FenceConditionNV',
182    'BufferPointerNameARB',
183    'MatrixIndexPointerTypeARB',
184    'PointParameterNameARB',
185    'ClampColorTargetARB',
186    'ClampColorModeARB',
187}
188
189
190def script_relative(path):
191    return os.path.join(os.path.dirname(sys.argv[0]), path)
192
193
194def path_to(folder, file):
195    return os.path.join(script_relative(".."), "src", folder, file)
196
197
198class GLCommandNames:
199
200    def __init__(self):
201        self.command_names = {}
202
203    def get_commands(self, version):
204        return self.command_names[version]
205
206    def get_all_commands(self):
207        cmd_names = []
208        # Combine all the version lists into a single list
209        for version, version_cmd_names in sorted(self.command_names.iteritems()):
210            cmd_names += version_cmd_names
211
212        return cmd_names
213
214    def add_commands(self, version, commands):
215        # Add key if it doesn't exist
216        if version not in self.command_names:
217            self.command_names[version] = []
218        # Add the commands that aren't duplicates
219        self.command_names[version] += commands
220
221
222class RegistryXML:
223
224    def __init__(self, xml_file, ext_file=None):
225        tree = etree.parse(script_relative(xml_file))
226        self.root = tree.getroot()
227        if (ext_file):
228            self._AppendANGLEExts(ext_file)
229        self.all_commands = self.root.findall('commands/command')
230        self.all_cmd_names = GLCommandNames()
231        self.commands = {}
232
233    def _AppendANGLEExts(self, ext_file):
234        angle_ext_tree = etree.parse(script_relative(ext_file))
235        angle_ext_root = angle_ext_tree.getroot()
236
237        insertion_point = self.root.findall("./commands")[0]
238        for command in angle_ext_root.iter('commands'):
239            insertion_point.extend(command)
240
241        insertion_point = self.root.findall("./extensions")[0]
242        for extension in angle_ext_root.iter('extensions'):
243            insertion_point.extend(extension)
244
245        insertion_point = self.root
246        for enums in angle_ext_root.iter('enums'):
247            insertion_point.append(enums)
248
249    def AddCommands(self, feature_name, annotation):
250        xpath = ".//feature[@name='%s']//command" % feature_name
251        commands = [cmd.attrib['name'] for cmd in self.root.findall(xpath)]
252
253        # Remove commands that have already been processed
254        current_cmds = self.all_cmd_names.get_all_commands()
255        commands = [cmd for cmd in commands if cmd not in current_cmds]
256
257        self.all_cmd_names.add_commands(annotation, commands)
258        self.commands[annotation] = commands
259
260    def _ClassifySupport(self, supported):
261        if 'gles2' in supported:
262            return 'gl2ext'
263        elif 'gles1' in supported:
264            return 'glext'
265        elif 'egl' in supported:
266            return 'eglext'
267        elif 'wgl' in supported:
268            return 'wglext'
269        else:
270            assert False
271            return 'unknown'
272
273    def AddExtensionCommands(self, supported_extensions, apis):
274        # Use a first step to run through the extensions so we can generate them
275        # in sorted order.
276        self.ext_data = {}
277        self.ext_dupes = {}
278        ext_annotations = {}
279
280        for extension in self.root.findall("extensions/extension"):
281            extension_name = extension.attrib['name']
282            if not extension_name in supported_extensions:
283                continue
284
285            ext_annotations[extension_name] = self._ClassifySupport(extension.attrib['supported'])
286
287            ext_cmd_names = []
288
289            # There's an extra step here to filter out 'api=gl' extensions. This
290            # is necessary for handling KHR extensions, which have separate entry
291            # point signatures (without the suffix) for desktop GL. Note that this
292            # extra step is necessary because of Etree's limited Xpath support.
293            for require in extension.findall('require'):
294                if 'api' in require.attrib and require.attrib['api'] not in apis:
295                    continue
296
297                # A special case for EXT_texture_storage
298                filter_out_comment = "Supported only if GL_EXT_direct_state_access is supported"
299                if 'comment' in require.attrib and require.attrib['comment'] == filter_out_comment:
300                    continue
301
302                extension_commands = require.findall('command')
303                ext_cmd_names += [command.attrib['name'] for command in extension_commands]
304
305            self.ext_data[extension_name] = sorted(ext_cmd_names)
306
307        for extension_name, ext_cmd_names in sorted(self.ext_data.iteritems()):
308
309            # Detect and filter duplicate extensions.
310            dupes = []
311            for ext_cmd in ext_cmd_names:
312                if ext_cmd in self.all_cmd_names.get_all_commands():
313                    dupes.append(ext_cmd)
314
315            for dupe in dupes:
316                ext_cmd_names.remove(dupe)
317
318            self.ext_data[extension_name] = sorted(ext_cmd_names)
319            self.ext_dupes[extension_name] = dupes
320            self.all_cmd_names.add_commands(ext_annotations[extension_name], ext_cmd_names)
321