summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/angle/src/compiler/translator/VariableInfo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/angle/src/compiler/translator/VariableInfo.cpp')
-rw-r--r--src/3rdparty/angle/src/compiler/translator/VariableInfo.cpp197
1 files changed, 130 insertions, 67 deletions
diff --git a/src/3rdparty/angle/src/compiler/translator/VariableInfo.cpp b/src/3rdparty/angle/src/compiler/translator/VariableInfo.cpp
index 153455c4f1..f26c1566ac 100644
--- a/src/3rdparty/angle/src/compiler/translator/VariableInfo.cpp
+++ b/src/3rdparty/angle/src/compiler/translator/VariableInfo.cpp
@@ -9,20 +9,46 @@
#include "compiler/translator/util.h"
#include "common/utilities.h"
-template <typename VarT>
-static void ExpandUserDefinedVariable(const VarT &variable,
- const std::string &name,
- const std::string &mappedName,
- bool markStaticUse,
- std::vector<VarT> *expanded);
+namespace sh
+{
-// Returns info for an attribute, uniform, or varying.
-template <typename VarT>
-static void ExpandVariable(const VarT &variable,
- const std::string &name,
- const std::string &mappedName,
- bool markStaticUse,
- std::vector<VarT> *expanded)
+namespace
+{
+
+TString InterfaceBlockFieldName(const TInterfaceBlock &interfaceBlock, const TField &field)
+{
+ if (interfaceBlock.hasInstanceName())
+ {
+ return interfaceBlock.name() + "." + field.name();
+ }
+ else
+ {
+ return field.name();
+ }
+}
+
+BlockLayoutType GetBlockLayoutType(TLayoutBlockStorage blockStorage)
+{
+ switch (blockStorage)
+ {
+ case EbsPacked: return BLOCKLAYOUT_PACKED;
+ case EbsShared: return BLOCKLAYOUT_SHARED;
+ case EbsStd140: return BLOCKLAYOUT_STANDARD;
+ default: UNREACHABLE(); return BLOCKLAYOUT_SHARED;
+ }
+}
+
+void ExpandUserDefinedVariable(const ShaderVariable &variable,
+ const std::string &name,
+ const std::string &mappedName,
+ bool markStaticUse,
+ std::vector<ShaderVariable> *expanded);
+
+void ExpandVariable(const ShaderVariable &variable,
+ const std::string &name,
+ const std::string &mappedName,
+ bool markStaticUse,
+ std::vector<ShaderVariable> *expanded)
{
if (variable.isStruct())
{
@@ -30,8 +56,8 @@ static void ExpandVariable(const VarT &variable,
{
for (size_t elementIndex = 0; elementIndex < variable.elementCount(); elementIndex++)
{
- std::string lname = name + ArrayString(elementIndex);
- std::string lmappedName = mappedName + ArrayString(elementIndex);
+ std::string lname = name + ::ArrayString(elementIndex);
+ std::string lmappedName = mappedName + ::ArrayString(elementIndex);
ExpandUserDefinedVariable(variable, lname, lmappedName, markStaticUse, expanded);
}
}
@@ -42,7 +68,7 @@ static void ExpandVariable(const VarT &variable,
}
else
{
- VarT expandedVar = variable;
+ ShaderVariable expandedVar = variable;
expandedVar.name = name;
expandedVar.mappedName = mappedName;
@@ -63,20 +89,19 @@ static void ExpandVariable(const VarT &variable,
}
}
-template <class VarT>
-static void ExpandUserDefinedVariable(const VarT &variable,
- const std::string &name,
- const std::string &mappedName,
- bool markStaticUse,
- std::vector<VarT> *expanded)
+void ExpandUserDefinedVariable(const ShaderVariable &variable,
+ const std::string &name,
+ const std::string &mappedName,
+ bool markStaticUse,
+ std::vector<ShaderVariable> *expanded)
{
ASSERT(variable.isStruct());
- const std::vector<VarT> &fields = variable.fields;
+ const std::vector<ShaderVariable> &fields = variable.fields;
for (size_t fieldIndex = 0; fieldIndex < fields.size(); fieldIndex++)
{
- const VarT &field = fields[fieldIndex];
+ const ShaderVariable &field = fields[fieldIndex];
ExpandVariable(field,
name + "." + field.name,
mappedName + "." + field.mappedName,
@@ -86,8 +111,8 @@ static void ExpandUserDefinedVariable(const VarT &variable,
}
template <class VarT>
-static VarT *FindVariable(const TString &name,
- std::vector<VarT> *infoList)
+VarT *FindVariable(const TString &name,
+ std::vector<VarT> *infoList)
{
// TODO(zmo): optimize this function.
for (size_t ii = 0; ii < infoList->size(); ++ii)
@@ -99,6 +124,8 @@ static VarT *FindVariable(const TString &name,
return NULL;
}
+}
+
CollectVariables::CollectVariables(std::vector<sh::Attribute> *attribs,
std::vector<sh::Attribute> *outputVariables,
std::vector<sh::Uniform> *uniforms,
@@ -125,14 +152,18 @@ CollectVariables::CollectVariables(std::vector<sh::Attribute> *attribs,
void CollectVariables::visitSymbol(TIntermSymbol *symbol)
{
ASSERT(symbol != NULL);
- sh::ShaderVariable *var = NULL;
+ ShaderVariable *var = NULL;
const TString &symbolName = symbol->getSymbol();
- if (sh::IsVarying(symbol->getQualifier()))
+ if (IsVarying(symbol->getQualifier()))
{
var = FindVariable(symbolName, mVaryings);
}
- else if (symbol->getType() != EbtInterfaceBlock)
+ else if (symbol->getType().getBasicType() == EbtInterfaceBlock)
+ {
+ UNREACHABLE();
+ }
+ else
{
switch (symbol->getQualifier())
{
@@ -148,12 +179,13 @@ void CollectVariables::visitSymbol(TIntermSymbol *symbol)
const TInterfaceBlock *interfaceBlock = symbol->getType().getInterfaceBlock();
if (interfaceBlock)
{
- sh::InterfaceBlock *namedBlock = FindVariable(interfaceBlock->name(), mInterfaceBlocks);
+ InterfaceBlock *namedBlock = FindVariable(interfaceBlock->name(), mInterfaceBlocks);
ASSERT(namedBlock);
var = FindVariable(symbolName, &namedBlock->fields);
// Set static use on the parent interface block here
namedBlock->staticUse = true;
+
}
else
{
@@ -167,7 +199,7 @@ void CollectVariables::visitSymbol(TIntermSymbol *symbol)
case EvqFragCoord:
if (!mFragCoordAdded)
{
- sh::Varying info;
+ Varying info;
info.name = "gl_FragCoord";
info.mappedName = "gl_FragCoord";
info.type = GL_FLOAT_VEC4;
@@ -181,7 +213,7 @@ void CollectVariables::visitSymbol(TIntermSymbol *symbol)
case EvqFrontFacing:
if (!mFrontFacingAdded)
{
- sh::Varying info;
+ Varying info;
info.name = "gl_FrontFacing";
info.mappedName = "gl_FrontFacing";
info.type = GL_BOOL;
@@ -195,7 +227,7 @@ void CollectVariables::visitSymbol(TIntermSymbol *symbol)
case EvqPointCoord:
if (!mPointCoordAdded)
{
- sh::Varying info;
+ Varying info;
info.name = "gl_PointCoord";
info.mappedName = "gl_PointCoord";
info.type = GL_FLOAT_VEC2;
@@ -216,17 +248,17 @@ void CollectVariables::visitSymbol(TIntermSymbol *symbol)
}
}
-template <typename VarT>
-class NameHashingTraverser : public sh::GetVariableTraverser<VarT>
+class NameHashingTraverser : public GetVariableTraverser
{
public:
- NameHashingTraverser(std::vector<VarT> *output, ShHashFunction64 hashFunction)
- : sh::GetVariableTraverser<VarT>(output),
- mHashFunction(hashFunction)
+ NameHashingTraverser(ShHashFunction64 hashFunction)
+ : mHashFunction(hashFunction)
{}
private:
- void visitVariable(VarT *variable)
+ DISALLOW_COPY_AND_ASSIGN(NameHashingTraverser);
+
+ virtual void visitVariable(ShaderVariable *variable)
{
TString stringName = TString(variable->name.c_str());
variable->mappedName = TIntermTraverser::hash(stringName, mHashFunction).c_str();
@@ -238,16 +270,16 @@ class NameHashingTraverser : public sh::GetVariableTraverser<VarT>
// Attributes, which cannot have struct fields, are a special case
template <>
void CollectVariables::visitVariable(const TIntermSymbol *variable,
- std::vector<sh::Attribute> *infoList) const
+ std::vector<Attribute> *infoList) const
{
ASSERT(variable);
const TType &type = variable->getType();
ASSERT(!type.getStruct());
- sh::Attribute attribute;
+ Attribute attribute;
- attribute.type = sh::GLVariableType(type);
- attribute.precision = sh::GLVariablePrecision(type);
+ attribute.type = GLVariableType(type);
+ attribute.precision = GLVariablePrecision(type);
attribute.name = variable->getSymbol().c_str();
attribute.arraySize = static_cast<unsigned int>(type.getArraySize());
attribute.mappedName = TIntermTraverser::hash(variable->getSymbol(), mHashFunction).c_str();
@@ -258,29 +290,32 @@ void CollectVariables::visitVariable(const TIntermSymbol *variable,
template <>
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();
-
- bool isRowMajor = (blockType->matrixPacking() == EmpRowMajor);
+ ASSERT(blockType);
interfaceBlock.name = blockType->name().c_str();
interfaceBlock.mappedName = TIntermTraverser::hash(variable->getSymbol(), mHashFunction).c_str();
+ interfaceBlock.instanceName = (blockType->hasInstanceName() ? blockType->instanceName().c_str() : "");
interfaceBlock.arraySize = variable->getArraySize();
- interfaceBlock.isRowMajorLayout = isRowMajor;
- interfaceBlock.layout = sh::GetBlockLayoutType(blockType->blockStorage());
+ interfaceBlock.isRowMajorLayout = (blockType->matrixPacking() == EmpRowMajor);
+ interfaceBlock.layout = GetBlockLayoutType(blockType->blockStorage());
- ASSERT(blockType);
- const TFieldList &blockFields = blockType->fields();
+ // Gather field information
+ const TFieldList &fieldList = blockType->fields();
- for (size_t fieldIndex = 0; fieldIndex < blockFields.size(); fieldIndex++)
+ for (size_t fieldIndex = 0; fieldIndex < fieldList.size(); ++fieldIndex)
{
- const TField *field = blockFields[fieldIndex];
- ASSERT(field);
+ const TField &field = *fieldList[fieldIndex];
+ const TString &fullFieldName = InterfaceBlockFieldName(*blockType, field);
+ const TType &fieldType = *field.type();
- sh::GetInterfaceBlockFieldTraverser traverser(&interfaceBlock.fields, isRowMajor);
- traverser.traverse(*field->type(), field->name());
+ GetVariableTraverser traverser;
+ traverser.traverse(fieldType, fullFieldName, &interfaceBlock.fields);
+
+ interfaceBlock.fields.back().isRowMajorLayout = (fieldType.getLayoutQualifier().matrixPacking == EmpRowMajor);
}
infoList->push_back(interfaceBlock);
@@ -290,8 +325,8 @@ template <typename VarT>
void CollectVariables::visitVariable(const TIntermSymbol *variable,
std::vector<VarT> *infoList) const
{
- NameHashingTraverser<VarT> traverser(infoList, mHashFunction);
- traverser.traverse(variable->getType(), variable->getSymbol());
+ NameHashingTraverser traverser(mHashFunction);
+ traverser.traverse(variable->getType(), variable->getSymbol(), infoList);
}
template <typename VarT>
@@ -320,16 +355,19 @@ bool CollectVariables::visitAggregate(Visit, TIntermAggregate *node)
case EOpDeclaration:
{
const TIntermSequence &sequence = *(node->getSequence());
+ ASSERT(!sequence.empty());
+
const TIntermTyped &typedNode = *(sequence.front()->getAsTyped());
TQualifier qualifier = typedNode.getQualifier();
if (typedNode.getBasicType() == EbtInterfaceBlock)
{
visitInfoList(sequence, mInterfaceBlocks);
+ visitChildren = false;
}
else if (qualifier == EvqAttribute || qualifier == EvqVertexIn ||
qualifier == EvqFragmentOut || qualifier == EvqUniform ||
- sh::IsVarying(qualifier))
+ IsVarying(qualifier))
{
switch (qualifier)
{
@@ -348,10 +386,7 @@ bool CollectVariables::visitAggregate(Visit, TIntermAggregate *node)
break;
}
- if (!sequence.empty())
- {
- visitChildren = false;
- }
+ visitChildren = false;
}
break;
}
@@ -361,15 +396,43 @@ bool CollectVariables::visitAggregate(Visit, TIntermAggregate *node)
return visitChildren;
}
+bool CollectVariables::visitBinary(Visit, TIntermBinary *binaryNode)
+{
+ if (binaryNode->getOp() == EOpIndexDirectInterfaceBlock)
+ {
+ // NOTE: we do not determine static use for individual blocks of an array
+ TIntermTyped *blockNode = binaryNode->getLeft()->getAsTyped();
+ ASSERT(blockNode);
+
+ TIntermConstantUnion *constantUnion = binaryNode->getRight()->getAsConstantUnion();
+ ASSERT(constantUnion);
+
+ const TInterfaceBlock *interfaceBlock = blockNode->getType().getInterfaceBlock();
+ InterfaceBlock *namedBlock = FindVariable(interfaceBlock->name(), mInterfaceBlocks);
+ ASSERT(namedBlock);
+ namedBlock->staticUse = true;
+
+ unsigned int fieldIndex = constantUnion->getUConst(0);
+ ASSERT(fieldIndex < namedBlock->fields.size());
+ namedBlock->fields[fieldIndex].staticUse = true;
+ return false;
+ }
+
+ return true;
+}
+
template <typename VarT>
-void ExpandVariables(const std::vector<VarT> &compact, std::vector<VarT> *expanded)
+void ExpandVariables(const std::vector<VarT> &compact,
+ std::vector<ShaderVariable> *expanded)
{
for (size_t variableIndex = 0; variableIndex < compact.size(); variableIndex++)
{
- const VarT &variable = compact[variableIndex];
+ const ShaderVariable &variable = compact[variableIndex];
ExpandVariable(variable, variable.name, variable.mappedName, variable.staticUse, expanded);
}
}
-template void ExpandVariables(const std::vector<sh::Uniform> &, std::vector<sh::Uniform> *);
-template void ExpandVariables(const std::vector<sh::Varying> &, std::vector<sh::Varying> *);
+template void ExpandVariables(const std::vector<Uniform> &, std::vector<ShaderVariable> *);
+template void ExpandVariables(const std::vector<Varying> &, std::vector<ShaderVariable> *);
+
+}