Commit e41df655 by Jiawei Shao Committed by Commit Bot

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: 's avatarOlli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent f7f0b8c3
...@@ -353,9 +353,8 @@ TIntermBlock *TCompiler::compileTreeImpl(const char *const shaderStrings[], ...@@ -353,9 +353,8 @@ TIntermBlock *TCompiler::compileTreeImpl(const char *const shaderStrings[],
setASTMetadata(parseContext); setASTMetadata(parseContext);
if (MapSpecToShaderVersion(shaderSpec) < shaderVersion) if (!checkShaderVersion(&parseContext))
{ {
mDiagnostics.globalError("unsupported shader version");
return nullptr; return nullptr;
} }
...@@ -368,6 +367,50 @@ TIntermBlock *TCompiler::compileTreeImpl(const char *const shaderStrings[], ...@@ -368,6 +367,50 @@ TIntermBlock *TCompiler::compileTreeImpl(const char *const shaderStrings[],
return root; 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) void TCompiler::setASTMetadata(const TParseContext &parseContext)
{ {
shaderVersion = parseContext.getShaderVersion(); shaderVersion = parseContext.getShaderVersion();
......
...@@ -228,6 +228,9 @@ class TCompiler : public TShHandleBase ...@@ -228,6 +228,9 @@ class TCompiler : public TShHandleBase
// version. // version.
void setASTMetadata(const TParseContext &parseContext); void setASTMetadata(const TParseContext &parseContext);
// Check if shader version meets the requirement.
bool checkShaderVersion(TParseContext *parseContext);
// Does checks that need to be run after parsing is complete and returns true if they pass. // Does checks that need to be run after parsing is complete and returns true if they pass.
bool checkAndSimplifyAST(TIntermBlock *root, bool checkAndSimplifyAST(TIntermBlock *root,
const TParseContext &parseContext, const TParseContext &parseContext,
......
...@@ -127,8 +127,6 @@ TEST_F(GeometryShaderTest, Version300) ...@@ -127,8 +127,6 @@ TEST_F(GeometryShaderTest, Version300)
{ {
const std::string &shaderString = const std::string &shaderString =
R"(#version 300 es R"(#version 300 es
layout(points) in;
layout(points, max_vertices = 1) out;
void main() void main()
{ {
})"; })";
...@@ -145,8 +143,23 @@ TEST_F(GeometryShaderTest, Version310WithoutExtension) ...@@ -145,8 +143,23 @@ TEST_F(GeometryShaderTest, Version310WithoutExtension)
{ {
const std::string &shaderString = const std::string &shaderString =
R"(#version 310 es R"(#version 310 es
layout(points) in; void main()
layout(points, max_vertices = 1) out; {
})";
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
}
}
// Geometry Shaders are not supported in GLSL ES shaders version 310 with extension
// EXT_geometry_shader disabled.
TEST_F(GeometryShaderTest, Version310ExtensionDisabled)
{
const std::string &shaderString =
R"(#version 310 es
#extension GL_EXT_geometry_shader : disable
void main() void main()
{ {
})"; })";
...@@ -158,7 +171,7 @@ TEST_F(GeometryShaderTest, Version310WithoutExtension) ...@@ -158,7 +171,7 @@ TEST_F(GeometryShaderTest, Version310WithoutExtension)
} }
// Geometry Shaders are supported in GLSL ES shaders version 310 with EXT_geometry_shader enabled. // Geometry Shaders are supported in GLSL ES shaders version 310 with EXT_geometry_shader enabled.
TEST_F(GeometryShaderTest, Version310WithOESExtension) TEST_F(GeometryShaderTest, Version310WithEXTExtension)
{ {
const std::string &shaderString = const std::string &shaderString =
R"(#version 310 es R"(#version 310 es
......
...@@ -1748,10 +1748,9 @@ TEST_F(FragmentShaderValidationTest, StructEqDifferentStruct) ...@@ -1748,10 +1748,9 @@ TEST_F(FragmentShaderValidationTest, StructEqDifferentStruct)
TEST_F(ComputeShaderValidationTest, Version100) TEST_F(ComputeShaderValidationTest, Version100)
{ {
const std::string &shaderString = const std::string &shaderString =
"void main()\n" R"(void main()
"layout(local_size_x=1) in;\n" {
"{\n" })";
"}\n";
if (compile(shaderString)) if (compile(shaderString))
{ {
FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog; FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
...@@ -1762,11 +1761,10 @@ TEST_F(ComputeShaderValidationTest, Version100) ...@@ -1762,11 +1761,10 @@ TEST_F(ComputeShaderValidationTest, Version100)
TEST_F(ComputeShaderValidationTest, Version300) TEST_F(ComputeShaderValidationTest, Version300)
{ {
const std::string &shaderString = const std::string &shaderString =
"#version 300 es\n" R"(#version 300 es
"void main()\n" void main()
"layout(local_size_x=1) in;\n" {
"{\n" })";
"}\n";
if (compile(shaderString)) if (compile(shaderString))
{ {
FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog; FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
......
...@@ -688,11 +688,11 @@ TEST_F(WEBGLMultiviewFragmentShaderOutputCodeTest, ViewportArray2IsNotEmitted) ...@@ -688,11 +688,11 @@ TEST_F(WEBGLMultiviewFragmentShaderOutputCodeTest, ViewportArray2IsNotEmitted)
TEST_F(WEBGLMultiviewComputeShaderOutputCodeTest, ViewportArray2IsNotEmitted) TEST_F(WEBGLMultiviewComputeShaderOutputCodeTest, ViewportArray2IsNotEmitted)
{ {
const std::string &shaderString = const std::string &shaderString =
"#version 300 es\n" R"(#version 310 es
"#extension GL_OVR_multiview : require\n" #extension GL_OVR_multiview : require
"void main()\n" void main()
"{\n" {
"}\n"; })";
compile(shaderString, SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW | compile(shaderString, SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW |
SH_SELECT_VIEW_IN_NV_GLSL_VERTEX_SHADER); SH_SELECT_VIEW_IN_NV_GLSL_VERTEX_SHADER);
EXPECT_FALSE(foundInGLSLCode("#extension GL_NV_viewport_array2")); EXPECT_FALSE(foundInGLSLCode("#extension GL_NV_viewport_array2"));
......
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