Commit de318b26 by Olli Etuaho Committed by Commit Bot

Disallow samplers as ternary operands

Quoting the ESSL 1.00 spec section 4.1.7: "Except for parameters to texture lookup functions, array indexing, structure field selection, and parentheses, samplers are not allowed to be operands in expressions." ESSL 3.00 has a similar passage related to opaque types. Validate this correctly. Compatibility risk should be low, since attempting to use samplers in ternary operators was already failing before this in most cases. BUG=angleproject:1551 TEST=angle_unittests Change-Id: I6cbb536f473ba9674d558b14a458f3799f9c7c9c Reviewed-on: https://chromium-review.googlesource.com/402694Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent d842a6b2
...@@ -4321,6 +4321,17 @@ TIntermTyped *TParseContext::addTernarySelection(TIntermTyped *cond, ...@@ -4321,6 +4321,17 @@ TIntermTyped *TParseContext::addTernarySelection(TIntermTyped *cond,
falseExpression->getCompleteString()); falseExpression->getCompleteString());
return falseExpression; return falseExpression;
} }
if (IsOpaqueType(trueExpression->getBasicType()))
{
// ESSL 1.00 section 4.1.7
// ESSL 3.00 section 4.1.7
// Opaque/sampler types are not allowed in most types of expressions, including ternary.
// Note that structs containing opaque types don't need to be checked as structs are
// forbidden below.
error(loc, "ternary operator is not allowed for opaque types", ":");
return falseExpression;
}
// ESSL1 sections 5.2 and 5.7: // ESSL1 sections 5.2 and 5.7:
// ESSL3 section 5.7: // ESSL3 section 5.7:
// Ternary operator is not among the operators allowed for structures/arrays. // Ternary operator is not among the operators allowed for structures/arrays.
......
...@@ -2981,3 +2981,22 @@ TEST_F(MalformedFragmentShaderGLES31Test, ImageInternalFormatInGlobalLayoutQuali ...@@ -2981,3 +2981,22 @@ TEST_F(MalformedFragmentShaderGLES31Test, ImageInternalFormatInGlobalLayoutQuali
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog; FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
} }
} }
// ESSL 1.00 section 4.1.7.
// Samplers are not allowed as operands for most operations. Test this for ternary operator.
TEST_F(MalformedShaderTest, SamplerAsTernaryOperand)
{
const std::string &shaderString =
"precision mediump float;\n"
"uniform bool u;\n"
"uniform sampler2D s1;\n"
"uniform sampler2D s2;\n"
"void main() {\n"
" gl_FragColor = texture2D(u ? s1 : s2, vec2(0, 0));\n"
"}\n";
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
}
}
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