summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLingfeng Yang <lfy@google.com>2017-01-09 11:51:45 -0800
committerGreg Hartman <ghartman@google.com>2018-08-23 17:30:51 -0700
commit1d7dfe4817ab5901e37baca26ef8d3ad87752743 (patch)
treef9df2e965fd1d1f06ea9536bfe460cbd1be7ba04
parentf6ba3d3c42eb5970afc115cb2ab1ee121e312049 (diff)
downloadopengl-transport-1d7dfe4817ab5901e37baca26ef8d3ad87752743.tar.gz
[GLESv3] ES 3.x API implementation v1
- ES 3.0 almost conformant (~80 failing tests not having to do w/ compressed texture support) - ES 3.1 has a first cut, still lots TODO Change-Id: I3aaafa6f42aba5ba7b1937556529b746d54cfb95
-rwxr-xr-xhost/commands/gen-entries.py166
1 files changed, 165 insertions, 1 deletions
diff --git a/host/commands/gen-entries.py b/host/commands/gen-entries.py
index d5fc59fe9..a122ef7e3 100755
--- a/host/commands/gen-entries.py
+++ b/host/commands/gen-entries.py
@@ -42,9 +42,13 @@ class Entry:
self.func_name = func_name
self.return_type = return_type
self.parameters = ""
+ self.vartypes = []
+ self.varnames = []
self.call = ""
comma = ""
for param in parameters:
+ self.vartypes.append(param[0])
+ self.varnames.append(param[1])
self.parameters += "%s%s %s" % (comma, param[0], param[1])
self.call += "%s%s" % (comma, param[1])
comma = ", "
@@ -148,6 +152,164 @@ def gen_functions_header(entries, prefix_name, verbatim, filename, with_args):
print "#endif // %s_FUNCTIONS_H" % prefix_name
+
+# The purpose of gen_translator()
+# is to quickly generate implementations on the host Translator,
+# which processes commands that just got onto the renderthread off goldfish pipe
+# and are fed to system OpenGL.
+
+def gen_translator(entries):
+ # Definitions for custom implementation bodies go in
+ # android/scripts/gles3translatorgen/gles30_custom.py
+ # android/scripts/gles3translatorgen/gles31_custom.py
+ from gles3translatorgen import gles30_custom
+ from gles3translatorgen import gles31_custom
+
+ translator_custom_share_processing = { }
+ for (k, v) in gles30_custom.custom_share_processing.items():
+ translator_custom_share_processing[k] = v
+ for (k, v) in gles31_custom.custom_share_processing.items():
+ translator_custom_share_processing[k] = v
+
+ translator_custom_pre = { }
+ for (k, v) in gles30_custom.custom_preprocesses.items():
+ translator_custom_pre[k] = v
+ for (k, v) in gles31_custom.custom_preprocesses.items():
+ translator_custom_pre[k] = v
+
+ translator_custom_post = { }
+ for (k, v) in gles30_custom.custom_postprocesses.items():
+ translator_custom_post[k] = v
+ for (k, v) in gles31_custom.custom_postprocesses.items():
+ translator_custom_post[k] = v
+
+ translator_no_passthrough = {}
+ for (k, v) in gles30_custom.no_passthrough.items():
+ translator_no_passthrough[k] = v
+ for (k, v) in gles31_custom.no_passthrough.items():
+ translator_no_passthrough[k] = v
+
+ translator_needexternc = {
+ "glGetStringi": 1,
+ "glUniform4ui": 1,
+ "glGetUniformIndices": 1,
+ "glTransformFeedbackVaryings": 1,
+ "glCreateShaderProgramv": 1,
+ "glProgramUniform2ui": 1,
+ "glProgramUniform3ui": 1,
+ "glProgramUniform4ui": 1,
+ "glBindVertexBuffer": 1,
+ };
+ translator_nocontext_fail_codes = {
+ "glClientWaitSync" : "GL_WAIT_FAILED",
+ };
+ def needExternC(entry):
+ if translator_needexternc.has_key(entry.func_name):
+ return "extern \"C\" "
+ else:
+ return ""
+ def get_fail_code(entry):
+ if translator_nocontext_fail_codes.has_key(entry.func_name):
+ return translator_nocontext_fail_codes[entry.func_name];
+ else:
+ return "0"
+ def gen_cxt_getter(entry):
+ if (entry.return_type == "void"):
+ print " GET_CTX_V2();"
+ else:
+ print " GET_CTX_V2_RET(%s);" % get_fail_code(entry)
+
+ def gen_validations_custom_impl(entry):
+ isGen = entry.func_name.startswith("glGen")
+ isDelete = entry.func_name.startswith("glDelete")
+ isBufferOp = "Buffer" in entry.func_name
+
+ hasTargetArg = "target" in entry.varnames
+ hasProgramArg = "program" in entry.varnames
+
+ def mySetError(condition, glerr):
+ if entry.return_type == "void":
+ return "SET_ERROR_IF(%s,%s)" % (condition, glerr);
+ else:
+ return "RET_AND_SET_ERROR_IF(%s,%s,%s)" % (condition, glerr, get_fail_code(entry));
+
+ if (isGen or isDelete) and ("n" in entry.varnames):
+ print " %s;" % mySetError("n < 0", "GL_INVALID_VALUE");
+ if (isBufferOp and hasTargetArg):
+ print " %s;" % mySetError("!GLESv2Validate::bufferTarget(ctx, target)", "GL_INVALID_ENUM");
+ if translator_custom_pre.has_key(entry.func_name):
+ print translator_custom_pre[entry.func_name],
+
+ def gen_call_ret(entry):
+ globalNameTypes = {
+ ("GLuint", "program") : "NamedObjectType::SHADER_OR_PROGRAM",
+ ("GLuint", "texture") : "NamedObjectType::TEXTURE",
+ ("GLuint", "buffer") : "NamedObjectType::VERTEXBUFFER",
+ ("GLuint", "sampler") : "NamedObjectType::SAMPLER",
+ ("GLuint", "query") : "NamedObjectType::QUERY",
+ }
+ globalNames = {
+ ("GLuint", "program") : "globalProgramName",
+ ("GLuint", "texture") : "globalTextureName",
+ ("GLuint", "buffer") : "globalBufferName",
+ ("GLuint", "sampler") : "globalSampler",
+ ("GLuint", "query") : "globalQuery",
+ }
+
+ needsShareGroup = False
+ for v in zip(entry.vartypes, entry.varnames):
+ if v in globalNameTypes.keys():
+ needsShareGroup = True
+
+ if needsShareGroup:
+ print " if (ctx->shareGroup().get()) {"
+ for key in zip(entry.vartypes, entry.varnames):
+ vartype, varname = key
+ if globalNames.has_key(key):
+ print " const GLuint %s = ctx->shareGroup()->getGlobalName(%s, %s);" % (globalNames[key], globalNameTypes[key], varname)
+
+ globalCall = ", ".join(map(lambda k: globalNames.get(k, k[1]), zip(entry.vartypes, entry.varnames)))
+
+ if needsShareGroup and translator_custom_share_processing.has_key(entry.func_name):
+ print translator_custom_share_processing[entry.func_name],
+
+ if (entry.return_type == "void"):
+ if (needsShareGroup):
+ print " ",
+
+ if not translator_no_passthrough.has_key(entry.func_name):
+ print " ctx->dispatcher().%s(%s);" % (entry.func_name, globalCall)
+
+ if needsShareGroup:
+ print " }"
+ if translator_custom_post.has_key(entry.func_name):
+ print translator_custom_post[entry.func_name];
+ else:
+ if (needsShareGroup):
+ print " ",
+ if not translator_no_passthrough.has_key(entry.func_name):
+ print " %s %s = ctx->dispatcher().%s(%s);" % (entry.return_type, entry.func_name + "RET", entry.func_name, globalCall)
+ else:
+ print " %s %s = %s" % (entry.return_type, entry_func_name + "RET", get_fail_code(entry))
+
+ if translator_custom_post.has_key(entry.func_name):
+ print translator_custom_post[entry.func_name];
+
+ print " return %s;" % (entry.func_name + "RET");
+ if needsShareGroup:
+ print " } else return %s;" % (get_fail_code(entry))
+
+ print "// Auto-generated with: %s" % banner_command(sys.argv)
+ print "// This file is best left unedited."
+ print "// Try to make changes through gen_translator in gen-entries.py,"
+ print "// and/or parcel out custom functionality in separate code."
+ for entry in entries:
+ print "%sGL_APICALL %s GL_APIENTRY %s(%s) {" % (needExternC(entry), entry.return_type, entry.func_name, entry.parameters)
+ gen_cxt_getter(entry);
+ gen_validations_custom_impl(entry);
+ gen_call_ret(entry);
+ print "}\n"
+
def gen_dll_wrapper(entries, prefix_name, verbatim, filename):
"""Generate a C source file that contains functions that act as wrappers
for entry points located in another shared library. This allows the
@@ -261,6 +423,8 @@ def parse_file(filename, lines, mode):
gen_windows_def_file(entries)
elif mode == 'sym':
gen_unix_sym_file(entries)
+ elif mode == 'translator_passthrough':
+ gen_translator(entries)
elif mode == 'wrapper':
gen_dll_wrapper(entries, prefix_name, verbatim, filename)
elif mode == 'symbols':
@@ -275,7 +439,7 @@ def parse_file(filename, lines, mode):
# List of valid --mode option values.
mode_list = [
- 'def', 'sym', 'wrapper', 'symbols', '_symbols', 'functions', 'funcargs'
+ 'def', 'sym', 'translator_passthrough', 'wrapper', 'symbols', '_symbols', 'functions', 'funcargs'
]
# Argument parsing.