Commit 1734e171 by Olli Etuaho Committed by Commit Bot

Only store innermost array offset in VariableLocation

Separate entries will be generated for each innermost array of arrays of arrays in the variable tables. Because of this VariableLocation actually only needs to store the innermost array index. BUG=angleproject:2125 TEST=angle_end2end_tests Change-Id: Id1ee35b3cecfc011d96b58e43cf0b1cccbfed408 Reviewed-on: https://chromium-review.googlesource.com/741742 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent fb05264b
...@@ -238,9 +238,8 @@ LinkResult MemoryProgramCache::Deserialize(const Context *context, ...@@ -238,9 +238,8 @@ LinkResult MemoryProgramCache::Deserialize(const Context *context,
uniformIndexIndex++) uniformIndexIndex++)
{ {
VariableLocation variable; VariableLocation variable;
stream.readIntVector<unsigned int>(&variable.arrayIndices); stream.readInt(&variable.arrayIndex);
stream.readInt(&variable.index); stream.readInt(&variable.index);
stream.readInt(&variable.flattenedArrayOffset);
stream.readBool(&variable.ignored); stream.readBool(&variable.ignored);
state->mUniformLocations.push_back(variable); state->mUniformLocations.push_back(variable);
...@@ -320,9 +319,8 @@ LinkResult MemoryProgramCache::Deserialize(const Context *context, ...@@ -320,9 +319,8 @@ LinkResult MemoryProgramCache::Deserialize(const Context *context,
for (unsigned int outputIndex = 0; outputIndex < outputVarCount; ++outputIndex) for (unsigned int outputIndex = 0; outputIndex < outputVarCount; ++outputIndex)
{ {
VariableLocation locationData; VariableLocation locationData;
stream.readIntVector<unsigned int>(&locationData.arrayIndices); stream.readInt(&locationData.arrayIndex);
stream.readInt(&locationData.index); stream.readInt(&locationData.index);
stream.readInt(&locationData.flattenedArrayOffset);
stream.readBool(&locationData.ignored); stream.readBool(&locationData.ignored);
state->mOutputLocations.push_back(locationData); state->mOutputLocations.push_back(locationData);
} }
...@@ -429,9 +427,8 @@ void MemoryProgramCache::Serialize(const Context *context, ...@@ -429,9 +427,8 @@ void MemoryProgramCache::Serialize(const Context *context,
stream.writeInt(state.getUniformLocations().size()); stream.writeInt(state.getUniformLocations().size());
for (const auto &variable : state.getUniformLocations()) for (const auto &variable : state.getUniformLocations())
{ {
stream.writeIntVector(variable.arrayIndices); stream.writeInt(variable.arrayIndex);
stream.writeIntOrNegOne(variable.index); stream.writeIntOrNegOne(variable.index);
stream.writeInt(variable.flattenedArrayOffset);
stream.writeInt(variable.ignored); stream.writeInt(variable.ignored);
} }
...@@ -483,9 +480,8 @@ void MemoryProgramCache::Serialize(const Context *context, ...@@ -483,9 +480,8 @@ void MemoryProgramCache::Serialize(const Context *context,
stream.writeInt(state.getOutputLocations().size()); stream.writeInt(state.getOutputLocations().size());
for (const auto &outputVar : state.getOutputLocations()) for (const auto &outputVar : state.getOutputLocations())
{ {
stream.writeIntVector(outputVar.arrayIndices); stream.writeInt(outputVar.arrayIndex);
stream.writeIntOrNegOne(outputVar.index); stream.writeIntOrNegOne(outputVar.index);
stream.writeInt(outputVar.flattenedArrayOffset);
stream.writeInt(outputVar.ignored); stream.writeInt(outputVar.ignored);
} }
......
...@@ -190,7 +190,7 @@ GLint GetVariableLocation(const std::vector<VarT> &list, ...@@ -190,7 +190,7 @@ GLint GetVariableLocation(const std::vector<VarT> &list,
return static_cast<GLint>(location); return static_cast<GLint>(location);
} }
} }
if (variable.isArray() && variableLocation.arrayIndices[0] == arrayIndex && if (variable.isArray() && variableLocation.arrayIndex == arrayIndex &&
nameLengthWithoutArrayIndex + 3u == variable.name.length() && nameLengthWithoutArrayIndex + 3u == variable.name.length() &&
angle::BeginsWith(variable.name, name, nameLengthWithoutArrayIndex)) angle::BeginsWith(variable.name, name, nameLengthWithoutArrayIndex))
{ {
...@@ -378,28 +378,16 @@ void InfoLog::reset() ...@@ -378,28 +378,16 @@ void InfoLog::reset()
{ {
} }
VariableLocation::VariableLocation() : index(kUnused), flattenedArrayOffset(0u), ignored(false) VariableLocation::VariableLocation() : arrayIndex(0), index(kUnused), ignored(false)
{ {
} }
VariableLocation::VariableLocation(unsigned int arrayIndex, unsigned int index) VariableLocation::VariableLocation(unsigned int arrayIndex, unsigned int index)
: arrayIndices(1, arrayIndex), index(index), flattenedArrayOffset(arrayIndex), ignored(false) : arrayIndex(arrayIndex), index(index), ignored(false)
{ {
ASSERT(arrayIndex != GL_INVALID_INDEX); ASSERT(arrayIndex != GL_INVALID_INDEX);
} }
bool VariableLocation::areAllArrayIndicesZero() const
{
for (unsigned int arrayIndex : arrayIndices)
{
if (arrayIndex != 0)
{
return false;
}
}
return true;
}
void Program::Bindings::bindLocation(GLuint index, const std::string &name) void Program::Bindings::bindLocation(GLuint index, const std::string &name)
{ {
mBindings[name] = index; mBindings[name] = index;
...@@ -2952,7 +2940,7 @@ void Program::updateSamplerUniform(const VariableLocation &locationInfo, ...@@ -2952,7 +2940,7 @@ void Program::updateSamplerUniform(const VariableLocation &locationInfo,
std::vector<GLuint> *boundTextureUnits = std::vector<GLuint> *boundTextureUnits =
&mState.mSamplerBindings[samplerIndex].boundTextureUnits; &mState.mSamplerBindings[samplerIndex].boundTextureUnits;
std::copy(v, v + clampedCount, boundTextureUnits->begin() + locationInfo.flattenedArrayOffset); std::copy(v, v + clampedCount, boundTextureUnits->begin() + locationInfo.arrayIndex);
// Invalidate the validation cache. // Invalidate the validation cache.
mCachedValidateSamplersResult.reset(); mCachedValidateSamplersResult.reset();
...@@ -2971,8 +2959,7 @@ GLsizei Program::clampUniformCount(const VariableLocation &locationInfo, ...@@ -2971,8 +2959,7 @@ GLsizei Program::clampUniformCount(const VariableLocation &locationInfo,
// OpenGL ES 3.0.4 spec pg 67: "Values for any array element that exceeds the highest array // OpenGL ES 3.0.4 spec pg 67: "Values for any array element that exceeds the highest array
// element index used, as reported by GetActiveUniform, will be ignored by the GL." // element index used, as reported by GetActiveUniform, will be ignored by the GL."
unsigned int remainingElements = unsigned int remainingElements = linkedUniform.elementCount() - locationInfo.arrayIndex;
linkedUniform.elementCount() - locationInfo.flattenedArrayOffset;
GLsizei maxElementCount = GLsizei maxElementCount =
static_cast<GLsizei>(remainingElements * linkedUniform.getElementComponents()); static_cast<GLsizei>(remainingElements * linkedUniform.getElementComponents());
...@@ -3001,8 +2988,7 @@ GLsizei Program::clampMatrixUniformCount(GLint location, ...@@ -3001,8 +2988,7 @@ GLsizei Program::clampMatrixUniformCount(GLint location,
// OpenGL ES 3.0.4 spec pg 67: "Values for any array element that exceeds the highest array // OpenGL ES 3.0.4 spec pg 67: "Values for any array element that exceeds the highest array
// element index used, as reported by GetActiveUniform, will be ignored by the GL." // element index used, as reported by GetActiveUniform, will be ignored by the GL."
unsigned int remainingElements = unsigned int remainingElements = linkedUniform.elementCount() - locationInfo.arrayIndex;
linkedUniform.elementCount() - locationInfo.flattenedArrayOffset;
return std::min(count, static_cast<GLsizei>(remainingElements)); return std::min(count, static_cast<GLsizei>(remainingElements));
} }
......
...@@ -147,18 +147,12 @@ struct VariableLocation ...@@ -147,18 +147,12 @@ struct VariableLocation
void markUnused() { index = kUnused; } void markUnused() { index = kUnused; }
void markIgnored() { ignored = true; } void markIgnored() { ignored = true; }
bool areAllArrayIndicesZero() const; // "arrayIndex" stores the index of the innermost GLSL array. It's zero for non-arrays.
unsigned int arrayIndex;
// The "arrayIndices" vector stores indices for the GLSL array. "index" is an index of the // "index" is an index of the variable. The variable contains the indices for other than the
// location. // innermost GLSL arrays.
std::vector<unsigned int> arrayIndices; // Outermost array indices are in the back.
unsigned int index; unsigned int index;
unsigned int flattenedArrayOffset; // For non-nested arrays this is the same as the array
// index. For arrays of arrays, the indices are converted to
// a single offset inside a one-dimensional array made up of
// the elements of the innermost arrays.
// If this location was bound to an unreferenced uniform. Setting data on this uniform is a // If this location was bound to an unreferenced uniform. Setting data on this uniform is a
// no-op. // no-op.
bool ignored; bool ignored;
......
...@@ -1278,17 +1278,17 @@ void DynamicHLSL::getPixelShaderOutputKey(const gl::ContextState &data, ...@@ -1278,17 +1278,17 @@ void DynamicHLSL::getPixelShaderOutputKey(const gl::ContextState &data,
const std::string &variableName = "out_" + outputVariable.name; const std::string &variableName = "out_" + outputVariable.name;
// Fragment outputs can't be arrays of arrays. ESSL 3.10 section 4.3.6. // Fragment outputs can't be arrays of arrays. ESSL 3.10 section 4.3.6.
ASSERT(outputLocation.arrayIndices.size() <= 1u);
const std::string &elementString = const std::string &elementString =
(outputLocation.arrayIndices.empty() ? "" (outputVariable.isArray() ? Str(outputLocation.arrayIndex) : "");
: Str(outputLocation.arrayIndices.back()));
ASSERT(outputVariable.staticUse); ASSERT(outputVariable.staticUse);
PixelShaderOutputVariable outputKeyVariable; PixelShaderOutputVariable outputKeyVariable;
outputKeyVariable.type = outputVariable.type; outputKeyVariable.type = outputVariable.type;
outputKeyVariable.name = variableName + elementString; outputKeyVariable.name = variableName + elementString;
outputKeyVariable.source = variableName + ArrayIndexString(outputLocation.arrayIndices); outputKeyVariable.source =
variableName +
(outputVariable.isArray() ? ArrayString(outputLocation.arrayIndex) : "");
outputKeyVariable.outputIndex = outputLocationIndex; outputKeyVariable.outputIndex = outputLocationIndex;
outPixelShaderKey->push_back(outputKeyVariable); outPixelShaderKey->push_back(outputKeyVariable);
......
...@@ -2134,7 +2134,7 @@ void ProgramD3D::setUniformImpl(const gl::VariableLocation &locationInfo, ...@@ -2134,7 +2134,7 @@ void ProgramD3D::setUniformImpl(const gl::VariableLocation &locationInfo,
{ {
D3DUniform *targetUniform = mD3DUniforms[locationInfo.index]; D3DUniform *targetUniform = mD3DUniforms[locationInfo.index];
const int components = targetUniform->typeInfo.componentCount; const int components = targetUniform->typeInfo.componentCount;
unsigned int arrayElementOffset = locationInfo.flattenedArrayOffset; const unsigned int arrayElementOffset = locationInfo.arrayIndex;
if (targetUniform->typeInfo.type == uniformType) if (targetUniform->typeInfo.type == uniformType)
{ {
...@@ -2174,7 +2174,7 @@ void ProgramD3D::setUniformInternal(GLint location, GLsizei count, const T *v, G ...@@ -2174,7 +2174,7 @@ void ProgramD3D::setUniformInternal(GLint location, GLsizei count, const T *v, G
{ {
ASSERT(uniformType == GL_INT); ASSERT(uniformType == GL_INT);
size_t size = count * sizeof(T); size_t size = count * sizeof(T);
auto dest = &targetUniform->mSamplerData[locationInfo.flattenedArrayOffset]; auto dest = &targetUniform->mSamplerData[locationInfo.arrayIndex];
if (memcmp(dest, v, size) != 0) if (memcmp(dest, v, size) != 0)
{ {
memcpy(dest, v, size); memcpy(dest, v, size);
...@@ -2213,7 +2213,7 @@ bool ProgramD3D::setUniformMatrixfvImpl(GLint location, ...@@ -2213,7 +2213,7 @@ bool ProgramD3D::setUniformMatrixfvImpl(GLint location,
D3DUniform *targetUniform = getD3DUniformFromLocation(location); D3DUniform *targetUniform = getD3DUniformFromLocation(location);
unsigned int elementCount = targetUniform->elementCount(); unsigned int elementCount = targetUniform->elementCount();
unsigned int arrayElementOffset = mState.getUniformLocations()[location].flattenedArrayOffset; unsigned int arrayElementOffset = mState.getUniformLocations()[location].arrayIndex;
unsigned int count = unsigned int count =
std::min(elementCount - arrayElementOffset, static_cast<unsigned int>(countIn)); std::min(elementCount - arrayElementOffset, static_cast<unsigned int>(countIn));
...@@ -2666,8 +2666,7 @@ void ProgramD3D::getUniformInternal(GLint location, DestT *dataOut) const ...@@ -2666,8 +2666,7 @@ void ProgramD3D::getUniformInternal(GLint location, DestT *dataOut) const
const gl::LinkedUniform &uniform = mState.getUniforms()[locationInfo.index]; const gl::LinkedUniform &uniform = mState.getUniforms()[locationInfo.index];
const D3DUniform *targetUniform = getD3DUniformFromLocation(location); const D3DUniform *targetUniform = getD3DUniformFromLocation(location);
const uint8_t *srcPointer = targetUniform->getDataPtrToElement( const uint8_t *srcPointer = targetUniform->getDataPtrToElement(locationInfo.arrayIndex);
locationInfo.arrayIndices.empty() ? 0u : locationInfo.flattenedArrayOffset);
if (gl::IsMatrixType(uniform.type)) if (gl::IsMatrixType(uniform.type))
{ {
......
...@@ -667,7 +667,7 @@ void ProgramGL::postLink() ...@@ -667,7 +667,7 @@ void ProgramGL::postLink()
{ {
ASSERT(angle::EndsWith(uniform.mappedName, "[0]")); ASSERT(angle::EndsWith(uniform.mappedName, "[0]"));
fullNameStr << uniform.mappedName.substr(0, uniform.mappedName.length() - 3); fullNameStr << uniform.mappedName.substr(0, uniform.mappedName.length() - 3);
fullNameStr << "[" << entry.arrayIndices[0] << "]"; fullNameStr << "[" << entry.arrayIndex << "]";
} }
else else
{ {
......
...@@ -283,7 +283,7 @@ gl::Error ProgramVk::initDefaultUniformBlocks(const gl::Context *glContext) ...@@ -283,7 +283,7 @@ gl::Error ProgramVk::initDefaultUniformBlocks(const gl::Context *glContext)
std::string uniformName = uniform.name; std::string uniformName = uniform.name;
if (uniform.isArray()) if (uniform.isArray())
{ {
uniformName += ArrayIndexString(location.arrayIndices); uniformName += ArrayString(location.arrayIndex);
} }
bool found = false; bool found = false;
......
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