blob: 375741deb02e01b7039604aaeac3bf065364f1bc [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{
33 const std::string csSource =
34 "#version 310 es\n"
35 "layout(local_size_x=1) in;\n"
36 "void main()\n"
37 "{\n"
38 "}\n";
39
40 ANGLE_GL_COMPUTE_PROGRAM(program, csSource);
41
42 EXPECT_GL_NO_ERROR();
43}
44
45// link a simple compute program. There is no local size and linking should fail.
46TEST_P(ComputeShaderTest, LinkComputeProgramNoLocalSizeLinkError)
47{
48 const std::string csSource =
49 "#version 310 es\n"
50 "void main()\n"
51 "{\n"
52 "}\n";
53
54 GLuint program = CompileComputeProgram(csSource, false);
55 EXPECT_EQ(0u, program);
56
57 glDeleteProgram(program);
58
59 EXPECT_GL_NO_ERROR();
60}
61
62// link a simple compute program.
63// make sure that uniforms and uniform samplers get recorded
64TEST_P(ComputeShaderTest, LinkComputeProgramWithUniforms)
65{
66 const std::string csSource =
67 "#version 310 es\n"
68 "precision mediump sampler2D;\n"
69 "layout(local_size_x=1) in;\n"
70 "uniform int myUniformInt;\n"
71 "uniform sampler2D myUniformSampler;\n"
72 "void main()\n"
73 "{\n"
74 "int q = myUniformInt;\n"
75 "texture(myUniformSampler, vec2(0.0));\n"
76 "}\n";
77
78 ANGLE_GL_COMPUTE_PROGRAM(program, csSource);
79
80 GLint uniformLoc = glGetUniformLocation(program.get(), "myUniformInt");
81 EXPECT_NE(-1, uniformLoc);
82
83 uniformLoc = glGetUniformLocation(program.get(), "myUniformSampler");
84 EXPECT_NE(-1, uniformLoc);
85
86 EXPECT_GL_NO_ERROR();
87}
88
89// Attach both compute and non-compute shaders. A link time error should occur.
90// OpenGL ES 3.10, 7.3 Program Objects
91TEST_P(ComputeShaderTest, AttachMultipleShaders)
92{
93 const std::string csSource =
94 "#version 310 es\n"
95 "layout(local_size_x=1) in;\n"
96 "void main()\n"
97 "{\n"
98 "}\n";
99
100 const std::string vsSource =
101 "#version 310 es\n"
102 "void main()\n"
103 "{\n"
104 "}\n";
105
106 const std::string fsSource =
107 "#version 310 es\n"
108 "void main()\n"
109 "{\n"
110 "}\n";
111
112 GLuint program = glCreateProgram();
113
114 GLuint vs = CompileShader(GL_VERTEX_SHADER, vsSource);
115 GLuint fs = CompileShader(GL_FRAGMENT_SHADER, fsSource);
116 GLuint cs = CompileShader(GL_COMPUTE_SHADER, csSource);
117
118 EXPECT_NE(0u, vs);
119 EXPECT_NE(0u, fs);
120 EXPECT_NE(0u, cs);
121
122 glAttachShader(program, vs);
123 glDeleteShader(vs);
124
125 glAttachShader(program, fs);
126 glDeleteShader(fs);
127
128 glAttachShader(program, cs);
129 glDeleteShader(cs);
130
131 glLinkProgram(program);
132
133 GLint linkStatus;
134 glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
135
136 EXPECT_EQ(0, linkStatus);
137
138 EXPECT_GL_NO_ERROR();
139}
140
141// Attach a vertex, fragment and compute shader.
142// Query for the number of attached shaders and check the count.
143TEST_P(ComputeShaderTest, AttachmentCount)
144{
145 const std::string csSource =
146 "#version 310 es\n"
147 "layout(local_size_x=1) in;\n"
148 "void main()\n"
149 "{\n"
150 "}\n";
151
152 const std::string vsSource =
153 "#version 310 es\n"
154 "void main()\n"
155 "{\n"
156 "}\n";
157
158 const std::string fsSource =
159 "#version 310 es\n"
160 "void main()\n"
161 "{\n"
162 "}\n";
163
164 GLuint program = glCreateProgram();
165
166 GLuint vs = CompileShader(GL_VERTEX_SHADER, vsSource);
167 GLuint fs = CompileShader(GL_FRAGMENT_SHADER, fsSource);
168 GLuint cs = CompileShader(GL_COMPUTE_SHADER, csSource);
169
170 EXPECT_NE(0u, vs);
171 EXPECT_NE(0u, fs);
172 EXPECT_NE(0u, cs);
173
174 glAttachShader(program, vs);
175 glDeleteShader(vs);
176
177 glAttachShader(program, fs);
178 glDeleteShader(fs);
179
180 glAttachShader(program, cs);
181 glDeleteShader(cs);
182
183 GLint numAttachedShaders;
184 glGetProgramiv(program, GL_ATTACHED_SHADERS, &numAttachedShaders);
185
186 EXPECT_EQ(3, numAttachedShaders);
187
188 glDeleteProgram(program);
189
190 EXPECT_GL_NO_ERROR();
191}
192
193// Check that it is not possible to create a compute shader when the context does not support ES
194// 3.10
195TEST_P(ComputeShaderTestES3, NotSupported)
196{
197 GLuint computeShaderHandle = glCreateShader(GL_COMPUTE_SHADER);
198 EXPECT_EQ(0u, computeShaderHandle);
199 EXPECT_GL_ERROR(GL_INVALID_ENUM);
200}
201
202ANGLE_INSTANTIATE_TEST(ComputeShaderTest, ES31_OPENGL(), ES31_OPENGLES());
203ANGLE_INSTANTIATE_TEST(ComputeShaderTestES3, ES3_OPENGL(), ES3_OPENGLES());
204
205} // namespace