Commit 4a92cebc by Olli Etuaho Committed by Commit Bot

Clarify code around setting uniform locations

Use the name "uniformLocationBindings" for location information set by the API instead of "uniformBindings", which can be easily confused with binding layout qualifiers that can be set for some types of uniforms. Also use more straightforward names throughout the indexUniforms function. BUG=angleproject:1442 Change-Id: I47d504479b36def696305f060e9c9bd3de3ade48 Reviewed-on: https://chromium-review.googlesource.com/445236Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent f5bb220f
...@@ -510,7 +510,7 @@ void Program::bindAttributeLocation(GLuint index, const char *name) ...@@ -510,7 +510,7 @@ void Program::bindAttributeLocation(GLuint index, const char *name)
void Program::bindUniformLocation(GLuint index, const char *name) void Program::bindUniformLocation(GLuint index, const char *name)
{ {
// Bind the base uniform name only since array indices other than 0 cannot be bound // Bind the base uniform name only since array indices other than 0 cannot be bound
mUniformBindings.bindLocation(index, ParseUniformName(name, nullptr)); mUniformLocationBindings.bindLocation(index, ParseUniformName(name, nullptr));
} }
void Program::bindFragmentInputLocation(GLint index, const char *name) void Program::bindFragmentInputLocation(GLint index, const char *name)
...@@ -637,7 +637,7 @@ Error Program::link(const gl::Context *context) ...@@ -637,7 +637,7 @@ Error Program::link(const gl::Context *context)
return NoError(); return NoError();
} }
if (!linkUniforms(mInfoLog, caps, mUniformBindings)) if (!linkUniforms(mInfoLog, caps, mUniformLocationBindings))
{ {
return NoError(); return NoError();
} }
...@@ -685,7 +685,7 @@ Error Program::link(const gl::Context *context) ...@@ -685,7 +685,7 @@ Error Program::link(const gl::Context *context)
return NoError(); return NoError();
} }
if (!linkUniforms(mInfoLog, caps, mUniformBindings)) if (!linkUniforms(mInfoLog, caps, mUniformLocationBindings))
{ {
return NoError(); return NoError();
} }
...@@ -1951,7 +1951,9 @@ bool Program::validateVertexAndFragmentUniforms(InfoLog &infoLog) const ...@@ -1951,7 +1951,9 @@ bool Program::validateVertexAndFragmentUniforms(InfoLog &infoLog) const
return true; return true;
} }
bool Program::linkUniforms(InfoLog &infoLog, const Caps &caps, const Bindings &uniformBindings) bool Program::linkUniforms(InfoLog &infoLog,
const Caps &caps,
const Bindings &uniformLocationBindings)
{ {
if (mState.mAttachedVertexShader && mState.mAttachedFragmentShader) if (mState.mAttachedVertexShader && mState.mAttachedFragmentShader)
{ {
...@@ -1969,7 +1971,7 @@ bool Program::linkUniforms(InfoLog &infoLog, const Caps &caps, const Bindings &u ...@@ -1969,7 +1971,7 @@ bool Program::linkUniforms(InfoLog &infoLog, const Caps &caps, const Bindings &u
return false; return false;
} }
if (!indexUniforms(infoLog, caps, uniformBindings)) if (!indexUniforms(infoLog, caps, uniformLocationBindings))
{ {
return false; return false;
} }
...@@ -1977,14 +1979,15 @@ bool Program::linkUniforms(InfoLog &infoLog, const Caps &caps, const Bindings &u ...@@ -1977,14 +1979,15 @@ bool Program::linkUniforms(InfoLog &infoLog, const Caps &caps, const Bindings &u
return true; return true;
} }
bool Program::indexUniforms(InfoLog &infoLog, const Caps &caps, const Bindings &uniformBindings) bool Program::indexUniforms(InfoLog &infoLog,
const Caps &caps,
const Bindings &uniformLocationBindings)
{ {
// Uniforms awaiting a location std::vector<VariableLocation> unlocatedUniforms;
std::vector<VariableLocation> unboundUniforms; std::map<GLuint, VariableLocation> preLocatedUniforms;
std::map<GLuint, VariableLocation> boundUniforms;
int maxUniformLocation = -1; int maxUniformLocation = -1;
// Gather bound and unbound uniforms // Gather uniforms that have their location pre-set and uniforms that don't yet have a location.
for (size_t uniformIndex = 0; uniformIndex < mState.mUniforms.size(); uniformIndex++) for (size_t uniformIndex = 0; uniformIndex < mState.mUniforms.size(); uniformIndex++)
{ {
const LinkedUniform &uniform = mState.mUniforms[uniformIndex]; const LinkedUniform &uniform = mState.mUniforms[uniformIndex];
...@@ -1994,12 +1997,13 @@ bool Program::indexUniforms(InfoLog &infoLog, const Caps &caps, const Bindings & ...@@ -1994,12 +1997,13 @@ bool Program::indexUniforms(InfoLog &infoLog, const Caps &caps, const Bindings &
continue; continue;
} }
int bindingLocation = uniformBindings.getBinding(uniform.name); int preSetLocation = uniformLocationBindings.getBinding(uniform.name);
// Verify that this location isn't bound twice // Verify that this location isn't used twice
if (bindingLocation != -1 && boundUniforms.find(bindingLocation) != boundUniforms.end()) if (preSetLocation != -1 &&
preLocatedUniforms.find(preSetLocation) != preLocatedUniforms.end())
{ {
infoLog << "Multiple uniforms bound to location " << bindingLocation << "."; infoLog << "Multiple uniforms bound to location " << preSetLocation << ".";
return false; return false;
} }
...@@ -2008,40 +2012,40 @@ bool Program::indexUniforms(InfoLog &infoLog, const Caps &caps, const Bindings & ...@@ -2008,40 +2012,40 @@ bool Program::indexUniforms(InfoLog &infoLog, const Caps &caps, const Bindings &
VariableLocation location(uniform.name, arrayIndex, VariableLocation location(uniform.name, arrayIndex,
static_cast<unsigned int>(uniformIndex)); static_cast<unsigned int>(uniformIndex));
if (arrayIndex == 0 && bindingLocation != -1) if (arrayIndex == 0 && preSetLocation != -1)
{ {
boundUniforms[bindingLocation] = location; preLocatedUniforms[preSetLocation] = location;
maxUniformLocation = std::max(maxUniformLocation, bindingLocation); maxUniformLocation = std::max(maxUniformLocation, preSetLocation);
} }
else else
{ {
unboundUniforms.push_back(location); unlocatedUniforms.push_back(location);
} }
} }
} }
// Gather the reserved bindings, ones that are bound but not referenced. Other uniforms should // Gather the reserved locations, ones that are bound but not referenced. Other uniforms should
// not be assigned to those locations. // not be assigned to those locations.
std::set<GLuint> reservedLocations; std::set<GLuint> reservedLocations;
for (const auto &binding : uniformBindings) for (const auto &locationBinding : uniformLocationBindings)
{ {
GLuint location = binding.second; GLuint location = locationBinding.second;
if (boundUniforms.find(location) == boundUniforms.end()) if (preLocatedUniforms.find(location) == preLocatedUniforms.end())
{ {
reservedLocations.insert(location); reservedLocations.insert(location);
maxUniformLocation = std::max(maxUniformLocation, static_cast<int>(location)); maxUniformLocation = std::max(maxUniformLocation, static_cast<int>(location));
} }
} }
// Make enough space for all uniforms, bound and unbound // Make enough space for all uniforms, with pre-set locations or not.
mState.mUniformLocations.resize( mState.mUniformLocations.resize(
std::max(unboundUniforms.size() + boundUniforms.size() + reservedLocations.size(), std::max(unlocatedUniforms.size() + preLocatedUniforms.size() + reservedLocations.size(),
static_cast<size_t>(maxUniformLocation + 1))); static_cast<size_t>(maxUniformLocation + 1)));
// Assign bound uniforms // Assign uniforms with pre-set locations
for (const auto &boundUniform : boundUniforms) for (const auto &uniform : preLocatedUniforms)
{ {
mState.mUniformLocations[boundUniform.first] = boundUniform.second; mState.mUniformLocations[uniform.first] = uniform.second;
} }
// Assign reserved uniforms // Assign reserved uniforms
...@@ -2050,9 +2054,9 @@ bool Program::indexUniforms(InfoLog &infoLog, const Caps &caps, const Bindings & ...@@ -2050,9 +2054,9 @@ bool Program::indexUniforms(InfoLog &infoLog, const Caps &caps, const Bindings &
mState.mUniformLocations[reservedLocation].ignored = true; mState.mUniformLocations[reservedLocation].ignored = true;
} }
// Assign unbound uniforms // Automatically assign locations for the rest of the uniforms
size_t nextUniformLocation = 0; size_t nextUniformLocation = 0;
for (const auto &unboundUniform : unboundUniforms) for (const auto &unlocatedUniform : unlocatedUniforms)
{ {
while (mState.mUniformLocations[nextUniformLocation].used || while (mState.mUniformLocations[nextUniformLocation].used ||
mState.mUniformLocations[nextUniformLocation].ignored) mState.mUniformLocations[nextUniformLocation].ignored)
...@@ -2061,7 +2065,7 @@ bool Program::indexUniforms(InfoLog &infoLog, const Caps &caps, const Bindings & ...@@ -2061,7 +2065,7 @@ bool Program::indexUniforms(InfoLog &infoLog, const Caps &caps, const Bindings &
} }
ASSERT(nextUniformLocation < mState.mUniformLocations.size()); ASSERT(nextUniformLocation < mState.mUniformLocations.size());
mState.mUniformLocations[nextUniformLocation] = unboundUniform; mState.mUniformLocations[nextUniformLocation] = unlocatedUniform;
nextUniformLocation++; nextUniformLocation++;
} }
......
...@@ -447,8 +447,8 @@ class Program final : angle::NonCopyable, public LabeledObject ...@@ -447,8 +447,8 @@ class Program final : angle::NonCopyable, public LabeledObject
bool linkUniformBlocks(InfoLog &infoLog, const Caps &caps); bool linkUniformBlocks(InfoLog &infoLog, const Caps &caps);
bool linkVaryings(InfoLog &infoLog) const; bool linkVaryings(InfoLog &infoLog) const;
bool validateVertexAndFragmentUniforms(InfoLog &infoLog) const; bool validateVertexAndFragmentUniforms(InfoLog &infoLog) const;
bool linkUniforms(InfoLog &infoLog, const Caps &caps, const Bindings &uniformBindings); bool linkUniforms(InfoLog &infoLog, const Caps &caps, const Bindings &uniformLocationBindings);
bool indexUniforms(InfoLog &infoLog, const Caps &caps, const Bindings &uniformBindings); bool indexUniforms(InfoLog &infoLog, const Caps &caps, const Bindings &uniformLocationBindings);
bool areMatchingInterfaceBlocks(InfoLog &infoLog, bool areMatchingInterfaceBlocks(InfoLog &infoLog,
const sh::InterfaceBlock &vertexInterfaceBlock, const sh::InterfaceBlock &vertexInterfaceBlock,
const sh::InterfaceBlock &fragmentInterfaceBlock) const; const sh::InterfaceBlock &fragmentInterfaceBlock) const;
...@@ -536,7 +536,10 @@ class Program final : angle::NonCopyable, public LabeledObject ...@@ -536,7 +536,10 @@ class Program final : angle::NonCopyable, public LabeledObject
bool mValidated; bool mValidated;
Bindings mAttributeBindings; Bindings mAttributeBindings;
Bindings mUniformBindings;
// Note that this has nothing to do with binding layout qualifiers that can be set for some
// uniforms in GLES3.1+. It is used to pre-set the location of uniforms.
Bindings mUniformLocationBindings;
// CHROMIUM_path_rendering // CHROMIUM_path_rendering
Bindings mFragmentInputBindings; Bindings mFragmentInputBindings;
......
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