Commit cddcb59e by Yunchao He Committed by Commit Bot

ES31: Fix the issue when rendering against compute program.

It is a undefined behavior in gles spec, but we should generate an error. This change also refactored the coding style for shader in the test. BUG=angleproject:2260 Change-Id: I7b480e8b66486d9954f7c7f6e8683298e94b6ad7 Reviewed-on: https://chromium-review.googlesource.com/764797Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Corentin Wallez <cwallez@chromium.org>
parent 994ee3f2
...@@ -2537,6 +2537,18 @@ bool ValidateDrawBase(ValidationContext *context, GLenum mode, GLsizei count) ...@@ -2537,6 +2537,18 @@ bool ValidateDrawBase(ValidationContext *context, GLenum mode, GLsizei count)
return false; return false;
} }
// In OpenGL ES spec for UseProgram at section 7.3, trying to render without
// vertex shader stage or fragment shader stage is a undefined behaviour.
// But ANGLE should clearly generate an INVALID_OPERATION error instead of
// produce undefined result.
if (program->isLinked() &&
(!program->hasLinkedVertexShader() || !program->hasLinkedFragmentShader()))
{
context->handleError(InvalidOperation() << "It is a undefined behaviour to render without "
"vertex shader stage or fragment shader stage.");
return false;
}
if (!program->validateSamplers(nullptr, context->getCaps())) if (!program->validateSamplers(nullptr, context->getCaps()))
{ {
context->handleError(InvalidOperation()); context->handleError(InvalidOperation());
......
...@@ -31,11 +31,11 @@ class ComputeShaderTestES3 : public ANGLETest ...@@ -31,11 +31,11 @@ class ComputeShaderTestES3 : public ANGLETest
TEST_P(ComputeShaderTest, LinkComputeProgram) TEST_P(ComputeShaderTest, LinkComputeProgram)
{ {
const std::string csSource = const std::string csSource =
"#version 310 es\n" R"(#version 310 es
"layout(local_size_x=1) in;\n" layout(local_size_x=1) in;
"void main()\n" void main()
"{\n" {\
"}\n"; })";
ANGLE_GL_COMPUTE_PROGRAM(program, csSource); ANGLE_GL_COMPUTE_PROGRAM(program, csSource);
...@@ -78,10 +78,10 @@ TEST_P(ComputeShaderTest, DetachShaderAfterLinkSuccess) ...@@ -78,10 +78,10 @@ TEST_P(ComputeShaderTest, DetachShaderAfterLinkSuccess)
TEST_P(ComputeShaderTest, LinkComputeProgramNoLocalSizeLinkError) TEST_P(ComputeShaderTest, LinkComputeProgramNoLocalSizeLinkError)
{ {
const std::string csSource = const std::string csSource =
"#version 310 es\n" R"(#version 310 es
"void main()\n" void main()
"{\n" {
"}\n"; })";
GLuint program = CompileComputeProgram(csSource, false); GLuint program = CompileComputeProgram(csSource, false);
EXPECT_EQ(0u, program); EXPECT_EQ(0u, program);
...@@ -125,23 +125,23 @@ TEST_P(ComputeShaderTest, LinkComputeProgramWithUniforms) ...@@ -125,23 +125,23 @@ TEST_P(ComputeShaderTest, LinkComputeProgramWithUniforms)
TEST_P(ComputeShaderTest, AttachMultipleShaders) TEST_P(ComputeShaderTest, AttachMultipleShaders)
{ {
const std::string csSource = const std::string csSource =
"#version 310 es\n" R"(#version 310 es
"layout(local_size_x=1) in;\n" layout(local_size_x=1) in;
"void main()\n" void main()
"{\n" {
"}\n"; })";
const std::string vsSource = const std::string vsSource =
"#version 310 es\n" R"(#version 310 es
"void main()\n" void main()
"{\n" {
"}\n"; })";
const std::string fsSource = const std::string fsSource =
"#version 310 es\n" R"(#version 310 es
"void main()\n" void main()
"{\n" {
"}\n"; })";
GLuint program = glCreateProgram(); GLuint program = glCreateProgram();
...@@ -177,23 +177,23 @@ TEST_P(ComputeShaderTest, AttachMultipleShaders) ...@@ -177,23 +177,23 @@ TEST_P(ComputeShaderTest, AttachMultipleShaders)
TEST_P(ComputeShaderTest, AttachmentCount) TEST_P(ComputeShaderTest, AttachmentCount)
{ {
const std::string csSource = const std::string csSource =
"#version 310 es\n" R"(#version 310 es
"layout(local_size_x=1) in;\n" layout(local_size_x=1) in;
"void main()\n" void main()
"{\n" {
"}\n"; })";
const std::string vsSource = const std::string vsSource =
"#version 310 es\n" R"(#version 310 es
"void main()\n" void main()
"{\n" {
"}\n"; })";
const std::string fsSource = const std::string fsSource =
"#version 310 es\n" R"(#version 310 es
"void main()\n" void main()
"{\n" {
"}\n"; })";
GLuint program = glCreateProgram(); GLuint program = glCreateProgram();
...@@ -224,20 +224,38 @@ TEST_P(ComputeShaderTest, AttachmentCount) ...@@ -224,20 +224,38 @@ TEST_P(ComputeShaderTest, AttachmentCount)
EXPECT_GL_NO_ERROR(); EXPECT_GL_NO_ERROR();
} }
// Attach a compute shader and link, but start rendering.
TEST_P(ComputeShaderTest, StartRenderingWithComputeProgram)
{
const std::string csSource =
R"(#version 310 es
layout(local_size_x=1) in;
void main()
{
})";
ANGLE_GL_COMPUTE_PROGRAM(program, csSource);
EXPECT_GL_NO_ERROR();
glUseProgram(program);
glDrawArrays(GL_POINTS, 0, 2);
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
}
// Attach a vertex and fragment shader and link, but dispatch compute. // Attach a vertex and fragment shader and link, but dispatch compute.
TEST_P(ComputeShaderTest, DispatchComputeWithRenderingProgram) TEST_P(ComputeShaderTest, DispatchComputeWithRenderingProgram)
{ {
const std::string vsSource = const std::string vsSource =
"#version 310 es\n" R"(#version 310 es
"void main()\n" void main()
"{\n" {
"}\n"; })";
const std::string fsSource = const std::string fsSource =
"#version 310 es\n" R"(#version 310 es
"void main()\n" void main()
"{\n" {
"}\n"; })";
GLuint program = glCreateProgram(); GLuint program = glCreateProgram();
...@@ -333,16 +351,16 @@ TEST_P(ComputeShaderTest, BindImageTexture) ...@@ -333,16 +351,16 @@ TEST_P(ComputeShaderTest, BindImageTexture)
GLTexture mTexture[2]; GLTexture mTexture[2];
GLFramebuffer mFramebuffer; GLFramebuffer mFramebuffer;
const std::string csSource = const std::string csSource =
"#version 310 es\n" R"(#version 310 es
"layout(local_size_x=2, local_size_y=2, local_size_z=1) in;\n" layout(local_size_x=2, local_size_y=2, local_size_z=1) in;
"layout(r32ui, binding = 0) writeonly uniform highp uimage2D uImage[2];" layout(r32ui, binding = 0) writeonly uniform highp uimage2D uImage[2];
"void main()\n" void main()
"{\n" {
" imageStore(uImage[0], ivec2(gl_LocalInvocationIndex, gl_WorkGroupID.x), uvec4(100, 0, " imageStore(uImage[0], ivec2(gl_LocalInvocationIndex, gl_WorkGroupID.x), uvec4(100, 0,
"0, 0));" 0, 0));
" imageStore(uImage[1], ivec2(gl_LocalInvocationIndex, gl_WorkGroupID.x), uvec4(100, 0, " imageStore(uImage[1], ivec2(gl_LocalInvocationIndex, gl_WorkGroupID.x), uvec4(100, 0,
"0, 0));" 0, 0));
"}\n"; })";
ANGLE_GL_COMPUTE_PROGRAM(program, csSource); ANGLE_GL_COMPUTE_PROGRAM(program, csSource);
glUseProgram(program.get()); glUseProgram(program.get());
...@@ -406,14 +424,14 @@ TEST_P(ComputeShaderTest, ImageArrayWithoutBindingQualifier) ...@@ -406,14 +424,14 @@ TEST_P(ComputeShaderTest, ImageArrayWithoutBindingQualifier)
GLTexture mTexture; GLTexture mTexture;
GLFramebuffer mFramebuffer; GLFramebuffer mFramebuffer;
const std::string csSource = const std::string csSource =
"#version 310 es\n" R"(#version 310 es
"layout(local_size_x=2, local_size_y=2, local_size_z=1) in;\n" layout(local_size_x=2, local_size_y=2, local_size_z=1) in;
"layout(r32ui) writeonly uniform highp uimage2D uImage[2];" layout(r32ui) writeonly uniform highp uimage2D uImage[2];
"void main()\n" void main()
"{\n" {
" imageStore(uImage[0], ivec2(gl_LocalInvocationIndex, 0), uvec4(100, 0, 0, 0));" imageStore(uImage[0], ivec2(gl_LocalInvocationIndex, 0), uvec4(100, 0, 0, 0));
" imageStore(uImage[1], ivec2(gl_LocalInvocationIndex, 1), uvec4(100, 0, 0, 0));" imageStore(uImage[1], ivec2(gl_LocalInvocationIndex, 1), uvec4(100, 0, 0, 0));
"}\n"; })";
ANGLE_GL_COMPUTE_PROGRAM(program, csSource); ANGLE_GL_COMPUTE_PROGRAM(program, csSource);
glUseProgram(program.get()); glUseProgram(program.get());
...@@ -472,17 +490,17 @@ TEST_P(ComputeShaderTest, ImageLoad) ...@@ -472,17 +490,17 @@ TEST_P(ComputeShaderTest, ImageLoad)
TEST_P(ComputeShaderTest, ImageStore) TEST_P(ComputeShaderTest, ImageStore)
{ {
const std::string csSource = const std::string csSource =
"#version 310 es\n" R"(#version 310 es
"layout(local_size_x=8) in;\n" layout(local_size_x=8) in;
"layout(rgba16f) uniform highp writeonly imageCube mImageCubeOutput;\n" layout(rgba16f) uniform highp writeonly imageCube mImageCubeOutput;
"layout(r32f) uniform highp writeonly image3D mImage3DOutput;\n" layout(r32f) uniform highp writeonly image3D mImage3DOutput;
"layout(rgba8ui) uniform highp writeonly uimage2DArray mImage2DArrayOutput;\n" layout(rgba8ui) uniform highp writeonly uimage2DArray mImage2DArrayOutput;
"void main()\n" void main()
"{\n" {
" imageStore(mImageCubeOutput, ivec3(gl_LocalInvocationID.xyz), vec4(0.0));\n" imageStore(mImageCubeOutput, ivec3(gl_LocalInvocationID.xyz), vec4(0.0));
" imageStore(mImage3DOutput, ivec3(gl_LocalInvocationID.xyz), vec4(0.0));\n" imageStore(mImage3DOutput, ivec3(gl_LocalInvocationID.xyz), vec4(0.0));
" imageStore(mImage2DArrayOutput, ivec3(gl_LocalInvocationID.xyz), uvec4(0));\n" imageStore(mImage2DArrayOutput, ivec3(gl_LocalInvocationID.xyz), uvec4(0));
"}\n"; })";
ANGLE_GL_COMPUTE_PROGRAM(program, csSource); ANGLE_GL_COMPUTE_PROGRAM(program, csSource);
EXPECT_GL_NO_ERROR(); EXPECT_GL_NO_ERROR();
......
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