Jeff Gilbert | 1b605ee | 2017-10-30 18:41:46 -0700 | [diff] [blame] | 1 | #!/usr/bin/python2 |
Jamie Madill | 2e16d96 | 2017-04-19 14:06:36 -0400 | [diff] [blame] | 2 | # |
| 3 | # Copyright 2017 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 | # generate_entry_points.py: |
| 8 | # Generates the OpenGL bindings and entry point layers for ANGLE. |
| 9 | |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 10 | import sys, os, pprint, json |
Jamie Madill | 2e16d96 | 2017-04-19 14:06:36 -0400 | [diff] [blame] | 11 | import xml.etree.ElementTree as etree |
| 12 | from datetime import date |
| 13 | |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 14 | # List of supported extensions. Add to this list to enable new extensions |
| 15 | # available in gl.xml. |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 16 | |
| 17 | angle_extensions = [ |
| 18 | # ANGLE extensions |
| 19 | "GL_CHROMIUM_bind_uniform_location", |
| 20 | "GL_CHROMIUM_framebuffer_mixed_samples", |
| 21 | "GL_CHROMIUM_path_rendering", |
| 22 | "GL_CHROMIUM_copy_texture", |
| 23 | "GL_CHROMIUM_copy_compressed_texture", |
| 24 | "GL_ANGLE_request_extension", |
| 25 | "GL_ANGLE_robust_client_memory", |
| 26 | "GL_ANGLE_multiview", |
Brandon Jones | 4e6f2ae | 2018-09-19 11:09:51 -0700 | [diff] [blame^] | 27 | "GL_ANGLE_copy_texture_3d", |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 28 | ] |
| 29 | |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 30 | gles1_extensions = [ |
| 31 | # ES1 (Possibly the min set of extensions needed by Android) |
| 32 | "GL_OES_draw_texture", |
| 33 | "GL_OES_framebuffer_object", |
| 34 | "GL_OES_matrix_palette", |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 35 | "GL_OES_point_size_array", |
| 36 | "GL_OES_query_matrix", |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 37 | "GL_OES_texture_cube_map", |
| 38 | ] |
| 39 | |
| 40 | # List of GLES1 extensions for which we don't need to add Context.h decls. |
| 41 | gles1_no_context_decl_extensions = [ |
| 42 | "GL_OES_framebuffer_object", |
| 43 | ] |
| 44 | |
| 45 | # List of GLES1 API calls that have had their semantics changed in later GLES versions, but the |
| 46 | # name was kept the same |
| 47 | gles1_overloaded = [ |
| 48 | "glGetPointerv", |
| 49 | ] |
| 50 | |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 51 | supported_extensions = sorted(angle_extensions + gles1_extensions + [ |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 52 | # ES2+ |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 53 | "GL_ANGLE_framebuffer_blit", |
| 54 | "GL_ANGLE_framebuffer_multisample", |
| 55 | "GL_ANGLE_instanced_arrays", |
| 56 | "GL_ANGLE_translated_shader_source", |
| 57 | "GL_EXT_debug_marker", |
| 58 | "GL_EXT_discard_framebuffer", |
| 59 | "GL_EXT_disjoint_timer_query", |
| 60 | "GL_EXT_draw_buffers", |
Jiawei Shao | 5f9482f | 2018-05-18 09:00:09 +0800 | [diff] [blame] | 61 | "GL_EXT_geometry_shader", |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 62 | "GL_EXT_map_buffer_range", |
| 63 | "GL_EXT_occlusion_query_boolean", |
| 64 | "GL_EXT_robustness", |
| 65 | "GL_EXT_texture_storage", |
| 66 | "GL_KHR_debug", |
| 67 | "GL_NV_fence", |
| 68 | "GL_OES_EGL_image", |
| 69 | "GL_OES_get_program_binary", |
| 70 | "GL_OES_mapbuffer", |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 71 | "GL_OES_texture_storage_multisample_2d_array", |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 72 | "GL_OES_vertex_array_object", |
jchen10 | 82af620 | 2018-06-22 10:59:52 +0800 | [diff] [blame] | 73 | "GL_KHR_parallel_shader_compile", |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 74 | ]) |
| 75 | |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 76 | # The EGL_ANGLE_explicit_context extension is generated differently from other extensions. |
| 77 | # Toggle generation here. |
| 78 | support_EGL_ANGLE_explicit_context = True |
| 79 | |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 80 | # This is a list of exceptions for entry points which don't want to have |
| 81 | # the EVENT macro. This is required for some debug marker entry points. |
| 82 | no_event_marker_exceptions_list = sorted([ |
| 83 | "glPushGroupMarkerEXT", |
| 84 | "glPopGroupMarkerEXT", |
| 85 | "glInsertEventMarkerEXT", |
| 86 | ]) |
| 87 | |
| 88 | # Strip these suffixes from Context entry point names. NV is excluded (for now). |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 89 | strip_suffixes = ["ANGLE", "EXT", "KHR", "OES", "CHROMIUM"] |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 90 | |
Jamie Madill | 2e16d96 | 2017-04-19 14:06:36 -0400 | [diff] [blame] | 91 | template_entry_point_header = """// GENERATED FILE - DO NOT EDIT. |
| 92 | // Generated by {script_name} using data from {data_source_name}. |
| 93 | // |
| 94 | // Copyright {year} The ANGLE Project Authors. All rights reserved. |
| 95 | // Use of this source code is governed by a BSD-style license that can be |
| 96 | // found in the LICENSE file. |
| 97 | // |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 98 | // entry_points_gles_{annotation_lower}_autogen.h: |
| 99 | // Defines the GLES {comment} entry points. |
Jamie Madill | 2e16d96 | 2017-04-19 14:06:36 -0400 | [diff] [blame] | 100 | |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 101 | #ifndef LIBGLESV2_ENTRY_POINTS_GLES_{annotation_upper}_AUTOGEN_H_ |
| 102 | #define LIBGLESV2_ENTRY_POINTS_GLES_{annotation_upper}_AUTOGEN_H_ |
Jamie Madill | 2e16d96 | 2017-04-19 14:06:36 -0400 | [diff] [blame] | 103 | |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 104 | {includes} |
| 105 | |
Jamie Madill | 2e16d96 | 2017-04-19 14:06:36 -0400 | [diff] [blame] | 106 | namespace gl |
| 107 | {{ |
| 108 | {entry_points} |
| 109 | }} // namespace gl |
| 110 | |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 111 | #endif // LIBGLESV2_ENTRY_POINTS_GLES_{annotation_upper}_AUTOGEN_H_ |
Jamie Madill | 2e16d96 | 2017-04-19 14:06:36 -0400 | [diff] [blame] | 112 | """ |
| 113 | |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 114 | template_entry_point_source = """// GENERATED FILE - DO NOT EDIT. |
| 115 | // Generated by {script_name} using data from {data_source_name}. |
| 116 | // |
| 117 | // Copyright {year} The ANGLE Project Authors. All rights reserved. |
| 118 | // Use of this source code is governed by a BSD-style license that can be |
| 119 | // found in the LICENSE file. |
| 120 | // |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 121 | // entry_points_gles_{annotation_lower}_autogen.cpp: |
| 122 | // Defines the GLES {comment} entry points. |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 123 | |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 124 | {includes} |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 125 | |
| 126 | namespace gl |
| 127 | {{ |
| 128 | {entry_points}}} // namespace gl |
| 129 | """ |
| 130 | |
| 131 | template_entry_points_enum_header = """// GENERATED FILE - DO NOT EDIT. |
| 132 | // Generated by {script_name} using data from {data_source_name}. |
| 133 | // |
| 134 | // Copyright {year} The ANGLE Project Authors. All rights reserved. |
| 135 | // Use of this source code is governed by a BSD-style license that can be |
| 136 | // found in the LICENSE file. |
| 137 | // |
| 138 | // entry_points_enum_autogen.h: |
| 139 | // Defines the GLES entry points enumeration. |
| 140 | |
| 141 | #ifndef LIBGLESV2_ENTRYPOINTSENUM_AUTOGEN_H_ |
| 142 | #define LIBGLESV2_ENTRYPOINTSENUM_AUTOGEN_H_ |
| 143 | |
| 144 | namespace gl |
| 145 | {{ |
| 146 | enum class EntryPoint |
| 147 | {{ |
| 148 | {entry_points_list} |
| 149 | }}; |
| 150 | }} // namespace gl |
| 151 | #endif // LIBGLESV2_ENTRY_POINTS_ENUM_AUTOGEN_H_ |
| 152 | """ |
| 153 | |
Brandon Jones | 41e59f5 | 2018-05-02 12:45:28 -0700 | [diff] [blame] | 154 | template_libgles_entry_point_source = """// GENERATED FILE - DO NOT EDIT. |
| 155 | // Generated by {script_name} using data from {data_source_name}. |
| 156 | // |
| 157 | // Copyright {year} The ANGLE Project Authors. All rights reserved. |
| 158 | // Use of this source code is governed by a BSD-style license that can be |
| 159 | // found in the LICENSE file. |
| 160 | // |
| 161 | // libGLESv2.cpp: Implements the exported OpenGL ES functions. |
| 162 | |
| 163 | {includes} |
| 164 | extern "C" {{ |
| 165 | {entry_points} |
| 166 | }} // extern "C" |
| 167 | """ |
| 168 | |
| 169 | template_libgles_entry_point_export = """; GENERATED FILE - DO NOT EDIT. |
| 170 | ; Generated by {script_name} using data from {data_source_name}. |
| 171 | ; |
| 172 | ; Copyright {year} The ANGLE Project Authors. All rights reserved. |
| 173 | ; Use of this source code is governed by a BSD-style license that can be |
| 174 | ; found in the LICENSE file. |
| 175 | LIBRARY libGLESv2 |
| 176 | EXPORTS |
| 177 | {exports} |
| 178 | """ |
| 179 | |
Jamie Madill | 2e16d96 | 2017-04-19 14:06:36 -0400 | [diff] [blame] | 180 | template_entry_point_decl = """ANGLE_EXPORT {return_type}GL_APIENTRY {name}({params});""" |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 181 | template_entry_point_decl = """ANGLE_EXPORT {return_type}GL_APIENTRY {name}{explicit_context_suffix}({explicit_context_param}{explicit_context_comma}{params});""" |
Jamie Madill | 2e16d96 | 2017-04-19 14:06:36 -0400 | [diff] [blame] | 182 | |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 183 | template_entry_point_def = """{return_type}GL_APIENTRY {name}{explicit_context_suffix}({explicit_context_param}{explicit_context_comma}{params}) |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 184 | {{ |
Geoff Lang | b02fc66 | 2018-08-21 09:48:01 -0400 | [diff] [blame] | 185 | ANGLE_SCOPED_GLOBAL_LOCK(); |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 186 | {event_comment}EVENT("({format_params})"{comma_if_needed}{pass_params}); |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 187 | |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 188 | Context *context = {context_getter}; |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 189 | if (context) |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 190 | {{{assert_explicit_context}{packed_gl_enum_conversions} |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 191 | context->gatherParams<EntryPoint::{name}>({internal_params}); |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 192 | |
Jamie Madill | 53d3841 | 2017-04-20 11:33:00 -0400 | [diff] [blame] | 193 | if (context->skipValidation() || Validate{name}({validate_params})) |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 194 | {{ |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 195 | {return_if_needed}context->{name_lower_no_suffix}({internal_params}); |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 196 | }} |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 197 | }} |
| 198 | {default_return_if_needed}}} |
| 199 | """ |
| 200 | |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 201 | context_gles_header = """// GENERATED FILE - DO NOT EDIT. |
| 202 | // Generated by {script_name} using data from {data_source_name}. |
| 203 | // |
| 204 | // Copyright {year} The ANGLE Project Authors. All rights reserved. |
| 205 | // Use of this source code is governed by a BSD-style license that can be |
| 206 | // found in the LICENSE file. |
| 207 | // |
| 208 | // Context_gles_{annotation_lower}_autogen.h: Creates a macro for interfaces in Context. |
| 209 | |
| 210 | #ifndef ANGLE_CONTEXT_GLES_{annotation_upper}_AUTOGEN_H_ |
| 211 | #define ANGLE_CONTEXT_GLES_{annotation_upper}_AUTOGEN_H_ |
| 212 | |
| 213 | #define ANGLE_GLES1_CONTEXT_API \\ |
| 214 | {interface} |
| 215 | |
| 216 | #endif // ANGLE_CONTEXT_API_{annotation_upper}_AUTOGEN_H_ |
| 217 | """ |
| 218 | |
| 219 | context_gles_decl = """ {return_type} {name_lower_no_suffix}({internal_params}); \\""" |
| 220 | |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 221 | libgles_entry_point_def = """{return_type}GL_APIENTRY gl{name}{explicit_context_suffix}({explicit_context_param}{explicit_context_comma}{params}) |
Brandon Jones | 41e59f5 | 2018-05-02 12:45:28 -0700 | [diff] [blame] | 222 | {{ |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 223 | return gl::{name}{explicit_context_suffix}({explicit_context_internal_param}{explicit_context_comma}{internal_params}); |
Brandon Jones | 41e59f5 | 2018-05-02 12:45:28 -0700 | [diff] [blame] | 224 | }} |
| 225 | """ |
| 226 | |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 227 | libgles_entry_point_export = """ {name}{explicit_context_suffix}{spaces}@{ordinal}""" |
| 228 | |
| 229 | template_glext_explicit_context_inc = """// GENERATED FILE - DO NOT EDIT. |
| 230 | // Generated by {script_name} using data from {data_source_name}. |
| 231 | // |
| 232 | // Copyright {year} The ANGLE Project Authors. All rights reserved. |
| 233 | // Use of this source code is governed by a BSD-style license that can be |
| 234 | // found in the LICENSE file. |
| 235 | // |
| 236 | // gl{version}ext_explicit_context_autogen.inc: |
| 237 | // Function declarations for the EGL_ANGLE_explicit_context extension |
| 238 | |
| 239 | {function_pointers} |
| 240 | #ifdef GL_GLEXT_PROTOTYPES |
| 241 | {function_prototypes} |
| 242 | #endif |
| 243 | """ |
| 244 | |
| 245 | template_glext_function_pointer = """typedef {return_type}(GL_APIENTRYP PFN{name_upper}{explicit_context_suffix_upper})({explicit_context_param}{explicit_context_comma}{params});""" |
| 246 | template_glext_function_prototype = """{apicall} {return_type}GL_APIENTRY {name}{explicit_context_suffix}({explicit_context_param}{explicit_context_comma}{params});""" |
Brandon Jones | 41e59f5 | 2018-05-02 12:45:28 -0700 | [diff] [blame] | 247 | |
Jamie Madill | 16daadb | 2017-08-26 23:34:31 -0400 | [diff] [blame] | 248 | def script_relative(path): |
| 249 | return os.path.join(os.path.dirname(sys.argv[0]), path) |
| 250 | |
| 251 | tree = etree.parse(script_relative('gl.xml')) |
| 252 | root = tree.getroot() |
Jamie Madill | 2e16d96 | 2017-04-19 14:06:36 -0400 | [diff] [blame] | 253 | commands = root.find(".//commands[@namespace='GL']") |
Jamie Madill | 2e16d96 | 2017-04-19 14:06:36 -0400 | [diff] [blame] | 254 | |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 255 | with open(script_relative('entry_point_packed_gl_enums.json')) as f: |
| 256 | cmd_packed_gl_enums = json.loads(f.read()) |
| 257 | |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 258 | def format_entry_point_decl(cmd_name, proto, params, is_explicit_context): |
| 259 | comma_if_needed = ", " if len(params) > 0 else "" |
Jamie Madill | 2e16d96 | 2017-04-19 14:06:36 -0400 | [diff] [blame] | 260 | return template_entry_point_decl.format( |
| 261 | name = cmd_name[2:], |
| 262 | return_type = proto[:-len(cmd_name)], |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 263 | params = ", ".join(params), |
| 264 | comma_if_needed = comma_if_needed, |
| 265 | explicit_context_suffix = "ContextANGLE" if is_explicit_context else "", |
| 266 | explicit_context_param = "GLeglContext ctx" if is_explicit_context else "", |
| 267 | explicit_context_comma = ", " if is_explicit_context and len(params) > 0 else "") |
Jamie Madill | 2e16d96 | 2017-04-19 14:06:36 -0400 | [diff] [blame] | 268 | |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 269 | def type_name_sep_index(param): |
| 270 | space = param.rfind(" ") |
| 271 | pointer = param.rfind("*") |
| 272 | return max(space, pointer) |
| 273 | |
| 274 | def just_the_type(param): |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 275 | if "*" in param: |
| 276 | return param[:type_name_sep_index(param) + 1] |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 277 | return param[:type_name_sep_index(param)] |
| 278 | |
| 279 | def just_the_name(param): |
| 280 | return param[type_name_sep_index(param)+1:] |
| 281 | |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 282 | def make_param(param_type, param_name): |
| 283 | return param_type + " " + param_name |
| 284 | |
| 285 | def just_the_type_packed(param, entry): |
| 286 | name = just_the_name(param) |
| 287 | if entry.has_key(name): |
| 288 | return entry[name] |
| 289 | else: |
| 290 | return just_the_type(param) |
| 291 | |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 292 | def just_the_name_packed(param, reserved_set): |
| 293 | name = just_the_name(param) |
| 294 | if name in reserved_set: |
| 295 | return name + 'Packed' |
| 296 | else: |
| 297 | return name |
| 298 | |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 299 | format_dict = { |
| 300 | "GLbitfield": "0x%X", |
| 301 | "GLboolean": "%u", |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 302 | "GLclampx": "0x%X", |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 303 | "GLenum": "0x%X", |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 304 | "GLfixed": "0x%X", |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 305 | "GLfloat": "%f", |
| 306 | "GLint": "%d", |
| 307 | "GLintptr": "%d", |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 308 | "GLshort": "%d", |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 309 | "GLsizei": "%d", |
| 310 | "GLsizeiptr": "%d", |
Jamie Madill | 16daadb | 2017-08-26 23:34:31 -0400 | [diff] [blame] | 311 | "GLsync": "0x%0.8p", |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 312 | "GLubyte": "%d", |
Jamie Madill | ff161f8 | 2017-08-26 23:49:10 -0400 | [diff] [blame] | 313 | "GLuint": "%u", |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 314 | "GLuint64": "%llu", |
| 315 | "GLDEBUGPROC": "0x%0.8p", |
| 316 | "GLDEBUGPROCKHR": "0x%0.8p", |
| 317 | "GLeglImageOES": "0x%0.8p", |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | def param_format_string(param): |
| 321 | if "*" in param: |
| 322 | return param + " = 0x%0.8p" |
| 323 | else: |
Jamie Madill | 16daadb | 2017-08-26 23:34:31 -0400 | [diff] [blame] | 324 | type_only = just_the_type(param) |
| 325 | if type_only not in format_dict: |
| 326 | raise Exception(type_only + " is not a known type in 'format_dict'") |
| 327 | |
| 328 | return param + " = " + format_dict[type_only] |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 329 | |
Jamie Madill | 2e29b13 | 2017-08-28 17:22:11 -0400 | [diff] [blame] | 330 | def default_return_value(cmd_name, return_type): |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 331 | if return_type == "void": |
| 332 | return "" |
Jamie Madill | 2e29b13 | 2017-08-28 17:22:11 -0400 | [diff] [blame] | 333 | return "GetDefaultReturnValue<EntryPoint::" + cmd_name[2:] + ", " + return_type + ">()" |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 334 | |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 335 | def get_context_getter_function(cmd_name, is_explicit_context): |
Geoff Lang | cae72d6 | 2017-06-01 11:53:45 -0400 | [diff] [blame] | 336 | if cmd_name == "glGetError": |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 337 | return "GetGlobalContext()" |
| 338 | elif is_explicit_context: |
| 339 | return "static_cast<gl::Context *>(ctx)" |
Geoff Lang | cae72d6 | 2017-06-01 11:53:45 -0400 | [diff] [blame] | 340 | else: |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 341 | return "GetValidGlobalContext()" |
Geoff Lang | cae72d6 | 2017-06-01 11:53:45 -0400 | [diff] [blame] | 342 | |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 343 | template_event_comment = """// Don't run an EVENT() macro on the EXT_debug_marker entry points. |
| 344 | // It can interfere with the debug events being set by the caller. |
| 345 | // """ |
| 346 | |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 347 | def format_entry_point_def(cmd_name, proto, params, is_explicit_context): |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 348 | packed_gl_enums = cmd_packed_gl_enums.get(cmd_name, {}) |
| 349 | internal_params = [just_the_name_packed(param, packed_gl_enums) for param in params] |
| 350 | packed_gl_enum_conversions = [] |
| 351 | for param in params: |
| 352 | name = just_the_name(param) |
| 353 | if name in packed_gl_enums: |
| 354 | internal_name = name + "Packed" |
| 355 | internal_type = packed_gl_enums[name] |
| 356 | packed_gl_enum_conversions += ["\n " + internal_type + " " + internal_name +" = FromGLenum<" + |
| 357 | internal_type + ">(" + name + ");"] |
| 358 | |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 359 | pass_params = [just_the_name(param) for param in params] |
| 360 | format_params = [param_format_string(param) for param in params] |
| 361 | return_type = proto[:-len(cmd_name)] |
Jamie Madill | 2e29b13 | 2017-08-28 17:22:11 -0400 | [diff] [blame] | 362 | default_return = default_return_value(cmd_name, return_type.strip()) |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 363 | event_comment = template_event_comment if cmd_name in no_event_marker_exceptions_list else "" |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 364 | name_lower_no_suffix = cmd_name[2:3].lower() + cmd_name[3:] |
| 365 | |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 366 | for suffix in strip_suffixes: |
| 367 | if name_lower_no_suffix.endswith(suffix): |
| 368 | name_lower_no_suffix = name_lower_no_suffix[0:-len(suffix)] |
| 369 | |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 370 | return template_entry_point_def.format( |
| 371 | name = cmd_name[2:], |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 372 | name_lower_no_suffix = name_lower_no_suffix, |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 373 | return_type = return_type, |
| 374 | params = ", ".join(params), |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 375 | internal_params = ", ".join(internal_params), |
| 376 | packed_gl_enum_conversions = "".join(packed_gl_enum_conversions), |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 377 | pass_params = ", ".join(pass_params), |
| 378 | comma_if_needed = ", " if len(params) > 0 else "", |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 379 | validate_params = ", ".join(["context"] + internal_params), |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 380 | format_params = ", ".join(format_params), |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 381 | return_if_needed = "" if default_return == "" else "return ", |
Geoff Lang | cae72d6 | 2017-06-01 11:53:45 -0400 | [diff] [blame] | 382 | default_return_if_needed = "" if default_return == "" else "\n return " + default_return + ";\n", |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 383 | context_getter = get_context_getter_function(cmd_name, is_explicit_context), |
| 384 | event_comment = event_comment, |
| 385 | explicit_context_suffix = "ContextANGLE" if is_explicit_context else "", |
| 386 | explicit_context_param = "GLeglContext ctx" if is_explicit_context else "", |
| 387 | explicit_context_comma = ", " if is_explicit_context and len(params) > 0 else "", |
| 388 | assert_explicit_context = "\nASSERT(context == GetValidGlobalContext());" |
| 389 | if is_explicit_context else "") |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 390 | |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 391 | def format_context_gles_decl(cmd_name, proto, params): |
| 392 | packed_gl_enums = cmd_packed_gl_enums.get(cmd_name, {}) |
| 393 | internal_params = ", ".join([make_param(just_the_type_packed(param, packed_gl_enums), |
| 394 | just_the_name_packed(param, packed_gl_enums)) for param in params]) |
| 395 | |
| 396 | return_type = proto[:-len(cmd_name)] |
| 397 | name_lower_no_suffix = cmd_name[2:3].lower() + cmd_name[3:] |
| 398 | |
| 399 | for suffix in strip_suffixes: |
| 400 | if name_lower_no_suffix.endswith(suffix): |
| 401 | name_lower_no_suffix = name_lower_no_suffix[0:-len(suffix)] |
| 402 | |
| 403 | return context_gles_decl.format( |
| 404 | return_type = return_type, |
| 405 | name_lower_no_suffix = name_lower_no_suffix, |
| 406 | internal_params = internal_params) |
| 407 | |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 408 | def format_libgles_entry_point_def(cmd_name, proto, params, is_explicit_context): |
Brandon Jones | 41e59f5 | 2018-05-02 12:45:28 -0700 | [diff] [blame] | 409 | internal_params = [just_the_name(param) for param in params] |
| 410 | return_type = proto[:-len(cmd_name)] |
| 411 | |
| 412 | return libgles_entry_point_def.format( |
| 413 | name = cmd_name[2:], |
| 414 | return_type = return_type, |
| 415 | params = ", ".join(params), |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 416 | internal_params = ", ".join(internal_params), |
| 417 | explicit_context_suffix = "ContextANGLE" if is_explicit_context else "", |
| 418 | explicit_context_param = "GLeglContext ctx" if is_explicit_context else "", |
| 419 | explicit_context_comma = ", " if is_explicit_context and len(params) > 0 else "", |
| 420 | explicit_context_internal_param = "ctx" if is_explicit_context else "") |
Brandon Jones | 41e59f5 | 2018-05-02 12:45:28 -0700 | [diff] [blame] | 421 | |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 422 | def format_libgles_entry_point_export(cmd_name, ordinal, is_explicit_context): |
Brandon Jones | 41e59f5 | 2018-05-02 12:45:28 -0700 | [diff] [blame] | 423 | return libgles_entry_point_export.format( |
| 424 | name = cmd_name, |
| 425 | ordinal = ordinal, |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 426 | spaces = " "*(50 - len(cmd_name)), |
| 427 | explicit_context_suffix = "ContextANGLE" if is_explicit_context else "") |
Brandon Jones | 41e59f5 | 2018-05-02 12:45:28 -0700 | [diff] [blame] | 428 | |
Jiajia Qin | cb59a90 | 2017-11-22 13:03:42 +0800 | [diff] [blame] | 429 | def path_to(folder, file): |
| 430 | return os.path.join(script_relative(".."), "src", folder, file) |
Jamie Madill | 2e16d96 | 2017-04-19 14:06:36 -0400 | [diff] [blame] | 431 | |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 432 | def get_entry_points(all_commands, gles_commands, ordinal, is_explicit_context): |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 433 | decls = [] |
| 434 | defs = [] |
Brandon Jones | 41e59f5 | 2018-05-02 12:45:28 -0700 | [diff] [blame] | 435 | export_defs = [] |
| 436 | exports = [] |
| 437 | |
Jamie Madill | ffa2cd0 | 2017-12-28 14:57:53 -0500 | [diff] [blame] | 438 | for command in all_commands: |
| 439 | proto = command.find('proto') |
| 440 | cmd_name = proto.find('name').text |
| 441 | |
| 442 | if cmd_name not in gles_commands: |
| 443 | continue |
| 444 | |
| 445 | param_text = ["".join(param.itertext()) for param in command.findall('param')] |
| 446 | proto_text = "".join(proto.itertext()) |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 447 | decls.append(format_entry_point_decl(cmd_name, proto_text, param_text, |
| 448 | is_explicit_context)) |
| 449 | defs.append(format_entry_point_def(cmd_name, proto_text, param_text, is_explicit_context)) |
Brandon Jones | 41e59f5 | 2018-05-02 12:45:28 -0700 | [diff] [blame] | 450 | |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 451 | export_defs.append(format_libgles_entry_point_def(cmd_name, proto_text, param_text, |
| 452 | is_explicit_context)) |
| 453 | exports.append(format_libgles_entry_point_export(cmd_name, ordinal, is_explicit_context)) |
Brandon Jones | 41e59f5 | 2018-05-02 12:45:28 -0700 | [diff] [blame] | 454 | ordinal = ordinal + 1 |
| 455 | |
| 456 | return decls, defs, export_defs, exports |
Jamie Madill | 16daadb | 2017-08-26 23:34:31 -0400 | [diff] [blame] | 457 | |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 458 | def get_gles1_decls(all_commands, gles_commands): |
| 459 | decls = [] |
| 460 | for command in all_commands: |
| 461 | proto = command.find('proto') |
| 462 | cmd_name = proto.find('name').text |
| 463 | |
| 464 | if cmd_name not in gles_commands: |
| 465 | continue |
| 466 | |
| 467 | if cmd_name in gles1_overloaded: |
| 468 | continue |
| 469 | |
| 470 | param_text = ["".join(param.itertext()) for param in command.findall('param')] |
| 471 | proto_text = "".join(proto.itertext()) |
| 472 | decls.append(format_context_gles_decl(cmd_name, proto_text, param_text)) |
| 473 | |
| 474 | return decls |
| 475 | |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 476 | def get_glext_decls(all_commands, gles_commands, version, is_explicit_context): |
| 477 | glext_ptrs = [] |
| 478 | glext_protos = [] |
| 479 | is_gles1 = False |
| 480 | |
| 481 | if(version == ""): |
| 482 | is_gles1 = True |
| 483 | |
| 484 | for command in all_commands: |
| 485 | proto = command.find('proto') |
| 486 | cmd_name = proto.find('name').text |
| 487 | |
| 488 | if cmd_name not in gles_commands: |
| 489 | continue |
| 490 | |
| 491 | param_text = ["".join(param.itertext()) for param in command.findall('param')] |
| 492 | proto_text = "".join(proto.itertext()) |
| 493 | |
| 494 | return_type = proto_text[:-len(cmd_name)] |
| 495 | params = ", ".join(param_text) |
| 496 | |
| 497 | format_params = { |
| 498 | "apicall": "GL_API" if is_gles1 else "GL_APICALL", |
| 499 | "name": cmd_name, |
| 500 | "name_upper": cmd_name.upper(), |
| 501 | "return_type": return_type, |
| 502 | "params": params, |
| 503 | "explicit_context_comma": ", " if is_explicit_context and len(params) > 0 else "", |
| 504 | "explicit_context_suffix": "ContextANGLE" if is_explicit_context else "", |
| 505 | "explicit_context_suffix_upper": "CONTEXTANGLE" if is_explicit_context else "", |
| 506 | "explicit_context_param": "GLeglContext ctx" if is_explicit_context else ""} |
| 507 | |
| 508 | glext_ptrs.append(template_glext_function_pointer.format( |
| 509 | **format_params)) |
| 510 | glext_protos.append(template_glext_function_prototype.format( |
| 511 | **format_params)) |
| 512 | |
| 513 | return glext_ptrs, glext_protos |
| 514 | |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 515 | def write_file(annotation, comment, template, entry_points, suffix, includes, file): |
Jiajia Qin | cb59a90 | 2017-11-22 13:03:42 +0800 | [diff] [blame] | 516 | |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 517 | content = template.format( |
| 518 | script_name = os.path.basename(sys.argv[0]), |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 519 | data_source_name = file, |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 520 | year = date.today().year, |
| 521 | annotation_lower = annotation.lower(), |
| 522 | annotation_upper = annotation.upper(), |
| 523 | comment = comment, |
| 524 | includes = includes, |
| 525 | entry_points = entry_points) |
Jiajia Qin | cb59a90 | 2017-11-22 13:03:42 +0800 | [diff] [blame] | 526 | |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 527 | path = path_to("libGLESv2", "entry_points_gles_{}_autogen.{}".format( |
| 528 | annotation.lower(), suffix)) |
| 529 | |
| 530 | with open(path, "w") as out: |
| 531 | out.write(content) |
| 532 | out.close() |
| 533 | |
Brandon Jones | 41e59f5 | 2018-05-02 12:45:28 -0700 | [diff] [blame] | 534 | def write_export_files(entry_points, includes, exports): |
| 535 | |
| 536 | content = template_libgles_entry_point_source.format( |
| 537 | script_name = os.path.basename(sys.argv[0]), |
| 538 | data_source_name = "gl.xml and gl_angle_ext.xml", |
| 539 | year = date.today().year, |
| 540 | includes = includes, |
| 541 | entry_points = entry_points) |
| 542 | |
| 543 | path = path_to("libGLESv2", "libGLESv2_autogen.cpp") |
| 544 | |
| 545 | with open(path, "w") as out: |
| 546 | out.write(content) |
| 547 | out.close() |
| 548 | |
| 549 | content = template_libgles_entry_point_export.format( |
| 550 | script_name = os.path.basename(sys.argv[0]), |
| 551 | data_source_name = "gl.xml and gl_angle_ext.xml", |
| 552 | exports = exports, |
| 553 | year = date.today().year) |
| 554 | |
| 555 | path = path_to("libGLESv2", "libGLESv2_autogen.def") |
| 556 | |
| 557 | with open(path, "w") as out: |
| 558 | out.write(content) |
| 559 | out.close() |
| 560 | |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 561 | def write_context_api_decls(annotation, template, decls): |
| 562 | |
| 563 | interface_lines = [] |
| 564 | |
| 565 | for i in decls['core']: |
| 566 | interface_lines.append(i) |
| 567 | |
| 568 | for extname in sorted(decls['exts'].keys()): |
| 569 | interface_lines.append(" /* " + extname + " */ \\") |
| 570 | interface_lines.extend(decls['exts'][extname]) |
| 571 | |
| 572 | content = template.format( |
| 573 | annotation_lower = annotation.lower(), |
| 574 | annotation_upper = annotation.upper(), |
| 575 | script_name = os.path.basename(sys.argv[0]), |
| 576 | data_source_name = "gl.xml", |
| 577 | year = date.today().year, |
| 578 | interface = "\n".join(interface_lines)) |
| 579 | |
| 580 | path = path_to("libANGLE", "Context_gles_%s_autogen.h" % annotation.lower()) |
| 581 | |
| 582 | with open(path, "w") as out: |
| 583 | out.write(content) |
| 584 | out.close() |
| 585 | |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 586 | def write_glext_explicit_context_inc(version, ptrs, protos): |
| 587 | folder_version = version if version != "31" else "3" |
| 588 | |
| 589 | content = template_glext_explicit_context_inc.format( |
| 590 | script_name = os.path.basename(sys.argv[0]), |
| 591 | data_source_name = "gl.xml and gl_angle_ext.xml", |
| 592 | year = date.today().year, |
| 593 | version = version, |
| 594 | function_pointers = ptrs, |
| 595 | function_prototypes = protos) |
| 596 | |
Brandon Jones | 795ab71 | 2018-05-24 15:45:40 -0700 | [diff] [blame] | 597 | path = os.path.join(script_relative(".."), "include", "GLES{}".format(folder_version), |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 598 | "gl{}ext_explicit_context_autogen.inc".format(version)) |
| 599 | |
| 600 | with open(path, "w") as out: |
| 601 | out.write(content) |
| 602 | out.close() |
| 603 | |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 604 | def append_angle_extensions(base_root): |
| 605 | angle_ext_tree = etree.parse(script_relative('gl_angle_ext.xml')) |
| 606 | angle_ext_root = angle_ext_tree.getroot() |
| 607 | |
| 608 | insertion_point = base_root.findall("./commands")[0] |
| 609 | for command in angle_ext_root.iter('commands'): |
| 610 | insertion_point.extend(command) |
| 611 | |
| 612 | insertion_point = base_root.findall("./extensions")[0] |
| 613 | for extension in angle_ext_root.iter('extensions'): |
| 614 | insertion_point.extend(extension) |
| 615 | return base_root |
| 616 | |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 617 | class GLCommandNames: |
| 618 | def __init__(self): |
| 619 | self.command_names = {} |
| 620 | |
| 621 | def get_commands(self, version): |
| 622 | return self.command_names[version] |
| 623 | |
| 624 | def get_all_commands(self): |
| 625 | cmd_names = [] |
| 626 | # Combine all the version lists into a single list |
| 627 | for version, version_cmd_names in sorted(self.command_names.iteritems()): |
| 628 | cmd_names += version_cmd_names |
| 629 | |
| 630 | return cmd_names |
| 631 | |
| 632 | def add_commands(self, version, commands): |
| 633 | # Add key if it doesn't exist |
| 634 | if version not in self.command_names: |
| 635 | self.command_names[version] = [] |
| 636 | # Add the commands that aren't duplicates |
| 637 | self.command_names[version] += commands |
| 638 | |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 639 | root = append_angle_extensions(root) |
| 640 | |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 641 | all_commands = root.findall('commands/command') |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 642 | all_cmd_names = GLCommandNames() |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 643 | |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 644 | template_header_includes = """#include <GLES{major}/gl{major}{minor}.h> |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 645 | #include <export.h>""" |
| 646 | |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 647 | template_sources_includes = """#include "libGLESv2/entry_points_gles_{}_autogen.h" |
| 648 | |
| 649 | #include "libANGLE/Context.h" |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 650 | #include "libANGLE/validationES{}{}.h" |
| 651 | #include "libGLESv2/global_state.h" |
| 652 | """ |
| 653 | |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 654 | gles1decls = {} |
| 655 | |
| 656 | gles1decls['core'] = [] |
| 657 | gles1decls['exts'] = {} |
| 658 | |
Brandon Jones | 41e59f5 | 2018-05-02 12:45:28 -0700 | [diff] [blame] | 659 | libgles_ep_defs = [] |
| 660 | libgles_ep_exports = [] |
| 661 | |
| 662 | ordinal_start = 1 |
| 663 | |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 664 | # First run through the main GLES entry points. Since ES2+ is the primary use |
| 665 | # case, we go through those first and then add ES1-only APIs at the end. |
| 666 | for major_version, minor_version in [[2, 0], [3, 0], [3, 1], [1, 0]]: |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 667 | annotation = "{}_{}".format(major_version, minor_version) |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 668 | name_prefix = "GL_ES_VERSION_" |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 669 | |
| 670 | is_gles1 = major_version == 1 |
| 671 | if is_gles1: |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 672 | name_prefix = "GL_VERSION_ES_CM_" |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 673 | |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 674 | comment = annotation.replace("_", ".") |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 675 | gles_xpath = ".//feature[@name='{}{}']//command".format(name_prefix, annotation) |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 676 | gles_commands = [cmd.attrib['name'] for cmd in root.findall(gles_xpath)] |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 677 | |
| 678 | # Remove commands that have already been processed |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 679 | gles_commands = [cmd for cmd in gles_commands if cmd not in all_cmd_names.get_all_commands()] |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 680 | |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 681 | all_cmd_names.add_commands(annotation, gles_commands) |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 682 | |
Brandon Jones | 41e59f5 | 2018-05-02 12:45:28 -0700 | [diff] [blame] | 683 | decls, defs, libgles_defs, libgles_exports = get_entry_points( |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 684 | all_commands, gles_commands, ordinal_start, False) |
Brandon Jones | 41e59f5 | 2018-05-02 12:45:28 -0700 | [diff] [blame] | 685 | |
| 686 | # Increment the ordinal before inserting the version comment |
| 687 | ordinal_start += len(libgles_exports) |
| 688 | |
| 689 | # Write the version as a comment before the first EP. |
| 690 | libgles_defs.insert(0, "\n// OpenGL ES {}.{}".format(major_version, minor_version)) |
| 691 | libgles_exports.insert(0, "\n ; OpenGL ES {}.{}".format(major_version, minor_version)) |
| 692 | |
| 693 | libgles_ep_defs += libgles_defs |
| 694 | libgles_ep_exports += libgles_exports |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 695 | |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 696 | major_if_not_one = major_version if major_version != 1 else "" |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 697 | minor_if_not_zero = minor_version if minor_version != 0 else "" |
| 698 | |
| 699 | header_includes = template_header_includes.format( |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 700 | major=major_if_not_one, minor=minor_if_not_zero) |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 701 | |
| 702 | # We include the platform.h header since it undefines the conflicting MemoryBarrier macro. |
| 703 | if major_version == 3 and minor_version == 1: |
| 704 | header_includes += "\n#include \"common/platform.h\"\n" |
| 705 | |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 706 | source_includes = template_sources_includes.format( |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 707 | annotation.lower(), major_version, minor_if_not_zero) |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 708 | |
| 709 | write_file(annotation, comment, template_entry_point_header, |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 710 | "\n".join(decls), "h", header_includes, "gl.xml") |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 711 | write_file(annotation, comment, template_entry_point_source, |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 712 | "\n".join(defs), "cpp", source_includes, "gl.xml") |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 713 | if is_gles1: |
| 714 | gles1decls['core'] = get_gles1_decls(all_commands, gles_commands) |
| 715 | |
Jamie Madill | 57ae8c1 | 2017-08-30 12:14:29 -0400 | [diff] [blame] | 716 | |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 717 | # After we finish with the main entry points, we process the extensions. |
| 718 | extension_defs = [] |
| 719 | extension_decls = [] |
| 720 | |
| 721 | # Use a first step to run through the extensions so we can generate them |
| 722 | # in sorted order. |
| 723 | ext_data = {} |
| 724 | |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 725 | for gles1ext in gles1_extensions: |
| 726 | gles1decls['exts'][gles1ext] = [] |
| 727 | |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 728 | for extension in root.findall("extensions/extension"): |
| 729 | extension_name = extension.attrib['name'] |
| 730 | if not extension_name in supported_extensions: |
| 731 | continue |
| 732 | |
| 733 | ext_cmd_names = [] |
| 734 | |
| 735 | # There's an extra step here to filter out 'api=gl' extensions. This |
| 736 | # is necessary for handling KHR extensions, which have separate entry |
| 737 | # point signatures (without the suffix) for desktop GL. Note that this |
| 738 | # extra step is necessary because of Etree's limited Xpath support. |
| 739 | for require in extension.findall('require'): |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 740 | if 'api' in require.attrib and require.attrib['api'] != 'gles2' and require.attrib['api'] != 'gles1': |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 741 | continue |
| 742 | |
| 743 | # Another special case for EXT_texture_storage |
| 744 | filter_out_comment = "Supported only if GL_EXT_direct_state_access is supported" |
| 745 | if 'comment' in require.attrib and require.attrib['comment'] == filter_out_comment: |
| 746 | continue |
| 747 | |
| 748 | extension_commands = require.findall('command') |
| 749 | ext_cmd_names += [command.attrib['name'] for command in extension_commands] |
| 750 | |
| 751 | ext_data[extension_name] = sorted(ext_cmd_names) |
| 752 | |
| 753 | for extension_name, ext_cmd_names in sorted(ext_data.iteritems()): |
| 754 | |
| 755 | # Detect and filter duplicate extensions. |
| 756 | dupes = [] |
| 757 | for ext_cmd in ext_cmd_names: |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 758 | if ext_cmd in all_cmd_names.get_all_commands(): |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 759 | dupes.append(ext_cmd) |
| 760 | |
| 761 | for dupe in dupes: |
| 762 | ext_cmd_names.remove(dupe) |
| 763 | |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 764 | if extension_name in gles1_extensions: |
| 765 | all_cmd_names.add_commands("glext", ext_cmd_names) |
| 766 | else: |
| 767 | all_cmd_names.add_commands("gl2ext", ext_cmd_names) |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 768 | |
Brandon Jones | 41e59f5 | 2018-05-02 12:45:28 -0700 | [diff] [blame] | 769 | decls, defs, libgles_defs, libgles_exports = get_entry_points( |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 770 | all_commands, ext_cmd_names, ordinal_start, False) |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 771 | |
| 772 | # Avoid writing out entry points defined by a prior extension. |
| 773 | for dupe in dupes: |
| 774 | msg = "// {} is already defined.\n".format(dupe[2:]) |
| 775 | defs.append(msg) |
| 776 | |
Brandon Jones | 41e59f5 | 2018-05-02 12:45:28 -0700 | [diff] [blame] | 777 | # Increment starting ordinal before adding extension comment |
| 778 | ordinal_start += len(libgles_exports) |
| 779 | |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 780 | # Write the extension name as a comment before the first EP. |
| 781 | comment = "\n// {}".format(extension_name) |
| 782 | defs.insert(0, comment) |
| 783 | decls.insert(0, comment) |
Brandon Jones | 41e59f5 | 2018-05-02 12:45:28 -0700 | [diff] [blame] | 784 | libgles_defs.insert(0, comment) |
| 785 | libgles_exports.insert(0, "\n ; {}".format(extension_name)) |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 786 | |
| 787 | extension_defs += defs |
| 788 | extension_decls += decls |
| 789 | |
Brandon Jones | 41e59f5 | 2018-05-02 12:45:28 -0700 | [diff] [blame] | 790 | libgles_ep_defs += libgles_defs |
| 791 | libgles_ep_exports += libgles_exports |
| 792 | |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 793 | if extension_name in gles1_extensions: |
| 794 | if extension_name not in gles1_no_context_decl_extensions: |
| 795 | gles1decls['exts'][extension_name] = get_gles1_decls(all_commands, ext_cmd_names) |
| 796 | |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 797 | # Special handling for EGL_ANGLE_explicit_context extension |
| 798 | if support_EGL_ANGLE_explicit_context: |
| 799 | comment = "\n// EGL_ANGLE_explicit_context" |
| 800 | extension_defs.append(comment) |
| 801 | extension_decls.append(comment) |
| 802 | libgles_ep_defs.append(comment) |
| 803 | libgles_ep_exports.append("\n ; EGL_ANGLE_explicit_context") |
| 804 | |
| 805 | # Get the explicit context entry points |
| 806 | decls, defs, libgles_defs, libgles_exports = get_entry_points(all_commands, |
| 807 | all_cmd_names.get_all_commands(), ordinal_start, True) |
| 808 | |
| 809 | # Append the explicit context entry points |
| 810 | extension_decls += decls |
| 811 | extension_defs += defs |
| 812 | libgles_ep_defs += libgles_defs |
| 813 | libgles_ep_exports += libgles_exports |
| 814 | |
| 815 | # Generate .inc files for extension function pointers and declarations |
| 816 | for major, minor in [[2, 0], [3, 0], [3, 1], [1, 0]]: |
| 817 | annotation = "{}_{}".format(major, minor) |
| 818 | |
| 819 | major_if_not_one = major if major != 1 else "" |
| 820 | minor_if_not_zero = minor if minor != 0 else "" |
| 821 | version = "{}{}".format(major_if_not_one, minor_if_not_zero) |
| 822 | |
| 823 | glext_ptrs, glext_protos = get_glext_decls(all_commands, |
| 824 | all_cmd_names.get_commands(annotation), version, True) |
| 825 | |
| 826 | glext_ext_ptrs = [] |
| 827 | glext_ext_protos = [] |
| 828 | |
| 829 | # Append extensions for 1.0 and 2.0 |
| 830 | if(annotation == "1_0"): |
| 831 | glext_ext_ptrs, glext_ext_protos = get_glext_decls(all_commands, |
| 832 | all_cmd_names.get_commands("glext"), version, True) |
| 833 | elif(annotation == "2_0"): |
| 834 | glext_ext_ptrs, glext_ext_protos = get_glext_decls(all_commands, |
| 835 | all_cmd_names.get_commands("gl2ext"), version, True) |
| 836 | |
| 837 | glext_ptrs += glext_ext_ptrs |
| 838 | glext_protos += glext_ext_protos |
| 839 | |
| 840 | write_glext_explicit_context_inc(version, "\n".join(glext_ptrs), "\n".join(glext_protos)) |
| 841 | |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 842 | header_includes = template_header_includes.format( |
| 843 | major="", minor="") |
| 844 | header_includes += """ |
| 845 | #include <GLES/gl.h> |
| 846 | #include <GLES/glext.h> |
| 847 | #include <GLES2/gl2.h> |
| 848 | #include <GLES2/gl2ext.h> |
| 849 | """ |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 850 | |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 851 | source_includes = template_sources_includes.format("ext", "", "") |
| 852 | source_includes += """ |
| 853 | #include "libANGLE/validationES.h" |
| 854 | #include "libANGLE/validationES1.h" |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 855 | #include "libANGLE/validationES3.h" |
| 856 | #include "libANGLE/validationES31.h" |
| 857 | """ |
| 858 | |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 859 | write_file("ext", "extension", template_entry_point_header, |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 860 | "\n".join([item for item in extension_decls]), "h", header_includes, |
| 861 | "gl.xml and gl_angle_ext.xml") |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 862 | write_file("ext", "extension", template_entry_point_source, |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 863 | "\n".join([item for item in extension_defs]), "cpp", source_includes, |
| 864 | "gl.xml and gl_angle_ext.xml") |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 865 | |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 866 | write_context_api_decls("1_0", context_gles_header, gles1decls) |
| 867 | |
Brandon Jones | 2b0cdcc | 2018-05-02 08:02:50 -0700 | [diff] [blame] | 868 | sorted_cmd_names = ["Invalid"] + [cmd[2:] for cmd in sorted(all_cmd_names.get_all_commands())] |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 869 | |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 870 | entry_points_enum = template_entry_points_enum_header.format( |
| 871 | script_name = os.path.basename(sys.argv[0]), |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 872 | data_source_name = "gl.xml and gl_angle_ext.xml", |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 873 | year = date.today().year, |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 874 | entry_points_list = ",\n".join([" " + cmd for cmd in sorted_cmd_names])) |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 875 | |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 876 | entry_points_enum_header_path = path_to("libANGLE", "entry_points_enum_autogen.h") |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 877 | with open(entry_points_enum_header_path, "w") as out: |
| 878 | out.write(entry_points_enum) |
Geoff Lang | cae72d6 | 2017-06-01 11:53:45 -0400 | [diff] [blame] | 879 | out.close() |
Brandon Jones | 41e59f5 | 2018-05-02 12:45:28 -0700 | [diff] [blame] | 880 | |
| 881 | source_includes = """ |
| 882 | #include "angle_gl.h" |
| 883 | |
| 884 | #include "libGLESv2/entry_points_gles_1_0_autogen.h" |
| 885 | #include "libGLESv2/entry_points_gles_2_0_autogen.h" |
| 886 | #include "libGLESv2/entry_points_gles_3_0_autogen.h" |
| 887 | #include "libGLESv2/entry_points_gles_3_1_autogen.h" |
| 888 | #include "libGLESv2/entry_points_gles_ext_autogen.h" |
| 889 | |
| 890 | #include "common/event_tracer.h" |
| 891 | """ |
| 892 | |
jchen10 | 82af620 | 2018-06-22 10:59:52 +0800 | [diff] [blame] | 893 | write_export_files("\n".join([item for item in libgles_ep_defs]), source_includes, "\n".join([item for item in libgles_ep_exports])) |