Hash :
ed2e6aa5
Author :
Date :
2017-11-23T17:17:17
GLES31: Use more compact entry point style. This migrates to the new generation style used in GLES2 and GLES3. BUG=angleproject:2254 Change-Id: I10afa1f006ff68e8bafda2bd45dd9a048f8f7dff Reviewed-on: https://chromium-review.googlesource.com/787172 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
#!/usr/bin/python2
#
# Copyright 2017 The ANGLE Project Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# generate_entry_points.py:
# Generates the OpenGL bindings and entry point layers for ANGLE.
import sys, os, pprint, json
import xml.etree.ElementTree as etree
from datetime import date
template_entry_point_header = """// GENERATED FILE - DO NOT EDIT.
// Generated by {script_name} using data from {data_source_name}.
//
// Copyright {year} The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// entry_points_gles_{major_version}_{minor_version}_autogen.h:
// Defines the GLES {major_version}.{minor_version} entry points.
#ifndef LIBGLESV2_ENTRYPOINTSGLES{major_version}{minor_version}_AUTOGEN_H_
#define LIBGLESV2_ENTRYPOINTSGLES{major_version}{minor_version}_AUTOGEN_H_
#include <GLES{major_version}/gl{major_version}{minor_version_nonzero}.h>
#include <export.h>
{include_platform}
namespace gl
{{
{entry_points}
}} // namespace gl
#endif // LIBGLESV2_ENTRYPOINTSGLES{major_version}{minor_version}_AUTOGEN_H_
"""
template_entry_point_source = """// GENERATED FILE - DO NOT EDIT.
// Generated by {script_name} using data from {data_source_name}.
//
// Copyright {year} The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// entry_points_gles_{major_version}_{minor_version}_autogen.cpp:
// Defines the GLES {major_version}.{minor_version} entry points.
#include "libANGLE/Context.h"
#include "libANGLE/validationES{major_version}{minor_version_nonzero}.h"
#include "libGLESv2/global_state.h"
namespace gl
{{
{entry_points}}} // namespace gl
"""
template_entry_points_enum_header = """// GENERATED FILE - DO NOT EDIT.
// Generated by {script_name} using data from {data_source_name}.
//
// Copyright {year} The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// entry_points_enum_autogen.h:
// Defines the GLES entry points enumeration.
#ifndef LIBGLESV2_ENTRYPOINTSENUM_AUTOGEN_H_
#define LIBGLESV2_ENTRYPOINTSENUM_AUTOGEN_H_
namespace gl
{{
enum class EntryPoint
{{
{entry_points_list}
}};
}} // namespace gl
#endif // LIBGLESV2_ENTRY_POINTS_ENUM_AUTOGEN_H_
"""
template_entry_point_decl = """ANGLE_EXPORT {return_type}GL_APIENTRY {name}({params});"""
template_entry_point_def = """{return_type}GL_APIENTRY {name}({params})
{{
EVENT("({format_params})"{comma_if_needed}{pass_params});
Context *context = {context_getter}();
if (context)
{{{packed_gl_enum_conversions}
context->gatherParams<EntryPoint::{name}>({internal_params});
if (context->skipValidation() || Validate{name}({validate_params}))
{{
{return_if_needed}context->{name_lower}({internal_params});
}}
}}
{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):
return os.path.join(os.path.dirname(sys.argv[0]), path)
tree = etree.parse(script_relative('gl.xml'))
root = tree.getroot()
commands = root.find(".//commands[@namespace='GL']")
cmd_names = []
with open(script_relative('entry_point_packed_gl_enums.json')) as f:
cmd_packed_gl_enums = json.loads(f.read())
def format_entry_point_decl(cmd_name, proto, params):
return template_entry_point_decl.format(
name = cmd_name[2:],
return_type = proto[:-len(cmd_name)],
params = ", ".join(params))
def type_name_sep_index(param):
space = param.rfind(" ")
pointer = param.rfind("*")
return max(space, pointer)
def just_the_type(param):
return param[:type_name_sep_index(param)]
def just_the_name(param):
return param[type_name_sep_index(param)+1:]
def just_the_name_packed(param, reserved_set):
name = just_the_name(param)
if name in reserved_set:
return name + 'Packed'
else:
return name
format_dict = {
"GLbitfield": "0x%X",
"GLboolean": "%u",
"GLenum": "0x%X",
"GLfloat": "%f",
"GLint": "%d",
"GLintptr": "%d",
"GLsizei": "%d",
"GLsizeiptr": "%d",
"GLsync": "0x%0.8p",
"GLuint": "%u",
"GLuint64": "%llu"
}
def param_format_string(param):
if "*" in param:
return param + " = 0x%0.8p"
else:
type_only = just_the_type(param)
if type_only not in format_dict:
raise Exception(type_only + " is not a known type in 'format_dict'")
return param + " = " + format_dict[type_only]
def default_return_value(cmd_name, return_type):
if return_type == "void":
return ""
return "GetDefaultReturnValue<EntryPoint::" + cmd_name[2:] + ", " + return_type + ">()"
def get_context_getter_function(cmd_name):
if cmd_name == "glGetError":
return "GetGlobalContext"
else:
return "GetValidGlobalContext"
def format_entry_point_def(cmd_name, proto, params):
packed_gl_enums = cmd_packed_gl_enums.get(cmd_name, {})
internal_params = [just_the_name_packed(param, packed_gl_enums) for param in params]
packed_gl_enum_conversions = []
for param in params:
name = just_the_name(param)
if name in packed_gl_enums:
internal_name = name + "Packed"
internal_type = packed_gl_enums[name]
packed_gl_enum_conversions += ["\n " + internal_type + " " + internal_name +" = FromGLenum<" +
internal_type + ">(" + name + ");"]
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.format(
name = cmd_name[2:],
name_lower = cmd_name[2:3].lower() + cmd_name[3:],
return_type = return_type,
params = ", ".join(params),
internal_params = ", ".join(internal_params),
packed_gl_enum_conversions = "".join(packed_gl_enum_conversions),
pass_params = ", ".join(pass_params),
comma_if_needed = ", " if len(params) > 0 else "",
validate_params = ", ".join(["context"] + internal_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",
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):
return os.path.join(script_relative(".."), "src", folder, file)
for major_version, minor_version in [[2, 0], [3, 0], [3, 1]]:
gles_xpath = ".//feature[@name='GL_ES_VERSION_{}_{}']//command".format(major_version, minor_version)
gles_commands = [cmd.attrib['name'] for cmd in root.findall(gles_xpath)]
entry_point_decls = []
entry_point_defs = []
for cmd_name in gles_commands:
command_xpath = "command/proto[name='" + cmd_name + "']/.."
command = commands.find(command_xpath)
params = ["".join(param.itertext()) for param in command.findall("./param")]
proto = "".join(command.find("./proto").itertext())
cmd_names += [cmd_name]
entry_point_decls += [format_entry_point_decl(cmd_name, proto, params)]
entry_point_defs += [format_entry_point_def(cmd_name, proto, params)]
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:
# We include the platform.h header since it undefines the conflicting MemoryBarrier macro.
include_platform = "\n#include \"common/platform.h\"\n"
else:
include_platform = ""
content = template.format(
script_name = os.path.basename(sys.argv[0]),
data_source_name = "gl.xml",
year = date.today().year,
major_version = major_version,
minor_version = minor_version,
minor_version_nonzero = minor_version if minor_version else "",
include_platform = include_platform,
entry_points = entry_points)
path = path_to("libGLESv2", "entry_points_gles_{}_{}_autogen.{}".format(major_version, minor_version, suffix))
with open(path, "w") as out:
out.write(content)
out.close()
# TODO(jmadill): Remove manually added entry points once we auto-gen them.
manual_cmd_names = ["Invalid"] + [cmd[2:] for cmd in cmd_names] + ["DrawElementsInstancedANGLE"]
entry_points_enum = template_entry_points_enum_header.format(
script_name = os.path.basename(sys.argv[0]),
data_source_name = "gl.xml",
year = date.today().year,
entry_points_list = ",\n".join([" " + cmd for cmd in manual_cmd_names]))
entry_points_enum_header_path = path_to("libANGLE", "entry_points_enum_autogen.h")
with open(entry_points_enum_header_path, "w") as out:
out.write(entry_points_enum)
out.close()