1 //
2 // Copyright 2019 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 // MatrixTest:
7 // Test various shader matrix variable declarations.
8
9 #include <vector>
10 #include "test_utils/ANGLETest.h"
11 #include "test_utils/gl_raii.h"
12
13 using namespace angle;
14
15 namespace
16 {
17
18 class MatrixTest31 : public ANGLETest
19 {
20 protected:
MatrixTest31()21 MatrixTest31()
22 {
23 setWindowWidth(64);
24 setWindowHeight(64);
25 setConfigRedBits(8);
26 setConfigGreenBits(8);
27 setConfigBlueBits(8);
28 setConfigAlphaBits(8);
29 }
30 };
31
TEST_P(MatrixTest31,Mat3Varying)32 TEST_P(MatrixTest31, Mat3Varying)
33 {
34 constexpr char kVS[] = R"(#version 310 es
35 precision mediump float;
36
37 in vec4 a_position;
38
39 layout(location=0) out mat3 matrix;
40 layout(location=3) out vec3 vector;
41
42 void main()
43 {
44 matrix = mat3(1.0);
45 vector = vec3(1.0);
46 gl_Position = a_position;
47 })";
48
49 constexpr char kFS[] = R"(#version 310 es
50 precision mediump float;
51
52 layout(location=0) in mat3 matrix;
53 layout(location=3) in vec3 vector;
54
55 out vec4 oColor;
56
57 void main()
58 {
59 oColor = vec4(matrix[0], 1.0);
60 })";
61
62 ANGLE_GL_PROGRAM(program, kVS, kFS);
63 glUseProgram(program);
64 drawQuad(program, "a_position", 0.5f);
65 EXPECT_GL_NO_ERROR();
66 }
67
TEST_P(MatrixTest31,Mat3VaryingBadLocation)68 TEST_P(MatrixTest31, Mat3VaryingBadLocation)
69 {
70 constexpr char kVS[] = R"(#version 310 es
71 precision mediump float;
72
73 in vec4 a_position;
74
75 layout(location=0) out mat3 matrix;
76 layout(location=2) out vec3 vector;
77
78 void main()
79 {
80 matrix = mat3(1.0);
81 vector = vec3(1.0);
82 gl_Position = a_position;
83 })";
84
85 GLProgram program;
86
87 GLuint vs = glCreateShader(GL_VERTEX_SHADER);
88 const char *sourceVsArray[1] = {kVS};
89 glShaderSource(vs, 1, sourceVsArray, nullptr);
90 glCompileShader(vs);
91 GLint compileResult;
92 glGetShaderiv(vs, GL_COMPILE_STATUS, &compileResult);
93 EXPECT_GL_FALSE(compileResult);
94 }
95
TEST_P(MatrixTest31,Mat3x4Varying)96 TEST_P(MatrixTest31, Mat3x4Varying)
97 {
98 constexpr char kVS[] = R"(#version 310 es
99 precision mediump float;
100
101 in vec4 a_position;
102
103 layout(location=0) out mat3x4 matrix;
104 layout(location=3) out vec3 vector;
105
106 void main()
107 {
108 matrix = mat3x4(1.0);
109 vector = vec3(1.0);
110 gl_Position = a_position;
111 })";
112
113 constexpr char kFS[] = R"(#version 310 es
114 precision mediump float;
115
116 layout(location=0) in mat3x4 matrix;
117 layout(location=3) in vec3 vector;
118
119 out vec4 oColor;
120
121 void main()
122 {
123 oColor = vec4(matrix[0]);
124 })";
125
126 ANGLE_GL_PROGRAM(program, kVS, kFS);
127 glUseProgram(program);
128 drawQuad(program, "a_position", 0.5f);
129 EXPECT_GL_NO_ERROR();
130 }
131
TEST_P(MatrixTest31,Mat3x4VaryingBadLocation)132 TEST_P(MatrixTest31, Mat3x4VaryingBadLocation)
133 {
134 constexpr char kVS[] = R"(#version 310 es
135 precision mediump float;
136
137 in vec4 a_position;
138
139 layout(location=0) out mat3x4 matrix;
140 layout(location=2) out vec3 vector;
141
142 void main()
143 {
144 matrix = mat3x4(1.0);
145 vector = vec3(1.0);
146 gl_Position = a_position;
147 })";
148
149 GLProgram program;
150
151 GLuint vs = glCreateShader(GL_VERTEX_SHADER);
152 const char *sourceVsArray[1] = {kVS};
153 glShaderSource(vs, 1, sourceVsArray, nullptr);
154 glCompileShader(vs);
155 GLint compileResult;
156 glGetShaderiv(vs, GL_COMPILE_STATUS, &compileResult);
157 EXPECT_GL_FALSE(compileResult);
158 }
159
TEST_P(MatrixTest31,Mat3x4ArrayVarying)160 TEST_P(MatrixTest31, Mat3x4ArrayVarying)
161 {
162 constexpr char kVS[] = R"(#version 310 es
163 precision mediump float;
164
165 in vec4 a_position;
166
167 layout(location=0) out mat3x4[2] matrix;
168 layout(location=6) out vec3 vector;
169
170 void main()
171 {
172 matrix[0] = mat3x4(1.0);
173 matrix[1] = mat3x4(1.0);
174 vector = vec3(1.0);
175 gl_Position = a_position;
176 })";
177
178 constexpr char kFS[] = R"(#version 310 es
179 precision mediump float;
180
181 layout(location=0) in mat3x4[2] matrix;
182 layout(location=6) in vec3 vector;
183
184 out vec4 oColor;
185
186 void main()
187 {
188 oColor = vec4(matrix[0][0]);
189 })";
190
191 ANGLE_GL_PROGRAM(program, kVS, kFS);
192 glUseProgram(program);
193 drawQuad(program, "a_position", 0.5f);
194 EXPECT_GL_NO_ERROR();
195 }
196
TEST_P(MatrixTest31,Mat3x4ArrayVaryingBadLocation)197 TEST_P(MatrixTest31, Mat3x4ArrayVaryingBadLocation)
198 {
199 constexpr char kVS[] = R"(#version 310 es
200 precision mediump float;
201
202 in vec4 a_position;
203
204 layout(location=0) out mat3x4[2] matrix;
205 layout(location=5) out vec3 vector;
206
207 void main()
208 {
209 matrix[0] = mat3x4(1.0);
210 matrix[1] = mat3x4(1.0);
211 vector = vec3(1.0);
212 gl_Position = a_position;
213 })";
214
215 GLProgram program;
216
217 GLuint vs = glCreateShader(GL_VERTEX_SHADER);
218 const char *sourceVsArray[1] = {kVS};
219 glShaderSource(vs, 1, sourceVsArray, nullptr);
220 glCompileShader(vs);
221 GLint compileResult;
222 glGetShaderiv(vs, GL_COMPILE_STATUS, &compileResult);
223 EXPECT_GL_FALSE(compileResult);
224 }
225
TEST_P(MatrixTest31,Mat3x4StructVarying)226 TEST_P(MatrixTest31, Mat3x4StructVarying)
227 {
228 constexpr char kVS[] = R"(#version 310 es
229 precision mediump float;
230
231 in vec4 a_position;
232
233 struct S
234 {
235 mat3x4 m;
236 };
237 layout(location=0) out S matrix;
238 layout(location=3) out vec3 vector;
239
240 void main()
241 {
242 matrix.m = mat3x4(1.0);
243 vector = vec3(1.0);
244 gl_Position = a_position;
245 })";
246
247 constexpr char kFS[] = R"(#version 310 es
248 precision mediump float;
249
250 struct S
251 {
252 mat3x4 m;
253 };
254 layout(location=0) in S matrix;
255 layout(location=3) in vec3 vector;
256
257 out vec4 oColor;
258
259 void main()
260 {
261 oColor = vec4(matrix.m[0]);
262 })";
263
264 ANGLE_GL_PROGRAM(program, kVS, kFS);
265 glUseProgram(program);
266 drawQuad(program, "a_position", 0.5f);
267 EXPECT_GL_NO_ERROR();
268 }
269
TEST_P(MatrixTest31,Mat3x4StructVaryingBadLocation)270 TEST_P(MatrixTest31, Mat3x4StructVaryingBadLocation)
271 {
272 constexpr char kVS[] = R"(#version 310 es
273 precision mediump float;
274
275 in vec4 a_position;
276
277 struct S
278 {
279 mat3x4 m;
280 };
281 layout(location=0) out S matrix;
282 layout(location=2) out vec3 vector;
283
284 void main()
285 {
286 matrix.m = mat3x4(1.0);
287 vector = vec3(1.0);
288 gl_Position = a_position;
289 })";
290
291 GLProgram program;
292
293 GLuint vs = glCreateShader(GL_VERTEX_SHADER);
294 const char *sourceVsArray[1] = {kVS};
295 glShaderSource(vs, 1, sourceVsArray, nullptr);
296 glCompileShader(vs);
297 GLint compileResult;
298 glGetShaderiv(vs, GL_COMPILE_STATUS, &compileResult);
299 EXPECT_GL_FALSE(compileResult);
300 }
301
302 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(MatrixTest31);
303 ANGLE_INSTANTIATE_TEST_ES31(MatrixTest31);
304
305 } // namespace
306