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