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