Commit c8c9a24a by Jamie Madill Committed by Commit Bot

Entry Points: Refactor generator script.

This cleans up some of the organization of the python generator. It will make the extension entry point generation simpler. It also changes the header guards to use more underscores, which produces a small diff. Also updates the copyright year in a few generated files. Bug: angleproject:2263 Change-Id: I42f061c24a6cfcd8328c56c57eaed9ca6c7bb293 Reviewed-on: https://chromium-review.googlesource.com/846306Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent c33f1e8c
...@@ -18,21 +18,20 @@ template_entry_point_header = """// GENERATED FILE - DO NOT EDIT. ...@@ -18,21 +18,20 @@ template_entry_point_header = """// GENERATED FILE - DO NOT EDIT.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
// entry_points_gles_{major_version}_{minor_version}_autogen.h: // entry_points_gles_{annotation_lower}_autogen.h:
// Defines the GLES {major_version}.{minor_version} entry points. // Defines the GLES {comment} entry points.
#ifndef LIBGLESV2_ENTRYPOINTSGLES{major_version}{minor_version}_AUTOGEN_H_ #ifndef LIBGLESV2_ENTRY_POINTS_GLES_{annotation_upper}_AUTOGEN_H_
#define LIBGLESV2_ENTRYPOINTSGLES{major_version}{minor_version}_AUTOGEN_H_ #define LIBGLESV2_ENTRY_POINTS_GLES_{annotation_upper}_AUTOGEN_H_
{includes}
#include <GLES{major_version}/gl{major_version}{minor_version_nonzero}.h>
#include <export.h>
{include_platform}
namespace gl namespace gl
{{ {{
{entry_points} {entry_points}
}} // namespace gl }} // namespace gl
#endif // LIBGLESV2_ENTRYPOINTSGLES{major_version}{minor_version}_AUTOGEN_H_ #endif // LIBGLESV2_ENTRY_POINTS_GLES_{annotation_upper}_AUTOGEN_H_
""" """
template_entry_point_source = """// GENERATED FILE - DO NOT EDIT. template_entry_point_source = """// GENERATED FILE - DO NOT EDIT.
...@@ -42,12 +41,10 @@ template_entry_point_source = """// GENERATED FILE - DO NOT EDIT. ...@@ -42,12 +41,10 @@ template_entry_point_source = """// GENERATED FILE - DO NOT EDIT.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
// entry_points_gles_{major_version}_{minor_version}_autogen.cpp: // entry_points_gles_{annotation_lower}_autogen.cpp:
// Defines the GLES {major_version}.{minor_version} entry points. // Defines the GLES {comment} entry points.
#include "libANGLE/Context.h" {includes}
#include "libANGLE/validationES{major_version}{minor_version_nonzero}.h"
#include "libGLESv2/global_state.h"
namespace gl namespace gl
{{ {{
...@@ -90,36 +87,18 @@ template_entry_point_def = """{return_type}GL_APIENTRY {name}({params}) ...@@ -90,36 +87,18 @@ template_entry_point_def = """{return_type}GL_APIENTRY {name}({params})
if (context->skipValidation() || Validate{name}({validate_params})) if (context->skipValidation() || Validate{name}({validate_params}))
{{ {{
{return_if_needed}context->{name_lower}({internal_params}); {return_if_needed}context->{name_lower_no_suffix}({internal_params});
}} }}
}} }}
{default_return_if_needed}}} {default_return_if_needed}}}
""" """
template_entry_point_def_oldstyle = """{return_type}GL_APIENTRY {name}({params})
{{
EVENT("({format_params})"{comma_if_needed}{pass_params});
Context *context = {context_getter}();
if (context)
{{
if (!context->skipValidation() && !Validate{name}({validate_params}))
{{
return{default_value_if_needed};
}}
{return_if_needed}context->{name_lower}({pass_params});
}}
{default_return_if_needed}}}
"""
def script_relative(path): def script_relative(path):
return os.path.join(os.path.dirname(sys.argv[0]), path) return os.path.join(os.path.dirname(sys.argv[0]), path)
tree = etree.parse(script_relative('gl.xml')) tree = etree.parse(script_relative('gl.xml'))
root = tree.getroot() root = tree.getroot()
commands = root.find(".//commands[@namespace='GL']") commands = root.find(".//commands[@namespace='GL']")
cmd_names = []
with open(script_relative('entry_point_packed_gl_enums.json')) as f: with open(script_relative('entry_point_packed_gl_enums.json')) as f:
cmd_packed_gl_enums = json.loads(f.read()) cmd_packed_gl_enums = json.loads(f.read())
...@@ -199,9 +178,11 @@ def format_entry_point_def(cmd_name, proto, params): ...@@ -199,9 +178,11 @@ def format_entry_point_def(cmd_name, proto, params):
format_params = [param_format_string(param) for param in params] format_params = [param_format_string(param) for param in params]
return_type = proto[:-len(cmd_name)] return_type = proto[:-len(cmd_name)]
default_return = default_return_value(cmd_name, return_type.strip()) default_return = default_return_value(cmd_name, return_type.strip())
name_lower_no_suffix = cmd_name[2:3].lower() + cmd_name[3:]
return template_entry_point_def.format( return template_entry_point_def.format(
name = cmd_name[2:], name = cmd_name[2:],
name_lower = cmd_name[2:3].lower() + cmd_name[3:], name_lower_no_suffix = name_lower_no_suffix,
return_type = return_type, return_type = return_type,
params = ", ".join(params), params = ", ".join(params),
internal_params = ", ".join(internal_params), internal_params = ", ".join(internal_params),
...@@ -214,36 +195,13 @@ def format_entry_point_def(cmd_name, proto, params): ...@@ -214,36 +195,13 @@ def format_entry_point_def(cmd_name, proto, params):
default_return_if_needed = "" if default_return == "" else "\n return " + default_return + ";\n", default_return_if_needed = "" if default_return == "" else "\n return " + default_return + ";\n",
context_getter = get_context_getter_function(cmd_name)) context_getter = get_context_getter_function(cmd_name))
def format_entry_point_def_oldstyle(cmd_name, proto, params):
pass_params = [just_the_name(param) for param in params]
format_params = [param_format_string(param) for param in params]
return_type = proto[:-len(cmd_name)]
default_return = default_return_value(cmd_name, return_type.strip())
return template_entry_point_def_oldstyle.format(
name = cmd_name[2:],
name_lower = cmd_name[2:3].lower() + cmd_name[3:],
return_type = return_type,
params = ", ".join(params),
pass_params = ", ".join(pass_params),
comma_if_needed = ", " if len(params) > 0 else "",
validate_params = ", ".join(["context"] + pass_params),
format_params = ", ".join(format_params),
return_if_needed = "" if default_return == "" else "return ",
default_return_if_needed = "" if default_return == "" else "\n return " + default_return + ";\n",
default_value_if_needed = "" if default_return == "" else (" " + default_return),
context_getter = get_context_getter_function(cmd_name))
def path_to(folder, file): def path_to(folder, file):
return os.path.join(script_relative(".."), "src", folder, file) return os.path.join(script_relative(".."), "src", folder, file)
all_commands = root.findall('commands/command') def get_entry_points(all_commands, gles_commands):
for major_version, minor_version in [[2, 0], [3, 0], [3, 1]]: decls = []
gles_xpath = ".//feature[@name='GL_ES_VERSION_{}_{}']//command".format(major_version, minor_version) defs = []
gles_commands = [cmd.attrib['name'] for cmd in root.findall(gles_xpath)]
entry_point_decls = []
entry_point_defs = []
for command in all_commands: for command in all_commands:
proto = command.find('proto') proto = command.find('proto')
...@@ -254,49 +212,78 @@ for major_version, minor_version in [[2, 0], [3, 0], [3, 1]]: ...@@ -254,49 +212,78 @@ for major_version, minor_version in [[2, 0], [3, 0], [3, 1]]:
param_text = ["".join(param.itertext()) for param in command.findall('param')] param_text = ["".join(param.itertext()) for param in command.findall('param')]
proto_text = "".join(proto.itertext()) proto_text = "".join(proto.itertext())
cmd_names += [cmd_name]
entry_point_decls += [format_entry_point_decl(cmd_name, proto_text, param_text)]
entry_point_defs += [format_entry_point_def(cmd_name, proto_text, param_text)]
for type in ["header", "source"]:
if type == "header":
template = template_entry_point_header
entry_points = "\n".join(entry_point_decls)
suffix = "h"
else:
template = template_entry_point_source
entry_points = "\n".join(entry_point_defs)
suffix = "cpp"
if type == "header" and major_version == 3 and minor_version == 1: decls.append(format_entry_point_decl(cmd_name, proto_text, param_text))
# We include the platform.h header since it undefines the conflicting MemoryBarrier macro. defs.append(format_entry_point_def(cmd_name, proto_text, param_text))
include_platform = "\n#include \"common/platform.h\"\n"
else: return decls, defs
include_platform = ""
def write_file(annotation, comment, template, entry_points, suffix, includes):
content = template.format( content = template.format(
script_name = os.path.basename(sys.argv[0]), script_name = os.path.basename(sys.argv[0]),
data_source_name = "gl.xml", data_source_name = "gl.xml",
year = date.today().year, year = date.today().year,
major_version = major_version, annotation_lower = annotation.lower(),
minor_version = minor_version, annotation_upper = annotation.upper(),
minor_version_nonzero = minor_version if minor_version else "", comment = comment,
include_platform = include_platform, includes = includes,
entry_points = entry_points) entry_points = entry_points)
path = path_to("libGLESv2", "entry_points_gles_{}_{}_autogen.{}".format(major_version, minor_version, suffix)) path = path_to("libGLESv2", "entry_points_gles_{}_autogen.{}".format(
annotation.lower(), suffix))
with open(path, "w") as out: with open(path, "w") as out:
out.write(content) out.write(content)
out.close() out.close()
all_commands = root.findall('commands/command')
all_cmd_names = []
template_header_includes = """#include <GLES{}/gl{}{}.h>
#include <export.h>"""
template_sources_includes = """#include "libANGLE/Context.h"
#include "libANGLE/validationES{}{}.h"
#include "libGLESv2/global_state.h"
"""
# First run through the main GLES entry points.
for major_version, minor_version in [[2, 0], [3, 0], [3, 1]]:
annotation = "{}_{}".format(major_version, minor_version)
comment = annotation.replace("_", ".")
gles_xpath = ".//feature[@name='GL_ES_VERSION_{}']//command".format(annotation)
gles_commands = [cmd.attrib['name'] for cmd in root.findall(gles_xpath)]
all_cmd_names += gles_commands
decls, defs = get_entry_points(all_commands, gles_commands)
minor_if_not_zero = minor_version if minor_version != 0 else ""
header_includes = template_header_includes.format(
major_version, major_version, minor_if_not_zero)
# We include the platform.h header since it undefines the conflicting MemoryBarrier macro.
if major_version == 3 and minor_version == 1:
header_includes += "\n#include \"common/platform.h\"\n"
source_includes = template_sources_includes.format(major_version, minor_if_not_zero)
write_file(annotation, comment, template_entry_point_header,
"\n".join(decls), "h", header_includes)
write_file(annotation, comment, template_entry_point_source,
"\n".join(defs), "cpp", source_includes)
# TODO(jmadill): Remove manually added entry points once we auto-gen them. # TODO(jmadill): Remove manually added entry points once we auto-gen them.
manual_cmd_names = ["Invalid"] + [cmd[2:] for cmd in sorted(cmd_names)] + ["DrawElementsInstancedANGLE"] all_cmd_names += ["glDrawElementsInstancedANGLE"]
sorted_cmd_names = ["Invalid"] + [cmd[2:] for cmd in sorted(all_cmd_names)]
entry_points_enum = template_entry_points_enum_header.format( entry_points_enum = template_entry_points_enum_header.format(
script_name = os.path.basename(sys.argv[0]), script_name = os.path.basename(sys.argv[0]),
data_source_name = "gl.xml", data_source_name = "gl.xml",
year = date.today().year, year = date.today().year,
entry_points_list = ",\n".join([" " + cmd for cmd in manual_cmd_names])) entry_points_list = ",\n".join([" " + cmd for cmd in sorted_cmd_names]))
entry_points_enum_header_path = path_to("libANGLE", "entry_points_enum_autogen.h") entry_points_enum_header_path = path_to("libANGLE", "entry_points_enum_autogen.h")
with open(entry_points_enum_header_path, "w") as out: with open(entry_points_enum_header_path, "w") as out:
......
// GENERATED FILE - DO NOT EDIT. // GENERATED FILE - DO NOT EDIT.
// Generated by gen_packed_gl_enums.py using data from packed_gl_enums.json. // Generated by gen_packed_gl_enums.py using data from packed_gl_enums.json.
// //
// Copyright 2017 The ANGLE Project Authors. All rights reserved. // Copyright 2018 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
......
// GENERATED FILE - DO NOT EDIT. // GENERATED FILE - DO NOT EDIT.
// Generated by gen_packed_gl_enums.py using data from packed_gl_enums.json. // Generated by gen_packed_gl_enums.py using data from packed_gl_enums.json.
// //
// Copyright 2017 The ANGLE Project Authors. All rights reserved. // Copyright 2018 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
......
// GENERATED FILE - DO NOT EDIT. // GENERATED FILE - DO NOT EDIT.
// Generated by generate_entry_points.py using data from gl.xml. // Generated by generate_entry_points.py using data from gl.xml.
// //
// Copyright 2017 The ANGLE Project Authors. All rights reserved. // Copyright 2018 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
...@@ -93,6 +93,7 @@ enum class EntryPoint ...@@ -93,6 +93,7 @@ enum class EntryPoint
DrawElements, DrawElements,
DrawElementsIndirect, DrawElementsIndirect,
DrawElementsInstanced, DrawElementsInstanced,
DrawElementsInstancedANGLE,
DrawRangeElements, DrawRangeElements,
Enable, Enable,
EnableVertexAttribArray, EnableVertexAttribArray,
...@@ -329,8 +330,7 @@ enum class EntryPoint ...@@ -329,8 +330,7 @@ enum class EntryPoint
VertexAttribPointer, VertexAttribPointer,
VertexBindingDivisor, VertexBindingDivisor,
Viewport, Viewport,
WaitSync, WaitSync
DrawElementsInstancedANGLE
}; };
} // namespace gl } // namespace gl
#endif // LIBGLESV2_ENTRY_POINTS_ENUM_AUTOGEN_H_ #endif // LIBGLESV2_ENTRY_POINTS_ENUM_AUTOGEN_H_
// GENERATED FILE - DO NOT EDIT. // GENERATED FILE - DO NOT EDIT.
// Generated by gen_angle_format_table.py using data from angle_format_data.json // Generated by gen_angle_format_table.py using data from angle_format_data.json
// //
// Copyright 2017 The ANGLE Project Authors. All rights reserved. // Copyright 2018 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
......
// GENERATED FILE - DO NOT EDIT. // GENERATED FILE - DO NOT EDIT.
// Generated by gen_angle_format_table.py using data from angle_format_data.json // Generated by gen_angle_format_table.py using data from angle_format_data.json
// //
// Copyright 2017 The ANGLE Project Authors. All rights reserved. // Copyright 2018 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
......
// GENERATED FILE - DO NOT EDIT. // GENERATED FILE - DO NOT EDIT.
// Generated by generate_entry_points.py using data from gl.xml. // Generated by generate_entry_points.py using data from gl.xml.
// //
// Copyright 2017 The ANGLE Project Authors. All rights reserved. // Copyright 2018 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
......
// GENERATED FILE - DO NOT EDIT. // GENERATED FILE - DO NOT EDIT.
// Generated by generate_entry_points.py using data from gl.xml. // Generated by generate_entry_points.py using data from gl.xml.
// //
// Copyright 2017 The ANGLE Project Authors. All rights reserved. // Copyright 2018 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
// entry_points_gles_2_0_autogen.h: // entry_points_gles_2_0_autogen.h:
// Defines the GLES 2.0 entry points. // Defines the GLES 2.0 entry points.
#ifndef LIBGLESV2_ENTRYPOINTSGLES20_AUTOGEN_H_ #ifndef LIBGLESV2_ENTRY_POINTS_GLES_2_0_AUTOGEN_H_
#define LIBGLESV2_ENTRYPOINTSGLES20_AUTOGEN_H_ #define LIBGLESV2_ENTRY_POINTS_GLES_2_0_AUTOGEN_H_
#include <GLES2/gl2.h> #include <GLES2/gl2.h>
#include <export.h> #include <export.h>
...@@ -294,4 +294,4 @@ ANGLE_EXPORT void GL_APIENTRY VertexAttribPointer(GLuint index, ...@@ -294,4 +294,4 @@ ANGLE_EXPORT void GL_APIENTRY VertexAttribPointer(GLuint index,
ANGLE_EXPORT void GL_APIENTRY Viewport(GLint x, GLint y, GLsizei width, GLsizei height); ANGLE_EXPORT void GL_APIENTRY Viewport(GLint x, GLint y, GLsizei width, GLsizei height);
} // namespace gl } // namespace gl
#endif // LIBGLESV2_ENTRYPOINTSGLES20_AUTOGEN_H_ #endif // LIBGLESV2_ENTRY_POINTS_GLES_2_0_AUTOGEN_H_
// GENERATED FILE - DO NOT EDIT. // GENERATED FILE - DO NOT EDIT.
// Generated by generate_entry_points.py using data from gl.xml. // Generated by generate_entry_points.py using data from gl.xml.
// //
// Copyright 2017 The ANGLE Project Authors. All rights reserved. // Copyright 2018 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
......
// GENERATED FILE - DO NOT EDIT. // GENERATED FILE - DO NOT EDIT.
// Generated by generate_entry_points.py using data from gl.xml. // Generated by generate_entry_points.py using data from gl.xml.
// //
// Copyright 2017 The ANGLE Project Authors. All rights reserved. // Copyright 2018 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
// entry_points_gles_3_0_autogen.h: // entry_points_gles_3_0_autogen.h:
// Defines the GLES 3.0 entry points. // Defines the GLES 3.0 entry points.
#ifndef LIBGLESV2_ENTRYPOINTSGLES30_AUTOGEN_H_ #ifndef LIBGLESV2_ENTRY_POINTS_GLES_3_0_AUTOGEN_H_
#define LIBGLESV2_ENTRYPOINTSGLES30_AUTOGEN_H_ #define LIBGLESV2_ENTRY_POINTS_GLES_3_0_AUTOGEN_H_
#include <GLES3/gl3.h> #include <GLES3/gl3.h>
#include <export.h> #include <export.h>
...@@ -281,4 +281,4 @@ VertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, cons ...@@ -281,4 +281,4 @@ VertexAttribIPointer(GLuint index, GLint size, GLenum type, GLsizei stride, cons
ANGLE_EXPORT void GL_APIENTRY WaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout); ANGLE_EXPORT void GL_APIENTRY WaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout);
} // namespace gl } // namespace gl
#endif // LIBGLESV2_ENTRYPOINTSGLES30_AUTOGEN_H_ #endif // LIBGLESV2_ENTRY_POINTS_GLES_3_0_AUTOGEN_H_
// GENERATED FILE - DO NOT EDIT. // GENERATED FILE - DO NOT EDIT.
// Generated by generate_entry_points.py using data from gl.xml. // Generated by generate_entry_points.py using data from gl.xml.
// //
// Copyright 2017 The ANGLE Project Authors. All rights reserved. // Copyright 2018 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
......
// GENERATED FILE - DO NOT EDIT. // GENERATED FILE - DO NOT EDIT.
// Generated by generate_entry_points.py using data from gl.xml. // Generated by generate_entry_points.py using data from gl.xml.
// //
// Copyright 2017 The ANGLE Project Authors. All rights reserved. // Copyright 2018 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
// entry_points_gles_3_1_autogen.h: // entry_points_gles_3_1_autogen.h:
// Defines the GLES 3.1 entry points. // Defines the GLES 3.1 entry points.
#ifndef LIBGLESV2_ENTRYPOINTSGLES31_AUTOGEN_H_ #ifndef LIBGLESV2_ENTRY_POINTS_GLES_3_1_AUTOGEN_H_
#define LIBGLESV2_ENTRYPOINTSGLES31_AUTOGEN_H_ #define LIBGLESV2_ENTRY_POINTS_GLES_3_1_AUTOGEN_H_
#include <GLES3/gl31.h> #include <GLES3/gl31.h>
#include <export.h> #include <export.h>
#include "common/platform.h" #include "common/platform.h"
namespace gl namespace gl
...@@ -225,4 +224,4 @@ ANGLE_EXPORT void GL_APIENTRY VertexAttribIFormat(GLuint attribindex, ...@@ -225,4 +224,4 @@ ANGLE_EXPORT void GL_APIENTRY VertexAttribIFormat(GLuint attribindex,
ANGLE_EXPORT void GL_APIENTRY VertexBindingDivisor(GLuint bindingindex, GLuint divisor); ANGLE_EXPORT void GL_APIENTRY VertexBindingDivisor(GLuint bindingindex, GLuint divisor);
} // namespace gl } // namespace gl
#endif // LIBGLESV2_ENTRYPOINTSGLES31_AUTOGEN_H_ #endif // LIBGLESV2_ENTRY_POINTS_GLES_3_1_AUTOGEN_H_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment