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,
uniformIndexIndex++)
{
VariableLocation variable;
stream.readIntVector<unsigned int>(&variable.arrayIndices);
stream.readInt(&variable.arrayIndex);
stream.readInt(&variable.index);
stream.readInt(&variable.flattenedArrayOffset);
stream.readBool(&variable.ignored);
state->mUniformLocations.push_back(variable);
......@@ -320,9 +319,8 @@ LinkResult MemoryProgramCache::Deserialize(const Context *context,
for (unsigned int outputIndex = 0; outputIndex < outputVarCount; ++outputIndex)
{
VariableLocation locationData;
stream.readIntVector<unsigned int>(&locationData.arrayIndices);
stream.readInt(&locationData.arrayIndex);
stream.readInt(&locationData.index);
stream.readInt(&locationData.flattenedArrayOffset);
stream.readBool(&locationData.ignored);
state->mOutputLocations.push_back(locationData);
}
......@@ -429,9 +427,8 @@ void MemoryProgramCache::Serialize(const Context *context,
stream.writeInt(state.getUniformLocations().size());
for (const auto &variable : state.getUniformLocations())
{
stream.writeIntVector(variable.arrayIndices);
stream.writeInt(variable.arrayIndex);
stream.writeIntOrNegOne(variable.index);
stream.writeInt(variable.flattenedArrayOffset);
stream.writeInt(variable.ignored);
}
......@@ -483,9 +480,8 @@ void MemoryProgramCache::Serialize(const Context *context,
stream.writeInt(state.getOutputLocations().size());
for (const auto &outputVar : state.getOutputLocations())
{
stream.writeIntVector(outputVar.arrayIndices);
stream.writeInt(outputVar.arrayIndex);
stream.writeIntOrNegOne(outputVar.index);
stream.writeInt(outputVar.flattenedArrayOffset);
stream.writeInt(outputVar.ignored);
}
......
......@@ -190,7 +190,7 @@ GLint GetVariableLocation(const std::vector<VarT> &list,
return static_cast<GLint>(location);
}
}
if (variable.isArray() && variableLocation.arrayIndices[0] == arrayIndex &&
if (variable.isArray() && variableLocation.arrayIndex == arrayIndex &&
nameLengthWithoutArrayIndex + 3u == variable.name.length() &&
angle::BeginsWith(variable.name, name, nameLengthWithoutArrayIndex))
{
......@@ -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)
: arrayIndices(1, arrayIndex), index(index), flattenedArrayOffset(arrayIndex), ignored(false)
: arrayIndex(arrayIndex), index(index), ignored(false)
{
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)
{
mBindings[name] = index;
......@@ -2952,7 +2940,7 @@ void Program::updateSamplerUniform(const VariableLocation &locationInfo,
std::vector<GLuint> *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.
mCachedValidateSamplersResult.reset();
......@@ -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
// element index used, as reported by GetActiveUniform, will be ignored by the GL."
unsigned int remainingElements =
linkedUniform.elementCount() - locationInfo.flattenedArrayOffset;
unsigned int remainingElements = linkedUniform.elementCount() - locationInfo.arrayIndex;
GLsizei maxElementCount =
static_cast<GLsizei>(remainingElements * linkedUniform.getElementComponents());
......@@ -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
// element index used, as reported by GetActiveUniform, will be ignored by the GL."
unsigned int remainingElements =
linkedUniform.elementCount() - locationInfo.flattenedArrayOffset;
unsigned int remainingElements = linkedUniform.elementCount() - locationInfo.arrayIndex;
return std::min(count, static_cast<GLsizei>(remainingElements));
}
......
......@@ -147,18 +147,12 @@ struct VariableLocation
void markUnused() { index = kUnused; }
void markIgnored() { ignored = true; }
bool areAllArrayIndicesZero() const;
// The "arrayIndices" vector stores indices for the GLSL array. "index" is an index of the
// location.
std::vector<unsigned int> arrayIndices; // Outermost array indices are in the back.
// "arrayIndex" stores the index of the innermost GLSL array. It's zero for non-arrays.
unsigned int arrayIndex;
// "index" is an index of the variable. The variable contains the indices for other than the
// innermost GLSL arrays.
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
// no-op.
bool ignored;
......
......@@ -1278,17 +1278,17 @@ void DynamicHLSL::getPixelShaderOutputKey(const gl::ContextState &data,
const std::string &variableName = "out_" + outputVariable.name;
// Fragment outputs can't be arrays of arrays. ESSL 3.10 section 4.3.6.
ASSERT(outputLocation.arrayIndices.size() <= 1u);
const std::string &elementString =
(outputLocation.arrayIndices.empty() ? ""
: Str(outputLocation.arrayIndices.back()));
(outputVariable.isArray() ? Str(outputLocation.arrayIndex) : "");
ASSERT(outputVariable.staticUse);
PixelShaderOutputVariable outputKeyVariable;
outputKeyVariable.type = outputVariable.type;
outputKeyVariable.name = variableName + elementString;
outputKeyVariable.source = variableName + ArrayIndexString(outputLocation.arrayIndices);
outputKeyVariable.source =
variableName +
(outputVariable.isArray() ? ArrayString(outputLocation.arrayIndex) : "");
outputKeyVariable.outputIndex = outputLocationIndex;
outPixelShaderKey->push_back(outputKeyVariable);
......
......@@ -2134,7 +2134,7 @@ void ProgramD3D::setUniformImpl(const gl::VariableLocation &locationInfo,
{
D3DUniform *targetUniform = mD3DUniforms[locationInfo.index];
const int components = targetUniform->typeInfo.componentCount;
unsigned int arrayElementOffset = locationInfo.flattenedArrayOffset;
const unsigned int arrayElementOffset = locationInfo.arrayIndex;
if (targetUniform->typeInfo.type == uniformType)
{
......@@ -2174,7 +2174,7 @@ void ProgramD3D::setUniformInternal(GLint location, GLsizei count, const T *v, G
{
ASSERT(uniformType == GL_INT);
size_t size = count * sizeof(T);
auto dest = &targetUniform->mSamplerData[locationInfo.flattenedArrayOffset];
auto dest = &targetUniform->mSamplerData[locationInfo.arrayIndex];
if (memcmp(dest, v, size) != 0)
{
memcpy(dest, v, size);
......@@ -2213,7 +2213,7 @@ bool ProgramD3D::setUniformMatrixfvImpl(GLint location,
D3DUniform *targetUniform = getD3DUniformFromLocation(location);
unsigned int elementCount = targetUniform->elementCount();
unsigned int arrayElementOffset = mState.getUniformLocations()[location].flattenedArrayOffset;
unsigned int arrayElementOffset = mState.getUniformLocations()[location].arrayIndex;
unsigned int count =
std::min(elementCount - arrayElementOffset, static_cast<unsigned int>(countIn));
......@@ -2666,8 +2666,7 @@ void ProgramD3D::getUniformInternal(GLint location, DestT *dataOut) const
const gl::LinkedUniform &uniform = mState.getUniforms()[locationInfo.index];
const D3DUniform *targetUniform = getD3DUniformFromLocation(location);
const uint8_t *srcPointer = targetUniform->getDataPtrToElement(
locationInfo.arrayIndices.empty() ? 0u : locationInfo.flattenedArrayOffset);
const uint8_t *srcPointer = targetUniform->getDataPtrToElement(locationInfo.arrayIndex);
if (gl::IsMatrixType(uniform.type))
{
......
......@@ -667,7 +667,7 @@ void ProgramGL::postLink()
{
ASSERT(angle::EndsWith(uniform.mappedName, "[0]"));
fullNameStr << uniform.mappedName.substr(0, uniform.mappedName.length() - 3);
fullNameStr << "[" << entry.arrayIndices[0] << "]";
fullNameStr << "[" << entry.arrayIndex << "]";
}
else
{
......
......@@ -283,7 +283,7 @@ gl::Error ProgramVk::initDefaultUniformBlocks(const gl::Context *glContext)
std::string uniformName = uniform.name;
if (uniform.isArray())
{
uniformName += ArrayIndexString(location.arrayIndices);
uniformName += ArrayString(location.arrayIndex);
}
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