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", |
| 27 | ] |
| 28 | |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 29 | gles1_extensions = [ |
| 30 | # ES1 (Possibly the min set of extensions needed by Android) |
| 31 | "GL_OES_draw_texture", |
| 32 | "GL_OES_framebuffer_object", |
| 33 | "GL_OES_matrix_palette", |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 34 | "GL_OES_point_size_array", |
| 35 | "GL_OES_query_matrix", |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 36 | "GL_OES_texture_cube_map", |
| 37 | ] |
| 38 | |
| 39 | # List of GLES1 extensions for which we don't need to add Context.h decls. |
| 40 | gles1_no_context_decl_extensions = [ |
| 41 | "GL_OES_framebuffer_object", |
| 42 | ] |
| 43 | |
| 44 | # List of GLES1 API calls that have had their semantics changed in later GLES versions, but the |
| 45 | # name was kept the same |
| 46 | gles1_overloaded = [ |
| 47 | "glGetPointerv", |
| 48 | ] |
| 49 | |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame^] | 50 | supported_extensions = sorted(angle_extensions + gles1_extensions + [ |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 51 | # ES2+ |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 52 | "GL_ANGLE_framebuffer_blit", |
| 53 | "GL_ANGLE_framebuffer_multisample", |
| 54 | "GL_ANGLE_instanced_arrays", |
| 55 | "GL_ANGLE_translated_shader_source", |
| 56 | "GL_EXT_debug_marker", |
| 57 | "GL_EXT_discard_framebuffer", |
| 58 | "GL_EXT_disjoint_timer_query", |
| 59 | "GL_EXT_draw_buffers", |
| 60 | "GL_EXT_map_buffer_range", |
| 61 | "GL_EXT_occlusion_query_boolean", |
| 62 | "GL_EXT_robustness", |
| 63 | "GL_EXT_texture_storage", |
| 64 | "GL_KHR_debug", |
| 65 | "GL_NV_fence", |
| 66 | "GL_OES_EGL_image", |
| 67 | "GL_OES_get_program_binary", |
| 68 | "GL_OES_mapbuffer", |
| 69 | "GL_OES_vertex_array_object", |
| 70 | ]) |
| 71 | |
| 72 | # This is a list of exceptions for entry points which don't want to have |
| 73 | # the EVENT macro. This is required for some debug marker entry points. |
| 74 | no_event_marker_exceptions_list = sorted([ |
| 75 | "glPushGroupMarkerEXT", |
| 76 | "glPopGroupMarkerEXT", |
| 77 | "glInsertEventMarkerEXT", |
| 78 | ]) |
| 79 | |
| 80 | # 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^] | 81 | strip_suffixes = ["ANGLE", "EXT", "KHR", "OES", "CHROMIUM"] |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 82 | |
Jamie Madill | 2e16d96 | 2017-04-19 14:06:36 -0400 | [diff] [blame] | 83 | template_entry_point_header = """// GENERATED FILE - DO NOT EDIT. |
| 84 | // Generated by {script_name} using data from {data_source_name}. |
| 85 | // |
| 86 | // Copyright {year} The ANGLE Project Authors. All rights reserved. |
| 87 | // Use of this source code is governed by a BSD-style license that can be |
| 88 | // found in the LICENSE file. |
| 89 | // |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 90 | // entry_points_gles_{annotation_lower}_autogen.h: |
| 91 | // Defines the GLES {comment} entry points. |
Jamie Madill | 2e16d96 | 2017-04-19 14:06:36 -0400 | [diff] [blame] | 92 | |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 93 | #ifndef LIBGLESV2_ENTRY_POINTS_GLES_{annotation_upper}_AUTOGEN_H_ |
| 94 | #define LIBGLESV2_ENTRY_POINTS_GLES_{annotation_upper}_AUTOGEN_H_ |
Jamie Madill | 2e16d96 | 2017-04-19 14:06:36 -0400 | [diff] [blame] | 95 | |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 96 | {includes} |
| 97 | |
Jamie Madill | 2e16d96 | 2017-04-19 14:06:36 -0400 | [diff] [blame] | 98 | namespace gl |
| 99 | {{ |
| 100 | {entry_points} |
| 101 | }} // namespace gl |
| 102 | |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 103 | #endif // LIBGLESV2_ENTRY_POINTS_GLES_{annotation_upper}_AUTOGEN_H_ |
Jamie Madill | 2e16d96 | 2017-04-19 14:06:36 -0400 | [diff] [blame] | 104 | """ |
| 105 | |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 106 | template_entry_point_source = """// GENERATED FILE - DO NOT EDIT. |
| 107 | // Generated by {script_name} using data from {data_source_name}. |
| 108 | // |
| 109 | // Copyright {year} The ANGLE Project Authors. All rights reserved. |
| 110 | // Use of this source code is governed by a BSD-style license that can be |
| 111 | // found in the LICENSE file. |
| 112 | // |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 113 | // entry_points_gles_{annotation_lower}_autogen.cpp: |
| 114 | // Defines the GLES {comment} entry points. |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 115 | |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 116 | {includes} |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 117 | |
| 118 | namespace gl |
| 119 | {{ |
| 120 | {entry_points}}} // namespace gl |
| 121 | """ |
| 122 | |
| 123 | template_entry_points_enum_header = """// GENERATED FILE - DO NOT EDIT. |
| 124 | // Generated by {script_name} using data from {data_source_name}. |
| 125 | // |
| 126 | // Copyright {year} The ANGLE Project Authors. All rights reserved. |
| 127 | // Use of this source code is governed by a BSD-style license that can be |
| 128 | // found in the LICENSE file. |
| 129 | // |
| 130 | // entry_points_enum_autogen.h: |
| 131 | // Defines the GLES entry points enumeration. |
| 132 | |
| 133 | #ifndef LIBGLESV2_ENTRYPOINTSENUM_AUTOGEN_H_ |
| 134 | #define LIBGLESV2_ENTRYPOINTSENUM_AUTOGEN_H_ |
| 135 | |
| 136 | namespace gl |
| 137 | {{ |
| 138 | enum class EntryPoint |
| 139 | {{ |
| 140 | {entry_points_list} |
| 141 | }}; |
| 142 | }} // namespace gl |
| 143 | #endif // LIBGLESV2_ENTRY_POINTS_ENUM_AUTOGEN_H_ |
| 144 | """ |
| 145 | |
Jamie Madill | 2e16d96 | 2017-04-19 14:06:36 -0400 | [diff] [blame] | 146 | template_entry_point_decl = """ANGLE_EXPORT {return_type}GL_APIENTRY {name}({params});""" |
| 147 | |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 148 | template_entry_point_def = """{return_type}GL_APIENTRY {name}({params}) |
| 149 | {{ |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 150 | {event_comment}EVENT("({format_params})"{comma_if_needed}{pass_params}); |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 151 | |
Geoff Lang | cae72d6 | 2017-06-01 11:53:45 -0400 | [diff] [blame] | 152 | Context *context = {context_getter}(); |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 153 | if (context) |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 154 | {{{packed_gl_enum_conversions} |
| 155 | context->gatherParams<EntryPoint::{name}>({internal_params}); |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 156 | |
Jamie Madill | 53d3841 | 2017-04-20 11:33:00 -0400 | [diff] [blame] | 157 | if (context->skipValidation() || Validate{name}({validate_params})) |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 158 | {{ |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 159 | {return_if_needed}context->{name_lower_no_suffix}({internal_params}); |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 160 | }} |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 161 | }} |
| 162 | {default_return_if_needed}}} |
| 163 | """ |
| 164 | |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 165 | context_gles_header = """// GENERATED FILE - DO NOT EDIT. |
| 166 | // Generated by {script_name} using data from {data_source_name}. |
| 167 | // |
| 168 | // Copyright {year} The ANGLE Project Authors. All rights reserved. |
| 169 | // Use of this source code is governed by a BSD-style license that can be |
| 170 | // found in the LICENSE file. |
| 171 | // |
| 172 | // Context_gles_{annotation_lower}_autogen.h: Creates a macro for interfaces in Context. |
| 173 | |
| 174 | #ifndef ANGLE_CONTEXT_GLES_{annotation_upper}_AUTOGEN_H_ |
| 175 | #define ANGLE_CONTEXT_GLES_{annotation_upper}_AUTOGEN_H_ |
| 176 | |
| 177 | #define ANGLE_GLES1_CONTEXT_API \\ |
| 178 | {interface} |
| 179 | |
| 180 | #endif // ANGLE_CONTEXT_API_{annotation_upper}_AUTOGEN_H_ |
| 181 | """ |
| 182 | |
| 183 | context_gles_decl = """ {return_type} {name_lower_no_suffix}({internal_params}); \\""" |
| 184 | |
Jamie Madill | 16daadb | 2017-08-26 23:34:31 -0400 | [diff] [blame] | 185 | def script_relative(path): |
| 186 | return os.path.join(os.path.dirname(sys.argv[0]), path) |
| 187 | |
| 188 | tree = etree.parse(script_relative('gl.xml')) |
| 189 | root = tree.getroot() |
Jamie Madill | 2e16d96 | 2017-04-19 14:06:36 -0400 | [diff] [blame] | 190 | commands = root.find(".//commands[@namespace='GL']") |
Jamie Madill | 2e16d96 | 2017-04-19 14:06:36 -0400 | [diff] [blame] | 191 | |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 192 | with open(script_relative('entry_point_packed_gl_enums.json')) as f: |
| 193 | cmd_packed_gl_enums = json.loads(f.read()) |
| 194 | |
Jamie Madill | 2e16d96 | 2017-04-19 14:06:36 -0400 | [diff] [blame] | 195 | def format_entry_point_decl(cmd_name, proto, params): |
| 196 | return template_entry_point_decl.format( |
| 197 | name = cmd_name[2:], |
| 198 | return_type = proto[:-len(cmd_name)], |
| 199 | params = ", ".join(params)) |
| 200 | |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 201 | def type_name_sep_index(param): |
| 202 | space = param.rfind(" ") |
| 203 | pointer = param.rfind("*") |
| 204 | return max(space, pointer) |
| 205 | |
| 206 | def just_the_type(param): |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 207 | if "*" in param: |
| 208 | return param[:type_name_sep_index(param) + 1] |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 209 | return param[:type_name_sep_index(param)] |
| 210 | |
| 211 | def just_the_name(param): |
| 212 | return param[type_name_sep_index(param)+1:] |
| 213 | |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 214 | def make_param(param_type, param_name): |
| 215 | return param_type + " " + param_name |
| 216 | |
| 217 | def just_the_type_packed(param, entry): |
| 218 | name = just_the_name(param) |
| 219 | if entry.has_key(name): |
| 220 | return entry[name] |
| 221 | else: |
| 222 | return just_the_type(param) |
| 223 | |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 224 | def just_the_name_packed(param, reserved_set): |
| 225 | name = just_the_name(param) |
| 226 | if name in reserved_set: |
| 227 | return name + 'Packed' |
| 228 | else: |
| 229 | return name |
| 230 | |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 231 | format_dict = { |
| 232 | "GLbitfield": "0x%X", |
| 233 | "GLboolean": "%u", |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 234 | "GLclampx": "0x%X", |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 235 | "GLenum": "0x%X", |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 236 | "GLfixed": "0x%X", |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 237 | "GLfloat": "%f", |
| 238 | "GLint": "%d", |
| 239 | "GLintptr": "%d", |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 240 | "GLshort": "%d", |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 241 | "GLsizei": "%d", |
| 242 | "GLsizeiptr": "%d", |
Jamie Madill | 16daadb | 2017-08-26 23:34:31 -0400 | [diff] [blame] | 243 | "GLsync": "0x%0.8p", |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 244 | "GLubyte": "%d", |
Jamie Madill | ff161f8 | 2017-08-26 23:49:10 -0400 | [diff] [blame] | 245 | "GLuint": "%u", |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 246 | "GLuint64": "%llu", |
| 247 | "GLDEBUGPROC": "0x%0.8p", |
| 248 | "GLDEBUGPROCKHR": "0x%0.8p", |
| 249 | "GLeglImageOES": "0x%0.8p", |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | def param_format_string(param): |
| 253 | if "*" in param: |
| 254 | return param + " = 0x%0.8p" |
| 255 | else: |
Jamie Madill | 16daadb | 2017-08-26 23:34:31 -0400 | [diff] [blame] | 256 | type_only = just_the_type(param) |
| 257 | if type_only not in format_dict: |
| 258 | raise Exception(type_only + " is not a known type in 'format_dict'") |
| 259 | |
| 260 | return param + " = " + format_dict[type_only] |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 261 | |
Jamie Madill | 2e29b13 | 2017-08-28 17:22:11 -0400 | [diff] [blame] | 262 | def default_return_value(cmd_name, return_type): |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 263 | if return_type == "void": |
| 264 | return "" |
Jamie Madill | 2e29b13 | 2017-08-28 17:22:11 -0400 | [diff] [blame] | 265 | return "GetDefaultReturnValue<EntryPoint::" + cmd_name[2:] + ", " + return_type + ">()" |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 266 | |
Geoff Lang | cae72d6 | 2017-06-01 11:53:45 -0400 | [diff] [blame] | 267 | def get_context_getter_function(cmd_name): |
| 268 | if cmd_name == "glGetError": |
| 269 | return "GetGlobalContext" |
| 270 | else: |
| 271 | return "GetValidGlobalContext" |
| 272 | |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 273 | template_event_comment = """// Don't run an EVENT() macro on the EXT_debug_marker entry points. |
| 274 | // It can interfere with the debug events being set by the caller. |
| 275 | // """ |
| 276 | |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 277 | def format_entry_point_def(cmd_name, proto, params): |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 278 | packed_gl_enums = cmd_packed_gl_enums.get(cmd_name, {}) |
| 279 | internal_params = [just_the_name_packed(param, packed_gl_enums) for param in params] |
| 280 | packed_gl_enum_conversions = [] |
| 281 | for param in params: |
| 282 | name = just_the_name(param) |
| 283 | if name in packed_gl_enums: |
| 284 | internal_name = name + "Packed" |
| 285 | internal_type = packed_gl_enums[name] |
| 286 | packed_gl_enum_conversions += ["\n " + internal_type + " " + internal_name +" = FromGLenum<" + |
| 287 | internal_type + ">(" + name + ");"] |
| 288 | |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 289 | pass_params = [just_the_name(param) for param in params] |
| 290 | format_params = [param_format_string(param) for param in params] |
| 291 | return_type = proto[:-len(cmd_name)] |
Jamie Madill | 2e29b13 | 2017-08-28 17:22:11 -0400 | [diff] [blame] | 292 | default_return = default_return_value(cmd_name, return_type.strip()) |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 293 | 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] | 294 | name_lower_no_suffix = cmd_name[2:3].lower() + cmd_name[3:] |
| 295 | |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 296 | for suffix in strip_suffixes: |
| 297 | if name_lower_no_suffix.endswith(suffix): |
| 298 | name_lower_no_suffix = name_lower_no_suffix[0:-len(suffix)] |
| 299 | |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 300 | return template_entry_point_def.format( |
| 301 | name = cmd_name[2:], |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 302 | name_lower_no_suffix = name_lower_no_suffix, |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 303 | return_type = return_type, |
| 304 | params = ", ".join(params), |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 305 | internal_params = ", ".join(internal_params), |
| 306 | packed_gl_enum_conversions = "".join(packed_gl_enum_conversions), |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 307 | pass_params = ", ".join(pass_params), |
| 308 | comma_if_needed = ", " if len(params) > 0 else "", |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 309 | validate_params = ", ".join(["context"] + internal_params), |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 310 | format_params = ", ".join(format_params), |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 311 | return_if_needed = "" if default_return == "" else "return ", |
Geoff Lang | cae72d6 | 2017-06-01 11:53:45 -0400 | [diff] [blame] | 312 | default_return_if_needed = "" if default_return == "" else "\n return " + default_return + ";\n", |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 313 | context_getter = get_context_getter_function(cmd_name), |
| 314 | event_comment = event_comment) |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 315 | |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 316 | def format_context_gles_decl(cmd_name, proto, params): |
| 317 | packed_gl_enums = cmd_packed_gl_enums.get(cmd_name, {}) |
| 318 | internal_params = ", ".join([make_param(just_the_type_packed(param, packed_gl_enums), |
| 319 | just_the_name_packed(param, packed_gl_enums)) for param in params]) |
| 320 | |
| 321 | return_type = proto[:-len(cmd_name)] |
| 322 | name_lower_no_suffix = cmd_name[2:3].lower() + cmd_name[3:] |
| 323 | |
| 324 | for suffix in strip_suffixes: |
| 325 | if name_lower_no_suffix.endswith(suffix): |
| 326 | name_lower_no_suffix = name_lower_no_suffix[0:-len(suffix)] |
| 327 | |
| 328 | return context_gles_decl.format( |
| 329 | return_type = return_type, |
| 330 | name_lower_no_suffix = name_lower_no_suffix, |
| 331 | internal_params = internal_params) |
| 332 | |
Jiajia Qin | cb59a90 | 2017-11-22 13:03:42 +0800 | [diff] [blame] | 333 | def path_to(folder, file): |
| 334 | return os.path.join(script_relative(".."), "src", folder, file) |
Jamie Madill | 2e16d96 | 2017-04-19 14:06:36 -0400 | [diff] [blame] | 335 | |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 336 | def get_entry_points(all_commands, gles_commands): |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 337 | decls = [] |
| 338 | defs = [] |
Jamie Madill | ffa2cd0 | 2017-12-28 14:57:53 -0500 | [diff] [blame] | 339 | for command in all_commands: |
| 340 | proto = command.find('proto') |
| 341 | cmd_name = proto.find('name').text |
| 342 | |
| 343 | if cmd_name not in gles_commands: |
| 344 | continue |
| 345 | |
| 346 | param_text = ["".join(param.itertext()) for param in command.findall('param')] |
| 347 | proto_text = "".join(proto.itertext()) |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 348 | decls.append(format_entry_point_decl(cmd_name, proto_text, param_text)) |
| 349 | defs.append(format_entry_point_def(cmd_name, proto_text, param_text)) |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 350 | |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 351 | return decls, defs |
Jamie Madill | 16daadb | 2017-08-26 23:34:31 -0400 | [diff] [blame] | 352 | |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 353 | def get_gles1_decls(all_commands, gles_commands): |
| 354 | decls = [] |
| 355 | for command in all_commands: |
| 356 | proto = command.find('proto') |
| 357 | cmd_name = proto.find('name').text |
| 358 | |
| 359 | if cmd_name not in gles_commands: |
| 360 | continue |
| 361 | |
| 362 | if cmd_name in gles1_overloaded: |
| 363 | continue |
| 364 | |
| 365 | param_text = ["".join(param.itertext()) for param in command.findall('param')] |
| 366 | proto_text = "".join(proto.itertext()) |
| 367 | decls.append(format_context_gles_decl(cmd_name, proto_text, param_text)) |
| 368 | |
| 369 | return decls |
| 370 | |
| 371 | |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame^] | 372 | def write_file(annotation, comment, template, entry_points, suffix, includes, file): |
Jiajia Qin | cb59a90 | 2017-11-22 13:03:42 +0800 | [diff] [blame] | 373 | |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 374 | content = template.format( |
| 375 | script_name = os.path.basename(sys.argv[0]), |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame^] | 376 | data_source_name = file, |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 377 | year = date.today().year, |
| 378 | annotation_lower = annotation.lower(), |
| 379 | annotation_upper = annotation.upper(), |
| 380 | comment = comment, |
| 381 | includes = includes, |
| 382 | entry_points = entry_points) |
Jiajia Qin | cb59a90 | 2017-11-22 13:03:42 +0800 | [diff] [blame] | 383 | |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 384 | path = path_to("libGLESv2", "entry_points_gles_{}_autogen.{}".format( |
| 385 | annotation.lower(), suffix)) |
| 386 | |
| 387 | with open(path, "w") as out: |
| 388 | out.write(content) |
| 389 | out.close() |
| 390 | |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 391 | def write_context_api_decls(annotation, template, decls): |
| 392 | |
| 393 | interface_lines = [] |
| 394 | |
| 395 | for i in decls['core']: |
| 396 | interface_lines.append(i) |
| 397 | |
| 398 | for extname in sorted(decls['exts'].keys()): |
| 399 | interface_lines.append(" /* " + extname + " */ \\") |
| 400 | interface_lines.extend(decls['exts'][extname]) |
| 401 | |
| 402 | content = template.format( |
| 403 | annotation_lower = annotation.lower(), |
| 404 | annotation_upper = annotation.upper(), |
| 405 | script_name = os.path.basename(sys.argv[0]), |
| 406 | data_source_name = "gl.xml", |
| 407 | year = date.today().year, |
| 408 | interface = "\n".join(interface_lines)) |
| 409 | |
| 410 | path = path_to("libANGLE", "Context_gles_%s_autogen.h" % annotation.lower()) |
| 411 | |
| 412 | with open(path, "w") as out: |
| 413 | out.write(content) |
| 414 | out.close() |
| 415 | |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame^] | 416 | def append_angle_extensions(base_root): |
| 417 | angle_ext_tree = etree.parse(script_relative('gl_angle_ext.xml')) |
| 418 | angle_ext_root = angle_ext_tree.getroot() |
| 419 | |
| 420 | insertion_point = base_root.findall("./commands")[0] |
| 421 | for command in angle_ext_root.iter('commands'): |
| 422 | insertion_point.extend(command) |
| 423 | |
| 424 | insertion_point = base_root.findall("./extensions")[0] |
| 425 | for extension in angle_ext_root.iter('extensions'): |
| 426 | insertion_point.extend(extension) |
| 427 | return base_root |
| 428 | |
| 429 | root = append_angle_extensions(root) |
| 430 | |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 431 | all_commands = root.findall('commands/command') |
| 432 | all_cmd_names = [] |
| 433 | |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 434 | template_header_includes = """#include <GLES{major}/gl{major}{minor}.h> |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 435 | #include <export.h>""" |
| 436 | |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 437 | template_sources_includes = """#include "libGLESv2/entry_points_gles_{}_autogen.h" |
| 438 | |
| 439 | #include "libANGLE/Context.h" |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 440 | #include "libANGLE/validationES{}{}.h" |
| 441 | #include "libGLESv2/global_state.h" |
| 442 | """ |
| 443 | |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 444 | gles1decls = {} |
| 445 | |
| 446 | gles1decls['core'] = [] |
| 447 | gles1decls['exts'] = {} |
| 448 | |
| 449 | # First run through the main GLES entry points. Since ES2+ is the primary use |
| 450 | # case, we go through those first and then add ES1-only APIs at the end. |
| 451 | 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] | 452 | annotation = "{}_{}".format(major_version, minor_version) |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 453 | name_prefix = "GL_ES_VERSION_" |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 454 | |
| 455 | is_gles1 = major_version == 1 |
| 456 | if is_gles1: |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 457 | name_prefix = "GL_VERSION_ES_CM_" |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 458 | |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 459 | comment = annotation.replace("_", ".") |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 460 | gles_xpath = ".//feature[@name='{}{}']//command".format(name_prefix, annotation) |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 461 | gles_commands = [cmd.attrib['name'] for cmd in root.findall(gles_xpath)] |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 462 | |
| 463 | # Remove commands that have already been processed |
| 464 | gles_commands = [cmd for cmd in gles_commands if cmd not in all_cmd_names] |
| 465 | |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 466 | all_cmd_names += gles_commands |
| 467 | |
| 468 | decls, defs = get_entry_points(all_commands, gles_commands) |
| 469 | |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 470 | major_if_not_one = major_version if major_version != 1 else "" |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 471 | minor_if_not_zero = minor_version if minor_version != 0 else "" |
| 472 | |
| 473 | header_includes = template_header_includes.format( |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 474 | major=major_if_not_one, minor=minor_if_not_zero) |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 475 | |
| 476 | # We include the platform.h header since it undefines the conflicting MemoryBarrier macro. |
| 477 | if major_version == 3 and minor_version == 1: |
| 478 | header_includes += "\n#include \"common/platform.h\"\n" |
| 479 | |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 480 | source_includes = template_sources_includes.format( |
| 481 | annotation.lower(), major_version,minor_if_not_zero) |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 482 | |
| 483 | write_file(annotation, comment, template_entry_point_header, |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame^] | 484 | "\n".join(decls), "h", header_includes, "gl.xml") |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 485 | write_file(annotation, comment, template_entry_point_source, |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame^] | 486 | "\n".join(defs), "cpp", source_includes, "gl.xml") |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 487 | if is_gles1: |
| 488 | gles1decls['core'] = get_gles1_decls(all_commands, gles_commands) |
| 489 | |
Jamie Madill | 57ae8c1 | 2017-08-30 12:14:29 -0400 | [diff] [blame] | 490 | |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 491 | # After we finish with the main entry points, we process the extensions. |
| 492 | extension_defs = [] |
| 493 | extension_decls = [] |
| 494 | |
| 495 | # Use a first step to run through the extensions so we can generate them |
| 496 | # in sorted order. |
| 497 | ext_data = {} |
| 498 | |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 499 | for gles1ext in gles1_extensions: |
| 500 | gles1decls['exts'][gles1ext] = [] |
| 501 | |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 502 | for extension in root.findall("extensions/extension"): |
| 503 | extension_name = extension.attrib['name'] |
| 504 | if not extension_name in supported_extensions: |
| 505 | continue |
| 506 | |
| 507 | ext_cmd_names = [] |
| 508 | |
| 509 | # There's an extra step here to filter out 'api=gl' extensions. This |
| 510 | # is necessary for handling KHR extensions, which have separate entry |
| 511 | # point signatures (without the suffix) for desktop GL. Note that this |
| 512 | # extra step is necessary because of Etree's limited Xpath support. |
| 513 | for require in extension.findall('require'): |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 514 | 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] | 515 | continue |
| 516 | |
| 517 | # Another special case for EXT_texture_storage |
| 518 | filter_out_comment = "Supported only if GL_EXT_direct_state_access is supported" |
| 519 | if 'comment' in require.attrib and require.attrib['comment'] == filter_out_comment: |
| 520 | continue |
| 521 | |
| 522 | extension_commands = require.findall('command') |
| 523 | ext_cmd_names += [command.attrib['name'] for command in extension_commands] |
| 524 | |
| 525 | ext_data[extension_name] = sorted(ext_cmd_names) |
| 526 | |
| 527 | for extension_name, ext_cmd_names in sorted(ext_data.iteritems()): |
| 528 | |
| 529 | # Detect and filter duplicate extensions. |
| 530 | dupes = [] |
| 531 | for ext_cmd in ext_cmd_names: |
| 532 | if ext_cmd in all_cmd_names: |
| 533 | dupes.append(ext_cmd) |
| 534 | |
| 535 | for dupe in dupes: |
| 536 | ext_cmd_names.remove(dupe) |
| 537 | |
| 538 | all_cmd_names += ext_cmd_names |
| 539 | |
| 540 | decls, defs = get_entry_points(all_commands, ext_cmd_names) |
| 541 | |
| 542 | # Avoid writing out entry points defined by a prior extension. |
| 543 | for dupe in dupes: |
| 544 | msg = "// {} is already defined.\n".format(dupe[2:]) |
| 545 | defs.append(msg) |
| 546 | |
| 547 | # Write the extension name as a comment before the first EP. |
| 548 | comment = "\n// {}".format(extension_name) |
| 549 | defs.insert(0, comment) |
| 550 | decls.insert(0, comment) |
| 551 | |
| 552 | extension_defs += defs |
| 553 | extension_decls += decls |
| 554 | |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 555 | if extension_name in gles1_extensions: |
| 556 | if extension_name not in gles1_no_context_decl_extensions: |
| 557 | gles1decls['exts'][extension_name] = get_gles1_decls(all_commands, ext_cmd_names) |
| 558 | |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 559 | header_includes = template_header_includes.format( |
| 560 | major="", minor="") |
| 561 | header_includes += """ |
| 562 | #include <GLES/gl.h> |
| 563 | #include <GLES/glext.h> |
| 564 | #include <GLES2/gl2.h> |
| 565 | #include <GLES2/gl2ext.h> |
| 566 | """ |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 567 | |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 568 | source_includes = template_sources_includes.format("ext", "", "") |
| 569 | source_includes += """ |
| 570 | #include "libANGLE/validationES.h" |
| 571 | #include "libANGLE/validationES1.h" |
Jamie Madill | fa920eb | 2018-01-04 11:45:50 -0500 | [diff] [blame] | 572 | #include "libANGLE/validationES3.h" |
| 573 | #include "libANGLE/validationES31.h" |
| 574 | """ |
| 575 | |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 576 | write_file("ext", "extension", template_entry_point_header, |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame^] | 577 | "\n".join([item for item in extension_decls]), "h", header_includes, |
| 578 | "gl.xml and gl_angle_ext.xml") |
Geoff Lang | 2aaa7b4 | 2018-01-12 17:17:27 -0500 | [diff] [blame] | 579 | write_file("ext", "extension", template_entry_point_source, |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame^] | 580 | "\n".join([item for item in extension_defs]), "cpp", source_includes, |
| 581 | "gl.xml and gl_angle_ext.xml") |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 582 | |
Lingfeng Yang | a064878 | 2018-03-12 14:45:25 -0700 | [diff] [blame] | 583 | write_context_api_decls("1_0", context_gles_header, gles1decls) |
| 584 | |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 585 | sorted_cmd_names = ["Invalid"] + [cmd[2:] for cmd in sorted(all_cmd_names)] |
| 586 | |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 587 | entry_points_enum = template_entry_points_enum_header.format( |
| 588 | script_name = os.path.basename(sys.argv[0]), |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame^] | 589 | data_source_name = "gl.xml and gl_angle_ext.xml", |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 590 | year = date.today().year, |
Jamie Madill | c8c9a24 | 2018-01-02 13:39:00 -0500 | [diff] [blame] | 591 | entry_points_list = ",\n".join([" " + cmd for cmd in sorted_cmd_names])) |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 592 | |
Jamie Madill | ee769dd | 2017-05-04 11:38:30 -0400 | [diff] [blame] | 593 | 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] | 594 | with open(entry_points_enum_header_path, "w") as out: |
| 595 | out.write(entry_points_enum) |
Geoff Lang | cae72d6 | 2017-06-01 11:53:45 -0400 | [diff] [blame] | 596 | out.close() |