Skip to content

Commit

Permalink
Hook up with Angle shader translator backend.
Browse files Browse the repository at this point in the history
Using the newly implemented Angle shader translator backend selection.  Before, we ignore the translated text if we run on top of Angle due to the lack of a GLSL ES backend.  Now we output GLSL ES source code and feed it to Angle instead of the original source code.  This allows us to perform processing during translation, for example, long variable name mapping.

BUG=84753
TEST=conformance/glsl-conformance.html passes on Windows/Angle
Review URL: http://codereview.chromium.org/7108049

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@89003 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
zmo@google.com committed Jun 14, 2011
1 parent 361123e commit 8f91d18
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 34 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ deps = {
(Var("googlecode_url") % "googlemock") + "/trunk@374",

"src/third_party/angle":
(Var("googlecode_url") % "angleproject") + "/trunk@686",
(Var("googlecode_url") % "angleproject") + "/trunk@687",

# Note that this is *not* where we check out WebKit -- this just
# puts some extra files into place for the real WebKit checkout to
Expand Down
29 changes: 11 additions & 18 deletions gpu/command_buffer/service/shader_translator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ bool ShaderTranslator::Init(ShShaderType shader_type,
if (!InitializeShaderTranslator())
return false;

compiler_ = ShConstructCompiler(shader_type, shader_spec, resources);
ShShaderOutput shader_output =
implementation_is_glsl_es ? SH_ESSL_OUTPUT : SH_GLSL_OUTPUT;

compiler_ = ShConstructCompiler(
shader_type, shader_spec, shader_output, resources);
implementation_is_glsl_es_ = implementation_is_glsl_es;
return compiler_ != NULL;
}
Expand All @@ -107,23 +111,12 @@ bool ShaderTranslator::Translate(const char* shader) {
SH_OBJECT_CODE | SH_ATTRIBUTES_UNIFORMS | SH_MAP_LONG_VARIABLE_NAMES;
if (ShCompile(compiler_, &shader, 1, compile_options)) {
success = true;
if (!implementation_is_glsl_es_) {
// Get translated shader.
int obj_code_len = 0;
ShGetInfo(compiler_, SH_OBJECT_CODE_LENGTH, &obj_code_len);
if (obj_code_len > 1) {
translated_shader_.reset(new char[obj_code_len]);
ShGetObjectCode(compiler_, translated_shader_.get());
}
} else {
// Pass down the original shader's source rather than the
// compiler's output. TODO(kbr): once the shader compiler has a
// GLSL ES backend, use its output.
int shader_code_len = 1 + strlen(shader);
if (shader_code_len > 1) {
translated_shader_.reset(new char[shader_code_len]);
strncpy(translated_shader_.get(), shader, shader_code_len);
}
// Get translated shader.
int obj_code_len = 0;
ShGetInfo(compiler_, SH_OBJECT_CODE_LENGTH, &obj_code_len);
if (obj_code_len > 1) {
translated_shader_.reset(new char[obj_code_len]);
ShGetObjectCode(compiler_, translated_shader_.get());
}
// Get info for attribs and uniforms.
GetVariableInfo(compiler_, SH_ACTIVE_ATTRIBUTES, &attrib_map_);
Expand Down
21 changes: 6 additions & 15 deletions webkit/gpu/webgraphicscontext3d_in_process_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1590,9 +1590,11 @@ bool WebGraphicsContext3DInProcessImpl::AngleCreateCompilers() {
resources.MaxDrawBuffers = 1;

fragment_compiler_ = ShConstructCompiler(
SH_FRAGMENT_SHADER, SH_WEBGL_SPEC, &resources);
SH_FRAGMENT_SHADER, SH_WEBGL_SPEC,
is_gles2_ ? SH_ESSL_OUTPUT : SH_GLSL_OUTPUT, &resources);
vertex_compiler_ = ShConstructCompiler(
SH_VERTEX_SHADER, SH_WEBGL_SPEC, &resources);
SH_VERTEX_SHADER, SH_WEBGL_SPEC,
is_gles2_ ? SH_ESSL_OUTPUT : SH_GLSL_OUTPUT, &resources);
return (fragment_compiler_ && vertex_compiler_);
}

Expand Down Expand Up @@ -1637,21 +1639,10 @@ bool WebGraphicsContext3DInProcessImpl::AngleValidateShaderSource(
}

int length = 0;
if (is_gles2_) {
// ANGLE does not yet have a GLSL ES backend. Therefore if the
// compile succeeds we send the original source down.
length = strlen(entry->source.get());
if (length > 0)
++length; // Add null terminator
} else {
ShGetInfo(compiler, SH_OBJECT_CODE_LENGTH, &length);
}
ShGetInfo(compiler, SH_OBJECT_CODE_LENGTH, &length);
if (length > 1) {
entry->translated_source.reset(new char[length]);
if (is_gles2_)
strncpy(entry->translated_source.get(), entry->source.get(), length);
else
ShGetObjectCode(compiler, entry->translated_source.get());
ShGetObjectCode(compiler, entry->translated_source.get());
}
entry->is_valid = true;
return true;
Expand Down

0 comments on commit 8f91d18

Please sign in to comment.