Commit a2f89c00 by Jiajie Hu Committed by Commit Bot

Add sampler array index validation for ESSL 3.00 onwards

In Section 12.30 of the ESSL 3.00 spec on p143-144: Indexing of arrays of samplers by constant-index-expressions is supported in GLSL ES 1.00. A constant-index-expression is an expression formed from constant-expressions and certain loop indices, defined for a subset of loop constructs. Should this functionality be included in GLSL ES 3.00? RESOLUTION: No. Arrays of samplers may only be indexed by constant- integral-expressions. Bug: chromium:985032 Change-Id: Iad9e4b8000b442a6631e1d2295c2670c4a79d486 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1849452 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 130fdbcc
......@@ -4024,6 +4024,29 @@ TIntermTyped *TParseContext::addIndexExpression(TIntermTyped *baseExpression,
{
error(location, "array index for gl_FragData must be constant zero", "[");
}
else if (baseExpression->isArray())
{
TType elementType;
switch (mShaderVersion)
{
case 100:
break;
case 300:
case 310:
elementType = baseExpression->getType();
elementType.toArrayElementType();
if (elementType.isSampler())
{
error(location,
"array index for samplers must be constant integral expressions",
"[");
}
break;
default:
UNREACHABLE();
break;
}
}
}
if (indexConstantUnion)
......
......@@ -1305,6 +1305,26 @@ TEST_F(FragmentShaderValidationTest, DynamicallyIndexedInterfaceBlock)
}
}
// Test that indexing a sampler array with a non-constant expression is forbidden, even if ANGLE is
// able to constant fold the index expression. ESSL 3.00 section 4.1.7.1.
TEST_F(FragmentShaderValidationTest, DynamicallyIndexedSampler)
{
const std::string &shaderString =
"#version 300 es\n"
"precision mediump float;\n"
"uniform int a;\n"
"uniform sampler2D s[2];\n"
"out vec4 my_FragColor;\n"
"void main()\n"
"{\n"
" my_FragColor = texture(s[true ? 0 : a], vec2(0));\n"
"}\n";
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
}
}
// Test that a shader that uses a struct definition in place of a struct constructor does not
// compile. See GLSL ES 1.00 section 5.4.3.
TEST_F(FragmentShaderValidationTest, StructConstructorWithStructDefinition)
......
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