Commit b5841ef2 by Olli Etuaho

Disallow texture lookup functions in global initializers

Do this by simply disallowing all function calls in global initializers - all built-in math ops are handled as other ops, not function calls. This change was tested extensively with popular WebGL content, with no regressions found. TEST=angle_unittests BUG=angleproject:988 Change-Id: Id1107fa294ae4012d5dd3949539d0b7b4cd21943 Reviewed-on: https://chromium-review.googlesource.com/283703Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org> Tested-by: 's avatarOlli Etuaho <oetuaho@nvidia.com>
parent e9cc78a1
......@@ -64,8 +64,9 @@ void ValidateGlobalInitializerTraverser::visitSymbol(TIntermSymbol *node)
bool ValidateGlobalInitializerTraverser::visitAggregate(Visit visit, TIntermAggregate *node)
{
// Disallow calls to user-defined functions in global variable initializers.
if (node->getOp() == EOpFunctionCall && node->isUserDefined())
// Disallow calls to user-defined functions and texture lookup functions in global variable initializers.
// This is done simply by disabling all function calls - built-in math functions don't use EOpFunctionCall.
if (node->getOp() == EOpFunctionCall)
{
mIsValid = false;
}
......
......@@ -559,6 +559,23 @@ TEST_F(MalformedShaderTest, AssignIncrementToGlobal)
}
}
// Global variable initializers need to be constant expressions (ESSL 1.00 section 4.3)
// Initializing with a texture lookup function call should be an error.
TEST_F(MalformedShaderTest, AssignTexture2DToGlobal)
{
const std::string &shaderString =
"precision mediump float;\n"
"uniform mediump sampler2D s;\n"
"float b = texture2D(s, vec2(0.5, 0.5)).x;\n"
"void main() {\n"
" gl_FragColor = vec4(b);\n"
"}\n";
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
}
}
// Global variable initializers need to be constant expressions (ESSL 3.00 section 4.3)
// Initializing with a non-constant global should be an error.
TEST_F(MalformedShaderTest, AssignNonConstGlobalToGlobal)
......
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