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