blob: 77194367ecbefd45841e784bdafb45c3017c04f6 [file] [log] [blame]
Jamie Madill55def582015-05-04 11:24:57 -04001//
2// Copyright 2015 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
Corentin Wallezd3970de2015-05-14 11:07:48 -04007#include "test_utils/ANGLETest.h"
Jamie Madill96509e42014-05-29 14:33:27 -04008
Jamie Madill1048e432016-07-23 18:51:28 -04009#include "test_utils/gl_raii.h"
Jamie Madill55def582015-05-04 11:24:57 -040010
Jamie Madillfa05f602015-05-07 13:47:11 -040011using namespace angle;
Austin Kinross18b931d2014-09-29 12:58:31 -070012
Jamie Madill6c9503e2016-08-16 14:06:32 -040013namespace
14{
15
Jamie Madill2bf8b372014-06-16 17:18:51 -040016class GLSLTest : public ANGLETest
Jamie Madill96509e42014-05-29 14:33:27 -040017{
Jamie Madillfa05f602015-05-07 13:47:11 -040018 protected:
19 GLSLTest()
Jamie Madill96509e42014-05-29 14:33:27 -040020 {
21 setWindowWidth(128);
22 setWindowHeight(128);
23 setConfigRedBits(8);
24 setConfigGreenBits(8);
25 setConfigBlueBits(8);
26 setConfigAlphaBits(8);
27 }
Jamie Madillbfa91f42014-06-05 15:45:18 -040028
29 virtual void SetUp()
30 {
31 ANGLETest::SetUp();
32
Jamie Madill2bf8b372014-06-16 17:18:51 -040033 mSimpleVSSource = SHADER_SOURCE
Jamie Madillbfa91f42014-06-05 15:45:18 -040034 (
35 attribute vec4 inputAttribute;
36 void main()
37 {
38 gl_Position = inputAttribute;
39 }
40 );
41 }
42
Austin Kinrossaf875522014-08-25 21:06:07 -070043 std::string GenerateVaryingType(GLint vectorSize)
44 {
45 char varyingType[10];
46
47 if (vectorSize == 1)
48 {
49 sprintf(varyingType, "float");
50 }
51 else
52 {
53 sprintf(varyingType, "vec%d", vectorSize);
54 }
55
56 return std::string(varyingType);
57 }
58
59 std::string GenerateVectorVaryingDeclaration(GLint vectorSize, GLint arraySize, GLint id)
60 {
61 char buff[100];
62
63 if (arraySize == 1)
64 {
65 sprintf(buff, "varying %s v%d;\n", GenerateVaryingType(vectorSize).c_str(), id);
66 }
67 else
68 {
69 sprintf(buff, "varying %s v%d[%d];\n", GenerateVaryingType(vectorSize).c_str(), id, arraySize);
70 }
71
72 return std::string(buff);
73 }
74
75 std::string GenerateVectorVaryingSettingCode(GLint vectorSize, GLint arraySize, GLint id)
76 {
77 std::string returnString;
78 char buff[100];
79
80 if (arraySize == 1)
81 {
82 sprintf(buff, "\t v%d = %s(1.0);\n", id, GenerateVaryingType(vectorSize).c_str());
83 returnString += buff;
84 }
85 else
86 {
87 for (int i = 0; i < arraySize; i++)
88 {
89 sprintf(buff, "\t v%d[%d] = %s(1.0);\n", id, i, GenerateVaryingType(vectorSize).c_str());
90 returnString += buff;
91 }
92 }
93
94 return returnString;
95 }
96
97 std::string GenerateVectorVaryingUseCode(GLint arraySize, GLint id)
98 {
99 if (arraySize == 1)
100 {
101 char buff[100];
102 sprintf(buff, "v%d + ", id);
103 return std::string(buff);
104 }
105 else
106 {
107 std::string returnString;
108 for (int i = 0; i < arraySize; i++)
109 {
110 char buff[100];
111 sprintf(buff, "v%d[%d] + ", id, i);
112 returnString += buff;
113 }
114 return returnString;
115 }
116 }
117
Austin Kinross8b695ee2015-03-12 13:12:20 -0700118 void GenerateGLSLWithVaryings(GLint floatCount, GLint floatArrayCount, GLint vec2Count, GLint vec2ArrayCount, GLint vec3Count, GLint vec3ArrayCount,
119 GLint vec4Count, GLint vec4ArrayCount, bool useFragCoord, bool usePointCoord, bool usePointSize,
120 std::string* fragmentShader, std::string* vertexShader)
Austin Kinrossaf875522014-08-25 21:06:07 -0700121 {
122 // Generate a string declaring the varyings, to share between the fragment shader and the vertex shader.
123 std::string varyingDeclaration;
124
125 unsigned int varyingCount = 0;
126
127 for (GLint i = 0; i < floatCount; i++)
128 {
129 varyingDeclaration += GenerateVectorVaryingDeclaration(1, 1, varyingCount);
130 varyingCount += 1;
131 }
132
133 for (GLint i = 0; i < floatArrayCount; i++)
134 {
135 varyingDeclaration += GenerateVectorVaryingDeclaration(1, 2, varyingCount);
136 varyingCount += 1;
137 }
138
139 for (GLint i = 0; i < vec2Count; i++)
140 {
141 varyingDeclaration += GenerateVectorVaryingDeclaration(2, 1, varyingCount);
142 varyingCount += 1;
143 }
144
145 for (GLint i = 0; i < vec2ArrayCount; i++)
146 {
147 varyingDeclaration += GenerateVectorVaryingDeclaration(2, 2, varyingCount);
148 varyingCount += 1;
149 }
150
151 for (GLint i = 0; i < vec3Count; i++)
152 {
153 varyingDeclaration += GenerateVectorVaryingDeclaration(3, 1, varyingCount);
154 varyingCount += 1;
155 }
156
157 for (GLint i = 0; i < vec3ArrayCount; i++)
158 {
159 varyingDeclaration += GenerateVectorVaryingDeclaration(3, 2, varyingCount);
160 varyingCount += 1;
161 }
162
Austin Kinross8b695ee2015-03-12 13:12:20 -0700163 for (GLint i = 0; i < vec4Count; i++)
164 {
165 varyingDeclaration += GenerateVectorVaryingDeclaration(4, 1, varyingCount);
166 varyingCount += 1;
167 }
168
169 for (GLint i = 0; i < vec4ArrayCount; i++)
170 {
171 varyingDeclaration += GenerateVectorVaryingDeclaration(4, 2, varyingCount);
172 varyingCount += 1;
173 }
174
Austin Kinrossaf875522014-08-25 21:06:07 -0700175 // Generate the vertex shader
176 vertexShader->clear();
177 vertexShader->append(varyingDeclaration);
178 vertexShader->append("\nvoid main()\n{\n");
179
180 unsigned int currentVSVarying = 0;
181
182 for (GLint i = 0; i < floatCount; i++)
183 {
184 vertexShader->append(GenerateVectorVaryingSettingCode(1, 1, currentVSVarying));
185 currentVSVarying += 1;
186 }
187
188 for (GLint i = 0; i < floatArrayCount; i++)
189 {
190 vertexShader->append(GenerateVectorVaryingSettingCode(1, 2, currentVSVarying));
191 currentVSVarying += 1;
192 }
193
194 for (GLint i = 0; i < vec2Count; i++)
195 {
196 vertexShader->append(GenerateVectorVaryingSettingCode(2, 1, currentVSVarying));
197 currentVSVarying += 1;
198 }
199
200 for (GLint i = 0; i < vec2ArrayCount; i++)
201 {
202 vertexShader->append(GenerateVectorVaryingSettingCode(2, 2, currentVSVarying));
203 currentVSVarying += 1;
204 }
205
206 for (GLint i = 0; i < vec3Count; i++)
207 {
208 vertexShader->append(GenerateVectorVaryingSettingCode(3, 1, currentVSVarying));
209 currentVSVarying += 1;
210 }
211
212 for (GLint i = 0; i < vec3ArrayCount; i++)
213 {
214 vertexShader->append(GenerateVectorVaryingSettingCode(3, 2, currentVSVarying));
215 currentVSVarying += 1;
216 }
217
Austin Kinross8b695ee2015-03-12 13:12:20 -0700218 for (GLint i = 0; i < vec4Count; i++)
219 {
220 vertexShader->append(GenerateVectorVaryingSettingCode(4, 1, currentVSVarying));
221 currentVSVarying += 1;
222 }
223
224 for (GLint i = 0; i < vec4ArrayCount; i++)
225 {
226 vertexShader->append(GenerateVectorVaryingSettingCode(4, 2, currentVSVarying));
227 currentVSVarying += 1;
228 }
229
230 if (usePointSize)
231 {
232 vertexShader->append("gl_PointSize = 1.0;\n");
233 }
234
Austin Kinrossaf875522014-08-25 21:06:07 -0700235 vertexShader->append("}\n");
236
237 // Generate the fragment shader
238 fragmentShader->clear();
239 fragmentShader->append("precision highp float;\n");
240 fragmentShader->append(varyingDeclaration);
241 fragmentShader->append("\nvoid main() \n{ \n\tvec4 retColor = vec4(0,0,0,0);\n");
242
243 unsigned int currentFSVarying = 0;
244
245 // Make use of the float varyings
246 fragmentShader->append("\tretColor += vec4(");
247
248 for (GLint i = 0; i < floatCount; i++)
249 {
250 fragmentShader->append(GenerateVectorVaryingUseCode(1, currentFSVarying));
251 currentFSVarying += 1;
252 }
253
254 for (GLint i = 0; i < floatArrayCount; i++)
255 {
256 fragmentShader->append(GenerateVectorVaryingUseCode(2, currentFSVarying));
257 currentFSVarying += 1;
258 }
259
260 fragmentShader->append("0.0, 0.0, 0.0, 0.0);\n");
261
262 // Make use of the vec2 varyings
263 fragmentShader->append("\tretColor += vec4(");
264
265 for (GLint i = 0; i < vec2Count; i++)
266 {
267 fragmentShader->append(GenerateVectorVaryingUseCode(1, currentFSVarying));
268 currentFSVarying += 1;
269 }
270
271 for (GLint i = 0; i < vec2ArrayCount; i++)
272 {
273 fragmentShader->append(GenerateVectorVaryingUseCode(2, currentFSVarying));
274 currentFSVarying += 1;
275 }
276
277 fragmentShader->append("vec2(0.0, 0.0), 0.0, 0.0);\n");
278
279 // Make use of the vec3 varyings
280 fragmentShader->append("\tretColor += vec4(");
281
282 for (GLint i = 0; i < vec3Count; i++)
283 {
284 fragmentShader->append(GenerateVectorVaryingUseCode(1, currentFSVarying));
285 currentFSVarying += 1;
286 }
287
288 for (GLint i = 0; i < vec3ArrayCount; i++)
289 {
290 fragmentShader->append(GenerateVectorVaryingUseCode(2, currentFSVarying));
291 currentFSVarying += 1;
292 }
293
294 fragmentShader->append("vec3(0.0, 0.0, 0.0), 0.0);\n");
Austin Kinross8b695ee2015-03-12 13:12:20 -0700295
296 // Make use of the vec4 varyings
297 fragmentShader->append("\tretColor += ");
298
299 for (GLint i = 0; i < vec4Count; i++)
300 {
301 fragmentShader->append(GenerateVectorVaryingUseCode(1, currentFSVarying));
302 currentFSVarying += 1;
303 }
304
305 for (GLint i = 0; i < vec4ArrayCount; i++)
306 {
307 fragmentShader->append(GenerateVectorVaryingUseCode(2, currentFSVarying));
308 currentFSVarying += 1;
309 }
310
311 fragmentShader->append("vec4(0.0, 0.0, 0.0, 0.0);\n");
312
313 // Set gl_FragColor, and use special variables if requested
314 fragmentShader->append("\tgl_FragColor = retColor");
315
316 if (useFragCoord)
317 {
318 fragmentShader->append(" + gl_FragCoord");
319 }
320
321 if (usePointCoord)
322 {
323 fragmentShader->append(" + vec4(gl_PointCoord, 0.0, 0.0)");
324 }
325
326 fragmentShader->append(";\n}");
327 }
328
329 void VaryingTestBase(GLint floatCount, GLint floatArrayCount, GLint vec2Count, GLint vec2ArrayCount, GLint vec3Count, GLint vec3ArrayCount,
330 GLint vec4Count, GLint vec4ArrayCount, bool useFragCoord, bool usePointCoord, bool usePointSize, bool expectSuccess)
331 {
332 std::string fragmentShaderSource;
333 std::string vertexShaderSource;
334
335 GenerateGLSLWithVaryings(floatCount, floatArrayCount, vec2Count, vec2ArrayCount, vec3Count, vec3ArrayCount,
336 vec4Count, vec4ArrayCount, useFragCoord, usePointCoord, usePointSize,
337 &fragmentShaderSource, &vertexShaderSource);
338
339 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
340
341 if (expectSuccess)
342 {
343 EXPECT_NE(0u, program);
344 }
345 else
346 {
347 EXPECT_EQ(0u, program);
348 }
Austin Kinrossaf875522014-08-25 21:06:07 -0700349 }
350
Austin Kinross7a3e8e22015-10-08 15:50:06 -0700351 void CompileGLSLWithUniformsAndSamplers(GLint vertexUniformCount,
352 GLint fragmentUniformCount,
353 GLint vertexSamplersCount,
354 GLint fragmentSamplersCount,
355 bool expectSuccess)
356 {
357 std::stringstream vertexShader;
358 std::stringstream fragmentShader;
359
360 // Generate the vertex shader
361 vertexShader << "precision mediump float;\n";
362
363 for (int i = 0; i < vertexUniformCount; i++)
364 {
365 vertexShader << "uniform vec4 v" << i << ";\n";
366 }
367
368 for (int i = 0; i < vertexSamplersCount; i++)
369 {
370 vertexShader << "uniform sampler2D s" << i << ";\n";
371 }
372
373 vertexShader << "void main()\n{\n";
374
375 for (int i = 0; i < vertexUniformCount; i++)
376 {
377 vertexShader << " gl_Position += v" << i << ";\n";
378 }
379
380 for (int i = 0; i < vertexSamplersCount; i++)
381 {
382 vertexShader << " gl_Position += texture2D(s" << i << ", vec2(0.0, 0.0));\n";
383 }
384
385 if (vertexUniformCount == 0 && vertexSamplersCount == 0)
386 {
387 vertexShader << " gl_Position = vec4(0.0);\n";
388 }
389
390 vertexShader << "}\n";
391
392 // Generate the fragment shader
393 fragmentShader << "precision mediump float;\n";
394
395 for (int i = 0; i < fragmentUniformCount; i++)
396 {
397 fragmentShader << "uniform vec4 v" << i << ";\n";
398 }
399
400 for (int i = 0; i < fragmentSamplersCount; i++)
401 {
402 fragmentShader << "uniform sampler2D s" << i << ";\n";
403 }
404
405 fragmentShader << "void main()\n{\n";
406
407 for (int i = 0; i < fragmentUniformCount; i++)
408 {
409 fragmentShader << " gl_FragColor += v" << i << ";\n";
410 }
411
412 for (int i = 0; i < fragmentSamplersCount; i++)
413 {
414 fragmentShader << " gl_FragColor += texture2D(s" << i << ", vec2(0.0, 0.0));\n";
415 }
416
417 if (fragmentUniformCount == 0 && fragmentSamplersCount == 0)
418 {
419 fragmentShader << " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n";
420 }
421
422 fragmentShader << "}\n";
423
424 GLuint program = CompileProgram(vertexShader.str(), fragmentShader.str());
425
426 if (expectSuccess)
427 {
428 EXPECT_NE(0u, program);
429 }
430 else
431 {
432 EXPECT_EQ(0u, program);
433 }
434 }
435
Jamie Madill2bf8b372014-06-16 17:18:51 -0400436 std::string mSimpleVSSource;
Jamie Madill96509e42014-05-29 14:33:27 -0400437};
438
Jamie Madille1faacb2016-12-13 12:42:14 -0500439class GLSLTestNoValidation : public GLSLTest
440{
441 public:
442 GLSLTestNoValidation() { setNoErrorEnabled(true); }
443};
444
Jamie Madillfa05f602015-05-07 13:47:11 -0400445class GLSLTest_ES3 : public GLSLTest
Gregoire Payen de La Garanderieb3dced22015-01-12 14:54:55 +0000446{
Olli Etuahoe1d199b2016-07-19 17:14:27 +0300447 void SetUp() override
448 {
449 ANGLETest::SetUp();
450
451 mSimpleVSSource =
452 "#version 300 es\n"
453 "in vec4 inputAttribute;"
454 "void main()"
455 "{"
456 " gl_Position = inputAttribute;"
457 "}";
458 }
Gregoire Payen de La Garanderieb3dced22015-01-12 14:54:55 +0000459};
460
Jamie Madillfa05f602015-05-07 13:47:11 -0400461TEST_P(GLSLTest, NamelessScopedStructs)
Jamie Madill96509e42014-05-29 14:33:27 -0400462{
Jamie Madillbfa91f42014-06-05 15:45:18 -0400463 const std::string fragmentShaderSource = SHADER_SOURCE
Jamie Madill96509e42014-05-29 14:33:27 -0400464 (
Jamie Madillbfa91f42014-06-05 15:45:18 -0400465 precision mediump float;
466
Jamie Madill96509e42014-05-29 14:33:27 -0400467 void main()
468 {
Jamie Madillbfa91f42014-06-05 15:45:18 -0400469 struct
470 {
471 float q;
472 } b;
473
474 gl_FragColor = vec4(1, 0, 0, 1);
475 gl_FragColor.a += b.q;
Jamie Madill96509e42014-05-29 14:33:27 -0400476 }
477 );
478
Jamie Madill5599c8f2014-08-26 13:16:39 -0400479 GLuint program = CompileProgram(mSimpleVSSource, fragmentShaderSource);
Jamie Madillbfa91f42014-06-05 15:45:18 -0400480 EXPECT_NE(0u, program);
481}
Austin Kinross18b931d2014-09-29 12:58:31 -0700482
Jamie Madillfa05f602015-05-07 13:47:11 -0400483TEST_P(GLSLTest, ScopedStructsOrderBug)
Jamie Madillbfa91f42014-06-05 15:45:18 -0400484{
Geoff Lange0cc2a42016-01-20 10:58:17 -0500485 // TODO(geofflang): Find out why this doesn't compile on Apple OpenGL drivers
486 // (http://anglebug.com/1292)
Geoff Lang5103f4c2016-01-26 11:40:18 -0500487 // TODO(geofflang): Find out why this doesn't compile on AMD OpenGL drivers
Geoff Lange0cc2a42016-01-20 10:58:17 -0500488 // (http://anglebug.com/1291)
Corentin Wallezc7f59d02016-06-20 10:12:08 -0400489 if (IsDesktopOpenGL() && (IsOSX() || !IsNVIDIA()))
Geoff Lange0cc2a42016-01-20 10:58:17 -0500490 {
Jamie Madill518b9fa2016-03-02 11:26:02 -0500491 std::cout << "Test disabled on this OpenGL configuration." << std::endl;
Geoff Lange0cc2a42016-01-20 10:58:17 -0500492 return;
493 }
Geoff Lange0cc2a42016-01-20 10:58:17 -0500494
Jamie Madillbfa91f42014-06-05 15:45:18 -0400495 const std::string fragmentShaderSource = SHADER_SOURCE
496 (
497 precision mediump float;
498
499 struct T
500 {
501 float f;
502 };
503
504 void main()
505 {
506 T a;
507
508 struct T
509 {
510 float q;
511 };
512
513 T b;
514
515 gl_FragColor = vec4(1, 0, 0, 1);
516 gl_FragColor.a += a.f;
517 gl_FragColor.a += b.q;
518 }
519 );
520
Jamie Madill5599c8f2014-08-26 13:16:39 -0400521 GLuint program = CompileProgram(mSimpleVSSource, fragmentShaderSource);
Jamie Madillbfa91f42014-06-05 15:45:18 -0400522 EXPECT_NE(0u, program);
523}
524
Jamie Madillfa05f602015-05-07 13:47:11 -0400525TEST_P(GLSLTest, ScopedStructsBug)
Jamie Madillbfa91f42014-06-05 15:45:18 -0400526{
Jamie Madill96509e42014-05-29 14:33:27 -0400527 const std::string fragmentShaderSource = SHADER_SOURCE
528 (
529 precision mediump float;
530
531 struct T_0
532 {
533 float f;
534 };
535
536 void main()
537 {
538 gl_FragColor = vec4(1, 0, 0, 1);
539
540 struct T
541 {
542 vec2 v;
543 };
544
545 T_0 a;
546 T b;
547
548 gl_FragColor.a += a.f;
549 gl_FragColor.a += b.v.x;
550 }
551 );
552
Jamie Madill5599c8f2014-08-26 13:16:39 -0400553 GLuint program = CompileProgram(mSimpleVSSource, fragmentShaderSource);
Jamie Madill2bf8b372014-06-16 17:18:51 -0400554 EXPECT_NE(0u, program);
555}
556
Jamie Madillfa05f602015-05-07 13:47:11 -0400557TEST_P(GLSLTest, DxPositionBug)
Jamie Madill2bf8b372014-06-16 17:18:51 -0400558{
559 const std::string &vertexShaderSource = SHADER_SOURCE
560 (
561 attribute vec4 inputAttribute;
562 varying float dx_Position;
563 void main()
564 {
565 gl_Position = vec4(inputAttribute);
566 dx_Position = 0.0;
567 }
568 );
569
570 const std::string &fragmentShaderSource = SHADER_SOURCE
571 (
572 precision mediump float;
573
574 varying float dx_Position;
575
576 void main()
577 {
578 gl_FragColor = vec4(dx_Position, 0, 0, 1);
579 }
580 );
581
Jamie Madill5599c8f2014-08-26 13:16:39 -0400582 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
Jamie Madill96509e42014-05-29 14:33:27 -0400583 EXPECT_NE(0u, program);
584}
Jamie Madill4836d222014-07-24 06:55:51 -0400585
Jamie Madillfa05f602015-05-07 13:47:11 -0400586TEST_P(GLSLTest, ElseIfRewriting)
Jamie Madill4836d222014-07-24 06:55:51 -0400587{
588 const std::string &vertexShaderSource =
589 "attribute vec4 a_position;\n"
590 "varying float v;\n"
591 "void main() {\n"
592 " gl_Position = a_position;\n"
593 " v = 1.0;\n"
594 " if (a_position.x <= 0.5) {\n"
595 " v = 0.0;\n"
596 " } else if (a_position.x >= 0.5) {\n"
597 " v = 2.0;\n"
598 " }\n"
599 "}\n";
600
601 const std::string &fragmentShaderSource =
602 "precision highp float;\n"
603 "varying float v;\n"
604 "void main() {\n"
605 " vec4 color = vec4(1.0, 0.0, 0.0, 1.0);\n"
606 " if (v >= 1.0) color = vec4(0.0, 1.0, 0.0, 1.0);\n"
607 " if (v >= 2.0) color = vec4(0.0, 0.0, 1.0, 1.0);\n"
608 " gl_FragColor = color;\n"
609 "}\n";
610
Jamie Madill5599c8f2014-08-26 13:16:39 -0400611 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
Jamie Madill4836d222014-07-24 06:55:51 -0400612 ASSERT_NE(0u, program);
613
614 drawQuad(program, "a_position", 0.5f);
Jamie Madill4836d222014-07-24 06:55:51 -0400615
616 EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255);
617 EXPECT_PIXEL_EQ(getWindowWidth()-1, 0, 0, 255, 0, 255);
618}
619
Jamie Madillfa05f602015-05-07 13:47:11 -0400620TEST_P(GLSLTest, TwoElseIfRewriting)
Jamie Madill4836d222014-07-24 06:55:51 -0400621{
622 const std::string &vertexShaderSource =
623 "attribute vec4 a_position;\n"
624 "varying float v;\n"
625 "void main() {\n"
626 " gl_Position = a_position;\n"
Jamie Madill778d5272014-08-04 13:13:25 -0400627 " if (a_position.x == 0.0) {\n"
Jamie Madill4836d222014-07-24 06:55:51 -0400628 " v = 1.0;\n"
629 " } else if (a_position.x > 0.5) {\n"
630 " v = 0.0;\n"
631 " } else if (a_position.x > 0.75) {\n"
632 " v = 0.5;\n"
633 " }\n"
634 "}\n";
635
636 const std::string &fragmentShaderSource =
637 "precision highp float;\n"
638 "varying float v;\n"
639 "void main() {\n"
640 " gl_FragColor = vec4(v, 0.0, 0.0, 1.0);\n"
641 "}\n";
642
Jamie Madill5599c8f2014-08-26 13:16:39 -0400643 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
Jamie Madill4836d222014-07-24 06:55:51 -0400644 EXPECT_NE(0u, program);
645}
Jamie Madill1c28e1f2014-08-04 11:37:54 -0400646
Jamie Madillfa05f602015-05-07 13:47:11 -0400647TEST_P(GLSLTest, FrontFacingAndVarying)
Jamie Madille6256f82014-09-17 10:31:15 -0400648{
Geoff Langdd323e92015-06-09 15:16:31 -0400649 EGLPlatformParameters platform = GetParam().eglParameters;
Austin Kinross8b695ee2015-03-12 13:12:20 -0700650
Jamie Madille6256f82014-09-17 10:31:15 -0400651 const std::string vertexShaderSource = SHADER_SOURCE
652 (
653 attribute vec4 a_position;
654 varying float v_varying;
655 void main()
656 {
657 v_varying = a_position.x;
658 gl_Position = a_position;
659 }
660 );
661
662 const std::string fragmentShaderSource = SHADER_SOURCE
663 (
664 precision mediump float;
665 varying float v_varying;
666 void main()
667 {
668 vec4 c;
669
670 if (gl_FrontFacing)
671 {
672 c = vec4(v_varying, 0, 0, 1.0);
673 }
674 else
675 {
676 c = vec4(0, v_varying, 0, 1.0);
677 }
678 gl_FragColor = c;
679 }
680 );
681
682 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
Austin Kinross02df7962015-07-01 10:03:42 -0700683
684 // Compilation should fail on D3D11 feature level 9_3, since gl_FrontFacing isn't supported.
685 if (platform.renderer == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE)
686 {
687 if (platform.majorVersion == 9 && platform.minorVersion == 3)
688 {
689 EXPECT_EQ(0u, program);
690 return;
691 }
692 }
693
694 // Otherwise, compilation should succeed
Jamie Madille6256f82014-09-17 10:31:15 -0400695 EXPECT_NE(0u, program);
696}
697
Yuly Novikova1f6dc92016-06-15 23:27:04 -0400698// Verify that linking shaders declaring different shading language versions fails.
699TEST_P(GLSLTest_ES3, VersionMismatch)
700{
701 const std::string fragmentShaderSource100 =
702 "precision mediump float;\n"
703 "varying float v_varying;\n"
704 "void main() { gl_FragColor = vec4(v_varying, 0, 0, 1.0); }\n";
705
706 const std::string vertexShaderSource100 =
707 "attribute vec4 a_position;\n"
708 "varying float v_varying;\n"
709 "void main() { v_varying = a_position.x; gl_Position = a_position; }\n";
710
711 const std::string fragmentShaderSource300 =
712 "#version 300 es\n"
713 "precision mediump float;\n"
714 "in float v_varying;\n"
715 "out vec4 my_FragColor;\n"
716 "void main() { my_FragColor = vec4(v_varying, 0, 0, 1.0); }\n";
717
718 const std::string vertexShaderSource300 =
719 "#version 300 es\n"
720 "in vec4 a_position;\n"
721 "out float v_varying;\n"
722 "void main() { v_varying = a_position.x; gl_Position = a_position; }\n";
723
724 GLuint program = CompileProgram(vertexShaderSource300, fragmentShaderSource100);
725 EXPECT_EQ(0u, program);
726
727 program = CompileProgram(vertexShaderSource100, fragmentShaderSource300);
728 EXPECT_EQ(0u, program);
729}
730
731// Verify that declaring varying as invariant only in vertex shader fails in ESSL 1.00.
732TEST_P(GLSLTest, InvariantVaryingOut)
733{
734 const std::string fragmentShaderSource =
735 "precision mediump float;\n"
736 "varying float v_varying;\n"
737 "void main() { gl_FragColor = vec4(v_varying, 0, 0, 1.0); }\n";
738
739 const std::string vertexShaderSource =
740 "attribute vec4 a_position;\n"
741 "invariant varying float v_varying;\n"
742 "void main() { v_varying = a_position.x; gl_Position = a_position; }\n";
743
744 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
745 EXPECT_EQ(0u, program);
746}
747
748// Verify that declaring varying as invariant only in vertex shader succeeds in ESSL 3.00.
749TEST_P(GLSLTest_ES3, InvariantVaryingOut)
750{
751 // TODO: ESSL 3.00 -> GLSL 1.20 translation should add "invariant" in fragment shader
752 // for varyings which are invariant in vertex shader (http://anglebug.com/1293)
Corentin Wallezc7f59d02016-06-20 10:12:08 -0400753 if (IsDesktopOpenGL())
Yuly Novikova1f6dc92016-06-15 23:27:04 -0400754 {
755 std::cout << "Test disabled on OpenGL." << std::endl;
756 return;
757 }
758
759 const std::string fragmentShaderSource =
760 "#version 300 es\n"
761 "precision mediump float;\n"
762 "in float v_varying;\n"
763 "out vec4 my_FragColor;\n"
764 "void main() { my_FragColor = vec4(v_varying, 0, 0, 1.0); }\n";
765
766 const std::string vertexShaderSource =
767 "#version 300 es\n"
768 "in vec4 a_position;\n"
769 "invariant out float v_varying;\n"
770 "void main() { v_varying = a_position.x; gl_Position = a_position; }\n";
771
772 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
773 EXPECT_NE(0u, program);
774}
775
776// Verify that declaring varying as invariant only in fragment shader fails in ESSL 1.00.
Jamie Madillfa05f602015-05-07 13:47:11 -0400777TEST_P(GLSLTest, InvariantVaryingIn)
Jamie Madill1c28e1f2014-08-04 11:37:54 -0400778{
Yuly Novikova1f6dc92016-06-15 23:27:04 -0400779 const std::string fragmentShaderSource =
780 "precision mediump float;\n"
781 "invariant varying float v_varying;\n"
782 "void main() { gl_FragColor = vec4(v_varying, 0, 0, 1.0); }\n";
Geoff Lange0cc2a42016-01-20 10:58:17 -0500783
Yuly Novikova1f6dc92016-06-15 23:27:04 -0400784 const std::string vertexShaderSource =
785 "attribute vec4 a_position;\n"
786 "varying float v_varying;\n"
787 "void main() { v_varying = a_position.x; gl_Position = a_position; }\n";
Jamie Madill1c28e1f2014-08-04 11:37:54 -0400788
Jamie Madill5599c8f2014-08-26 13:16:39 -0400789 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
Yuly Novikova1f6dc92016-06-15 23:27:04 -0400790 EXPECT_EQ(0u, program);
Jamie Madill1c28e1f2014-08-04 11:37:54 -0400791}
792
Yuly Novikova1f6dc92016-06-15 23:27:04 -0400793// Verify that declaring varying as invariant only in fragment shader fails in ESSL 3.00.
794TEST_P(GLSLTest_ES3, InvariantVaryingIn)
795{
796 const std::string fragmentShaderSource =
797 "#version 300 es\n"
798 "precision mediump float;\n"
799 "invariant in float v_varying;\n"
800 "out vec4 my_FragColor;\n"
801 "void main() { my_FragColor = vec4(v_varying, 0, 0, 1.0); }\n";
802
803 const std::string vertexShaderSource =
804 "#version 300 es\n"
805 "in vec4 a_position;\n"
806 "out float v_varying;\n"
807 "void main() { v_varying = a_position.x; gl_Position = a_position; }\n";
808
809 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
810 EXPECT_EQ(0u, program);
811}
812
813// Verify that declaring varying as invariant in both shaders succeeds in ESSL 1.00.
Jamie Madillfa05f602015-05-07 13:47:11 -0400814TEST_P(GLSLTest, InvariantVaryingBoth)
Jamie Madill1c28e1f2014-08-04 11:37:54 -0400815{
Yuly Novikova1f6dc92016-06-15 23:27:04 -0400816 const std::string fragmentShaderSource =
817 "precision mediump float;\n"
818 "invariant varying float v_varying;\n"
819 "void main() { gl_FragColor = vec4(v_varying, 0, 0, 1.0); }\n";
Jamie Madill1c28e1f2014-08-04 11:37:54 -0400820
Yuly Novikova1f6dc92016-06-15 23:27:04 -0400821 const std::string vertexShaderSource =
822 "attribute vec4 a_position;\n"
823 "invariant varying float v_varying;\n"
824 "void main() { v_varying = a_position.x; gl_Position = a_position; }\n";
Jamie Madill1c28e1f2014-08-04 11:37:54 -0400825
Jamie Madill5599c8f2014-08-26 13:16:39 -0400826 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
Jamie Madill1c28e1f2014-08-04 11:37:54 -0400827 EXPECT_NE(0u, program);
828}
829
Yuly Novikova1f6dc92016-06-15 23:27:04 -0400830// Verify that declaring varying as invariant in both shaders fails in ESSL 3.00.
831TEST_P(GLSLTest_ES3, InvariantVaryingBoth)
832{
833 const std::string fragmentShaderSource =
834 "#version 300 es\n"
835 "precision mediump float;\n"
836 "invariant in float v_varying;\n"
837 "out vec4 my_FragColor;\n"
838 "void main() { my_FragColor = vec4(v_varying, 0, 0, 1.0); }\n";
839
840 const std::string vertexShaderSource =
841 "#version 300 es\n"
842 "in vec4 a_position;\n"
843 "invariant out float v_varying;\n"
844 "void main() { v_varying = a_position.x; gl_Position = a_position; }\n";
845
846 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
847 EXPECT_EQ(0u, program);
848}
849
850// Verify that declaring gl_Position as invariant succeeds in ESSL 1.00.
Jamie Madillfa05f602015-05-07 13:47:11 -0400851TEST_P(GLSLTest, InvariantGLPosition)
Jamie Madill1c28e1f2014-08-04 11:37:54 -0400852{
Yuly Novikova1f6dc92016-06-15 23:27:04 -0400853 const std::string fragmentShaderSource =
854 "precision mediump float;\n"
855 "varying float v_varying;\n"
856 "void main() { gl_FragColor = vec4(v_varying, 0, 0, 1.0); }\n";
Jamie Madill1c28e1f2014-08-04 11:37:54 -0400857
Yuly Novikova1f6dc92016-06-15 23:27:04 -0400858 const std::string vertexShaderSource =
859 "attribute vec4 a_position;\n"
860 "invariant gl_Position;\n"
861 "varying float v_varying;\n"
862 "void main() { v_varying = a_position.x; gl_Position = a_position; }\n";
Jamie Madill1c28e1f2014-08-04 11:37:54 -0400863
Jamie Madill5599c8f2014-08-26 13:16:39 -0400864 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
Jamie Madill1c28e1f2014-08-04 11:37:54 -0400865 EXPECT_NE(0u, program);
866}
867
Yuly Novikova1f6dc92016-06-15 23:27:04 -0400868// Verify that declaring gl_Position as invariant succeeds in ESSL 3.00.
869TEST_P(GLSLTest_ES3, InvariantGLPosition)
Jamie Madill1c28e1f2014-08-04 11:37:54 -0400870{
Yuly Novikova1f6dc92016-06-15 23:27:04 -0400871 const std::string fragmentShaderSource =
872 "#version 300 es\n"
873 "precision mediump float;\n"
874 "in float v_varying;\n"
875 "out vec4 my_FragColor;\n"
876 "void main() { my_FragColor = vec4(v_varying, 0, 0, 1.0); }\n";
877
878 const std::string vertexShaderSource =
879 "#version 300 es\n"
880 "in vec4 a_position;\n"
881 "invariant gl_Position;\n"
882 "out float v_varying;\n"
883 "void main() { v_varying = a_position.x; gl_Position = a_position; }\n";
884
885 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
886 EXPECT_NE(0u, program);
887}
888
889// Verify that using invariant(all) in both shaders succeeds in ESSL 1.00.
890TEST_P(GLSLTest, InvariantAllBoth)
891{
892 // TODO: ESSL 1.00 -> GLSL 1.20 translation should add "invariant" in fragment shader
893 // for varyings which are invariant in vertex shader individually,
894 // and remove invariant(all) from fragment shader (http://anglebug.com/1293)
Corentin Wallezc7f59d02016-06-20 10:12:08 -0400895 if (IsDesktopOpenGL())
Geoff Lange0cc2a42016-01-20 10:58:17 -0500896 {
897 std::cout << "Test disabled on OpenGL." << std::endl;
898 return;
899 }
900
Yuly Novikova1f6dc92016-06-15 23:27:04 -0400901 const std::string fragmentShaderSource =
902 "#pragma STDGL invariant(all)\n"
903 "precision mediump float;\n"
904 "varying float v_varying;\n"
905 "void main() { gl_FragColor = vec4(v_varying, 0, 0, 1.0); }\n";
Jamie Madill1c28e1f2014-08-04 11:37:54 -0400906
907 const std::string vertexShaderSource =
908 "#pragma STDGL invariant(all)\n"
909 "attribute vec4 a_position;\n"
910 "varying float v_varying;\n"
911 "void main() { v_varying = a_position.x; gl_Position = a_position; }\n";
912
Jamie Madill5599c8f2014-08-26 13:16:39 -0400913 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
Jamie Madill1c28e1f2014-08-04 11:37:54 -0400914 EXPECT_NE(0u, program);
915}
Austin Kinrossaf875522014-08-25 21:06:07 -0700916
Geoff Lang156d7192016-07-21 16:11:00 -0400917// Verify that functions without return statements still compile
918TEST_P(GLSLTest, MissingReturnFloat)
919{
920 const std::string vertexShaderSource =
921 "varying float v_varying;\n"
922 "float f() { if (v_varying > 0.0) return 1.0; }\n"
923 "void main() { gl_Position = vec4(f(), 0, 0, 1); }\n";
924
925 const std::string fragmentShaderSource =
926 "precision mediump float;\n"
927 "void main() { gl_FragColor = vec4(0, 0, 0, 1); }\n";
928
929 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
930 EXPECT_NE(0u, program);
931}
932
933// Verify that functions without return statements still compile
934TEST_P(GLSLTest, MissingReturnVec2)
935{
936 const std::string vertexShaderSource =
937 "varying float v_varying;\n"
938 "vec2 f() { if (v_varying > 0.0) return vec2(1.0, 1.0); }\n"
939 "void main() { gl_Position = vec4(f().x, 0, 0, 1); }\n";
940
941 const std::string fragmentShaderSource =
942 "precision mediump float;\n"
943 "void main() { gl_FragColor = vec4(0, 0, 0, 1); }\n";
944
945 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
946 EXPECT_NE(0u, program);
947}
948
949// Verify that functions without return statements still compile
950TEST_P(GLSLTest, MissingReturnVec3)
951{
952 const std::string vertexShaderSource =
953 "varying float v_varying;\n"
954 "vec3 f() { if (v_varying > 0.0) return vec3(1.0, 1.0, 1.0); }\n"
955 "void main() { gl_Position = vec4(f().x, 0, 0, 1); }\n";
956
957 const std::string fragmentShaderSource =
958 "precision mediump float;\n"
959 "void main() { gl_FragColor = vec4(0, 0, 0, 1); }\n";
960
961 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
962 EXPECT_NE(0u, program);
963}
964
965// Verify that functions without return statements still compile
966TEST_P(GLSLTest, MissingReturnVec4)
967{
968 const std::string vertexShaderSource =
969 "varying float v_varying;\n"
970 "vec4 f() { if (v_varying > 0.0) return vec4(1.0, 1.0, 1.0, 1.0); }\n"
971 "void main() { gl_Position = vec4(f().x, 0, 0, 1); }\n";
972
973 const std::string fragmentShaderSource =
974 "precision mediump float;\n"
975 "void main() { gl_FragColor = vec4(0, 0, 0, 1); }\n";
976
977 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
978 EXPECT_NE(0u, program);
979}
980
981// Verify that functions without return statements still compile
982TEST_P(GLSLTest, MissingReturnIVec4)
983{
984 const std::string vertexShaderSource =
985 "varying float v_varying;\n"
986 "ivec4 f() { if (v_varying > 0.0) return ivec4(1, 1, 1, 1); }\n"
987 "void main() { gl_Position = vec4(f().x, 0, 0, 1); }\n";
988
989 const std::string fragmentShaderSource =
990 "precision mediump float;\n"
991 "void main() { gl_FragColor = vec4(0, 0, 0, 1); }\n";
992
993 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
994 EXPECT_NE(0u, program);
995}
996
997// Verify that functions without return statements still compile
998TEST_P(GLSLTest, MissingReturnMat4)
999{
1000 const std::string vertexShaderSource =
1001 "varying float v_varying;\n"
1002 "mat4 f() { if (v_varying > 0.0) return mat4(1.0); }\n"
1003 "void main() { gl_Position = vec4(f()[0][0], 0, 0, 1); }\n";
1004
1005 const std::string fragmentShaderSource =
1006 "precision mediump float;\n"
1007 "void main() { gl_FragColor = vec4(0, 0, 0, 1); }\n";
1008
1009 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
1010 EXPECT_NE(0u, program);
1011}
1012
1013// Verify that functions without return statements still compile
1014TEST_P(GLSLTest, MissingReturnStruct)
1015{
1016 const std::string vertexShaderSource =
1017 "varying float v_varying;\n"
1018 "struct s { float a; int b; vec2 c; };\n"
1019 "s f() { if (v_varying > 0.0) return s(1.0, 1, vec2(1.0, 1.0)); }\n"
1020 "void main() { gl_Position = vec4(f().a, 0, 0, 1); }\n";
1021
1022 const std::string fragmentShaderSource =
1023 "precision mediump float;\n"
1024 "void main() { gl_FragColor = vec4(0, 0, 0, 1); }\n";
1025
1026 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
1027 EXPECT_NE(0u, program);
1028}
1029
1030// Verify that functions without return statements still compile
1031TEST_P(GLSLTest_ES3, MissingReturnArray)
1032{
1033 const std::string vertexShaderSource =
1034 "#version 300 es\n"
1035 "in float v_varying;\n"
1036 "vec2[2] f() { if (v_varying > 0.0) { return vec2[2](vec2(1.0, 1.0), vec2(1.0, 1.0)); } }\n"
1037 "void main() { gl_Position = vec4(f()[0].x, 0, 0, 1); }\n";
1038
1039 const std::string fragmentShaderSource =
1040 "#version 300 es\n"
1041 "precision mediump float;\n"
1042 "out vec4 my_FragColor;\n"
1043 "void main() { my_FragColor = vec4(0, 0, 0, 1); }\n";
1044
1045 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
1046 EXPECT_NE(0u, program);
1047}
1048
1049// Verify that functions without return statements still compile
1050TEST_P(GLSLTest_ES3, MissingReturnArrayOfStructs)
1051{
1052 const std::string vertexShaderSource =
1053 "#version 300 es\n"
1054 "in float v_varying;\n"
1055 "struct s { float a; int b; vec2 c; };\n"
1056 "s[2] f() { if (v_varying > 0.0) { return s[2](s(1.0, 1, vec2(1.0, 1.0)), s(1.0, 1, "
1057 "vec2(1.0, 1.0))); } }\n"
1058 "void main() { gl_Position = vec4(f()[0].a, 0, 0, 1); }\n";
1059
1060 const std::string fragmentShaderSource =
1061 "#version 300 es\n"
1062 "precision mediump float;\n"
1063 "out vec4 my_FragColor;\n"
1064 "void main() { my_FragColor = vec4(0, 0, 0, 1); }\n";
1065
1066 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
1067 EXPECT_NE(0u, program);
1068}
1069
Corentin Wallez509e4562016-08-25 14:55:44 -04001070// Verify that functions without return statements still compile
1071TEST_P(GLSLTest_ES3, MissingReturnStructOfArrays)
1072{
1073 // TODO(cwallez) remove the suppression once NVIDIA removes the restriction for
1074 // GLSL >= 300. It was defined only in GLSL 2.0, section 6.1.
1075 if (IsNVIDIA() && IsOpenGLES())
1076 {
1077 std::cout << "Test skipped on NVIDIA OpenGL ES because it disallows returning "
1078 "structure of arrays"
1079 << std::endl;
1080 return;
1081 }
1082
1083 const std::string vertexShaderSource =
1084 "#version 300 es\n"
1085 "in float v_varying;\n"
1086 "struct s { float a[2]; int b[2]; vec2 c[2]; };\n"
1087 "s f() { if (v_varying > 0.0) { return s(float[2](1.0, 1.0), int[2](1, 1),"
1088 "vec2[2](vec2(1.0, 1.0), vec2(1.0, 1.0))); } }\n"
1089 "void main() { gl_Position = vec4(f().a[0], 0, 0, 1); }\n";
1090
1091 const std::string fragmentShaderSource =
1092 "#version 300 es\n"
1093 "precision mediump float;\n"
1094 "out vec4 my_FragColor;\n"
1095 "void main() { my_FragColor = vec4(0, 0, 0, 1); }\n";
1096
1097 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
1098 EXPECT_NE(0u, program);
1099}
1100
Yuly Novikova1f6dc92016-06-15 23:27:04 -04001101// Verify that using invariant(all) in both shaders fails in ESSL 3.00.
1102TEST_P(GLSLTest_ES3, InvariantAllBoth)
1103{
1104 const std::string fragmentShaderSource =
1105 "#version 300 es\n"
1106 "#pragma STDGL invariant(all)\n"
1107 "precision mediump float;\n"
1108 "in float v_varying;\n"
1109 "out vec4 my_FragColor;\n"
1110 "void main() { my_FragColor = vec4(v_varying, 0, 0, 1.0); }\n";
1111
1112 const std::string vertexShaderSource =
1113 "#version 300 es\n"
1114 "#pragma STDGL invariant(all)\n"
1115 "in vec4 a_position;\n"
1116 "out float v_varying;\n"
1117 "void main() { v_varying = a_position.x; gl_Position = a_position; }\n";
1118
1119 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
1120 EXPECT_EQ(0u, program);
1121}
1122
1123// Verify that using invariant(all) only in fragment shader fails in ESSL 1.00.
1124TEST_P(GLSLTest, InvariantAllIn)
1125{
1126 const std::string fragmentShaderSource =
1127 "#pragma STDGL invariant(all)\n"
1128 "precision mediump float;\n"
1129 "varying float v_varying;\n"
1130 "void main() { gl_FragColor = vec4(v_varying, 0, 0, 1.0); }\n";
1131
1132 const std::string vertexShaderSource =
1133 "attribute vec4 a_position;\n"
1134 "varying float v_varying;\n"
1135 "void main() { v_varying = a_position.x; gl_Position = a_position; }\n";
1136
1137 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
1138 EXPECT_EQ(0u, program);
1139}
1140
1141// Verify that using invariant(all) only in fragment shader fails in ESSL 3.00.
1142TEST_P(GLSLTest_ES3, InvariantAllIn)
1143{
1144 const std::string fragmentShaderSource =
1145 "#version 300 es\n"
1146 "#pragma STDGL invariant(all)\n"
1147 "precision mediump float;\n"
1148 "in float v_varying;\n"
1149 "out vec4 my_FragColor;\n"
1150 "void main() { my_FragColor = vec4(v_varying, 0, 0, 1.0); }\n";
1151
1152 const std::string vertexShaderSource =
1153 "#version 300 es\n"
1154 "in vec4 a_position;\n"
1155 "out float v_varying;\n"
1156 "void main() { v_varying = a_position.x; gl_Position = a_position; }\n";
1157
1158 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
1159 EXPECT_EQ(0u, program);
1160}
1161
1162// Verify that using invariant(all) only in vertex shader fails in ESSL 1.00.
1163TEST_P(GLSLTest, InvariantAllOut)
1164{
1165 const std::string fragmentShaderSource =
1166 "precision mediump float;\n"
1167 "varying float v_varying;\n"
1168 "void main() { gl_FragColor = vec4(v_varying, 0, 0, 1.0); }\n";
1169
1170 const std::string vertexShaderSource =
1171 "#pragma STDGL invariant(all)\n"
1172 "attribute vec4 a_position;\n"
1173 "varying float v_varying;\n"
1174 "void main() { v_varying = a_position.x; gl_Position = a_position; }\n";
1175
1176 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
1177 EXPECT_EQ(0u, program);
1178}
1179
1180// Verify that using invariant(all) only in vertex shader succeeds in ESSL 3.00.
1181TEST_P(GLSLTest_ES3, InvariantAllOut)
1182{
1183 // TODO: ESSL 3.00 -> GLSL 1.20 translation should add "invariant" in fragment shader
1184 // for varyings which are invariant in vertex shader,
1185 // because of invariant(all) being used in vertex shader (http://anglebug.com/1293)
Corentin Wallezc7f59d02016-06-20 10:12:08 -04001186 if (IsDesktopOpenGL())
Yuly Novikova1f6dc92016-06-15 23:27:04 -04001187 {
1188 std::cout << "Test disabled on OpenGL." << std::endl;
1189 return;
1190 }
1191
1192 const std::string fragmentShaderSource =
1193 "#version 300 es\n"
1194 "precision mediump float;\n"
1195 "in float v_varying;\n"
1196 "out vec4 my_FragColor;\n"
1197 "void main() { my_FragColor = vec4(v_varying, 0, 0, 1.0); }\n";
1198
1199 const std::string vertexShaderSource =
1200 "#version 300 es\n"
1201 "#pragma STDGL invariant(all)\n"
1202 "in vec4 a_position;\n"
1203 "out float v_varying;\n"
1204 "void main() { v_varying = a_position.x; gl_Position = a_position; }\n";
1205
1206 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
1207 EXPECT_NE(0u, program);
1208}
1209
Jamie Madillfa05f602015-05-07 13:47:11 -04001210TEST_P(GLSLTest, MaxVaryingVec4)
Austin Kinross8b695ee2015-03-12 13:12:20 -07001211{
Geoff Lang69accbd2016-01-25 16:22:32 -05001212#if defined(__APPLE__)
1213 // TODO(geofflang): Find out why this doesn't compile on Apple AND OpenGL drivers
1214 // (http://anglebug.com/1291)
Jamie Madill518b9fa2016-03-02 11:26:02 -05001215 if (IsAMD() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Geoff Lang69accbd2016-01-25 16:22:32 -05001216 {
1217 std::cout << "Test disabled on Apple AMD OpenGL." << std::endl;
1218 return;
1219 }
1220#endif
1221
Austin Kinross8b695ee2015-03-12 13:12:20 -07001222 GLint maxVaryings = 0;
1223 glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings);
1224
1225 VaryingTestBase(0, 0, 0, 0, 0, 0, maxVaryings, 0, false, false, false, true);
1226}
1227
Jamie Madillfa05f602015-05-07 13:47:11 -04001228TEST_P(GLSLTest, MaxMinusTwoVaryingVec4PlusTwoSpecialVariables)
Austin Kinross8b695ee2015-03-12 13:12:20 -07001229{
1230 GLint maxVaryings = 0;
1231 glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings);
1232
1233 // Generate shader code that uses gl_FragCoord and gl_PointCoord, two special fragment shader variables.
1234 VaryingTestBase(0, 0, 0, 0, 0, 0, maxVaryings - 2, 0, true, true, false, true);
1235}
1236
Jamie Madillfa05f602015-05-07 13:47:11 -04001237TEST_P(GLSLTest, MaxMinusTwoVaryingVec4PlusThreeSpecialVariables)
Austin Kinross8b695ee2015-03-12 13:12:20 -07001238{
Geoff Lange0cc2a42016-01-20 10:58:17 -05001239 // TODO(geofflang): Figure out why this fails on OpenGL AMD (http://anglebug.com/1291)
Jamie Madill518b9fa2016-03-02 11:26:02 -05001240 if (IsAMD() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Geoff Lange0cc2a42016-01-20 10:58:17 -05001241 {
1242 std::cout << "Test disabled on OpenGL." << std::endl;
1243 return;
1244 }
1245
Austin Kinross8b695ee2015-03-12 13:12:20 -07001246 GLint maxVaryings = 0;
1247 glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings);
1248
1249 // Generate shader code that uses gl_FragCoord, gl_PointCoord and gl_PointSize.
1250 VaryingTestBase(0, 0, 0, 0, 0, 0, maxVaryings - 2, 0, true, true, true, true);
1251}
1252
Jamie Madillfa05f602015-05-07 13:47:11 -04001253TEST_P(GLSLTest, MaxVaryingVec3)
Austin Kinrossaf875522014-08-25 21:06:07 -07001254{
1255 GLint maxVaryings = 0;
1256 glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings);
1257
Austin Kinross8b695ee2015-03-12 13:12:20 -07001258 VaryingTestBase(0, 0, 0, 0, maxVaryings, 0, 0, 0, false, false, false, true);
Austin Kinrossaf875522014-08-25 21:06:07 -07001259}
1260
Jamie Madillfa05f602015-05-07 13:47:11 -04001261TEST_P(GLSLTest, MaxVaryingVec3Array)
Austin Kinrossaf875522014-08-25 21:06:07 -07001262{
1263 GLint maxVaryings = 0;
1264 glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings);
1265
Austin Kinross8b695ee2015-03-12 13:12:20 -07001266 VaryingTestBase(0, 0, 0, 0, 0, maxVaryings / 2, 0, 0, false, false, false, true);
Austin Kinrossaf875522014-08-25 21:06:07 -07001267}
1268
Jamie Madillbee59e02014-10-02 10:44:18 -04001269// Disabled because of a failure in D3D9
Jamie Madill9fc36822015-11-18 13:08:07 -05001270TEST_P(GLSLTest, MaxVaryingVec3AndOneFloat)
Austin Kinrossaf875522014-08-25 21:06:07 -07001271{
Jamie Madill518b9fa2016-03-02 11:26:02 -05001272 if (IsD3D9())
Jamie Madill9fc36822015-11-18 13:08:07 -05001273 {
1274 std::cout << "Test disabled on D3D9." << std::endl;
1275 return;
1276 }
1277
Austin Kinrossaf875522014-08-25 21:06:07 -07001278 GLint maxVaryings = 0;
1279 glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings);
1280
Austin Kinross8b695ee2015-03-12 13:12:20 -07001281 VaryingTestBase(1, 0, 0, 0, maxVaryings, 0, 0, 0, false, false, false, true);
Austin Kinrossaf875522014-08-25 21:06:07 -07001282}
1283
Jamie Madillbee59e02014-10-02 10:44:18 -04001284// Disabled because of a failure in D3D9
Jamie Madill9fc36822015-11-18 13:08:07 -05001285TEST_P(GLSLTest, MaxVaryingVec3ArrayAndOneFloatArray)
Austin Kinrossaf875522014-08-25 21:06:07 -07001286{
Jamie Madill518b9fa2016-03-02 11:26:02 -05001287 if (IsD3D9())
Jamie Madill9fc36822015-11-18 13:08:07 -05001288 {
1289 std::cout << "Test disabled on D3D9." << std::endl;
1290 return;
1291 }
1292
Austin Kinrossaf875522014-08-25 21:06:07 -07001293 GLint maxVaryings = 0;
1294 glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings);
1295
Austin Kinross8b695ee2015-03-12 13:12:20 -07001296 VaryingTestBase(0, 1, 0, 0, 0, maxVaryings / 2, 0, 0, false, false, false, true);
Austin Kinrossaf875522014-08-25 21:06:07 -07001297}
1298
Jamie Madillbee59e02014-10-02 10:44:18 -04001299// Disabled because of a failure in D3D9
Jamie Madill9fc36822015-11-18 13:08:07 -05001300TEST_P(GLSLTest, TwiceMaxVaryingVec2)
Austin Kinrossaf875522014-08-25 21:06:07 -07001301{
Jamie Madill518b9fa2016-03-02 11:26:02 -05001302 if (IsD3D9())
Jamie Madill9fc36822015-11-18 13:08:07 -05001303 {
1304 std::cout << "Test disabled on D3D9." << std::endl;
1305 return;
1306 }
1307
Geoff Lange0cc2a42016-01-20 10:58:17 -05001308 if (getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE)
1309 {
1310 // TODO(geofflang): Figure out why this fails on NVIDIA's GLES driver
1311 std::cout << "Test disabled on OpenGL ES." << std::endl;
1312 return;
1313 }
1314
Geoff Lang69accbd2016-01-25 16:22:32 -05001315#if defined(__APPLE__)
1316 // TODO(geofflang): Find out why this doesn't compile on Apple AND OpenGL drivers
1317 // (http://anglebug.com/1291)
Jamie Madill518b9fa2016-03-02 11:26:02 -05001318 if (IsAMD() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Geoff Lang69accbd2016-01-25 16:22:32 -05001319 {
1320 std::cout << "Test disabled on Apple AMD OpenGL." << std::endl;
1321 return;
1322 }
1323#endif
1324
Austin Kinrossaf875522014-08-25 21:06:07 -07001325 GLint maxVaryings = 0;
1326 glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings);
1327
Austin Kinross8b695ee2015-03-12 13:12:20 -07001328 VaryingTestBase(0, 0, 2 * maxVaryings, 0, 0, 0, 0, 0, false, false, false, true);
Austin Kinrossaf875522014-08-25 21:06:07 -07001329}
1330
Jamie Madillbee59e02014-10-02 10:44:18 -04001331// Disabled because of a failure in D3D9
Jamie Madill9fc36822015-11-18 13:08:07 -05001332TEST_P(GLSLTest, MaxVaryingVec2Arrays)
Austin Kinrossaf875522014-08-25 21:06:07 -07001333{
Jamie Madill518b9fa2016-03-02 11:26:02 -05001334 if (IsD3DSM3())
Jamie Madill9fc36822015-11-18 13:08:07 -05001335 {
1336 std::cout << "Test disabled on SM3." << std::endl;
1337 return;
1338 }
1339
Geoff Lange0cc2a42016-01-20 10:58:17 -05001340 if (getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE)
1341 {
1342 // TODO(geofflang): Figure out why this fails on NVIDIA's GLES driver
1343 std::cout << "Test disabled on OpenGL ES." << std::endl;
1344 return;
1345 }
1346
Geoff Lang69accbd2016-01-25 16:22:32 -05001347#if defined(__APPLE__)
1348 // TODO(geofflang): Find out why this doesn't compile on Apple AND OpenGL drivers
1349 // (http://anglebug.com/1291)
Jamie Madill518b9fa2016-03-02 11:26:02 -05001350 if (IsAMD() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Geoff Lang69accbd2016-01-25 16:22:32 -05001351 {
1352 std::cout << "Test disabled on Apple AMD OpenGL." << std::endl;
1353 return;
1354 }
1355#endif
1356
Austin Kinrossaf875522014-08-25 21:06:07 -07001357 GLint maxVaryings = 0;
1358 glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings);
1359
Jamie Madill192745a2016-12-22 15:58:21 -05001360 // Special case: because arrays of mat2 are packed as small grids of two rows by two columns,
1361 // we should be aware that when we're packing into an odd number of varying registers the
1362 // last row will be empty and can not fit the final vec2 arrary.
1363 GLint maxVec2Arrays = (maxVaryings >> 1) << 1;
1364
1365 VaryingTestBase(0, 0, 0, maxVec2Arrays, 0, 0, 0, 0, false, false, false, true);
Austin Kinrossaf875522014-08-25 21:06:07 -07001366}
1367
Geoff Langf60fab62014-11-24 11:21:20 -05001368// Verify shader source with a fixed length that is less than the null-terminated length will compile.
Jamie Madillfa05f602015-05-07 13:47:11 -04001369TEST_P(GLSLTest, FixedShaderLength)
Geoff Langf60fab62014-11-24 11:21:20 -05001370{
1371 GLuint shader = glCreateShader(GL_FRAGMENT_SHADER);
1372
1373 const std::string appendGarbage = "abcasdfasdfasdfasdfasdf";
1374 const std::string source = "void main() { gl_FragColor = vec4(0, 0, 0, 0); }" + appendGarbage;
1375 const char *sourceArray[1] = { source.c_str() };
Corentin Wallez973402f2015-05-11 13:42:22 -04001376 GLint lengths[1] = { static_cast<GLint>(source.length() - appendGarbage.length()) };
Cooper Partin4d61f7e2015-08-12 10:56:50 -07001377 glShaderSource(shader, static_cast<GLsizei>(ArraySize(sourceArray)), sourceArray, lengths);
Geoff Langf60fab62014-11-24 11:21:20 -05001378 glCompileShader(shader);
1379
1380 GLint compileResult;
1381 glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult);
1382 EXPECT_NE(compileResult, 0);
1383}
1384
1385// Verify that a negative shader source length is treated as a null-terminated length.
Jamie Madillfa05f602015-05-07 13:47:11 -04001386TEST_P(GLSLTest, NegativeShaderLength)
Geoff Langf60fab62014-11-24 11:21:20 -05001387{
1388 GLuint shader = glCreateShader(GL_FRAGMENT_SHADER);
1389
1390 const char *sourceArray[1] = { "void main() { gl_FragColor = vec4(0, 0, 0, 0); }" };
1391 GLint lengths[1] = { -10 };
Cooper Partin4d61f7e2015-08-12 10:56:50 -07001392 glShaderSource(shader, static_cast<GLsizei>(ArraySize(sourceArray)), sourceArray, lengths);
Geoff Langf60fab62014-11-24 11:21:20 -05001393 glCompileShader(shader);
1394
1395 GLint compileResult;
1396 glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult);
1397 EXPECT_NE(compileResult, 0);
1398}
1399
Corentin Wallez9a9c0482016-04-12 10:36:25 -04001400// Check that having an invalid char after the "." doesn't cause an assert.
1401TEST_P(GLSLTest, InvalidFieldFirstChar)
1402{
1403 GLuint shader = glCreateShader(GL_VERTEX_SHADER);
1404 const char *source = "void main() {vec4 x; x.}";
1405 glShaderSource(shader, 1, &source, 0);
1406 glCompileShader(shader);
1407
1408 GLint compileResult;
1409 glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult);
1410 EXPECT_EQ(0, compileResult);
1411}
1412
Geoff Langf60fab62014-11-24 11:21:20 -05001413// Verify that a length array with mixed positive and negative values compiles.
Jamie Madillfa05f602015-05-07 13:47:11 -04001414TEST_P(GLSLTest, MixedShaderLengths)
Geoff Langf60fab62014-11-24 11:21:20 -05001415{
1416 GLuint shader = glCreateShader(GL_FRAGMENT_SHADER);
1417
1418 const char *sourceArray[] =
1419 {
1420 "void main()",
1421 "{",
1422 " gl_FragColor = vec4(0, 0, 0, 0);",
1423 "}",
1424 };
1425 GLint lengths[] =
1426 {
1427 -10,
1428 1,
Corentin Wallez973402f2015-05-11 13:42:22 -04001429 static_cast<GLint>(strlen(sourceArray[2])),
Geoff Langf60fab62014-11-24 11:21:20 -05001430 -1,
1431 };
1432 ASSERT_EQ(ArraySize(sourceArray), ArraySize(lengths));
1433
Cooper Partin4d61f7e2015-08-12 10:56:50 -07001434 glShaderSource(shader, static_cast<GLsizei>(ArraySize(sourceArray)), sourceArray, lengths);
Geoff Langf60fab62014-11-24 11:21:20 -05001435 glCompileShader(shader);
1436
1437 GLint compileResult;
1438 glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult);
1439 EXPECT_NE(compileResult, 0);
1440}
1441
1442// Verify that zero-length shader source does not affect shader compilation.
Jamie Madillfa05f602015-05-07 13:47:11 -04001443TEST_P(GLSLTest, ZeroShaderLength)
Geoff Langf60fab62014-11-24 11:21:20 -05001444{
1445 GLuint shader = glCreateShader(GL_FRAGMENT_SHADER);
1446
1447 const char *sourceArray[] =
1448 {
1449 "adfasdf",
1450 "34534",
1451 "void main() { gl_FragColor = vec4(0, 0, 0, 0); }",
1452 "",
1453 "asdfasdfsdsdf",
1454 };
1455 GLint lengths[] =
1456 {
1457 0,
1458 0,
1459 -1,
1460 0,
1461 0,
1462 };
1463 ASSERT_EQ(ArraySize(sourceArray), ArraySize(lengths));
1464
Cooper Partin4d61f7e2015-08-12 10:56:50 -07001465 glShaderSource(shader, static_cast<GLsizei>(ArraySize(sourceArray)), sourceArray, lengths);
Geoff Langf60fab62014-11-24 11:21:20 -05001466 glCompileShader(shader);
1467
1468 GLint compileResult;
1469 glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult);
1470 EXPECT_NE(compileResult, 0);
1471}
Jamie Madill21c1e452014-12-29 11:33:41 -05001472
1473// Tests that bad index expressions don't crash ANGLE's translator.
1474// https://code.google.com/p/angleproject/issues/detail?id=857
Jamie Madillfa05f602015-05-07 13:47:11 -04001475TEST_P(GLSLTest, BadIndexBug)
Jamie Madill21c1e452014-12-29 11:33:41 -05001476{
1477 const std::string &fragmentShaderSourceVec =
1478 "precision mediump float;\n"
1479 "uniform vec4 uniformVec;\n"
1480 "void main()\n"
1481 "{\n"
1482 " gl_FragColor = vec4(uniformVec[int()]);\n"
1483 "}";
1484
1485 GLuint shader = CompileShader(GL_FRAGMENT_SHADER, fragmentShaderSourceVec);
1486 EXPECT_EQ(0u, shader);
1487
1488 if (shader != 0)
1489 {
1490 glDeleteShader(shader);
1491 }
1492
1493 const std::string &fragmentShaderSourceMat =
1494 "precision mediump float;\n"
1495 "uniform mat4 uniformMat;\n"
1496 "void main()\n"
1497 "{\n"
1498 " gl_FragColor = vec4(uniformMat[int()]);\n"
1499 "}";
1500
1501 shader = CompileShader(GL_FRAGMENT_SHADER, fragmentShaderSourceMat);
1502 EXPECT_EQ(0u, shader);
1503
1504 if (shader != 0)
1505 {
1506 glDeleteShader(shader);
1507 }
1508
1509 const std::string &fragmentShaderSourceArray =
1510 "precision mediump float;\n"
1511 "uniform vec4 uniformArray;\n"
1512 "void main()\n"
1513 "{\n"
1514 " gl_FragColor = vec4(uniformArray[int()]);\n"
1515 "}";
1516
1517 shader = CompileShader(GL_FRAGMENT_SHADER, fragmentShaderSourceArray);
1518 EXPECT_EQ(0u, shader);
1519
1520 if (shader != 0)
1521 {
1522 glDeleteShader(shader);
1523 }
Jamie Madill37997142015-01-28 10:06:34 -05001524}
1525
Jamie Madill2e295e22015-04-29 10:41:33 -04001526// Test that structs defined in uniforms are translated correctly.
Jamie Madillfa05f602015-05-07 13:47:11 -04001527TEST_P(GLSLTest, StructSpecifiersUniforms)
Jamie Madill2e295e22015-04-29 10:41:33 -04001528{
1529 const std::string fragmentShaderSource = SHADER_SOURCE
1530 (
1531 precision mediump float;
1532
1533 uniform struct S { float field;} s;
1534
1535 void main()
1536 {
1537 gl_FragColor = vec4(1, 0, 0, 1);
1538 gl_FragColor.a += s.field;
1539 }
1540 );
1541
1542 GLuint program = CompileProgram(mSimpleVSSource, fragmentShaderSource);
1543 EXPECT_NE(0u, program);
1544}
Jamie Madill55def582015-05-04 11:24:57 -04001545
1546// Test that gl_DepthRange is not stored as a uniform location. Since uniforms
1547// beginning with "gl_" are filtered out by our validation logic, we must
1548// bypass the validation to test the behaviour of the implementation.
1549// (note this test is still Impl-independent)
Jamie Madille1faacb2016-12-13 12:42:14 -05001550TEST_P(GLSLTestNoValidation, DepthRangeUniforms)
Jamie Madill55def582015-05-04 11:24:57 -04001551{
1552 const std::string fragmentShaderSource = SHADER_SOURCE
1553 (
1554 precision mediump float;
1555
1556 void main()
1557 {
1558 gl_FragColor = vec4(gl_DepthRange.near, gl_DepthRange.far, gl_DepthRange.diff, 1);
1559 }
1560 );
1561
Jamie Madille1faacb2016-12-13 12:42:14 -05001562 ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShaderSource);
Jamie Madill55def582015-05-04 11:24:57 -04001563
Jamie Madille1faacb2016-12-13 12:42:14 -05001564 // We need to bypass validation for this call.
1565 GLint nearIndex = glGetUniformLocation(program.get(), "gl_DepthRange.near");
Jamie Madill55def582015-05-04 11:24:57 -04001566 EXPECT_EQ(-1, nearIndex);
1567
1568 // Test drawing does not throw an exception.
Jamie Madille1faacb2016-12-13 12:42:14 -05001569 drawQuad(program.get(), "inputAttribute", 0.5f);
Jamie Madill55def582015-05-04 11:24:57 -04001570
1571 EXPECT_GL_NO_ERROR();
Jamie Madill55def582015-05-04 11:24:57 -04001572}
Jamie Madill4052dfc2015-05-06 15:18:49 -04001573
Jamie Madill6c9503e2016-08-16 14:06:32 -04001574std::string GenerateSmallPowShader(double base, double exponent)
1575{
1576 std::stringstream stream;
1577
1578 stream.precision(8);
1579
1580 double result = pow(base, exponent);
1581
1582 stream << "precision highp float;\n"
1583 << "float fun(float arg)\n"
1584 << "{\n"
1585 << " return pow(arg, " << std::fixed << exponent << ");\n"
1586 << "}\n"
1587 << "\n"
1588 << "void main()\n"
1589 << "{\n"
1590 << " const float a = " << std::scientific << base << ";\n"
1591 << " float b = fun(a);\n"
1592 << " if (abs(" << result << " - b) < " << std::abs(result * 0.001) << ")\n"
1593 << " {\n"
1594 << " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n"
1595 << " }\n"
1596 << " else\n"
1597 << " {\n"
1598 << " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
1599 << " }\n"
1600 << "}\n";
1601
1602 return stream.str();
1603}
1604
Jamie Madill4052dfc2015-05-06 15:18:49 -04001605// Covers the WebGL test 'glsl/bugs/pow-of-small-constant-in-user-defined-function'
Jamie Madill1048e432016-07-23 18:51:28 -04001606// See http://anglebug.com/851
1607TEST_P(GLSLTest, PowOfSmallConstant)
Jamie Madill4052dfc2015-05-06 15:18:49 -04001608{
Jamie Madill6c9503e2016-08-16 14:06:32 -04001609 std::vector<double> bads;
1610 for (int eps = -1; eps <= 1; ++eps)
1611 {
1612 for (int i = -4; i <= 5; ++i)
Jamie Madill4052dfc2015-05-06 15:18:49 -04001613 {
Jamie Madill6c9503e2016-08-16 14:06:32 -04001614 if (i >= -1 && i <= 1)
1615 continue;
1616 const double epsilon = 1.0e-8;
1617 double bad = static_cast<double>(i) + static_cast<double>(eps) * epsilon;
1618 bads.push_back(bad);
Jamie Madill4052dfc2015-05-06 15:18:49 -04001619 }
Jamie Madill6c9503e2016-08-16 14:06:32 -04001620 }
Jamie Madill4052dfc2015-05-06 15:18:49 -04001621
Jamie Madill6c9503e2016-08-16 14:06:32 -04001622 for (double bad : bads)
1623 {
1624 const std::string &fragmentShaderSource = GenerateSmallPowShader(1.0e-6, bad);
Jamie Madill4052dfc2015-05-06 15:18:49 -04001625
Jamie Madill6c9503e2016-08-16 14:06:32 -04001626 ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShaderSource);
Jamie Madill4052dfc2015-05-06 15:18:49 -04001627
Jamie Madill6c9503e2016-08-16 14:06:32 -04001628 drawQuad(program.get(), "inputAttribute", 0.5f);
1629
1630 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
1631 EXPECT_GL_NO_ERROR();
1632 }
Jamie Madill4052dfc2015-05-06 15:18:49 -04001633}
Jamie Madillfa05f602015-05-07 13:47:11 -04001634
Cooper Partina5ef8d82015-08-19 14:52:21 -07001635// Test that fragment shaders which contain non-constant loop indexers and compiled for FL9_3 and
1636// below
1637// fail with a specific error message.
1638// Additionally test that the same fragment shader compiles successfully with feature levels greater
1639// than FL9_3.
1640TEST_P(GLSLTest, LoopIndexingValidation)
1641{
1642 const std::string fragmentShaderSource = SHADER_SOURCE
1643 (
1644 precision mediump float;
1645
1646 uniform float loopMax;
1647
1648 void main()
1649 {
1650 gl_FragColor = vec4(1, 0, 0, 1);
1651 for (float l = 0.0; l < loopMax; l++)
1652 {
1653 if (loopMax > 3.0)
1654 {
1655 gl_FragColor.a += 0.1;
1656 }
1657 }
1658 }
1659 );
1660
1661 GLuint shader = glCreateShader(GL_FRAGMENT_SHADER);
1662
1663 const char *sourceArray[1] = {fragmentShaderSource.c_str()};
1664 glShaderSource(shader, 1, sourceArray, nullptr);
1665 glCompileShader(shader);
1666
1667 GLint compileResult;
1668 glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult);
1669
1670 // If the test is configured to run limited to Feature Level 9_3, then it is
1671 // assumed that shader compilation will fail with an expected error message containing
1672 // "Loop index cannot be compared with non-constant expression"
Olli Etuaho814a54d2015-08-27 16:23:09 +03001673 if ((GetParam() == ES2_D3D11_FL9_3() || GetParam() == ES2_D3D9()))
Cooper Partina5ef8d82015-08-19 14:52:21 -07001674 {
1675 if (compileResult != 0)
1676 {
1677 FAIL() << "Shader compilation succeeded, expected failure";
1678 }
1679 else
1680 {
1681 GLint infoLogLength;
1682 glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);
1683
1684 std::string infoLog;
1685 infoLog.resize(infoLogLength);
1686 glGetShaderInfoLog(shader, static_cast<GLsizei>(infoLog.size()), NULL, &infoLog[0]);
1687
1688 if (infoLog.find("Loop index cannot be compared with non-constant expression") ==
1689 std::string::npos)
1690 {
1691 FAIL() << "Shader compilation failed with unexpected error message";
1692 }
1693 }
1694 }
1695 else
1696 {
1697 EXPECT_NE(0, compileResult);
1698 }
1699
1700 if (shader != 0)
1701 {
1702 glDeleteShader(shader);
1703 }
1704}
1705
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001706// Tests that the maximum uniforms count returned from querying GL_MAX_VERTEX_UNIFORM_VECTORS
1707// can actually be used.
1708TEST_P(GLSLTest, VerifyMaxVertexUniformVectors)
1709{
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001710 int maxUniforms = 10000;
1711 glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, &maxUniforms);
1712 EXPECT_GL_NO_ERROR();
1713 std::cout << "Validating GL_MAX_VERTEX_UNIFORM_VECTORS = " << maxUniforms << std::endl;
1714
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001715 CompileGLSLWithUniformsAndSamplers(maxUniforms, 0, 0, 0, true);
1716}
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001717
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001718// Tests that the maximum uniforms count returned from querying GL_MAX_VERTEX_UNIFORM_VECTORS
1719// can actually be used along with the maximum number of texture samplers.
1720TEST_P(GLSLTest, VerifyMaxVertexUniformVectorsWithSamplers)
1721{
Geoff Lange0cc2a42016-01-20 10:58:17 -05001722 if (GetParam().eglParameters.renderer == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE ||
1723 GetParam().eglParameters.renderer == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE)
1724 {
1725 std::cout << "Test disabled on OpenGL." << std::endl;
1726 return;
1727 }
1728
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001729 int maxUniforms = 10000;
1730 glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, &maxUniforms);
1731 EXPECT_GL_NO_ERROR();
1732 std::cout << "Validating GL_MAX_VERTEX_UNIFORM_VECTORS = " << maxUniforms << std::endl;
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001733
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001734 int maxTextureImageUnits = 0;
1735 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &maxTextureImageUnits);
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001736
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001737 CompileGLSLWithUniformsAndSamplers(maxUniforms, 0, maxTextureImageUnits, 0, true);
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001738}
1739
1740// Tests that the maximum uniforms count + 1 from querying GL_MAX_VERTEX_UNIFORM_VECTORS
1741// fails shader compilation.
1742TEST_P(GLSLTest, VerifyMaxVertexUniformVectorsExceeded)
1743{
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001744 int maxUniforms = 10000;
1745 glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, &maxUniforms);
1746 EXPECT_GL_NO_ERROR();
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001747 std::cout << "Validating GL_MAX_VERTEX_UNIFORM_VECTORS + 1 = " << maxUniforms + 1 << std::endl;
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001748
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001749 CompileGLSLWithUniformsAndSamplers(maxUniforms + 1, 0, 0, 0, false);
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001750}
1751
1752// Tests that the maximum uniforms count returned from querying GL_MAX_FRAGMENT_UNIFORM_VECTORS
1753// can actually be used.
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001754TEST_P(GLSLTest, VerifyMaxFragmentUniformVectors)
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001755{
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001756 int maxUniforms = 10000;
1757 glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, &maxUniforms);
1758 EXPECT_GL_NO_ERROR();
1759 std::cout << "Validating GL_MAX_FRAGMENT_UNIFORM_VECTORS = " << maxUniforms << std::endl;
1760
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001761 CompileGLSLWithUniformsAndSamplers(0, maxUniforms, 0, 0, true);
1762}
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001763
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001764// Tests that the maximum uniforms count returned from querying GL_MAX_FRAGMENT_UNIFORM_VECTORS
1765// can actually be used along with the maximum number of texture samplers.
1766TEST_P(GLSLTest, VerifyMaxFragmentUniformVectorsWithSamplers)
1767{
Geoff Lange0cc2a42016-01-20 10:58:17 -05001768 if (GetParam().eglParameters.renderer == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE ||
1769 GetParam().eglParameters.renderer == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE)
1770 {
1771 std::cout << "Test disabled on OpenGL." << std::endl;
1772 return;
1773 }
1774
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001775 int maxUniforms = 10000;
1776 glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, &maxUniforms);
1777 EXPECT_GL_NO_ERROR();
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001778
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001779 int maxTextureImageUnits = 0;
1780 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureImageUnits);
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001781
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001782 CompileGLSLWithUniformsAndSamplers(0, maxUniforms, 0, maxTextureImageUnits, true);
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001783}
1784
1785// Tests that the maximum uniforms count + 1 from querying GL_MAX_FRAGMENT_UNIFORM_VECTORS
1786// fails shader compilation.
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001787TEST_P(GLSLTest, VerifyMaxFragmentUniformVectorsExceeded)
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001788{
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001789 int maxUniforms = 10000;
1790 glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, &maxUniforms);
1791 EXPECT_GL_NO_ERROR();
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001792 std::cout << "Validating GL_MAX_FRAGMENT_UNIFORM_VECTORS + 1 = " << maxUniforms + 1
1793 << std::endl;
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001794
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001795 CompileGLSLWithUniformsAndSamplers(0, maxUniforms + 1, 0, 0, false);
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001796}
1797
Olli Etuahobe59c2f2016-03-07 11:32:34 +02001798// Test that two constructors which have vec4 and mat2 parameters get disambiguated (issue in
1799// HLSL).
1800TEST_P(GLSLTest_ES3, AmbiguousConstructorCall2x2)
1801{
1802 const std::string fragmentShaderSource =
1803 "#version 300 es\n"
1804 "precision highp float;\n"
1805 "out vec4 my_FragColor;\n"
1806 "void main()\n"
1807 "{\n"
1808 " my_FragColor = vec4(0.0);\n"
1809 "}";
1810
1811 const std::string vertexShaderSource =
1812 "#version 300 es\n"
1813 "precision highp float;\n"
1814 "in vec4 a_vec;\n"
1815 "in mat2 a_mat;\n"
1816 "void main()\n"
1817 "{\n"
1818 " gl_Position = vec4(a_vec) + vec4(a_mat);\n"
1819 "}";
1820
1821 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
1822 EXPECT_NE(0u, program);
1823}
1824
1825// Test that two constructors which have mat2x3 and mat3x2 parameters get disambiguated.
1826// This was suspected to be an issue in HLSL, but HLSL seems to be able to natively choose between
1827// the function signatures in this case.
1828TEST_P(GLSLTest_ES3, AmbiguousConstructorCall2x3)
1829{
1830 const std::string fragmentShaderSource =
1831 "#version 300 es\n"
1832 "precision highp float;\n"
1833 "out vec4 my_FragColor;\n"
1834 "void main()\n"
1835 "{\n"
1836 " my_FragColor = vec4(0.0);\n"
1837 "}";
1838
1839 const std::string vertexShaderSource =
1840 "#version 300 es\n"
1841 "precision highp float;\n"
1842 "in mat3x2 a_matA;\n"
1843 "in mat2x3 a_matB;\n"
1844 "void main()\n"
1845 "{\n"
1846 " gl_Position = vec4(a_matA) + vec4(a_matB);\n"
1847 "}";
1848
1849 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
1850 EXPECT_NE(0u, program);
1851}
1852
1853// Test that two functions which have vec4 and mat2 parameters get disambiguated (issue in HLSL).
1854TEST_P(GLSLTest_ES3, AmbiguousFunctionCall2x2)
1855{
1856 const std::string fragmentShaderSource =
1857 "#version 300 es\n"
1858 "precision highp float;\n"
1859 "out vec4 my_FragColor;\n"
1860 "void main()\n"
1861 "{\n"
1862 " my_FragColor = vec4(0.0);\n"
1863 "}";
1864
1865 const std::string vertexShaderSource =
1866 "#version 300 es\n"
1867 "precision highp float;\n"
1868 "in vec4 a_vec;\n"
1869 "in mat2 a_mat;\n"
1870 "vec4 foo(vec4 a)\n"
1871 "{\n"
1872 " return a;\n"
1873 "}\n"
1874 "vec4 foo(mat2 a)\n"
1875 "{\n"
1876 " return vec4(a[0][0]);\n"
1877 "}\n"
1878 "void main()\n"
1879 "{\n"
1880 " gl_Position = foo(a_vec) + foo(a_mat);\n"
1881 "}";
1882
1883 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
1884 EXPECT_NE(0u, program);
1885}
1886
1887// Test that an user-defined function with a large number of float4 parameters doesn't fail due to
1888// the function name being too long.
1889TEST_P(GLSLTest_ES3, LargeNumberOfFloat4Parameters)
1890{
1891 const std::string fragmentShaderSource =
1892 "#version 300 es\n"
1893 "precision highp float;\n"
1894 "out vec4 my_FragColor;\n"
1895 "void main()\n"
1896 "{\n"
1897 " my_FragColor = vec4(0.0);\n"
1898 "}";
1899
1900 std::stringstream vertexShaderStream;
1901 const unsigned int paramCount = 1024u;
1902
1903 vertexShaderStream << "#version 300 es\n"
1904 "precision highp float;\n"
1905 "in vec4 a_vec;\n"
1906 "vec4 lotsOfVec4Parameters(";
1907 for (unsigned int i = 0; i < paramCount; ++i)
1908 {
1909 vertexShaderStream << "vec4 a" << i << ", ";
1910 }
1911 vertexShaderStream << "vec4 aLast)\n"
1912 "{\n"
1913 " return ";
1914 for (unsigned int i = 0; i < paramCount; ++i)
1915 {
1916 vertexShaderStream << "a" << i << " + ";
1917 }
1918 vertexShaderStream << "aLast;\n"
1919 "}\n"
1920 "void main()\n"
1921 "{\n"
1922 " gl_Position = lotsOfVec4Parameters(";
1923 for (unsigned int i = 0; i < paramCount; ++i)
1924 {
1925 vertexShaderStream << "a_vec, ";
1926 }
1927 vertexShaderStream << "a_vec);\n"
1928 "}";
1929
1930 GLuint program = CompileProgram(vertexShaderStream.str(), fragmentShaderSource);
1931 EXPECT_NE(0u, program);
1932}
1933
Olli Etuahod4f4c112016-04-15 15:11:24 +03001934// This test was written specifically to stress DeferGlobalInitializers AST transformation.
1935// Test a shader where a global constant array is initialized with an expression containing array
1936// indexing. This initializer is tricky to constant fold, so if it's not constant folded it needs to
1937// be handled in a way that doesn't generate statements in the global scope in HLSL output.
1938// Also includes multiple array initializers in one declaration, where only the second one has
1939// array indexing. This makes sure that the qualifier for the declaration is set correctly if
1940// transformations are applied to the declaration also in the case of ESSL output.
1941TEST_P(GLSLTest_ES3, InitGlobalArrayWithArrayIndexing)
1942{
Yuly Novikov41db2242016-06-25 00:14:28 -04001943 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1428 is fixed
1944 if (IsAndroid() && IsAdreno() && IsOpenGLES())
1945 {
1946 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
1947 return;
1948 }
1949
Olli Etuahod4f4c112016-04-15 15:11:24 +03001950 const std::string vertexShaderSource =
1951 "#version 300 es\n"
1952 "precision highp float;\n"
1953 "in vec4 a_vec;\n"
1954 "void main()\n"
1955 "{\n"
1956 " gl_Position = vec4(a_vec);\n"
1957 "}";
1958
1959 const std::string fragmentShaderSource =
1960 "#version 300 es\n"
1961 "precision highp float;\n"
1962 "out vec4 my_FragColor;\n"
1963 "const highp float f[2] = float[2](0.1, 0.2);\n"
1964 "const highp float[2] g = float[2](0.3, 0.4), h = float[2](0.5, f[1]);\n"
1965 "void main()\n"
1966 "{\n"
1967 " my_FragColor = vec4(h[1]);\n"
1968 "}";
1969
1970 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
1971 EXPECT_NE(0u, program);
1972}
1973
Corentin Wallez419bfc92016-06-28 10:54:45 -07001974// Test that index-constant sampler array indexing is supported.
1975TEST_P(GLSLTest, IndexConstantSamplerArrayIndexing)
1976{
1977 if (IsD3D11_FL93()) {
1978 std::cout << "Test skipped on D3D11 FL 9.3." << std::endl;
1979 return;
1980 }
1981
1982 const std::string vertexShaderSource =
1983 "attribute vec4 vPosition;\n"
1984 "void main()\n"
1985 "{\n"
1986 " gl_Position = vPosition;\n"
1987 "}";
1988
1989 const std::string fragmentShaderSource =
1990 "precision mediump float;\n"
1991 "uniform sampler2D uni[2];\n"
1992 "\n"
1993 "float zero(int x)\n"
1994 "{\n"
1995 " return float(x) - float(x);\n"
1996 "}\n"
1997 "\n"
1998 "void main()\n"
1999 "{\n"
2000 " vec4 c = vec4(0,0,0,0);\n"
2001 " for (int ii = 1; ii < 3; ++ii) {\n"
2002 " if (c.x > 255.0) {\n"
2003 " c.x = 255.0 + zero(ii);\n"
2004 " break;\n"
2005 " }\n"
2006 // Index the sampler array with a predictable loop index (index-constant) as opposed to
2007 // a true constant. This is valid in OpenGL ES but isn't in many Desktop OpenGL versions,
2008 // without an extension.
2009 " c += texture2D(uni[ii - 1], vec2(0.5, 0.5));\n"
2010 " }\n"
2011 " gl_FragColor = c;\n"
2012 "}";
2013
2014 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
2015 EXPECT_NE(0u, program);
2016}
2017
Corentin Wallezb00dcee2016-07-11 17:42:58 -04002018// Test that the #pragma directive is supported and doesn't trigger a compilation failure on the
2019// native driver. The only pragma that gets passed to the OpenGL driver is "invariant" but we don't
2020// want to test its behavior, so don't use any varyings.
2021TEST_P(GLSLTest, PragmaDirective)
2022{
2023 const std::string vertexShaderSource =
2024 "#pragma STDGL invariant(all)\n"
2025 "void main()\n"
2026 "{\n"
2027 " gl_Position = vec4(1.0, 0.0, 0.0, 1.0);\n"
2028 "}\n";
2029
2030 const std::string fragmentShaderSource =
2031 "precision mediump float;\n"
2032 "void main()\n"
2033 "{\n"
2034 " gl_FragColor = vec4(1.0);\n"
2035 "}\n";
2036
2037 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
2038 EXPECT_NE(0u, program);
2039}
2040
Olli Etuahoe1d199b2016-07-19 17:14:27 +03002041// Sequence operator evaluates operands from left to right (ESSL 3.00 section 5.9).
2042// The function call that returns the array needs to be evaluated after ++j for the expression to
2043// return the correct value (true).
2044TEST_P(GLSLTest_ES3, SequenceOperatorEvaluationOrderArray)
2045{
2046 const std::string &fragmentShaderSource =
2047 "#version 300 es\n"
2048 "precision mediump float;\n"
2049 "out vec4 my_FragColor; \n"
2050 "int[2] func(int param) {\n"
2051 " return int[2](param, param);\n"
2052 "}\n"
2053 "void main() {\n"
2054 " int a[2]; \n"
2055 " for (int i = 0; i < 2; ++i) {\n"
2056 " a[i] = 1;\n"
2057 " }\n"
2058 " int j = 0; \n"
2059 " bool result = ((++j), (a == func(j)));\n"
2060 " my_FragColor = vec4(0.0, (result ? 1.0 : 0.0), 0.0, 1.0);\n"
2061 "}\n";
2062
2063 GLuint program = CompileProgram(mSimpleVSSource, fragmentShaderSource);
2064 ASSERT_NE(0u, program);
2065
2066 drawQuad(program, "inputAttribute", 0.5f);
2067
2068 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2069}
2070
2071// Sequence operator evaluates operands from left to right (ESSL 3.00 section 5.9).
2072// The short-circuiting expression needs to be evaluated after ++j for the expression to return the
2073// correct value (true).
2074TEST_P(GLSLTest_ES3, SequenceOperatorEvaluationOrderShortCircuit)
2075{
2076 const std::string &fragmentShaderSource =
2077 "#version 300 es\n"
2078 "precision mediump float;\n"
2079 "out vec4 my_FragColor; \n"
2080 "void main() {\n"
2081 " int j = 0; \n"
2082 " bool result = ((++j), (j == 1 ? true : (++j == 3)));\n"
2083 " my_FragColor = vec4(0.0, ((result && j == 1) ? 1.0 : 0.0), 0.0, 1.0);\n"
2084 "}\n";
2085
2086 GLuint program = CompileProgram(mSimpleVSSource, fragmentShaderSource);
2087 ASSERT_NE(0u, program);
2088
2089 drawQuad(program, "inputAttribute", 0.5f);
2090
2091 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2092}
2093
Jamie Madill666f65a2016-08-26 01:34:37 +00002094// Sequence operator evaluates operands from left to right (ESSL 3.00 section 5.9).
2095// Indexing the vector needs to be evaluated after func() for the right result.
2096TEST_P(GLSLTest_ES3, SequenceOperatorEvaluationOrderDynamicVectorIndexingInLValue)
2097{
2098 const std::string &fragmentShaderSource =
2099 "#version 300 es\n"
2100 "precision mediump float;\n"
2101 "out vec4 my_FragColor;\n"
2102 "uniform int u_zero;\n"
2103 "int sideEffectCount = 0;\n"
2104 "float func() {\n"
2105 " ++sideEffectCount;\n"
2106 " return -1.0;\n"
2107 "}\n"
2108 "void main() {\n"
2109 " vec4 v = vec4(0.0, 2.0, 4.0, 6.0); \n"
2110 " float f = (func(), (++v[u_zero + sideEffectCount]));\n"
2111 " bool green = abs(f - 3.0) < 0.01 && abs(v[1] - 3.0) < 0.01 && sideEffectCount == 1;\n"
2112 " my_FragColor = vec4(0.0, (green ? 1.0 : 0.0), 0.0, 1.0);\n"
2113 "}\n";
2114
2115 GLuint program = CompileProgram(mSimpleVSSource, fragmentShaderSource);
2116 ASSERT_NE(0u, program);
2117
2118 drawQuad(program, "inputAttribute", 0.5f);
2119
2120 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2121}
2122
Jamie Madillc9bde922016-07-24 17:58:50 -04002123// Test that using gl_PointCoord with GL_TRIANGLES doesn't produce a link error.
2124// From WebGL test conformance/rendering/point-specific-shader-variables.html
2125// See http://anglebug.com/1380
2126TEST_P(GLSLTest, RenderTrisWithPointCoord)
2127{
2128 const std::string &vert =
2129 "attribute vec2 aPosition;\n"
2130 "void main()\n"
2131 "{\n"
2132 " gl_Position = vec4(aPosition, 0, 1);\n"
2133 " gl_PointSize = 1.0;\n"
2134 "}";
2135 const std::string &frag =
2136 "void main()\n"
2137 "{\n"
2138 " gl_FragColor = vec4(gl_PointCoord.xy, 0, 1);\n"
2139 " gl_FragColor = vec4(0, 1, 0, 1);\n"
2140 "}";
2141
2142 ANGLE_GL_PROGRAM(prog, vert, frag);
2143 drawQuad(prog.get(), "aPosition", 0.5f);
2144 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2145}
2146
Jamie Madill5655b842016-08-02 11:00:07 -04002147// Convers a bug with the integer pow statement workaround.
2148TEST_P(GLSLTest, NestedPowStatements)
2149{
2150 const std::string &vert =
2151 "attribute vec2 position;\n"
2152 "void main()\n"
2153 "{\n"
2154 " gl_Position = vec4(position, 0, 1);\n"
2155 "}";
2156 const std::string &frag =
2157 "precision mediump float;\n"
2158 "float func(float v)\n"
2159 "{\n"
2160 " float f1 = pow(v, 2.0);\n"
2161 " return pow(f1 + v, 2.0);\n"
2162 "}\n"
2163 "void main()\n"
2164 "{\n"
2165 " float v = func(2.0);\n"
2166 " gl_FragColor = abs(v - 36.0) < 0.001 ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);\n"
2167 "}";
2168
2169 ANGLE_GL_PROGRAM(prog, vert, frag);
2170 drawQuad(prog.get(), "position", 0.5f);
2171 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2172}
2173
Qiankun Miaof52fe932016-12-07 13:39:15 +08002174// Test that -float calculation is correct.
2175TEST_P(GLSLTest_ES3, UnaryMinusOperatorFloat)
2176{
Qiankun Miaof52fe932016-12-07 13:39:15 +08002177 const std::string &vert =
2178 "#version 300 es\n"
2179 "in highp vec4 position;\n"
2180 "void main() {\n"
2181 " gl_Position = position;\n"
2182 "}\n";
2183 const std::string &frag =
2184 "#version 300 es\n"
2185 "out highp vec4 o_color;\n"
2186 "void main() {\n"
2187 " highp float f = -1.0;\n"
2188 " // atan(tan(0.5), -f) should be 0.5.\n"
2189 " highp float v = atan(tan(0.5), -f);\n"
2190 " o_color = abs(v - 0.5) < 0.001 ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);\n"
2191 "}\n";
2192
2193 ANGLE_GL_PROGRAM(prog, vert, frag);
2194 drawQuad(prog.get(), "position", 0.5f);
2195 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2196}
2197
Olli Etuahoda9fb092016-12-09 17:32:29 +00002198// Test that atan(vec2, vec2) calculation is correct.
2199TEST_P(GLSLTest_ES3, AtanVec2)
2200{
2201 const std::string &vert =
2202 "#version 300 es\n"
2203 "in highp vec4 position;\n"
2204 "void main() {\n"
2205 " gl_Position = position;\n"
2206 "}\n";
2207 const std::string &frag =
2208 "#version 300 es\n"
2209 "out highp vec4 o_color;\n"
2210 "void main() {\n"
2211 " highp float f = 1.0;\n"
2212 " // atan(tan(0.5), f) should be 0.5.\n"
2213 " highp vec2 v = atan(vec2(tan(0.5)), vec2(f));\n"
2214 " o_color = (abs(v[0] - 0.5) < 0.001 && abs(v[1] - 0.5) < 0.001) ? vec4(0, 1, 0, 1) : "
2215 "vec4(1, 0, 0, 1);\n"
2216 "}\n";
2217
2218 ANGLE_GL_PROGRAM(prog, vert, frag);
2219 drawQuad(prog.get(), "position", 0.5f);
2220 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2221}
2222
Jiawei-Shaoe292e902016-09-07 10:49:01 +08002223// Convers a bug with the unary minus operator on signed integer workaround.
2224TEST_P(GLSLTest_ES3, UnaryMinusOperatorSignedInt)
2225{
2226 const std::string &vert =
2227 "#version 300 es\n"
2228 "in highp vec4 position;\n"
2229 "out mediump vec4 v_color;\n"
2230 "uniform int ui_one;\n"
2231 "uniform int ui_two;\n"
2232 "uniform int ui_three;\n"
2233 "void main() {\n"
2234 " int s[3];\n"
2235 " s[0] = ui_one;\n"
2236 " s[1] = -(-(-ui_two + 1) + 1);\n" // s[1] = -ui_two
2237 " s[2] = ui_three;\n"
2238 " int result = 0;\n"
2239 " for (int i = 0; i < ui_three; i++) {\n"
2240 " result += s[i];\n"
2241 " }\n"
2242 " v_color = (result == 2) ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);\n"
2243 " gl_Position = position;\n"
2244 "}\n";
2245 const std::string &frag =
2246 "#version 300 es\n"
2247 "in mediump vec4 v_color;\n"
2248 "layout(location=0) out mediump vec4 o_color;\n"
2249 "void main() {\n"
2250 " o_color = v_color;\n"
2251 "}\n";
2252
2253 ANGLE_GL_PROGRAM(prog, vert, frag);
2254
Jamie Madille1faacb2016-12-13 12:42:14 -05002255 GLint oneIndex = glGetUniformLocation(prog.get(), "ui_one");
Jiawei-Shaoe292e902016-09-07 10:49:01 +08002256 ASSERT_NE(-1, oneIndex);
Jamie Madille1faacb2016-12-13 12:42:14 -05002257 GLint twoIndex = glGetUniformLocation(prog.get(), "ui_two");
Jiawei-Shaoe292e902016-09-07 10:49:01 +08002258 ASSERT_NE(-1, twoIndex);
Jamie Madille1faacb2016-12-13 12:42:14 -05002259 GLint threeIndex = glGetUniformLocation(prog.get(), "ui_three");
Jiawei-Shaoe292e902016-09-07 10:49:01 +08002260 ASSERT_NE(-1, threeIndex);
2261 glUseProgram(prog.get());
2262 glUniform1i(oneIndex, 1);
2263 glUniform1i(twoIndex, 2);
2264 glUniform1i(threeIndex, 3);
2265
2266 drawQuad(prog.get(), "position", 0.5f);
2267 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2268}
2269
2270// Convers a bug with the unary minus operator on unsigned integer workaround.
2271TEST_P(GLSLTest_ES3, UnaryMinusOperatorUnsignedInt)
2272{
2273 const std::string &vert =
2274 "#version 300 es\n"
2275 "in highp vec4 position;\n"
2276 "out mediump vec4 v_color;\n"
2277 "uniform uint ui_one;\n"
2278 "uniform uint ui_two;\n"
2279 "uniform uint ui_three;\n"
2280 "void main() {\n"
2281 " uint s[3];\n"
2282 " s[0] = ui_one;\n"
2283 " s[1] = -(-(-ui_two + 1u) + 1u);\n" // s[1] = -ui_two
2284 " s[2] = ui_three;\n"
2285 " uint result = 0u;\n"
2286 " for (uint i = 0u; i < ui_three; i++) {\n"
2287 " result += s[i];\n"
2288 " }\n"
2289 " v_color = (result == 2u) ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);\n"
2290 " gl_Position = position;\n"
2291 "}\n";
2292 const std::string &frag =
2293 "#version 300 es\n"
2294 "in mediump vec4 v_color;\n"
2295 "layout(location=0) out mediump vec4 o_color;\n"
2296 "void main() {\n"
2297 " o_color = v_color;\n"
2298 "}\n";
2299
2300 ANGLE_GL_PROGRAM(prog, vert, frag);
2301
Jamie Madille1faacb2016-12-13 12:42:14 -05002302 GLint oneIndex = glGetUniformLocation(prog.get(), "ui_one");
Jiawei-Shaoe292e902016-09-07 10:49:01 +08002303 ASSERT_NE(-1, oneIndex);
Jamie Madille1faacb2016-12-13 12:42:14 -05002304 GLint twoIndex = glGetUniformLocation(prog.get(), "ui_two");
Jiawei-Shaoe292e902016-09-07 10:49:01 +08002305 ASSERT_NE(-1, twoIndex);
Jamie Madille1faacb2016-12-13 12:42:14 -05002306 GLint threeIndex = glGetUniformLocation(prog.get(), "ui_three");
Jiawei-Shaoe292e902016-09-07 10:49:01 +08002307 ASSERT_NE(-1, threeIndex);
2308 glUseProgram(prog.get());
2309 glUniform1ui(oneIndex, 1u);
2310 glUniform1ui(twoIndex, 2u);
2311 glUniform1ui(threeIndex, 3u);
2312
2313 drawQuad(prog.get(), "position", 0.5f);
2314 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2315}
2316
Olli Etuahoab481642016-08-26 12:09:10 +03002317// Test a nested sequence operator with a ternary operator inside. The ternary operator is
2318// intended to be such that it gets converted to an if statement on the HLSL backend.
2319TEST_P(GLSLTest, NestedSequenceOperatorWithTernaryInside)
2320{
2321 const std::string &vert =
2322 "attribute vec2 position;\n"
2323 "void main()\n"
2324 "{\n"
2325 " gl_Position = vec4(position, 0, 1);\n"
2326 "}";
2327
2328 // Note that the uniform keep_flop_positive doesn't need to be set - the test expects it to have
2329 // its default value false.
2330 const std::string &frag =
2331 "precision mediump float;\n"
2332 "uniform bool keep_flop_positive;\n"
2333 "float flop;\n"
2334 "void main() {\n"
2335 " flop = -1.0,\n"
2336 " (flop *= -1.0,\n"
2337 " keep_flop_positive ? 0.0 : flop *= -1.0),\n"
2338 " gl_FragColor = vec4(0, -flop, 0, 1);\n"
2339 "}";
2340
2341 ANGLE_GL_PROGRAM(prog, vert, frag);
2342 drawQuad(prog.get(), "position", 0.5f);
2343 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2344}
2345
Geoff Lang28a97ee2016-09-22 13:01:26 -04002346// Test that using a sampler2D and samplerExternalOES in the same shader works (anglebug.com/1534)
2347TEST_P(GLSLTest, ExternalAnd2DSampler)
2348{
2349 if (!extensionEnabled("GL_OES_EGL_image_external"))
2350 {
2351 std::cout << "Test skipped because GL_OES_EGL_image_external is not available."
2352 << std::endl;
2353 return;
2354 }
2355
2356 const std::string fragmentShader =
2357 "precision mediump float;\n"
2358 "uniform samplerExternalOES tex0;\n"
2359 "uniform sampler2D tex1;\n"
2360 "void main(void)\n"
2361 "{\n"
2362 " vec2 uv = vec2(0.0, 0.0);"
2363 " gl_FragColor = texture2D(tex0, uv) + texture2D(tex1, uv);\n"
2364 "}\n";
2365
2366 ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader);
2367}
2368
Jamie Madill44ebf6b2016-09-22 13:00:02 -04002369// Test that using an invalid constant right-shift produces an error.
2370TEST_P(GLSLTest_ES3, FoldedInvalidRightShift)
2371{
2372 const std::string &fragmentShader =
2373 "#version 300 es\n"
2374 "precision mediump float;\n"
2375 "out vec4 color;\n"
2376 "void main(void)\n"
2377 "{\n"
2378 " int diff = -100 >> -100;\n"
2379 " color = vec4(float(diff));\n"
2380 "}\n";
2381
2382 GLuint program = CompileProgram(mSimpleVSSource, fragmentShader);
2383 EXPECT_EQ(0u, program);
2384 glDeleteProgram(program);
2385}
2386
2387// Test that using an invalid constant left-shift produces an error.
2388TEST_P(GLSLTest_ES3, FoldedInvalidLeftShift)
2389{
2390 const std::string &fragmentShader =
2391 "#version 300 es\n"
2392 "precision mediump float;\n"
2393 "out vec4 color;\n"
2394 "void main(void)\n"
2395 "{\n"
2396 " int diff = -100 << -100;\n"
2397 " color = vec4(float(diff));\n"
2398 "}\n";
2399
2400 GLuint program = CompileProgram(mSimpleVSSource, fragmentShader);
2401 EXPECT_EQ(0u, program);
2402 glDeleteProgram(program);
2403}
2404
Olli Etuaho56a2f952016-12-08 12:16:27 +00002405// Test that literal infinity can be written out from the shader translator.
2406// A similar test can't be made for NaNs, since ESSL 3.00.6 requirements for NaNs are very loose.
2407TEST_P(GLSLTest_ES3, LiteralInfinityOutput)
2408{
2409 const std::string &fragmentShader =
2410 "#version 300 es\n"
2411 "precision highp float;\n"
2412 "out vec4 out_color;\n"
2413 "uniform float u;\n"
2414 "void main()\n"
2415 "{\n"
2416 " float infVar = 1.0e40 - u;\n"
2417 " bool correct = isinf(infVar) && infVar > 0.0;\n"
2418 " out_color = correct ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(1.0, 0.0, 0.0, 1.0);\n"
2419 "}\n";
2420
2421 ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader);
2422 drawQuad(program.get(), "inputAttribute", 0.5f);
2423 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2424}
2425
2426// Test that literal negative infinity can be written out from the shader translator.
2427// A similar test can't be made for NaNs, since ESSL 3.00.6 requirements for NaNs are very loose.
2428TEST_P(GLSLTest_ES3, LiteralNegativeInfinityOutput)
2429{
2430 const std::string &fragmentShader =
2431 "#version 300 es\n"
2432 "precision highp float;\n"
2433 "out vec4 out_color;\n"
2434 "uniform float u;\n"
2435 "void main()\n"
2436 "{\n"
2437 " float infVar = -1.0e40 + u;\n"
2438 " bool correct = isinf(infVar) && infVar < 0.0;\n"
2439 " out_color = correct ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(1.0, 0.0, 0.0, 1.0);\n"
2440 "}\n";
2441
2442 ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader);
2443 drawQuad(program.get(), "inputAttribute", 0.5f);
2444 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2445}
2446
Corentin Wallez36fd1002016-12-08 11:30:44 -05002447// The following MultipleDeclaration* tests are testing TranslatorHLSL specific simplification
2448// passes. Because the interaction of multiple passes must be tested, it is difficult to write
2449// a unittest for them. Instead we add the tests as end2end so will in particular test
2450// TranslatorHLSL when run on Windows.
2451
2452// Test that passes splitting multiple declarations and comma operators are correctly ordered.
2453TEST_P(GLSLTest_ES3, MultipleDeclarationWithCommaOperator)
2454{
2455 const std::string &fragmentShader =
2456 "#version 300 es\n"
2457 "precision mediump float;\n"
2458 "out vec4 color;\n"
2459 "void main(void)\n"
2460 "{\n"
2461 " float a = 0.0, b = ((gl_FragCoord.x < 0.5 ? a : 0.0), 1.0);\n"
2462 " color = vec4(b);\n"
2463 "}\n";
2464
2465 ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader);
2466}
2467
2468// Test that passes splitting multiple declarations and comma operators and for loops are
2469// correctly ordered.
2470TEST_P(GLSLTest_ES3, MultipleDeclarationWithCommaOperatorInForLoop)
2471{
2472 const std::string &fragmentShader =
2473 "#version 300 es\n"
2474 "precision mediump float;\n"
2475 "out vec4 color;\n"
2476 "void main(void)\n"
2477 "{\n"
2478 " for(float a = 0.0, b = ((gl_FragCoord.x < 0.5 ? a : 0.0), 1.0); a < 10.0; a++)\n"
2479 " {\n"
2480 " b += 1.0;\n"
2481 " color = vec4(b);\n"
2482 " }\n"
2483 "}\n";
2484
2485 ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader);
2486}
2487
2488// Test that splitting multiple declaration in for loops works with no loop condition
2489TEST_P(GLSLTest_ES3, MultipleDeclarationInForLoopEmptyCondition)
2490{
2491 const std::string &fragmentShader =
2492 "#version 300 es\n"
2493 "precision mediump float;\n"
2494 "out vec4 color;\n"
2495 "void main(void)\n"
2496 "{\n"
2497 " for(float a = 0.0, b = 1.0;; a++)\n"
2498 " {\n"
2499 " b += 1.0;\n"
2500 " if (a > 10.0) {break;}\n"
2501 " color = vec4(b);\n"
2502 " }\n"
2503 "}\n";
2504
2505 ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader);
2506}
2507
2508// Test that splitting multiple declaration in for loops works with no loop expression
2509TEST_P(GLSLTest_ES3, MultipleDeclarationInForLoopEmptyExpression)
2510{
2511 const std::string &fragmentShader =
2512 "#version 300 es\n"
2513 "precision mediump float;\n"
2514 "out vec4 color;\n"
2515 "void main(void)\n"
2516 "{\n"
2517 " for(float a = 0.0, b = 1.0; a < 10.0;)\n"
2518 " {\n"
2519 " b += 1.0;\n"
2520 " a += 1.0;\n"
2521 " color = vec4(b);\n"
2522 " }\n"
2523 "}\n";
2524
2525 ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader);
2526}
2527
Jamie Madill192745a2016-12-22 15:58:21 -05002528class WebGLGLSLTest : public GLSLTest
2529{
2530 protected:
2531 WebGLGLSLTest() { setWebGLCompatibilityEnabled(true); }
2532};
2533
2534TEST_P(WebGLGLSLTest, MaxVaryingVec4PlusFragCoord)
2535{
2536 GLint maxVaryings = 0;
2537 glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings);
2538
2539 // Generate shader code that uses gl_FragCoord, a special fragment shader variables.
2540 // This test should fail, since we are really using (maxVaryings + 1) varyings.
2541 VaryingTestBase(0, 0, 0, 0, 0, 0, maxVaryings, 0, true, false, false, false);
2542}
2543
2544TEST_P(WebGLGLSLTest, MaxVaryingVec4PlusPointCoord)
2545{
2546 GLint maxVaryings = 0;
2547 glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings);
2548
2549 // Generate shader code that uses gl_FragCoord, a special fragment shader variables.
2550 // This test should fail, since we are really using (maxVaryings + 1) varyings.
2551 VaryingTestBase(0, 0, 0, 0, 0, 0, maxVaryings, 0, false, true, false, false);
2552}
2553
2554TEST_P(WebGLGLSLTest, MaxPlusOneVaryingVec3)
2555{
2556 GLint maxVaryings = 0;
2557 glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings);
2558
2559 VaryingTestBase(0, 0, 0, 0, maxVaryings + 1, 0, 0, 0, false, false, false, false);
2560}
2561
2562TEST_P(WebGLGLSLTest, MaxPlusOneVaryingVec3Array)
2563{
2564 GLint maxVaryings = 0;
2565 glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings);
2566
2567 VaryingTestBase(0, 0, 0, 0, 0, maxVaryings / 2 + 1, 0, 0, false, false, false, false);
2568}
2569
2570TEST_P(WebGLGLSLTest, MaxVaryingVec3AndOneVec2)
2571{
2572 GLint maxVaryings = 0;
2573 glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings);
2574
2575 VaryingTestBase(0, 0, 1, 0, maxVaryings, 0, 0, 0, false, false, false, false);
2576}
2577
2578TEST_P(WebGLGLSLTest, MaxPlusOneVaryingVec2)
2579{
2580 GLint maxVaryings = 0;
2581 glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings);
2582
2583 VaryingTestBase(0, 0, 2 * maxVaryings + 1, 0, 0, 0, 0, 0, false, false, false, false);
2584}
2585
2586TEST_P(WebGLGLSLTest, MaxVaryingVec3ArrayAndMaxPlusOneFloatArray)
2587{
2588 GLint maxVaryings = 0;
2589 glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings);
2590
2591 VaryingTestBase(0, maxVaryings / 2 + 1, 0, 0, 0, 0, 0, maxVaryings / 2, false, false, false,
2592 false);
2593}
2594
Jamie Madill6c9503e2016-08-16 14:06:32 -04002595} // anonymous namespace
2596
Jamie Madillfa05f602015-05-07 13:47:11 -04002597// Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
Geoff Lange0cc2a42016-01-20 10:58:17 -05002598ANGLE_INSTANTIATE_TEST(GLSLTest,
2599 ES2_D3D9(),
2600 ES2_D3D11(),
2601 ES2_D3D11_FL9_3(),
2602 ES2_OPENGL(),
2603 ES3_OPENGL(),
2604 ES2_OPENGLES(),
2605 ES3_OPENGLES());
Jamie Madillfa05f602015-05-07 13:47:11 -04002606
2607// Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
Geoff Lange0cc2a42016-01-20 10:58:17 -05002608ANGLE_INSTANTIATE_TEST(GLSLTest_ES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Jamie Madill192745a2016-12-22 15:58:21 -05002609
2610ANGLE_INSTANTIATE_TEST(WebGLGLSLTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES());