Commit 9dd217bc by Olli Etuaho

Disallow operations on structures containing arrays in ESSL1

Comparing structures that contain arrays to each other and assigning structures that contain arrays is "not defined" in ESSL 1.00 (section 5.7). Sections 5.8 and 5.9 further suggest that these operations are not allowed. Additionally some platform drivers on Linux seem to reject shaders produced by ANGLE which compare structures containing arrays. This might require changing the output GLSL version for ESSL 3.00. BUG=angleproject:954 TEST=angle_unittests Change-Id: I5f3a016f360f940f2fc1ec1ff8e60d13a977eb69 Reviewed-on: https://chromium-review.googlesource.com/261531Reviewed-by: 's avatarOlli Etuaho <oetuaho@nvidia.com> Tested-by: 's avatarOlli Etuaho <oetuaho@nvidia.com>
parent bdd419f9
......@@ -2791,13 +2791,20 @@ bool TParseContext::binaryOpCommonCheck(TOperator op, TIntermTyped *left, TInter
return false;
}
// Check that type sizes match exactly on ops that require that:
// Check that type sizes match exactly on ops that require that.
// Also check restrictions for structs that contain arrays.
switch(op)
{
case EOpAssign:
case EOpInitialize:
case EOpEqual:
case EOpNotEqual:
// ESSL 1.00 sections 5.7, 5.8, 5.9
if (shaderVersion < 300 && left->getType().isStructureContainingArrays())
{
error(loc, "undefined operation for structs containing arrays", GetOperatorString(op));
return false;
}
case EOpLessThan:
case EOpGreaterThan:
case EOpLessThanEqual:
......
......@@ -121,3 +121,40 @@ TEST_F(MalformedShaderTest, RedeclaringFunctionWithDifferentQualifiers)
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
}
};
// Assignment and equality are undefined for structures containing arrays (ESSL 1.00 section 5.7)
TEST_F(MalformedShaderTest, CompareStructsContainingArrays)
{
const std::string &shaderString =
"precision mediump float;\n"
"struct s { float a[3]; };\n"
"void main() {\n"
" s a;\n"
" s b;\n"
" bool c = (a == b);\n"
" gl_FragColor = vec4(c ? 1.0 : 0.0);\n"
"}\n";
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
}
}
// Assignment and equality are undefined for structures containing arrays (ESSL 1.00 section 5.7)
TEST_F(MalformedShaderTest, AssignStructsContainingArrays)
{
const std::string &shaderString =
"precision mediump float;\n"
"struct s { float a[3]; };\n"
"void main() {\n"
" s a;\n"
" s b;\n"
" b.a[0] = 0.0;\n"
" a = b;\n"
" gl_FragColor = vec4(a.a[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