Commit b4cf5656 by jchen10 Committed by Commit Bot

Validate opaque operands against binary operators

Add checks that opaque operands can only be used with array indexing and field section, as mentioned in ESSL 3.10 section 4.1.7. BUG=angleproject:2028 Change-Id: I41b7f10785bf712dfc999f85ebff925341c51911 Reviewed-on: https://chromium-review.googlesource.com/497767 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarOlli Etuaho <oetuaho@nvidia.com>
parent cc2a10e9
...@@ -3769,8 +3769,24 @@ bool TParseContext::binaryOpCommonCheck(TOperator op, ...@@ -3769,8 +3769,24 @@ bool TParseContext::binaryOpCommonCheck(TOperator op,
TIntermTyped *right, TIntermTyped *right,
const TSourceLoc &loc) const TSourceLoc &loc)
{ {
// TODO(jie.a.chen@intel.com): Validate opaque type variables can only be operands in array // Check opaque types are not allowed to be operands in expressions other than array indexing
// indexing, structure member selection, and parentheses expressions. // and structure member selection.
if (IsOpaqueType(left->getBasicType()) || IsOpaqueType(right->getBasicType()))
{
switch (op)
{
case EOpIndexDirect:
case EOpIndexIndirect:
break;
case EOpIndexDirectStruct:
UNREACHABLE();
default:
error(loc, "Invalid operation for variables with an opaque type",
GetOperatorString(op));
return false;
}
}
if (left->getType().getStruct() || right->getType().getStruct()) if (left->getType().getStruct() || right->getType().getStruct())
{ {
......
...@@ -3779,3 +3779,21 @@ TEST_F(FragmentShaderValidationTest, OpaqueParameterCanNotBeLValue) ...@@ -3779,3 +3779,21 @@ TEST_F(FragmentShaderValidationTest, OpaqueParameterCanNotBeLValue)
FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog; FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
} }
} }
// Test samplers must not be operands in expressions, except for array indexing, structure field
// selection and parentheses(ESSL 3.00 Secion 4.1.7).
TEST_F(FragmentShaderValidationTest, InvalidExpressionForSamplerOperands)
{
const std::string &shaderString =
"#version 300 es\n"
"uniform sampler2D s;\n"
"uniform sampler2D s2;\n"
"void main() {\n"
" s + s2;\n"
"}\n";
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure:\n" << 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