Commit c378cd8a by Olli Etuaho

Check that #version 300 es directive is on the first line

ESSL3.00 and 3.10 specs don't allow even newlines before the version directive. BUG=angleproject:1009 TEST=WebGL 2 conformance tests, angle_unittests Change-Id: Id7967829077e35e03572c724e0eafffbed0c975b Reviewed-on: https://chromium-review.googlesource.com/272719Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarOlli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org>
parent a357236f
...@@ -105,6 +105,8 @@ std::string Diagnostics::message(ID id) ...@@ -105,6 +105,8 @@ std::string Diagnostics::message(ID id)
case PP_VERSION_NOT_FIRST_STATEMENT: case PP_VERSION_NOT_FIRST_STATEMENT:
return "#version directive must occur before anything else, " return "#version directive must occur before anything else, "
"except for comments and white space"; "except for comments and white space";
case PP_VERSION_NOT_FIRST_LINE_ESSL3:
return "#version directive must occur on the first line of the shader";
case PP_INVALID_LINE_NUMBER: case PP_INVALID_LINE_NUMBER:
return "invalid line number"; return "invalid line number";
case PP_INVALID_FILE_NUMBER: case PP_INVALID_FILE_NUMBER:
......
...@@ -60,6 +60,7 @@ class Diagnostics ...@@ -60,6 +60,7 @@ class Diagnostics
PP_INVALID_VERSION_NUMBER, PP_INVALID_VERSION_NUMBER,
PP_INVALID_VERSION_DIRECTIVE, PP_INVALID_VERSION_DIRECTIVE,
PP_VERSION_NOT_FIRST_STATEMENT, PP_VERSION_NOT_FIRST_STATEMENT,
PP_VERSION_NOT_FIRST_LINE_ESSL3,
PP_INVALID_LINE_NUMBER, PP_INVALID_LINE_NUMBER,
PP_INVALID_FILE_NUMBER, PP_INVALID_FILE_NUMBER,
PP_INVALID_LINE_DIRECTIVE, PP_INVALID_LINE_DIRECTIVE,
......
...@@ -801,6 +801,13 @@ void DirectiveParser::parseVersion(Token *token) ...@@ -801,6 +801,13 @@ void DirectiveParser::parseVersion(Token *token)
valid = false; valid = false;
} }
if (valid && version >= 300 && token->location.line > 1)
{
mDiagnostics->report(Diagnostics::PP_VERSION_NOT_FIRST_LINE_ESSL3,
token->location, token->text);
valid = false;
}
if (valid) if (valid)
{ {
mDirectiveHandler->handleVersion(token->location, version); mDirectiveHandler->handleVersion(token->location, version);
......
...@@ -562,3 +562,20 @@ TEST_F(MalformedShaderTest, WriteBothFragDataAndFragColor) ...@@ -562,3 +562,20 @@ TEST_F(MalformedShaderTest, WriteBothFragDataAndFragColor)
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog; FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
} }
} }
// Version directive must be on the first line (ESSL 3.00 section 3.3)
TEST_F(MalformedShaderTest, VersionOnSecondLine)
{
const std::string &shaderString =
"\n"
"#version 300 es\n"
"precision mediump float;\n"
"out vec4 my_FragColor;\n"
"void main() {\n"
" my_FragColor = vec4(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