Commit a2fbb840 by Jamie Madill

Move CollectVariables to sh namespace.

BUG=angle:466 Change-Id: I903ea840e333dfeb44f242a1759aed39974d0510 Reviewed-on: https://chromium-review.googlesource.com/213505Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org> Reviewed-by: 's avatarNicolas Capens <capn@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 54ad4f81
...@@ -502,7 +502,7 @@ bool TCompiler::enforceVertexShaderTimingRestrictions(TIntermNode* root) ...@@ -502,7 +502,7 @@ bool TCompiler::enforceVertexShaderTimingRestrictions(TIntermNode* root)
void TCompiler::collectVariables(TIntermNode* root) void TCompiler::collectVariables(TIntermNode* root)
{ {
CollectVariables collect(&attributes, sh::CollectVariables collect(&attributes,
&outputVariables, &outputVariables,
&uniforms, &uniforms,
&varyings, &varyings,
...@@ -512,8 +512,8 @@ void TCompiler::collectVariables(TIntermNode* root) ...@@ -512,8 +512,8 @@ void TCompiler::collectVariables(TIntermNode* root)
// For backwards compatiblity with ShGetVariableInfo, expand struct // For backwards compatiblity with ShGetVariableInfo, expand struct
// uniforms and varyings into separate variables for each field. // uniforms and varyings into separate variables for each field.
ExpandVariables(uniforms, &expandedUniforms); sh::ExpandVariables(uniforms, &expandedUniforms);
ExpandVariables(varyings, &expandedVaryings); sh::ExpandVariables(varyings, &expandedVaryings);
} }
bool TCompiler::enforcePackingRestrictions() bool TCompiler::enforcePackingRestrictions()
......
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
#include "compiler/translator/util.h" #include "compiler/translator/util.h"
#include "common/utilities.h" #include "common/utilities.h"
namespace sh
{
namespace namespace
{ {
...@@ -24,28 +27,28 @@ TString InterfaceBlockFieldName(const TInterfaceBlock &interfaceBlock, const TFi ...@@ -24,28 +27,28 @@ TString InterfaceBlockFieldName(const TInterfaceBlock &interfaceBlock, const TFi
} }
} }
sh::BlockLayoutType GetBlockLayoutType(TLayoutBlockStorage blockStorage) BlockLayoutType GetBlockLayoutType(TLayoutBlockStorage blockStorage)
{ {
switch (blockStorage) switch (blockStorage)
{ {
case EbsPacked: return sh::BLOCKLAYOUT_PACKED; case EbsPacked: return BLOCKLAYOUT_PACKED;
case EbsShared: return sh::BLOCKLAYOUT_SHARED; case EbsShared: return BLOCKLAYOUT_SHARED;
case EbsStd140: return sh::BLOCKLAYOUT_STANDARD; case EbsStd140: return BLOCKLAYOUT_STANDARD;
default: UNREACHABLE(); return sh::BLOCKLAYOUT_SHARED; default: UNREACHABLE(); return BLOCKLAYOUT_SHARED;
} }
} }
void ExpandUserDefinedVariable(const sh::ShaderVariable &variable, void ExpandUserDefinedVariable(const ShaderVariable &variable,
const std::string &name, const std::string &name,
const std::string &mappedName, const std::string &mappedName,
bool markStaticUse, bool markStaticUse,
std::vector<sh::ShaderVariable> *expanded); std::vector<ShaderVariable> *expanded);
void ExpandVariable(const sh::ShaderVariable &variable, void ExpandVariable(const ShaderVariable &variable,
const std::string &name, const std::string &name,
const std::string &mappedName, const std::string &mappedName,
bool markStaticUse, bool markStaticUse,
std::vector<sh::ShaderVariable> *expanded) std::vector<ShaderVariable> *expanded)
{ {
if (variable.isStruct()) if (variable.isStruct())
{ {
...@@ -53,8 +56,8 @@ void ExpandVariable(const sh::ShaderVariable &variable, ...@@ -53,8 +56,8 @@ void ExpandVariable(const sh::ShaderVariable &variable,
{ {
for (size_t elementIndex = 0; elementIndex < variable.elementCount(); elementIndex++) for (size_t elementIndex = 0; elementIndex < variable.elementCount(); elementIndex++)
{ {
std::string lname = name + ArrayString(elementIndex); std::string lname = name + ::ArrayString(elementIndex);
std::string lmappedName = mappedName + ArrayString(elementIndex); std::string lmappedName = mappedName + ::ArrayString(elementIndex);
ExpandUserDefinedVariable(variable, lname, lmappedName, markStaticUse, expanded); ExpandUserDefinedVariable(variable, lname, lmappedName, markStaticUse, expanded);
} }
} }
...@@ -65,7 +68,7 @@ void ExpandVariable(const sh::ShaderVariable &variable, ...@@ -65,7 +68,7 @@ void ExpandVariable(const sh::ShaderVariable &variable,
} }
else else
{ {
sh::ShaderVariable expandedVar = variable; ShaderVariable expandedVar = variable;
expandedVar.name = name; expandedVar.name = name;
expandedVar.mappedName = mappedName; expandedVar.mappedName = mappedName;
...@@ -86,19 +89,19 @@ void ExpandVariable(const sh::ShaderVariable &variable, ...@@ -86,19 +89,19 @@ void ExpandVariable(const sh::ShaderVariable &variable,
} }
} }
void ExpandUserDefinedVariable(const sh::ShaderVariable &variable, void ExpandUserDefinedVariable(const ShaderVariable &variable,
const std::string &name, const std::string &name,
const std::string &mappedName, const std::string &mappedName,
bool markStaticUse, bool markStaticUse,
std::vector<sh::ShaderVariable> *expanded) std::vector<ShaderVariable> *expanded)
{ {
ASSERT(variable.isStruct()); ASSERT(variable.isStruct());
const std::vector<sh::ShaderVariable> &fields = variable.fields; const std::vector<ShaderVariable> &fields = variable.fields;
for (size_t fieldIndex = 0; fieldIndex < fields.size(); fieldIndex++) for (size_t fieldIndex = 0; fieldIndex < fields.size(); fieldIndex++)
{ {
const sh::ShaderVariable &field = fields[fieldIndex]; const ShaderVariable &field = fields[fieldIndex];
ExpandVariable(field, ExpandVariable(field,
name + "." + field.name, name + "." + field.name,
mappedName + "." + field.mappedName, mappedName + "." + field.mappedName,
...@@ -149,10 +152,10 @@ CollectVariables::CollectVariables(std::vector<sh::Attribute> *attribs, ...@@ -149,10 +152,10 @@ CollectVariables::CollectVariables(std::vector<sh::Attribute> *attribs,
void CollectVariables::visitSymbol(TIntermSymbol *symbol) void CollectVariables::visitSymbol(TIntermSymbol *symbol)
{ {
ASSERT(symbol != NULL); ASSERT(symbol != NULL);
sh::ShaderVariable *var = NULL; ShaderVariable *var = NULL;
const TString &symbolName = symbol->getSymbol(); const TString &symbolName = symbol->getSymbol();
if (sh::IsVarying(symbol->getQualifier())) if (IsVarying(symbol->getQualifier()))
{ {
var = FindVariable(symbolName, mVaryings); var = FindVariable(symbolName, mVaryings);
} }
...@@ -176,7 +179,7 @@ void CollectVariables::visitSymbol(TIntermSymbol *symbol) ...@@ -176,7 +179,7 @@ void CollectVariables::visitSymbol(TIntermSymbol *symbol)
const TInterfaceBlock *interfaceBlock = symbol->getType().getInterfaceBlock(); const TInterfaceBlock *interfaceBlock = symbol->getType().getInterfaceBlock();
if (interfaceBlock) if (interfaceBlock)
{ {
sh::InterfaceBlock *namedBlock = FindVariable(interfaceBlock->name(), mInterfaceBlocks); InterfaceBlock *namedBlock = FindVariable(interfaceBlock->name(), mInterfaceBlocks);
ASSERT(namedBlock); ASSERT(namedBlock);
var = FindVariable(symbolName, &namedBlock->fields); var = FindVariable(symbolName, &namedBlock->fields);
...@@ -196,7 +199,7 @@ void CollectVariables::visitSymbol(TIntermSymbol *symbol) ...@@ -196,7 +199,7 @@ void CollectVariables::visitSymbol(TIntermSymbol *symbol)
case EvqFragCoord: case EvqFragCoord:
if (!mFragCoordAdded) if (!mFragCoordAdded)
{ {
sh::Varying info; Varying info;
info.name = "gl_FragCoord"; info.name = "gl_FragCoord";
info.mappedName = "gl_FragCoord"; info.mappedName = "gl_FragCoord";
info.type = GL_FLOAT_VEC4; info.type = GL_FLOAT_VEC4;
...@@ -210,7 +213,7 @@ void CollectVariables::visitSymbol(TIntermSymbol *symbol) ...@@ -210,7 +213,7 @@ void CollectVariables::visitSymbol(TIntermSymbol *symbol)
case EvqFrontFacing: case EvqFrontFacing:
if (!mFrontFacingAdded) if (!mFrontFacingAdded)
{ {
sh::Varying info; Varying info;
info.name = "gl_FrontFacing"; info.name = "gl_FrontFacing";
info.mappedName = "gl_FrontFacing"; info.mappedName = "gl_FrontFacing";
info.type = GL_BOOL; info.type = GL_BOOL;
...@@ -224,7 +227,7 @@ void CollectVariables::visitSymbol(TIntermSymbol *symbol) ...@@ -224,7 +227,7 @@ void CollectVariables::visitSymbol(TIntermSymbol *symbol)
case EvqPointCoord: case EvqPointCoord:
if (!mPointCoordAdded) if (!mPointCoordAdded)
{ {
sh::Varying info; Varying info;
info.name = "gl_PointCoord"; info.name = "gl_PointCoord";
info.mappedName = "gl_PointCoord"; info.mappedName = "gl_PointCoord";
info.type = GL_FLOAT_VEC2; info.type = GL_FLOAT_VEC2;
...@@ -245,7 +248,7 @@ void CollectVariables::visitSymbol(TIntermSymbol *symbol) ...@@ -245,7 +248,7 @@ void CollectVariables::visitSymbol(TIntermSymbol *symbol)
} }
} }
class NameHashingTraverser : public sh::GetVariableTraverser class NameHashingTraverser : public GetVariableTraverser
{ {
public: public:
NameHashingTraverser(ShHashFunction64 hashFunction) NameHashingTraverser(ShHashFunction64 hashFunction)
...@@ -255,7 +258,7 @@ class NameHashingTraverser : public sh::GetVariableTraverser ...@@ -255,7 +258,7 @@ class NameHashingTraverser : public sh::GetVariableTraverser
private: private:
DISALLOW_COPY_AND_ASSIGN(NameHashingTraverser); DISALLOW_COPY_AND_ASSIGN(NameHashingTraverser);
virtual void visitVariable(sh::ShaderVariable *variable) virtual void visitVariable(ShaderVariable *variable)
{ {
TString stringName = TString(variable->name.c_str()); TString stringName = TString(variable->name.c_str());
variable->mappedName = TIntermTraverser::hash(stringName, mHashFunction).c_str(); variable->mappedName = TIntermTraverser::hash(stringName, mHashFunction).c_str();
...@@ -267,16 +270,16 @@ class NameHashingTraverser : public sh::GetVariableTraverser ...@@ -267,16 +270,16 @@ class NameHashingTraverser : public sh::GetVariableTraverser
// Attributes, which cannot have struct fields, are a special case // Attributes, which cannot have struct fields, are a special case
template <> template <>
void CollectVariables::visitVariable(const TIntermSymbol *variable, void CollectVariables::visitVariable(const TIntermSymbol *variable,
std::vector<sh::Attribute> *infoList) const std::vector<Attribute> *infoList) const
{ {
ASSERT(variable); ASSERT(variable);
const TType &type = variable->getType(); const TType &type = variable->getType();
ASSERT(!type.getStruct()); ASSERT(!type.getStruct());
sh::Attribute attribute; Attribute attribute;
attribute.type = sh::GLVariableType(type); attribute.type = GLVariableType(type);
attribute.precision = sh::GLVariablePrecision(type); attribute.precision = GLVariablePrecision(type);
attribute.name = variable->getSymbol().c_str(); attribute.name = variable->getSymbol().c_str();
attribute.arraySize = static_cast<unsigned int>(type.getArraySize()); attribute.arraySize = static_cast<unsigned int>(type.getArraySize());
attribute.mappedName = TIntermTraverser::hash(variable->getSymbol(), mHashFunction).c_str(); attribute.mappedName = TIntermTraverser::hash(variable->getSymbol(), mHashFunction).c_str();
...@@ -287,9 +290,9 @@ void CollectVariables::visitVariable(const TIntermSymbol *variable, ...@@ -287,9 +290,9 @@ void CollectVariables::visitVariable(const TIntermSymbol *variable,
template <> template <>
void CollectVariables::visitVariable(const TIntermSymbol *variable, void CollectVariables::visitVariable(const TIntermSymbol *variable,
std::vector<sh::InterfaceBlock> *infoList) const std::vector<InterfaceBlock> *infoList) const
{ {
sh::InterfaceBlock interfaceBlock; InterfaceBlock interfaceBlock;
const TInterfaceBlock *blockType = variable->getType().getInterfaceBlock(); const TInterfaceBlock *blockType = variable->getType().getInterfaceBlock();
ASSERT(blockType); ASSERT(blockType);
...@@ -309,7 +312,7 @@ void CollectVariables::visitVariable(const TIntermSymbol *variable, ...@@ -309,7 +312,7 @@ void CollectVariables::visitVariable(const TIntermSymbol *variable,
const TString &fullFieldName = InterfaceBlockFieldName(*blockType, field); const TString &fullFieldName = InterfaceBlockFieldName(*blockType, field);
const TType &fieldType = *field.type(); const TType &fieldType = *field.type();
sh::GetVariableTraverser traverser; GetVariableTraverser traverser;
traverser.traverse(fieldType, fullFieldName, &interfaceBlock.fields); traverser.traverse(fieldType, fullFieldName, &interfaceBlock.fields);
interfaceBlock.fields.back().isRowMajorLayout = (fieldType.getLayoutQualifier().matrixPacking == EmpRowMajor); interfaceBlock.fields.back().isRowMajorLayout = (fieldType.getLayoutQualifier().matrixPacking == EmpRowMajor);
...@@ -364,7 +367,7 @@ bool CollectVariables::visitAggregate(Visit, TIntermAggregate *node) ...@@ -364,7 +367,7 @@ bool CollectVariables::visitAggregate(Visit, TIntermAggregate *node)
} }
else if (qualifier == EvqAttribute || qualifier == EvqVertexIn || else if (qualifier == EvqAttribute || qualifier == EvqVertexIn ||
qualifier == EvqFragmentOut || qualifier == EvqUniform || qualifier == EvqFragmentOut || qualifier == EvqUniform ||
sh::IsVarying(qualifier)) IsVarying(qualifier))
{ {
switch (qualifier) switch (qualifier)
{ {
...@@ -405,7 +408,7 @@ bool CollectVariables::visitBinary(Visit, TIntermBinary *binaryNode) ...@@ -405,7 +408,7 @@ bool CollectVariables::visitBinary(Visit, TIntermBinary *binaryNode)
ASSERT(constantUnion); ASSERT(constantUnion);
const TInterfaceBlock *interfaceBlock = blockNode->getType().getInterfaceBlock(); const TInterfaceBlock *interfaceBlock = blockNode->getType().getInterfaceBlock();
sh::InterfaceBlock *namedBlock = FindVariable(interfaceBlock->name(), mInterfaceBlocks); InterfaceBlock *namedBlock = FindVariable(interfaceBlock->name(), mInterfaceBlocks);
ASSERT(namedBlock); ASSERT(namedBlock);
namedBlock->staticUse = true; namedBlock->staticUse = true;
...@@ -420,14 +423,16 @@ bool CollectVariables::visitBinary(Visit, TIntermBinary *binaryNode) ...@@ -420,14 +423,16 @@ bool CollectVariables::visitBinary(Visit, TIntermBinary *binaryNode)
template <typename VarT> template <typename VarT>
void ExpandVariables(const std::vector<VarT> &compact, void ExpandVariables(const std::vector<VarT> &compact,
std::vector<sh::ShaderVariable> *expanded) std::vector<ShaderVariable> *expanded)
{ {
for (size_t variableIndex = 0; variableIndex < compact.size(); variableIndex++) for (size_t variableIndex = 0; variableIndex < compact.size(); variableIndex++)
{ {
const sh::ShaderVariable &variable = compact[variableIndex]; const ShaderVariable &variable = compact[variableIndex];
ExpandVariable(variable, variable.name, variable.mappedName, variable.staticUse, expanded); ExpandVariable(variable, variable.name, variable.mappedName, variable.staticUse, expanded);
} }
} }
template void ExpandVariables(const std::vector<sh::Uniform> &, std::vector<sh::ShaderVariable> *); template void ExpandVariables(const std::vector<Uniform> &, std::vector<ShaderVariable> *);
template void ExpandVariables(const std::vector<sh::Varying> &, std::vector<sh::ShaderVariable> *); template void ExpandVariables(const std::vector<Varying> &, std::vector<ShaderVariable> *);
}
...@@ -11,15 +11,18 @@ ...@@ -11,15 +11,18 @@
#include "compiler/translator/IntermNode.h" #include "compiler/translator/IntermNode.h"
namespace sh
{
// Traverses intermediate tree to collect all attributes, uniforms, varyings. // Traverses intermediate tree to collect all attributes, uniforms, varyings.
class CollectVariables : public TIntermTraverser class CollectVariables : public TIntermTraverser
{ {
public: public:
CollectVariables(std::vector<sh::Attribute> *attribs, CollectVariables(std::vector<Attribute> *attribs,
std::vector<sh::Attribute> *outputVariables, std::vector<Attribute> *outputVariables,
std::vector<sh::Uniform> *uniforms, std::vector<Uniform> *uniforms,
std::vector<sh::Varying> *varyings, std::vector<Varying> *varyings,
std::vector<sh::InterfaceBlock> *interfaceBlocks, std::vector<InterfaceBlock> *interfaceBlocks,
ShHashFunction64 hashFunction); ShHashFunction64 hashFunction);
virtual void visitSymbol(TIntermSymbol *symbol); virtual void visitSymbol(TIntermSymbol *symbol);
...@@ -33,13 +36,13 @@ class CollectVariables : public TIntermTraverser ...@@ -33,13 +36,13 @@ class CollectVariables : public TIntermTraverser
template <typename VarT> template <typename VarT>
void visitInfoList(const TIntermSequence &sequence, std::vector<VarT> *infoList) const; void visitInfoList(const TIntermSequence &sequence, std::vector<VarT> *infoList) const;
std::vector<sh::Attribute> *mAttribs; std::vector<Attribute> *mAttribs;
std::vector<sh::Attribute> *mOutputVariables; std::vector<Attribute> *mOutputVariables;
std::vector<sh::Uniform> *mUniforms; std::vector<Uniform> *mUniforms;
std::vector<sh::Varying> *mVaryings; std::vector<Varying> *mVaryings;
std::vector<sh::InterfaceBlock> *mInterfaceBlocks; std::vector<InterfaceBlock> *mInterfaceBlocks;
std::map<std::string, sh::InterfaceBlockField *> mInterfaceBlockFields; std::map<std::string, InterfaceBlockField *> mInterfaceBlockFields;
bool mPointCoordAdded; bool mPointCoordAdded;
bool mFrontFacingAdded; bool mFrontFacingAdded;
...@@ -51,6 +54,8 @@ class CollectVariables : public TIntermTraverser ...@@ -51,6 +54,8 @@ class CollectVariables : public TIntermTraverser
// Expand struct variables to flattened lists of split variables // Expand struct variables to flattened lists of split variables
template <typename VarT> template <typename VarT>
void ExpandVariables(const std::vector<VarT> &compact, void ExpandVariables(const std::vector<VarT> &compact,
std::vector<sh::ShaderVariable> *expanded); std::vector<ShaderVariable> *expanded);
}
#endif // COMPILER_VARIABLE_INFO_H_ #endif // COMPILER_VARIABLE_INFO_H_
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