blob: 6db0ed2d9cbff7d392c573e01ee6125b73983af0 [file] [log] [blame]
Martin Radev4c4c8e72016-08-04 12:25:34 +03001//
2// Copyright 2016 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6// ComputeShaderTest:
7// Compute shader specific tests.
8
9#include "test_utils/ANGLETest.h"
10#include "test_utils/gl_raii.h"
11#include <vector>
12
13using namespace angle;
14
15namespace
16{
17
18class ComputeShaderTest : public ANGLETest
19{
20 protected:
21 ComputeShaderTest() {}
22};
23
24class ComputeShaderTestES3 : public ANGLETest
25{
26 protected:
27 ComputeShaderTestES3() {}
28};
29
30// link a simple compute program. It should be successful.
31TEST_P(ComputeShaderTest, LinkComputeProgram)
32{
Martin Radev9ddfa062016-08-29 13:56:39 +030033 if (IsIntel() && IsLinux())
34 {
35 std::cout << "Test skipped on Intel Linux due to failures." << std::endl;
36 return;
37 }
38
Martin Radev4c4c8e72016-08-04 12:25:34 +030039 const std::string csSource =
40 "#version 310 es\n"
41 "layout(local_size_x=1) in;\n"
42 "void main()\n"
43 "{\n"
44 "}\n";
45
46 ANGLE_GL_COMPUTE_PROGRAM(program, csSource);
47
48 EXPECT_GL_NO_ERROR();
49}
50
51// link a simple compute program. There is no local size and linking should fail.
52TEST_P(ComputeShaderTest, LinkComputeProgramNoLocalSizeLinkError)
53{
54 const std::string csSource =
55 "#version 310 es\n"
56 "void main()\n"
57 "{\n"
58 "}\n";
59
60 GLuint program = CompileComputeProgram(csSource, false);
61 EXPECT_EQ(0u, program);
62
63 glDeleteProgram(program);
64
65 EXPECT_GL_NO_ERROR();
66}
67
68// link a simple compute program.
69// make sure that uniforms and uniform samplers get recorded
70TEST_P(ComputeShaderTest, LinkComputeProgramWithUniforms)
71{
Martin Radev9ddfa062016-08-29 13:56:39 +030072 if (IsIntel() && IsLinux())
73 {
74 std::cout << "Test skipped on Intel Linux due to failures." << std::endl;
75 return;
76 }
Martin Radev4c4c8e72016-08-04 12:25:34 +030077 const std::string csSource =
78 "#version 310 es\n"
79 "precision mediump sampler2D;\n"
80 "layout(local_size_x=1) in;\n"
81 "uniform int myUniformInt;\n"
82 "uniform sampler2D myUniformSampler;\n"
83 "void main()\n"
84 "{\n"
85 "int q = myUniformInt;\n"
86 "texture(myUniformSampler, vec2(0.0));\n"
87 "}\n";
88
89 ANGLE_GL_COMPUTE_PROGRAM(program, csSource);
90
91 GLint uniformLoc = glGetUniformLocation(program.get(), "myUniformInt");
92 EXPECT_NE(-1, uniformLoc);
93
94 uniformLoc = glGetUniformLocation(program.get(), "myUniformSampler");
95 EXPECT_NE(-1, uniformLoc);
96
97 EXPECT_GL_NO_ERROR();
98}
99
100// Attach both compute and non-compute shaders. A link time error should occur.
101// OpenGL ES 3.10, 7.3 Program Objects
102TEST_P(ComputeShaderTest, AttachMultipleShaders)
103{
Martin Radev9ddfa062016-08-29 13:56:39 +0300104 if (IsIntel() && IsLinux())
105 {
106 std::cout << "Test skipped on Intel Linux due to failures." << std::endl;
107 return;
108 }
Martin Radev4c4c8e72016-08-04 12:25:34 +0300109 const std::string csSource =
110 "#version 310 es\n"
111 "layout(local_size_x=1) in;\n"
112 "void main()\n"
113 "{\n"
114 "}\n";
115
116 const std::string vsSource =
117 "#version 310 es\n"
118 "void main()\n"
119 "{\n"
120 "}\n";
121
122 const std::string fsSource =
123 "#version 310 es\n"
124 "void main()\n"
125 "{\n"
126 "}\n";
127
128 GLuint program = glCreateProgram();
129
130 GLuint vs = CompileShader(GL_VERTEX_SHADER, vsSource);
131 GLuint fs = CompileShader(GL_FRAGMENT_SHADER, fsSource);
132 GLuint cs = CompileShader(GL_COMPUTE_SHADER, csSource);
133
134 EXPECT_NE(0u, vs);
135 EXPECT_NE(0u, fs);
136 EXPECT_NE(0u, cs);
137
138 glAttachShader(program, vs);
139 glDeleteShader(vs);
140
141 glAttachShader(program, fs);
142 glDeleteShader(fs);
143
144 glAttachShader(program, cs);
145 glDeleteShader(cs);
146
147 glLinkProgram(program);
148
149 GLint linkStatus;
150 glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
151
152 EXPECT_EQ(0, linkStatus);
153
154 EXPECT_GL_NO_ERROR();
155}
156
157// Attach a vertex, fragment and compute shader.
158// Query for the number of attached shaders and check the count.
159TEST_P(ComputeShaderTest, AttachmentCount)
160{
Martin Radev9ddfa062016-08-29 13:56:39 +0300161 if (IsIntel() && IsLinux())
162 {
163 std::cout << "Test skipped on Intel Linux due to failures." << std::endl;
164 return;
165 }
Martin Radev4c4c8e72016-08-04 12:25:34 +0300166 const std::string csSource =
167 "#version 310 es\n"
168 "layout(local_size_x=1) in;\n"
169 "void main()\n"
170 "{\n"
171 "}\n";
172
173 const std::string vsSource =
174 "#version 310 es\n"
175 "void main()\n"
176 "{\n"
177 "}\n";
178
179 const std::string fsSource =
180 "#version 310 es\n"
181 "void main()\n"
182 "{\n"
183 "}\n";
184
185 GLuint program = glCreateProgram();
186
187 GLuint vs = CompileShader(GL_VERTEX_SHADER, vsSource);
188 GLuint fs = CompileShader(GL_FRAGMENT_SHADER, fsSource);
189 GLuint cs = CompileShader(GL_COMPUTE_SHADER, csSource);
190
191 EXPECT_NE(0u, vs);
192 EXPECT_NE(0u, fs);
193 EXPECT_NE(0u, cs);
194
195 glAttachShader(program, vs);
196 glDeleteShader(vs);
197
198 glAttachShader(program, fs);
199 glDeleteShader(fs);
200
201 glAttachShader(program, cs);
202 glDeleteShader(cs);
203
204 GLint numAttachedShaders;
205 glGetProgramiv(program, GL_ATTACHED_SHADERS, &numAttachedShaders);
206
207 EXPECT_EQ(3, numAttachedShaders);
208
209 glDeleteProgram(program);
210
211 EXPECT_GL_NO_ERROR();
212}
213
Xinghua Cao2cd9d7e2016-12-13 15:07:05 +0800214// Access all compute shader special variables.
215TEST_P(ComputeShaderTest, AccessAllSpecialVariables)
216{
217 const std::string csSource =
218 "#version 310 es\n"
219 "layout(local_size_x=4, local_size_y=3, local_size_z=2) in;\n"
220 "void main()\n"
221 "{\n"
222 " uvec3 temp1 = gl_NumWorkGroups;\n"
223 " uvec3 temp2 = gl_WorkGroupSize;\n"
224 " uvec3 temp3 = gl_WorkGroupID;\n"
225 " uvec3 temp4 = gl_LocalInvocationID;\n"
226 " uvec3 temp5 = gl_GlobalInvocationID;\n"
227 " uint temp6 = gl_LocalInvocationIndex;\n"
228 "}\n";
229
230 ANGLE_GL_COMPUTE_PROGRAM(program, csSource);
231}
232
233// Access part compute shader special variables.
234TEST_P(ComputeShaderTest, AccessPartSpecialVariables)
235{
236 const std::string csSource =
237 "#version 310 es\n"
238 "layout(local_size_x=4, local_size_y=3, local_size_z=2) in;\n"
239 "void main()\n"
240 "{\n"
241 " uvec3 temp1 = gl_WorkGroupSize;\n"
242 " uvec3 temp2 = gl_WorkGroupID;\n"
243 " uint temp3 = gl_LocalInvocationIndex;\n"
244 "}\n";
245
246 ANGLE_GL_COMPUTE_PROGRAM(program, csSource);
247}
248
Martin Radev4c4c8e72016-08-04 12:25:34 +0300249// Check that it is not possible to create a compute shader when the context does not support ES
250// 3.10
251TEST_P(ComputeShaderTestES3, NotSupported)
252{
253 GLuint computeShaderHandle = glCreateShader(GL_COMPUTE_SHADER);
254 EXPECT_EQ(0u, computeShaderHandle);
255 EXPECT_GL_ERROR(GL_INVALID_ENUM);
256}
257
Xinghua Cao2cd9d7e2016-12-13 15:07:05 +0800258ANGLE_INSTANTIATE_TEST(ComputeShaderTest, ES31_OPENGL(), ES31_OPENGLES(), ES31_D3D11());
Martin Radev4c4c8e72016-08-04 12:25:34 +0300259ANGLE_INSTANTIATE_TEST(ComputeShaderTestES3, ES3_OPENGL(), ES3_OPENGLES());
260
261} // namespace