Commit e26cb5e4 by kbr@chromium.org

Increase GLSL version to 1.20 if the shader contains any matrix constructor

calls taking a matrix as argument; these were reserved in GLSL 1.10. This makes http://sio29.sakura.ne.jp/tmp/webgl/index_eruru.html load correctly once https://bugs.webkit.org/show_bug.cgi?id=52390 is fixed. BUG=103 TEST=none Review URL: http://codereview.appspot.com/4034041 git-svn-id: https://angleproject.googlecode.com/svn/trunk@534 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 1fe96c9a
...@@ -9,13 +9,17 @@ ...@@ -9,13 +9,17 @@
static const int GLSL_VERSION_110 = 110; static const int GLSL_VERSION_110 = 110;
static const int GLSL_VERSION_120 = 120; static const int GLSL_VERSION_120 = 120;
// We need to scan for two things: // We need to scan for three things:
// 1. "invariant" keyword: This can occur in both - vertex and fragment shaders // 1. "invariant" keyword: This can occur in both - vertex and fragment shaders
// but only at the global scope. // but only at the global scope.
// 2. "gl_PointCoord" built-in variable: This can only occur in fragment shader // 2. "gl_PointCoord" built-in variable: This can only occur in fragment shader
// but inside any scope. // but inside any scope.
// So we need to scan the entire fragment shader but only the global scope // 3. Call to a matrix constructor with another matrix as argument.
// of vertex shader. // (These constructors were reserved in GLSL version 1.10.)
//
// If it weren't for (3) then we would only need to scan the global
// scope of the vertex shader. However, we need to scan the entire
// shader in both cases.
// //
// TODO(alokp): The following two cases of invariant decalaration get lost // TODO(alokp): The following two cases of invariant decalaration get lost
// during parsing - they do not get carried over to the intermediate tree. // during parsing - they do not get carried over to the intermediate tree.
...@@ -34,40 +38,32 @@ TVersionGLSL::TVersionGLSL(ShShaderType type) ...@@ -34,40 +38,32 @@ TVersionGLSL::TVersionGLSL(ShShaderType type)
void TVersionGLSL::visitSymbol(TIntermSymbol* node) void TVersionGLSL::visitSymbol(TIntermSymbol* node)
{ {
ASSERT(mShaderType == SH_FRAGMENT_SHADER);
if (node->getSymbol() == "gl_PointCoord") if (node->getSymbol() == "gl_PointCoord")
updateVersion(GLSL_VERSION_120); updateVersion(GLSL_VERSION_120);
} }
void TVersionGLSL::visitConstantUnion(TIntermConstantUnion*) void TVersionGLSL::visitConstantUnion(TIntermConstantUnion*)
{ {
ASSERT(mShaderType == SH_FRAGMENT_SHADER);
} }
bool TVersionGLSL::visitBinary(Visit, TIntermBinary*) bool TVersionGLSL::visitBinary(Visit, TIntermBinary*)
{ {
ASSERT(mShaderType == SH_FRAGMENT_SHADER);
return true; return true;
} }
bool TVersionGLSL::visitUnary(Visit, TIntermUnary*) bool TVersionGLSL::visitUnary(Visit, TIntermUnary*)
{ {
ASSERT(mShaderType == SH_FRAGMENT_SHADER);
return true; return true;
} }
bool TVersionGLSL::visitSelection(Visit, TIntermSelection*) bool TVersionGLSL::visitSelection(Visit, TIntermSelection*)
{ {
ASSERT(mShaderType == SH_FRAGMENT_SHADER);
return true; return true;
} }
bool TVersionGLSL::visitAggregate(Visit, TIntermAggregate* node) bool TVersionGLSL::visitAggregate(Visit, TIntermAggregate* node)
{ {
// We need to scan the entire fragment shader but only the global scope bool visitChildren = true;
// of vertex shader.
bool visitChildren = mShaderType == SH_FRAGMENT_SHADER ? true : false;
switch (node->getOp()) { switch (node->getOp()) {
case EOpSequence: case EOpSequence:
...@@ -83,6 +79,19 @@ bool TVersionGLSL::visitAggregate(Visit, TIntermAggregate* node) ...@@ -83,6 +79,19 @@ bool TVersionGLSL::visitAggregate(Visit, TIntermAggregate* node)
} }
break; break;
} }
case EOpConstructMat2:
case EOpConstructMat3:
case EOpConstructMat4: {
const TIntermSequence& sequence = node->getSequence();
if (sequence.size() == 1) {
TIntermTyped* typed = sequence.front()->getAsTyped();
if (typed && typed->isMatrix()) {
updateVersion(GLSL_VERSION_120);
}
}
break;
}
default: break; default: break;
} }
...@@ -91,13 +100,11 @@ bool TVersionGLSL::visitAggregate(Visit, TIntermAggregate* node) ...@@ -91,13 +100,11 @@ bool TVersionGLSL::visitAggregate(Visit, TIntermAggregate* node)
bool TVersionGLSL::visitLoop(Visit, TIntermLoop*) bool TVersionGLSL::visitLoop(Visit, TIntermLoop*)
{ {
ASSERT(mShaderType == SH_FRAGMENT_SHADER);
return true; return true;
} }
bool TVersionGLSL::visitBranch(Visit, TIntermBranch*) bool TVersionGLSL::visitBranch(Visit, TIntermBranch*)
{ {
ASSERT(mShaderType == SH_FRAGMENT_SHADER);
return true; return true;
} }
......
...@@ -21,13 +21,15 @@ ...@@ -21,13 +21,15 @@
// - invariant keyword and its support. // - invariant keyword and its support.
// - c++ style name hiding rules. // - c++ style name hiding rules.
// - built-in variable gl_PointCoord for fragment shaders. // - built-in variable gl_PointCoord for fragment shaders.
// - matrix constructors taking matrix as argument.
// //
class TVersionGLSL : public TIntermTraverser { class TVersionGLSL : public TIntermTraverser {
public: public:
TVersionGLSL(ShShaderType type); TVersionGLSL(ShShaderType type);
// Returns 120 if "invariant" keyword or "gl_PointCoord" is used // Returns 120 if "invariant" keyword, "gl_PointCoord", or
// in the shader. Else 110 is returned. // matrix/matrix constructors are used in the shader. Else 110 is
// returned.
int getVersion() { return mVersion; } int getVersion() { return mVersion; }
virtual void visitSymbol(TIntermSymbol*); virtual void visitSymbol(TIntermSymbol*);
......
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