Add static_use to shader variable info query.
BUG=249018
ANGLEBUG=465
R=kbr@chromium.org
Review URL: https://codereview.appspot.com/13158043
diff --git a/src/compiler/Compiler.cpp b/src/compiler/Compiler.cpp
index 90065a6..0a91f9b 100644
--- a/src/compiler/Compiler.cpp
+++ b/src/compiler/Compiler.cpp
@@ -281,6 +281,7 @@
attribs.clear();
uniforms.clear();
+ varyings.clear();
builtInFunctionEmulator.Cleanup();
diff --git a/src/compiler/ShaderLang.cpp b/src/compiler/ShaderLang.cpp
index b1364fd..6d954ca 100644
--- a/src/compiler/ShaderLang.cpp
+++ b/src/compiler/ShaderLang.cpp
@@ -257,10 +257,11 @@
int* size,
ShDataType* type,
ShPrecisionType* precision,
+ int* staticUse,
char* name,
char* mappedName)
{
- if (!handle || !size || !type || !name)
+ if (!handle || !size || !type || !precision || !staticUse || !name)
return;
ASSERT((varType == SH_ACTIVE_ATTRIBUTES) ||
(varType == SH_ACTIVE_UNIFORMS) ||
@@ -297,6 +298,7 @@
*precision = SH_PRECISION_UNDEFINED;
break;
}
+ *staticUse = varInfo.staticUse ? 1 : 0;
// This size must match that queried by
// SH_ACTIVE_UNIFORM_MAX_LENGTH, SH_ACTIVE_ATTRIBUTE_MAX_LENGTH, SH_VARYING_MAX_LENGTH
diff --git a/src/compiler/VariableInfo.cpp b/src/compiler/VariableInfo.cpp
index f6be240..a69abcd 100644
--- a/src/compiler/VariableInfo.cpp
+++ b/src/compiler/VariableInfo.cpp
@@ -6,15 +6,17 @@
#include "compiler/VariableInfo.h"
-static TString arrayBrackets(int index)
+namespace {
+
+TString arrayBrackets(int index)
{
TStringStream stream;
stream << "[" << index << "]";
return stream.str();
}
-// Returns the data type for an attribute or uniform.
-static ShDataType getVariableDataType(const TType& type)
+// Returns the data type for an attribute, uniform, or varying.
+ShDataType getVariableDataType(const TType& type)
{
switch (type.getBasicType()) {
case EbtFloat:
@@ -117,22 +119,22 @@
return SH_NONE;
}
-static void getBuiltInVariableInfo(const TType& type,
- const TString& name,
- const TString& mappedName,
- TVariableInfoList& infoList);
-static void getUserDefinedVariableInfo(const TType& type,
- const TString& name,
- const TString& mappedName,
- TVariableInfoList& infoList,
- ShHashFunction64 hashFunction);
-
-// Returns info for an attribute or uniform.
-static void getVariableInfo(const TType& type,
+void getBuiltInVariableInfo(const TType& type,
const TString& name,
const TString& mappedName,
- TVariableInfoList& infoList,
- ShHashFunction64 hashFunction)
+ TVariableInfoList& infoList);
+void getUserDefinedVariableInfo(const TType& type,
+ const TString& name,
+ const TString& mappedName,
+ TVariableInfoList& infoList,
+ ShHashFunction64 hashFunction);
+
+// Returns info for an attribute, uniform, or varying.
+void getVariableInfo(const TType& type,
+ const TString& name,
+ const TString& mappedName,
+ TVariableInfoList& infoList,
+ ShHashFunction64 hashFunction)
{
if (type.getBasicType() == EbtStruct) {
if (type.isArray()) {
@@ -191,13 +193,37 @@
}
}
+TVariableInfo* findVariable(const TType& type,
+ const TString& name,
+ TVariableInfoList& infoList)
+{
+ // TODO(zmo): optimize this function.
+ TString myName = name;
+ if (type.isArray())
+ myName += "[0]";
+ for (size_t ii = 0; ii < infoList.size(); ++ii)
+ {
+ if (infoList[ii].name.c_str() == myName)
+ return &(infoList[ii]);
+ }
+ return NULL;
+}
+
+} // namespace anonymous
+
TVariableInfo::TVariableInfo()
+ : type(SH_NONE),
+ size(0),
+ precision(EbpUndefined),
+ staticUse(false)
{
}
TVariableInfo::TVariableInfo(ShDataType type, int size)
: type(type),
- size(size)
+ size(size),
+ precision(EbpUndefined),
+ staticUse(false)
{
}
@@ -208,44 +234,85 @@
: mAttribs(attribs),
mUniforms(uniforms),
mVaryings(varyings),
+ mPointCoordAdded(false),
+ mFrontFacingAdded(false),
+ mFragCoordAdded(false),
mHashFunction(hashFunction)
{
}
-// We are only interested in attribute and uniform variable declaration.
-void CollectVariables::visitSymbol(TIntermSymbol*)
+// We want to check whether a uniform/varying is statically used
+// because we only count the used ones in packing computing.
+// Also, gl_FragCoord, gl_PointCoord, and gl_FrontFacing count
+// toward varying counting if they are statically used in a fragment
+// shader.
+void CollectVariables::visitSymbol(TIntermSymbol* symbol)
{
-}
-
-void CollectVariables::visitConstantUnion(TIntermConstantUnion*)
-{
-}
-
-bool CollectVariables::visitBinary(Visit, TIntermBinary*)
-{
- return false;
-}
-
-bool CollectVariables::visitUnary(Visit, TIntermUnary*)
-{
- return false;
-}
-
-bool CollectVariables::visitSelection(Visit, TIntermSelection*)
-{
- return false;
+ ASSERT(symbol != NULL);
+ TVariableInfo* var = NULL;
+ switch (symbol->getQualifier())
+ {
+ case EvqVaryingOut:
+ case EvqInvariantVaryingOut:
+ case EvqVaryingIn:
+ case EvqInvariantVaryingIn:
+ var = findVariable(symbol->getType(), symbol->getSymbol(), mVaryings);
+ break;
+ case EvqUniform:
+ var = findVariable(symbol->getType(), symbol->getSymbol(), mUniforms);
+ break;
+ case EvqFragCoord:
+ if (!mFragCoordAdded) {
+ TVariableInfo info;
+ info.name = "gl_FragCoord";
+ info.mappedName = "gl_FragCoord";
+ info.type = SH_FLOAT_VEC4;
+ info.size = 1;
+ info.precision = EbpMedium; // Use mediump as it doesn't really matter.
+ info.staticUse = true;
+ mVaryings.push_back(info);
+ mFragCoordAdded = true;
+ }
+ return;
+ case EvqFrontFacing:
+ if (!mFrontFacingAdded) {
+ TVariableInfo info;
+ info.name = "gl_FrontFacing";
+ info.mappedName = "gl_FrontFacing";
+ info.type = SH_BOOL;
+ info.size = 1;
+ info.precision = EbpUndefined;
+ info.staticUse = true;
+ mVaryings.push_back(info);
+ mFrontFacingAdded = true;
+ }
+ return;
+ case EvqPointCoord:
+ if (!mPointCoordAdded) {
+ TVariableInfo info;
+ info.name = "gl_PointCoord";
+ info.mappedName = "gl_PointCoord";
+ info.type = SH_FLOAT_VEC2;
+ info.size = 1;
+ info.precision = EbpMedium; // Use mediump as it doesn't really matter.
+ info.staticUse = true;
+ mVaryings.push_back(info);
+ mPointCoordAdded = true;
+ }
+ return;
+ default:
+ break;
+ }
+ if (var)
+ var->staticUse = true;
}
bool CollectVariables::visitAggregate(Visit, TIntermAggregate* node)
{
- bool visitChildren = false;
+ bool visitChildren = true;
switch (node->getOp())
{
- case EOpSequence:
- // We need to visit sequence children to get to variable declarations.
- visitChildren = true;
- break;
case EOpDeclaration: {
const TIntermSequence& sequence = node->getSequence();
TQualifier qualifier = sequence.front()->getAsTyped()->getQualifier();
@@ -275,9 +342,9 @@
const TIntermSymbol* variable = (*i)->getAsSymbolNode();
// The only case in which the sequence will not contain a
// TIntermSymbol node is initialization. It will contain a
- // TIntermBinary node in that case. Since attributes and uniforms
- // cannot be initialized in a shader, we must have only
- // TIntermSymbol nodes in the sequence.
+ // 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;
if (mHashFunction == NULL)
@@ -289,6 +356,7 @@
processedSymbol,
*infoList,
mHashFunction);
+ visitChildren = false;
}
}
break;
@@ -299,13 +367,3 @@
return visitChildren;
}
-bool CollectVariables::visitLoop(Visit, TIntermLoop*)
-{
- return false;
-}
-
-bool CollectVariables::visitBranch(Visit, TIntermBranch*)
-{
- return false;
-}
-
diff --git a/src/compiler/VariableInfo.h b/src/compiler/VariableInfo.h
index bef196d..3c7f2a5 100644
--- a/src/compiler/VariableInfo.h
+++ b/src/compiler/VariableInfo.h
@@ -21,6 +21,7 @@
ShDataType type;
int size;
TPrecision precision;
+ bool staticUse;
};
typedef std::vector<TVariableInfo> TVariableInfoList;
@@ -33,19 +34,17 @@
ShHashFunction64 hashFunction);
virtual void visitSymbol(TIntermSymbol*);
- virtual void visitConstantUnion(TIntermConstantUnion*);
- virtual bool visitBinary(Visit, TIntermBinary*);
- virtual bool visitUnary(Visit, TIntermUnary*);
- virtual bool visitSelection(Visit, TIntermSelection*);
virtual bool visitAggregate(Visit, TIntermAggregate*);
- virtual bool visitLoop(Visit, TIntermLoop*);
- virtual bool visitBranch(Visit, TIntermBranch*);
private:
TVariableInfoList& mAttribs;
TVariableInfoList& mUniforms;
TVariableInfoList& mVaryings;
+ bool mPointCoordAdded;
+ bool mFrontFacingAdded;
+ bool mFragCoordAdded;
+
ShHashFunction64 mHashFunction;
};