Commit 80ebce59 by Jamie Madill

Store the std140 layout offsets in a pre-pass.

Instead of recording data and mutating a local table as we parse, store all of the offsets for the std140 structs when we first generate the struct. This should have no behavioural change, as structs should always be defined first in any case. BUG=angle:466 Change-Id: I1b732d67bd4f5b908211410e5e7796d72d836174 Reviewed-on: https://chromium-review.googlesource.com/202910Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarNicolas Capens <nicolascapens@chromium.org> Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org>
parent 01f85ac8
...@@ -3483,12 +3483,6 @@ TString OutputHLSL::structureString(const TStructure &structure, bool useHLSLRow ...@@ -3483,12 +3483,6 @@ TString OutputHLSL::structureString(const TStructure &structure, bool useHLSLRow
// Nameless structs do not finish with a semicolon and newline, to leave room for an instance variable // Nameless structs do not finish with a semicolon and newline, to leave room for an instance variable
string += (isNameless ? "} " : "};\n"); string += (isNameless ? "} " : "};\n");
// Add remaining element index to the global map, for use with nested structs in standard layouts
if (useStd140Packing)
{
mStd140StructElementIndexes[structName] = elementIndex;
}
return string; return string;
} }
...@@ -3543,6 +3537,10 @@ void OutputHLSL::addConstructor(const TType &type, const TString &name, const TI ...@@ -3543,6 +3537,10 @@ void OutputHLSL::addConstructor(const TType &type, const TString &name, const TI
{ {
mStructNames.insert(name); mStructNames.insert(name);
// Add element index
storeStd140ElementIndex(*structure, false);
storeStd140ElementIndex(*structure, true);
const TString &structString = structureString(*structure, false, false); const TString &structString = structureString(*structure, false, false);
if (std::find(mStructDeclarations.begin(), mStructDeclarations.end(), structString) == mStructDeclarations.end()) if (std::find(mStructDeclarations.begin(), mStructDeclarations.end(), structString) == mStructDeclarations.end())
...@@ -3733,6 +3731,21 @@ void OutputHLSL::addConstructor(const TType &type, const TString &name, const TI ...@@ -3733,6 +3731,21 @@ void OutputHLSL::addConstructor(const TType &type, const TString &name, const TI
mConstructors.insert(constructor); mConstructors.insert(constructor);
} }
void OutputHLSL::storeStd140ElementIndex(const TStructure &structure, bool useHLSLRowMajorPacking)
{
int elementIndex = 0;
const TFieldList &fields = structure.fields();
for (unsigned int i = 0; i < fields.size(); i++)
{
std140PrePaddingString(*fields[i]->type(), &elementIndex);
}
// Add remaining element index to the global map, for use with nested structs in standard layouts
const TString &structName = structureTypeName(structure, useHLSLRowMajorPacking, true);
mStd140StructElementIndexes[structName] = elementIndex;
}
const ConstantUnion *OutputHLSL::writeConstantUnion(const TType &type, const ConstantUnion *constUnion) const ConstantUnion *OutputHLSL::writeConstantUnion(const TType &type, const ConstantUnion *constUnion)
{ {
TInfoSinkBase &out = mBody; TInfoSinkBase &out = mBody;
......
...@@ -72,6 +72,7 @@ class OutputHLSL : public TIntermTraverser ...@@ -72,6 +72,7 @@ class OutputHLSL : public TIntermTraverser
int vectorSize(const TType &type) const; int vectorSize(const TType &type) const;
void addConstructor(const TType &type, const TString &name, const TIntermSequence *parameters); void addConstructor(const TType &type, const TString &name, const TIntermSequence *parameters);
void storeStd140ElementIndex(const TStructure &structure, bool useHLSLRowMajorPacking);
const ConstantUnion *writeConstantUnion(const TType &type, const ConstantUnion *constUnion); const ConstantUnion *writeConstantUnion(const TType &type, const ConstantUnion *constUnion);
TString structNameString(const TStructure &structure); TString structNameString(const TStructure &structure);
......
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