Commit 4667c454 by Jamie Madill

Refactor style in VariableInfo.cpp.

This patch simplifies the functionality change in a subsequent patch. BUG=angle:466 Change-Id: Ib1c360438fad74fb15cd6cbf983240229c0eee76 Reviewed-on: https://chromium-review.googlesource.com/206568Reviewed-by: 's avatarNicolas Capens <capn@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 53cb14dc
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
// found in the LICENSE file. // found in the LICENSE file.
// //
#include "angle_gl.h"
#include "compiler/translator/VariableInfo.h" #include "compiler/translator/VariableInfo.h"
#include "compiler/translator/util.h" #include "compiler/translator/util.h"
#include "angle_gl.h"
namespace { namespace {
...@@ -62,11 +62,14 @@ void getBuiltInVariableInfo(const TType &type, ...@@ -62,11 +62,14 @@ void getBuiltInVariableInfo(const TType &type,
ASSERT(type.getBasicType() != EbtStruct); ASSERT(type.getBasicType() != EbtStruct);
VarT varInfo; VarT varInfo;
if (type.isArray()) { if (type.isArray())
{
varInfo.name = (name + "[0]").c_str(); varInfo.name = (name + "[0]").c_str();
varInfo.mappedName = (mappedName + "[0]").c_str(); varInfo.mappedName = (mappedName + "[0]").c_str();
varInfo.arraySize = type.getArraySize(); varInfo.arraySize = type.getArraySize();
} else { }
else
{
varInfo.name = name.c_str(); varInfo.name = name.c_str();
varInfo.mappedName = mappedName.c_str(); varInfo.mappedName = mappedName.c_str();
varInfo.arraySize = 0; varInfo.arraySize = 0;
...@@ -88,7 +91,8 @@ void getUserDefinedVariableInfo(const TType &type, ...@@ -88,7 +91,8 @@ void getUserDefinedVariableInfo(const TType &type,
const TFieldList& fields = type.isInterfaceBlock() ? const TFieldList& fields = type.isInterfaceBlock() ?
type.getInterfaceBlock()->fields() : type.getInterfaceBlock()->fields() :
type.getStruct()->fields(); type.getStruct()->fields();
for (size_t i = 0; i < fields.size(); ++i) { for (size_t i = 0; i < fields.size(); ++i)
{
const TType& fieldType = *(fields[i]->type()); const TType& fieldType = *(fields[i]->type());
const TString& fieldName = fields[i]->name(); const TString& fieldName = fields[i]->name();
getVariableInfo(fieldType, getVariableInfo(fieldType,
...@@ -137,18 +141,19 @@ CollectVariables::CollectVariables(std::vector<sh::Attribute> *attribs, ...@@ -137,18 +141,19 @@ CollectVariables::CollectVariables(std::vector<sh::Attribute> *attribs,
// Also, gl_FragCoord, gl_PointCoord, and gl_FrontFacing count // Also, gl_FragCoord, gl_PointCoord, and gl_FrontFacing count
// toward varying counting if they are statically used in a fragment // toward varying counting if they are statically used in a fragment
// shader. // shader.
void CollectVariables::visitSymbol(TIntermSymbol* symbol) void CollectVariables::visitSymbol(TIntermSymbol *symbol)
{ {
ASSERT(symbol != NULL); ASSERT(symbol != NULL);
sh::ShaderVariable *var = NULL; sh::ShaderVariable *var = NULL;
switch (symbol->getQualifier())
if (sh::IsVarying(symbol->getQualifier()))
{ {
case EvqVaryingOut:
case EvqInvariantVaryingOut:
case EvqVaryingIn:
case EvqInvariantVaryingIn:
var = findVariable(symbol->getType(), symbol->getSymbol(), mVaryings); var = findVariable(symbol->getType(), symbol->getSymbol(), mVaryings);
break; }
else
{
switch (symbol->getQualifier())
{
case EvqUniform: case EvqUniform:
var = findVariable(symbol->getType(), symbol->getSymbol(), mUniforms); var = findVariable(symbol->getType(), symbol->getSymbol(), mUniforms);
break; break;
...@@ -197,6 +202,7 @@ void CollectVariables::visitSymbol(TIntermSymbol* symbol) ...@@ -197,6 +202,7 @@ void CollectVariables::visitSymbol(TIntermSymbol* symbol)
default: default:
break; break;
} }
}
if (var) if (var)
{ {
var->staticUse = true; var->staticUse = true;
...@@ -204,17 +210,9 @@ void CollectVariables::visitSymbol(TIntermSymbol* symbol) ...@@ -204,17 +210,9 @@ void CollectVariables::visitSymbol(TIntermSymbol* symbol)
} }
template <typename VarT> template <typename VarT>
void CollectVariables::visitInfoList(const TIntermSequence& sequence, std::vector<VarT> *infoList) const void CollectVariables::visitVariable(const TIntermSymbol *variable,
std::vector<VarT> *infoList) const
{ {
for (size_t seqIndex = 0; seqIndex < sequence.size(); seqIndex++)
{
const TIntermSymbol* variable = sequence[seqIndex]->getAsSymbolNode();
// The only case in which the sequence will not contain a
// TIntermSymbol node is initialization. It will contain a
// TInterBinary node in that case. Since attributes, uniforms,
// and varyings cannot be initialized in a shader, we must have
// only TIntermSymbol nodes in the sequence.
ASSERT(variable != NULL);
TString processedSymbol; TString processedSymbol;
if (mHashFunction == NULL) if (mHashFunction == NULL)
processedSymbol = variable->getSymbol(); processedSymbol = variable->getSymbol();
...@@ -225,21 +223,37 @@ void CollectVariables::visitInfoList(const TIntermSequence& sequence, std::vecto ...@@ -225,21 +223,37 @@ void CollectVariables::visitInfoList(const TIntermSequence& sequence, std::vecto
processedSymbol, processedSymbol,
*infoList, *infoList,
mHashFunction); mHashFunction);
}
template <typename VarT>
void CollectVariables::visitInfoList(const TIntermSequence &sequence,
std::vector<VarT> *infoList) const
{
for (size_t seqIndex = 0; seqIndex < sequence.size(); seqIndex++)
{
const TIntermSymbol *variable = sequence[seqIndex]->getAsSymbolNode();
// The only case in which the sequence will not contain a
// TIntermSymbol node is initialization. It will contain a
// TInterBinary node in that case. Since attributes, uniforms,
// and varyings cannot be initialized in a shader, we must have
// only TIntermSymbol nodes in the sequence.
ASSERT(variable != NULL);
visitVariable(variable, infoList);
} }
} }
bool CollectVariables::visitAggregate(Visit, TIntermAggregate* node) bool CollectVariables::visitAggregate(Visit, TIntermAggregate *node)
{ {
bool visitChildren = true; bool visitChildren = true;
switch (node->getOp()) switch (node->getOp())
{ {
case EOpDeclaration: { case EOpDeclaration:
const TIntermSequence& sequence = node->getSequence(); {
const TIntermSequence &sequence = node->getSequence();
TQualifier qualifier = sequence.front()->getAsTyped()->getQualifier(); TQualifier qualifier = sequence.front()->getAsTyped()->getQualifier();
if (qualifier == EvqAttribute || qualifier == EvqVertexIn || qualifier == EvqUniform || if (qualifier == EvqAttribute || qualifier == EvqVertexIn || qualifier == EvqUniform ||
qualifier == EvqVaryingIn || qualifier == EvqVaryingOut || sh::IsVarying(qualifier))
qualifier == EvqInvariantVaryingIn || qualifier == EvqInvariantVaryingOut)
{ {
switch (qualifier) switch (qualifier)
{ {
......
...@@ -18,8 +18,8 @@ public: ...@@ -18,8 +18,8 @@ public:
std::vector<sh::Varying> *varyings, std::vector<sh::Varying> *varyings,
ShHashFunction64 hashFunction); ShHashFunction64 hashFunction);
virtual void visitSymbol(TIntermSymbol*); virtual void visitSymbol(TIntermSymbol *symbol);
virtual bool visitAggregate(Visit, TIntermAggregate*); virtual bool visitAggregate(Visit, TIntermAggregate *node);
private: private:
std::vector<sh::Attribute> *mAttribs; std::vector<sh::Attribute> *mAttribs;
...@@ -33,7 +33,10 @@ private: ...@@ -33,7 +33,10 @@ private:
ShHashFunction64 mHashFunction; ShHashFunction64 mHashFunction;
template <typename VarT> template <typename VarT>
void visitInfoList(const TIntermSequence& sequence, std::vector<VarT> *infoList) const; void visitVariable(const TIntermSymbol *variable, std::vector<VarT> *infoList) const;
template <typename VarT>
void visitInfoList(const TIntermSequence &sequence, std::vector<VarT> *infoList) const;
}; };
#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