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