ES31: support compute shader sampling on D3D backend
BUG=angleproject:2756
TEST=angle_end2end_tests.ComputeShaderTest.SamplingAndImageReadWrite/ES3_1_D3D11
Change-Id: I8f112227c5703fcaafffbd2262e6a039f869c483
Reviewed-on: https://chromium-review.googlesource.com/1161754
Commit-Queue: Xinghua Cao <xinghua.cao@intel.com>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
diff --git a/src/tests/gl_tests/ComputeShaderTest.cpp b/src/tests/gl_tests/ComputeShaderTest.cpp
index aa0d90e..4b9446a 100644
--- a/src/tests/gl_tests/ComputeShaderTest.cpp
+++ b/src/tests/gl_tests/ComputeShaderTest.cpp
@@ -654,6 +654,76 @@
EXPECT_GL_NO_ERROR();
}
+// Test mixed use of sampler and image.
+TEST_P(ComputeShaderTest, SamplingAndImageReadWrite)
+{
+ GLTexture texture[3];
+ GLFramebuffer framebuffer;
+ const std::string csSource =
+ R"(#version 310 es
+ layout(local_size_x=1, local_size_y=1, local_size_z=1) in;
+ layout(r32ui, binding = 0) readonly uniform highp uimage2D uImage_1;
+ layout(r32ui, binding = 1) writeonly uniform highp uimage2D uImage_2;
+ precision highp usampler2D;
+ uniform usampler2D tex;
+ void main()
+ {
+ uvec4 value_1 = texelFetch(tex, ivec2(gl_LocalInvocationID.xy), 0);
+ uvec4 value_2 = imageLoad(uImage_1, ivec2(gl_LocalInvocationID.xy));
+ imageStore(uImage_2, ivec2(gl_LocalInvocationID.xy), value_1 + value_2);
+ })";
+
+ constexpr int kWidth = 1, kHeight = 1;
+ constexpr GLuint kInputValues[3][1] = {{50}, {100}, {20}};
+
+ glBindTexture(GL_TEXTURE_2D, texture[0]);
+ glTexStorage2D(GL_TEXTURE_2D, 1, GL_R32UI, kWidth, kHeight);
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, kWidth, kHeight, GL_RED_INTEGER, GL_UNSIGNED_INT,
+ kInputValues[0]);
+ glBindTexture(GL_TEXTURE_2D, texture[2]);
+ glTexStorage2D(GL_TEXTURE_2D, 1, GL_R32UI, kWidth, kHeight);
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, kWidth, kHeight, GL_RED_INTEGER, GL_UNSIGNED_INT,
+ kInputValues[2]);
+ EXPECT_GL_NO_ERROR();
+ glBindTexture(GL_TEXTURE_2D, 0);
+
+ glBindTexture(GL_TEXTURE_2D, texture[1]);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexStorage2D(GL_TEXTURE_2D, 1, GL_R32UI, kWidth, kHeight);
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, kWidth, kHeight, GL_RED_INTEGER, GL_UNSIGNED_INT,
+ kInputValues[1]);
+
+ EXPECT_GL_NO_ERROR();
+
+ ANGLE_GL_COMPUTE_PROGRAM(program, csSource);
+ glUseProgram(program.get());
+
+ glBindImageTexture(0, texture[0], 0, GL_FALSE, 0, GL_READ_ONLY, GL_R32UI);
+ glBindImageTexture(1, texture[2], 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_R32UI);
+ EXPECT_GL_NO_ERROR();
+
+ glDispatchCompute(1, 1, 1);
+ EXPECT_GL_NO_ERROR();
+
+ glMemoryBarrier(GL_TEXTURE_UPDATE_BARRIER_BIT);
+ GLuint outputValues[kWidth * kHeight];
+ constexpr GLuint expectedValue = 150;
+ glUseProgram(0);
+ glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer);
+
+ glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture[2], 0);
+ EXPECT_GL_NO_ERROR();
+ glReadPixels(0, 0, kWidth, kHeight, GL_RED_INTEGER, GL_UNSIGNED_INT, outputValues);
+ EXPECT_GL_NO_ERROR();
+
+ for (int i = 0; i < kWidth * kHeight; i++)
+ {
+ EXPECT_EQ(expectedValue, outputValues[i]);
+ }
+}
+
// Use image uniform to read and write Texture2D in compute shader, and verify the contents.
TEST_P(ComputeShaderTest, BindImageTextureWithTexture2D)
{