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,65 +141,67 @@ CollectVariables::CollectVariables(std::vector<sh::Attribute> *attribs, ...@@ -137,65 +141,67 @@ 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; }
case EvqUniform: else
var = findVariable(symbol->getType(), symbol->getSymbol(), mUniforms); {
break; switch (symbol->getQualifier())
case EvqFragCoord:
if (!mFragCoordAdded)
{
sh::Varying info;
info.name = "gl_FragCoord";
info.mappedName = "gl_FragCoord";
info.type = GL_FLOAT_VEC4;
info.arraySize = 0;
info.precision = GL_MEDIUM_FLOAT; // Use mediump as it doesn't really matter.
info.staticUse = true;
mVaryings->push_back(info);
mFragCoordAdded = true;
}
return;
case EvqFrontFacing:
if (!mFrontFacingAdded)
{
sh::Varying info;
info.name = "gl_FrontFacing";
info.mappedName = "gl_FrontFacing";
info.type = GL_BOOL;
info.arraySize = 0;
info.precision = GL_NONE;
info.staticUse = true;
mVaryings->push_back(info);
mFrontFacingAdded = true;
}
return;
case EvqPointCoord:
if (!mPointCoordAdded)
{ {
sh::Varying info; case EvqUniform:
info.name = "gl_PointCoord"; var = findVariable(symbol->getType(), symbol->getSymbol(), mUniforms);
info.mappedName = "gl_PointCoord"; break;
info.type = GL_FLOAT_VEC2; case EvqFragCoord:
info.arraySize = 0; if (!mFragCoordAdded)
info.precision = GL_MEDIUM_FLOAT; // Use mediump as it doesn't really matter. {
info.staticUse = true; sh::Varying info;
mVaryings->push_back(info); info.name = "gl_FragCoord";
mPointCoordAdded = true; info.mappedName = "gl_FragCoord";
info.type = GL_FLOAT_VEC4;
info.arraySize = 0;
info.precision = GL_MEDIUM_FLOAT; // Use mediump as it doesn't really matter.
info.staticUse = true;
mVaryings->push_back(info);
mFragCoordAdded = true;
}
return;
case EvqFrontFacing:
if (!mFrontFacingAdded)
{
sh::Varying info;
info.name = "gl_FrontFacing";
info.mappedName = "gl_FrontFacing";
info.type = GL_BOOL;
info.arraySize = 0;
info.precision = GL_NONE;
info.staticUse = true;
mVaryings->push_back(info);
mFrontFacingAdded = true;
}
return;
case EvqPointCoord:
if (!mPointCoordAdded)
{
sh::Varying info;
info.name = "gl_PointCoord";
info.mappedName = "gl_PointCoord";
info.type = GL_FLOAT_VEC2;
info.arraySize = 0;
info.precision = GL_MEDIUM_FLOAT; // Use mediump as it doesn't really matter.
info.staticUse = true;
mVaryings->push_back(info);
mPointCoordAdded = true;
}
return;
default:
break;
} }
return;
default:
break;
} }
if (var) if (var)
{ {
...@@ -204,65 +210,73 @@ void CollectVariables::visitSymbol(TIntermSymbol* symbol) ...@@ -204,65 +210,73 @@ 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
{
TString processedSymbol;
if (mHashFunction == NULL)
processedSymbol = variable->getSymbol();
else
processedSymbol = TIntermTraverser::hash(variable->getSymbol(), mHashFunction);
getVariableInfo(variable->getType(),
variable->getSymbol(),
processedSymbol,
*infoList,
mHashFunction);
}
template <typename VarT>
void CollectVariables::visitInfoList(const TIntermSequence &sequence,
std::vector<VarT> *infoList) const
{ {
for (size_t seqIndex = 0; seqIndex < sequence.size(); seqIndex++) for (size_t seqIndex = 0; seqIndex < sequence.size(); seqIndex++)
{ {
const TIntermSymbol* variable = sequence[seqIndex]->getAsSymbolNode(); const TIntermSymbol *variable = sequence[seqIndex]->getAsSymbolNode();
// The only case in which the sequence will not contain a // The only case in which the sequence will not contain a
// TIntermSymbol node is initialization. It will contain a // TIntermSymbol node is initialization. It will contain a
// TInterBinary node in that case. Since attributes, uniforms, // TInterBinary node in that case. Since attributes, uniforms,
// and varyings cannot be initialized in a shader, we must have // and varyings cannot be initialized in a shader, we must have
// only TIntermSymbol nodes in the sequence. // only TIntermSymbol nodes in the sequence.
ASSERT(variable != NULL); ASSERT(variable != NULL);
TString processedSymbol; visitVariable(variable, infoList);
if (mHashFunction == NULL)
processedSymbol = variable->getSymbol();
else
processedSymbol = TIntermTraverser::hash(variable->getSymbol(), mHashFunction);
getVariableInfo(variable->getType(),
variable->getSymbol(),
processedSymbol,
*infoList,
mHashFunction);
} }
} }
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();
TQualifier qualifier = sequence.front()->getAsTyped()->getQualifier();
if (qualifier == EvqAttribute || qualifier == EvqVertexIn || qualifier == EvqUniform ||
qualifier == EvqVaryingIn || qualifier == EvqVaryingOut ||
qualifier == EvqInvariantVaryingIn || qualifier == EvqInvariantVaryingOut)
{ {
switch (qualifier) const TIntermSequence &sequence = node->getSequence();
TQualifier qualifier = sequence.front()->getAsTyped()->getQualifier();
if (qualifier == EvqAttribute || qualifier == EvqVertexIn || qualifier == EvqUniform ||
sh::IsVarying(qualifier))
{ {
case EvqAttribute: switch (qualifier)
case EvqVertexIn: {
visitInfoList(sequence, mAttribs); case EvqAttribute:
break; case EvqVertexIn:
case EvqUniform: visitInfoList(sequence, mAttribs);
visitInfoList(sequence, mUniforms); break;
break; case EvqUniform:
default: visitInfoList(sequence, mUniforms);
visitInfoList(sequence, mVaryings); break;
break; default:
} visitInfoList(sequence, mVaryings);
break;
}
if (!sequence.empty()) if (!sequence.empty())
{ {
visitChildren = false; visitChildren = false;
}
} }
break;
} }
break; default: break;
}
default: break;
} }
return visitChildren; return visitChildren;
......
...@@ -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