Commit 5f80d016 by Olli Etuaho

Disallow invariant(all) pragma in ESSL 3.00 fragment shaders

ESSL 3.00.4 section 4.6.1 says that using #pragma STDGL invariant(all) in a fragment shader is an error, so make it an error. This spec language is not found in ESSL 1.00, and it's been removed in ESSL 3.10. BUG=angleproject:1276 TEST=angle_unittests Change-Id: I2022f35475f867304b55dfb142f8568f6df28830 Reviewed-on: https://chromium-review.googlesource.com/321240 Tryjob-Request: Olli Etuaho <oetuaho@nvidia.com> Tested-by: 's avatarOlli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org> Reviewed-by: 's avatarKenneth Russell <kbr@chromium.org>
parent edbc2449
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <sstream> #include <sstream>
#include "angle_gl.h"
#include "common/debug.h" #include "common/debug.h"
#include "compiler/translator/Diagnostics.h" #include "compiler/translator/Diagnostics.h"
...@@ -25,13 +26,15 @@ static TBehavior getBehavior(const std::string& str) ...@@ -25,13 +26,15 @@ static TBehavior getBehavior(const std::string& str)
return EBhUndefined; return EBhUndefined;
} }
TDirectiveHandler::TDirectiveHandler(TExtensionBehavior& extBehavior, TDirectiveHandler::TDirectiveHandler(TExtensionBehavior &extBehavior,
TDiagnostics& diagnostics, TDiagnostics &diagnostics,
int& shaderVersion, int &shaderVersion,
sh::GLenum shaderType,
bool debugShaderPrecisionSupported) bool debugShaderPrecisionSupported)
: mExtensionBehavior(extBehavior), : mExtensionBehavior(extBehavior),
mDiagnostics(diagnostics), mDiagnostics(diagnostics),
mShaderVersion(shaderVersion), mShaderVersion(shaderVersion),
mShaderType(shaderType),
mDebugShaderPrecisionSupported(debugShaderPrecisionSupported) mDebugShaderPrecisionSupported(debugShaderPrecisionSupported)
{ {
} }
...@@ -57,7 +60,16 @@ void TDirectiveHandler::handlePragma(const pp::SourceLocation& loc, ...@@ -57,7 +60,16 @@ void TDirectiveHandler::handlePragma(const pp::SourceLocation& loc,
const char kAll[] = "all"; const char kAll[] = "all";
if (name == kInvariant && value == kAll) if (name == kInvariant && value == kAll)
{
if (mShaderVersion == 300 && mShaderType == GL_FRAGMENT_SHADER)
{
// ESSL 3.00.4 section 4.6.1
mDiagnostics.writeInfo(
pp::Diagnostics::PP_ERROR, loc,
"#pragma STDGL invariant(all) can not be used in fragment shader", name, value);
}
mPragma.stdgl.invariantAll = true; mPragma.stdgl.invariantAll = true;
}
// The STDGL pragma is used to reserve pragmas for use by future // The STDGL pragma is used to reserve pragmas for use by future
// revisions of GLSL. Do not generate an error on unexpected // revisions of GLSL. Do not generate an error on unexpected
// name and value. // name and value.
......
...@@ -11,15 +11,17 @@ ...@@ -11,15 +11,17 @@
#include "compiler/translator/ExtensionBehavior.h" #include "compiler/translator/ExtensionBehavior.h"
#include "compiler/translator/Pragma.h" #include "compiler/translator/Pragma.h"
#include "compiler/preprocessor/DirectiveHandlerBase.h" #include "compiler/preprocessor/DirectiveHandlerBase.h"
#include "GLSLANG/ShaderLang.h"
class TDiagnostics; class TDiagnostics;
class TDirectiveHandler : public pp::DirectiveHandler, angle::NonCopyable class TDirectiveHandler : public pp::DirectiveHandler, angle::NonCopyable
{ {
public: public:
TDirectiveHandler(TExtensionBehavior& extBehavior, TDirectiveHandler(TExtensionBehavior &extBehavior,
TDiagnostics& diagnostics, TDiagnostics &diagnostics,
int& shaderVersion, int &shaderVersion,
sh::GLenum shaderType,
bool debugShaderPrecisionSupported); bool debugShaderPrecisionSupported);
~TDirectiveHandler() override; ~TDirectiveHandler() override;
...@@ -44,6 +46,7 @@ class TDirectiveHandler : public pp::DirectiveHandler, angle::NonCopyable ...@@ -44,6 +46,7 @@ class TDirectiveHandler : public pp::DirectiveHandler, angle::NonCopyable
TExtensionBehavior& mExtensionBehavior; TExtensionBehavior& mExtensionBehavior;
TDiagnostics& mDiagnostics; TDiagnostics& mDiagnostics;
int& mShaderVersion; int& mShaderVersion;
sh::GLenum mShaderType;
bool mDebugShaderPrecisionSupported; bool mDebugShaderPrecisionSupported;
}; };
......
...@@ -57,6 +57,7 @@ class TParseContext : angle::NonCopyable ...@@ -57,6 +57,7 @@ class TParseContext : angle::NonCopyable
mDirectiveHandler(ext, mDirectiveHandler(ext,
mDiagnostics, mDiagnostics,
mShaderVersion, mShaderVersion,
mShaderType,
resources.WEBGL_debug_shader_precision == 1), resources.WEBGL_debug_shader_precision == 1),
mPreprocessor(&mDiagnostics, &mDirectiveHandler), mPreprocessor(&mDiagnostics, &mDirectiveHandler),
mScanner(nullptr), mScanner(nullptr),
......
...@@ -1513,3 +1513,22 @@ TEST_F(MalformedShaderTest, LocalFunctionPrototype) ...@@ -1513,3 +1513,22 @@ TEST_F(MalformedShaderTest, LocalFunctionPrototype)
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog; FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
} }
} }
// ESSL 3.00 fragment shaders can not use #pragma STDGL invariant(all).
// ESSL 3.00.4 section 4.6.1. Does not apply to other versions of ESSL.
TEST_F(MalformedShaderTest, ESSL300FragmentInvariantAll)
{
const std::string &shaderString =
"#version 300 es\n"
"#pragma STDGL invariant(all)\n"
"precision mediump float;\n"
"out vec4 my_FragColor;\n"
"void main()\n"
"{\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