ES31: Add shader version check for CS and GS
This patch adds the missing check on the shader version for compute
and geometry shaders, which can fix a bug that ANGLE GLSL compiler
doesn't report a compile error when compiling an empty compute or
geometry shader in version 100 or 300.
This patch also updates the original compiler tests on the check of
shader version. In these tests, the compile errors are all caused by
illegal layouts instead of shader versions, which is against the
purpose of the tests.
This patch also fixes an incorrect case that used an empty compute
shader in version 300.
BUG=angleproject:1442, angleproject:1941
TEST=angle_unittests
Change-Id: Ic26bb8eb312dbc0cec6a879997d0ae7a2e625a0f
Reviewed-on: https://chromium-review.googlesource.com/910715
Commit-Queue: Geoff Lang <geofflang@chromium.org>
Reviewed-by: Olli Etuaho <oetuaho@nvidia.com>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/compiler/translator/Compiler.cpp b/src/compiler/translator/Compiler.cpp
index 674b1e8..7c685d5 100644
--- a/src/compiler/translator/Compiler.cpp
+++ b/src/compiler/translator/Compiler.cpp
@@ -353,9 +353,8 @@
setASTMetadata(parseContext);
- if (MapSpecToShaderVersion(shaderSpec) < shaderVersion)
+ if (!checkShaderVersion(&parseContext))
{
- mDiagnostics.globalError("unsupported shader version");
return nullptr;
}
@@ -368,6 +367,50 @@
return root;
}
+bool TCompiler::checkShaderVersion(TParseContext *parseContext)
+{
+ if (MapSpecToShaderVersion(shaderSpec) < shaderVersion)
+ {
+ mDiagnostics.globalError("unsupported shader version");
+ return false;
+ }
+
+ ASSERT(parseContext);
+ switch (shaderType)
+ {
+ case GL_COMPUTE_SHADER:
+ if (shaderVersion < 310)
+ {
+ mDiagnostics.globalError("Compute shader is not supported in this shader version.");
+ return false;
+ }
+ break;
+
+ case GL_GEOMETRY_SHADER_EXT:
+ if (shaderVersion < 310)
+ {
+ mDiagnostics.globalError(
+ "Geometry shader is not supported in this shader version.");
+ return false;
+ }
+ else
+ {
+ ASSERT(shaderVersion == 310);
+ if (!parseContext->checkCanUseExtension(sh::TSourceLoc(),
+ TExtension::EXT_geometry_shader))
+ {
+ return false;
+ }
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ return true;
+}
+
void TCompiler::setASTMetadata(const TParseContext &parseContext)
{
shaderVersion = parseContext.getShaderVersion();