Commit 5b130dcc by Jamie Madill

Do not create dummy variables when linking uniforms.

This cleanup prepares us for removing the uniform register info from the shader translator types. BUG=angle:466 Change-Id: I86f47970b793135f410a5ef698fc96d44219ee96 Reviewed-on: https://chromium-review.googlesource.com/207253Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org>
parent 66d43d24
...@@ -1929,12 +1929,12 @@ bool ProgramBinary::linkUniforms(InfoLog &infoLog, const std::vector<sh::Uniform ...@@ -1929,12 +1929,12 @@ bool ProgramBinary::linkUniforms(InfoLog &infoLog, const std::vector<sh::Uniform
for (unsigned int uniformIndex = 0; uniformIndex < vertexUniforms.size(); uniformIndex++) for (unsigned int uniformIndex = 0; uniformIndex < vertexUniforms.size(); uniformIndex++)
{ {
defineUniform(GL_VERTEX_SHADER, vertexUniforms[uniformIndex]); defineUniformBase(GL_VERTEX_SHADER, vertexUniforms[uniformIndex]);
} }
for (unsigned int uniformIndex = 0; uniformIndex < fragmentUniforms.size(); uniformIndex++) for (unsigned int uniformIndex = 0; uniformIndex < fragmentUniforms.size(); uniformIndex++)
{ {
defineUniform(GL_FRAGMENT_SHADER, fragmentUniforms[uniformIndex]); defineUniformBase(GL_FRAGMENT_SHADER, fragmentUniforms[uniformIndex]);
} }
if (!indexUniforms(infoLog)) if (!indexUniforms(infoLog))
...@@ -1947,69 +1947,64 @@ bool ProgramBinary::linkUniforms(InfoLog &infoLog, const std::vector<sh::Uniform ...@@ -1947,69 +1947,64 @@ bool ProgramBinary::linkUniforms(InfoLog &infoLog, const std::vector<sh::Uniform
return true; return true;
} }
void ProgramBinary::defineUniform(GLenum shader, const sh::Uniform &constant) void ProgramBinary::defineUniformBase(GLenum shader, const sh::Uniform &uniform)
{ {
if (constant.isStruct()) defineUniform(shader, uniform, uniform.name, uniform.registerIndex);
}
void ProgramBinary::defineUniform(GLenum shader, const sh::Uniform &uniform,
const std::string &fullName, unsigned int baseRegisterIndex)
{
if (uniform.isStruct())
{ {
if (constant.arraySize > 0) if (uniform.arraySize > 0)
{ {
ShShaderOutput outputType = Shader::getCompilerOutputType(shader); ShShaderOutput outputType = Shader::getCompilerOutputType(shader);
const unsigned int elementRegisterCount = HLSLVariableRegisterCount(constant, outputType) / constant.arraySize; const unsigned int elementRegisterCount = HLSLVariableRegisterCount(uniform, outputType) / uniform.arraySize;
for (unsigned int elementIndex = 0; elementIndex < constant.arraySize; elementIndex++) for (unsigned int elementIndex = 0; elementIndex < uniform.arraySize; elementIndex++)
{ {
const unsigned int elementRegisterOffset = elementRegisterCount * elementIndex; const unsigned int elementRegisterOffset = elementRegisterCount * elementIndex;
for (size_t fieldIndex = 0; fieldIndex < constant.fields.size(); fieldIndex++) for (size_t fieldIndex = 0; fieldIndex < uniform.fields.size(); fieldIndex++)
{ {
const sh::Uniform &field = constant.fields[fieldIndex]; const sh::Uniform &field = uniform.fields[fieldIndex];
const std::string &uniformName = constant.name + ArrayString(elementIndex) + "." + field.name; const std::string &fieldFullName = fullName + ArrayString(elementIndex) + "." + field.name;
const unsigned int fieldRegisterIndex = field.registerIndex + elementRegisterOffset; const unsigned int fieldRegisterIndex = field.registerIndex + elementRegisterOffset;
sh::Uniform fieldUniform(field.type, field.precision, uniformName.c_str(), field.arraySize, defineUniform(shader, field, fieldFullName, fieldRegisterIndex);
fieldRegisterIndex, field.elementIndex);
fieldUniform.fields = field.fields;
defineUniform(shader, fieldUniform);
} }
} }
} }
else else
{ {
for (size_t fieldIndex = 0; fieldIndex < constant.fields.size(); fieldIndex++) for (size_t fieldIndex = 0; fieldIndex < uniform.fields.size(); fieldIndex++)
{ {
const sh::Uniform &field = constant.fields[fieldIndex]; const sh::Uniform &field = uniform.fields[fieldIndex];
const std::string &uniformName = constant.name + "." + field.name; const std::string &fieldFullName = fullName + "." + field.name;
defineUniform(shader, field, fieldFullName, field.registerIndex);
sh::Uniform fieldUniform(field.type, field.precision, uniformName.c_str(), field.arraySize,
field.registerIndex, field.elementIndex);
fieldUniform.fields = field.fields;
defineUniform(shader, fieldUniform);
} }
} }
} }
else // Not a struct else // Not a struct
{ {
LinkedUniform *linkedUniform = getUniformByName(constant.name); LinkedUniform *linkedUniform = getUniformByName(fullName);
if (!linkedUniform) if (!linkedUniform)
{ {
linkedUniform = new LinkedUniform(constant.type, constant.precision, constant.name, constant.arraySize, linkedUniform = new LinkedUniform(uniform.type, uniform.precision, fullName, uniform.arraySize,
-1, sh::BlockMemberInfo::getDefaultBlockInfo()); -1, sh::BlockMemberInfo::getDefaultBlockInfo());
ASSERT(linkedUniform); ASSERT(linkedUniform);
linkedUniform->registerElement = constant.elementIndex; linkedUniform->registerElement = uniform.elementIndex;
mUniforms.push_back(linkedUniform); mUniforms.push_back(linkedUniform);
} }
if (shader == GL_FRAGMENT_SHADER) if (shader == GL_FRAGMENT_SHADER)
{ {
linkedUniform->psRegisterIndex = constant.registerIndex; linkedUniform->psRegisterIndex = baseRegisterIndex;
} }
else if (shader == GL_VERTEX_SHADER) else if (shader == GL_VERTEX_SHADER)
{ {
linkedUniform->vsRegisterIndex = constant.registerIndex; linkedUniform->vsRegisterIndex = baseRegisterIndex;
} }
else UNREACHABLE(); else UNREACHABLE();
} }
......
...@@ -202,7 +202,8 @@ class ProgramBinary : public RefCountObject ...@@ -202,7 +202,8 @@ class ProgramBinary : public RefCountObject
bool linkValidateVariables(InfoLog &infoLog, const std::string &varyingName, const sh::Varying &vertexVarying, const sh::Varying &fragmentVarying); bool linkValidateVariables(InfoLog &infoLog, const std::string &varyingName, const sh::Varying &vertexVarying, const sh::Varying &fragmentVarying);
bool linkValidateVariables(InfoLog &infoLog, const std::string &uniformName, const sh::InterfaceBlockField &vertexUniform, const sh::InterfaceBlockField &fragmentUniform); bool linkValidateVariables(InfoLog &infoLog, const std::string &uniformName, const sh::InterfaceBlockField &vertexUniform, const sh::InterfaceBlockField &fragmentUniform);
bool linkUniforms(InfoLog &infoLog, const std::vector<sh::Uniform> &vertexUniforms, const std::vector<sh::Uniform> &fragmentUniforms); bool linkUniforms(InfoLog &infoLog, const std::vector<sh::Uniform> &vertexUniforms, const std::vector<sh::Uniform> &fragmentUniforms);
void defineUniform(GLenum shader, const sh::Uniform &constant); void defineUniformBase(GLenum shader, const sh::Uniform &uniform);
void defineUniform(GLenum shader, const sh::Uniform &uniform, const std::string &fullName, unsigned int baseRegisterIndex);
bool indexSamplerUniform(const LinkedUniform &uniform, InfoLog &infoLog); bool indexSamplerUniform(const LinkedUniform &uniform, InfoLog &infoLog);
bool indexUniforms(InfoLog &infoLog); bool indexUniforms(InfoLog &infoLog);
static bool assignSamplers(unsigned int startSamplerIndex, GLenum samplerType, unsigned int samplerCount, static bool assignSamplers(unsigned int startSamplerIndex, GLenum samplerType, unsigned int samplerCount,
......
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