Refactor ShaderVariables to store fields in the base.
Instead of only storing structure information in Varyings, Uniforms
and Interface Block Fields, store it in the base class. Also only
store base variable information for struct fields, instead of fully
typed information. This works because stuff like interpolation type,
invariance, and other properties are for the entire variable, not
individual fields.
Also add new fields for interface block instance name, varying
invariance and structure name for all struct types.
BUG=angle:466
Change-Id: If03fc071e6becb7aad6dea5093989bba7daee69e
Reviewed-on: https://chromium-review.googlesource.com/213501
Reviewed-by: Zhenyao Mo <zmo@chromium.org>
Tested-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Nicolas Capens <capn@chromium.org>
diff --git a/src/libGLESv2/ProgramBinary.cpp b/src/libGLESv2/ProgramBinary.cpp
index 4ec3f6c..5a667e8 100644
--- a/src/libGLESv2/ProgramBinary.cpp
+++ b/src/libGLESv2/ProgramBinary.cpp
@@ -1077,7 +1077,7 @@
PackedVarying *output = &vertexVaryings[vertVaryingIndex];
if (output->name == input->name)
{
- if (!linkValidateVariables(infoLog, output->name, *input, *output))
+ if (!linkValidateVaryings(infoLog, output->name, *input, *output))
{
return false;
}
@@ -1818,32 +1818,29 @@
return false;
}
- return true;
-}
-
-template <class ShaderVarType>
-bool ProgramBinary::linkValidateFields(InfoLog &infoLog, const std::string &varName, const ShaderVarType &vertexVar, const ShaderVarType &fragmentVar)
-{
- if (vertexVar.fields.size() != fragmentVar.fields.size())
+ if (vertexVariable.fields.size() != fragmentVariable.fields.size())
{
- infoLog.append("Structure lengths for %s differ between vertex and fragment shaders", varName.c_str());
+ infoLog.append("Structure lengths for %s differ between vertex and fragment shaders", variableName.c_str());
return false;
}
- const unsigned int numMembers = vertexVar.fields.size();
+ const unsigned int numMembers = vertexVariable.fields.size();
for (unsigned int memberIndex = 0; memberIndex < numMembers; memberIndex++)
{
- const ShaderVarType &vertexMember = vertexVar.fields[memberIndex];
- const ShaderVarType &fragmentMember = fragmentVar.fields[memberIndex];
+ const sh::ShaderVariable &vertexMember = vertexVariable.fields[memberIndex];
+ const sh::ShaderVariable &fragmentMember = fragmentVariable.fields[memberIndex];
if (vertexMember.name != fragmentMember.name)
{
infoLog.append("Name mismatch for field '%d' of %s: (in vertex: '%s', in fragment: '%s')",
- memberIndex, varName.c_str(), vertexMember.name.c_str(), fragmentMember.name.c_str());
+ memberIndex, variableName.c_str(),
+ vertexMember.name.c_str(), fragmentMember.name.c_str());
return false;
}
- const std::string memberName = varName.substr(0, varName.length()-1) + "." + vertexVar.name + "'";
- if (!linkValidateVariables(infoLog, memberName, vertexMember, fragmentMember))
+ const std::string memberName = variableName.substr(0, variableName.length() - 1) + "." +
+ vertexMember.name + "'";
+
+ if (!linkValidateVariablesBase(infoLog, vertexMember.name, vertexMember, fragmentMember, validatePrecision))
{
return false;
}
@@ -1852,22 +1849,17 @@
return true;
}
-bool ProgramBinary::linkValidateVariables(InfoLog &infoLog, const std::string &uniformName, const sh::Uniform &vertexUniform, const sh::Uniform &fragmentUniform)
+bool ProgramBinary::linkValidateUniforms(InfoLog &infoLog, const std::string &uniformName, const sh::Uniform &vertexUniform, const sh::Uniform &fragmentUniform)
{
if (!linkValidateVariablesBase(infoLog, uniformName, vertexUniform, fragmentUniform, true))
{
return false;
}
- if (!linkValidateFields<sh::Uniform>(infoLog, uniformName, vertexUniform, fragmentUniform))
- {
- return false;
- }
-
return true;
}
-bool ProgramBinary::linkValidateVariables(InfoLog &infoLog, const std::string &varyingName, const sh::Varying &vertexVarying, const sh::Varying &fragmentVarying)
+bool ProgramBinary::linkValidateVaryings(InfoLog &infoLog, const std::string &varyingName, const sh::Varying &vertexVarying, const sh::Varying &fragmentVarying)
{
if (!linkValidateVariablesBase(infoLog, varyingName, vertexVarying, fragmentVarying, false))
{
@@ -1880,15 +1872,10 @@
return false;
}
- if (!linkValidateFields<sh::Varying>(infoLog, varyingName, vertexVarying, fragmentVarying))
- {
- return false;
- }
-
return true;
}
-bool ProgramBinary::linkValidateVariables(InfoLog &infoLog, const std::string &uniformName, const sh::InterfaceBlockField &vertexUniform, const sh::InterfaceBlockField &fragmentUniform)
+bool ProgramBinary::linkValidateInterfaceBlockFields(InfoLog &infoLog, const std::string &uniformName, const sh::InterfaceBlockField &vertexUniform, const sh::InterfaceBlockField &fragmentUniform)
{
if (!linkValidateVariablesBase(infoLog, uniformName, vertexUniform, fragmentUniform, true))
{
@@ -1901,11 +1888,6 @@
return false;
}
- if (!linkValidateFields<sh::InterfaceBlockField>(infoLog, uniformName, vertexUniform, fragmentUniform))
- {
- return false;
- }
-
return true;
}
@@ -1932,7 +1914,7 @@
{
const sh::Uniform &vertexUniform = *entry->second;
const std::string &uniformName = "uniform '" + vertexUniform.name + "'";
- if (!linkValidateVariables(infoLog, uniformName, vertexUniform, fragmentUniform))
+ if (!linkValidateUniforms(infoLog, uniformName, vertexUniform, fragmentUniform))
{
return false;
}
@@ -1970,7 +1952,7 @@
defineUniform(shader, uniform, uniform.name, &encoder);
}
-void ProgramBinary::defineUniform(GLenum shader, const sh::Uniform &uniform,
+void ProgramBinary::defineUniform(GLenum shader, const sh::ShaderVariable &uniform,
const std::string &fullName, sh::HLSLBlockEncoder *encoder)
{
if (uniform.isStruct())
@@ -1983,7 +1965,7 @@
for (size_t fieldIndex = 0; fieldIndex < uniform.fields.size(); fieldIndex++)
{
- const sh::Uniform &field = uniform.fields[fieldIndex];
+ const sh::ShaderVariable &field = uniform.fields[fieldIndex];
const std::string &fieldFullName = (fullName + elementString + "." + field.name);
defineUniform(shader, field, fieldFullName, encoder);
@@ -2169,8 +2151,8 @@
return false;
}
- std::string uniformName = "interface block '" + vertexInterfaceBlock.name + "' member '" + vertexMember.name + "'";
- if (!linkValidateVariables(infoLog, uniformName, vertexMember, fragmentMember))
+ std::string memberName = "interface block '" + vertexInterfaceBlock.name + "' member '" + vertexMember.name + "'";
+ if (!linkValidateInterfaceBlockFields(infoLog, memberName, vertexMember, fragmentMember))
{
return false;
}
@@ -2286,12 +2268,13 @@
return true;
}
-void ProgramBinary::defineUniformBlockMembers(const std::vector<sh::InterfaceBlockField> &fields, const std::string &prefix, int blockIndex,
+template <typename VarT>
+void ProgramBinary::defineUniformBlockMembers(const std::vector<VarT> &fields, const std::string &prefix, int blockIndex,
sh::BlockLayoutEncoder *encoder, std::vector<unsigned int> *blockUniformIndexes)
{
for (unsigned int uniformIndex = 0; uniformIndex < fields.size(); uniformIndex++)
{
- const sh::InterfaceBlockField &field = fields[uniformIndex];
+ const VarT &field = fields[uniformIndex];
const std::string &fieldName = (prefix.empty() ? field.name : prefix + "." + field.name);
if (field.isStruct())
@@ -2308,7 +2291,7 @@
}
else
{
- sh::BlockMemberInfo memberInfo = encoder->encodeInterfaceBlockField(field);
+ sh::BlockMemberInfo memberInfo = encoder->encodeVariable(field);
LinkedUniform *newUniform = new LinkedUniform(field.type, field.precision, fieldName, field.arraySize,
blockIndex, memberInfo);