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