blob: d24253ae7c198dcedff458da4e8cc8f2ebe8e279 [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{
Zhenyao Mo1a256722017-01-12 11:52:57 -08001710 if (IsLinux() && IsIntel())
1711 {
1712 std::cout << "Test timed out on Linux Intel. See crbug.com/680631." << std::endl;
1713 return;
1714 }
1715
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001716 int maxUniforms = 10000;
1717 glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, &maxUniforms);
1718 EXPECT_GL_NO_ERROR();
1719 std::cout << "Validating GL_MAX_VERTEX_UNIFORM_VECTORS = " << maxUniforms << std::endl;
1720
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001721 CompileGLSLWithUniformsAndSamplers(maxUniforms, 0, 0, 0, true);
1722}
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001723
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001724// Tests that the maximum uniforms count returned from querying GL_MAX_VERTEX_UNIFORM_VECTORS
1725// can actually be used along with the maximum number of texture samplers.
1726TEST_P(GLSLTest, VerifyMaxVertexUniformVectorsWithSamplers)
1727{
Geoff Lange0cc2a42016-01-20 10:58:17 -05001728 if (GetParam().eglParameters.renderer == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE ||
1729 GetParam().eglParameters.renderer == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE)
1730 {
1731 std::cout << "Test disabled on OpenGL." << std::endl;
1732 return;
1733 }
1734
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001735 int maxUniforms = 10000;
1736 glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, &maxUniforms);
1737 EXPECT_GL_NO_ERROR();
1738 std::cout << "Validating GL_MAX_VERTEX_UNIFORM_VECTORS = " << maxUniforms << std::endl;
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001739
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001740 int maxTextureImageUnits = 0;
1741 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &maxTextureImageUnits);
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001742
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001743 CompileGLSLWithUniformsAndSamplers(maxUniforms, 0, maxTextureImageUnits, 0, true);
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001744}
1745
1746// Tests that the maximum uniforms count + 1 from querying GL_MAX_VERTEX_UNIFORM_VECTORS
1747// fails shader compilation.
1748TEST_P(GLSLTest, VerifyMaxVertexUniformVectorsExceeded)
1749{
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001750 int maxUniforms = 10000;
1751 glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, &maxUniforms);
1752 EXPECT_GL_NO_ERROR();
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001753 std::cout << "Validating GL_MAX_VERTEX_UNIFORM_VECTORS + 1 = " << maxUniforms + 1 << std::endl;
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001754
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001755 CompileGLSLWithUniformsAndSamplers(maxUniforms + 1, 0, 0, 0, false);
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001756}
1757
1758// Tests that the maximum uniforms count returned from querying GL_MAX_FRAGMENT_UNIFORM_VECTORS
1759// can actually be used.
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001760TEST_P(GLSLTest, VerifyMaxFragmentUniformVectors)
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001761{
Zhenyao Mo1a256722017-01-12 11:52:57 -08001762 if (IsLinux() && IsIntel())
1763 {
1764 std::cout << "Test timed out on Linux Intel. See crbug.com/680631." << std::endl;
1765 return;
1766 }
1767
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001768 int maxUniforms = 10000;
1769 glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, &maxUniforms);
1770 EXPECT_GL_NO_ERROR();
1771 std::cout << "Validating GL_MAX_FRAGMENT_UNIFORM_VECTORS = " << maxUniforms << std::endl;
1772
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001773 CompileGLSLWithUniformsAndSamplers(0, maxUniforms, 0, 0, true);
1774}
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001775
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001776// Tests that the maximum uniforms count returned from querying GL_MAX_FRAGMENT_UNIFORM_VECTORS
1777// can actually be used along with the maximum number of texture samplers.
1778TEST_P(GLSLTest, VerifyMaxFragmentUniformVectorsWithSamplers)
1779{
Geoff Lange0cc2a42016-01-20 10:58:17 -05001780 if (GetParam().eglParameters.renderer == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE ||
1781 GetParam().eglParameters.renderer == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE)
1782 {
1783 std::cout << "Test disabled on OpenGL." << std::endl;
1784 return;
1785 }
1786
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001787 int maxUniforms = 10000;
1788 glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, &maxUniforms);
1789 EXPECT_GL_NO_ERROR();
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001790
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001791 int maxTextureImageUnits = 0;
1792 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureImageUnits);
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001793
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001794 CompileGLSLWithUniformsAndSamplers(0, maxUniforms, 0, maxTextureImageUnits, true);
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001795}
1796
1797// Tests that the maximum uniforms count + 1 from querying GL_MAX_FRAGMENT_UNIFORM_VECTORS
1798// fails shader compilation.
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001799TEST_P(GLSLTest, VerifyMaxFragmentUniformVectorsExceeded)
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001800{
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001801 int maxUniforms = 10000;
1802 glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, &maxUniforms);
1803 EXPECT_GL_NO_ERROR();
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001804 std::cout << "Validating GL_MAX_FRAGMENT_UNIFORM_VECTORS + 1 = " << maxUniforms + 1
1805 << std::endl;
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001806
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001807 CompileGLSLWithUniformsAndSamplers(0, maxUniforms + 1, 0, 0, false);
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001808}
1809
Olli Etuahobe59c2f2016-03-07 11:32:34 +02001810// Test that two constructors which have vec4 and mat2 parameters get disambiguated (issue in
1811// HLSL).
1812TEST_P(GLSLTest_ES3, AmbiguousConstructorCall2x2)
1813{
1814 const std::string fragmentShaderSource =
1815 "#version 300 es\n"
1816 "precision highp float;\n"
1817 "out vec4 my_FragColor;\n"
1818 "void main()\n"
1819 "{\n"
1820 " my_FragColor = vec4(0.0);\n"
1821 "}";
1822
1823 const std::string vertexShaderSource =
1824 "#version 300 es\n"
1825 "precision highp float;\n"
1826 "in vec4 a_vec;\n"
1827 "in mat2 a_mat;\n"
1828 "void main()\n"
1829 "{\n"
1830 " gl_Position = vec4(a_vec) + vec4(a_mat);\n"
1831 "}";
1832
1833 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
1834 EXPECT_NE(0u, program);
1835}
1836
1837// Test that two constructors which have mat2x3 and mat3x2 parameters get disambiguated.
1838// This was suspected to be an issue in HLSL, but HLSL seems to be able to natively choose between
1839// the function signatures in this case.
1840TEST_P(GLSLTest_ES3, AmbiguousConstructorCall2x3)
1841{
1842 const std::string fragmentShaderSource =
1843 "#version 300 es\n"
1844 "precision highp float;\n"
1845 "out vec4 my_FragColor;\n"
1846 "void main()\n"
1847 "{\n"
1848 " my_FragColor = vec4(0.0);\n"
1849 "}";
1850
1851 const std::string vertexShaderSource =
1852 "#version 300 es\n"
1853 "precision highp float;\n"
1854 "in mat3x2 a_matA;\n"
1855 "in mat2x3 a_matB;\n"
1856 "void main()\n"
1857 "{\n"
1858 " gl_Position = vec4(a_matA) + vec4(a_matB);\n"
1859 "}";
1860
1861 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
1862 EXPECT_NE(0u, program);
1863}
1864
1865// Test that two functions which have vec4 and mat2 parameters get disambiguated (issue in HLSL).
1866TEST_P(GLSLTest_ES3, AmbiguousFunctionCall2x2)
1867{
1868 const std::string fragmentShaderSource =
1869 "#version 300 es\n"
1870 "precision highp float;\n"
1871 "out vec4 my_FragColor;\n"
1872 "void main()\n"
1873 "{\n"
1874 " my_FragColor = vec4(0.0);\n"
1875 "}";
1876
1877 const std::string vertexShaderSource =
1878 "#version 300 es\n"
1879 "precision highp float;\n"
1880 "in vec4 a_vec;\n"
1881 "in mat2 a_mat;\n"
1882 "vec4 foo(vec4 a)\n"
1883 "{\n"
1884 " return a;\n"
1885 "}\n"
1886 "vec4 foo(mat2 a)\n"
1887 "{\n"
1888 " return vec4(a[0][0]);\n"
1889 "}\n"
1890 "void main()\n"
1891 "{\n"
1892 " gl_Position = foo(a_vec) + foo(a_mat);\n"
1893 "}";
1894
1895 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
1896 EXPECT_NE(0u, program);
1897}
1898
1899// Test that an user-defined function with a large number of float4 parameters doesn't fail due to
1900// the function name being too long.
1901TEST_P(GLSLTest_ES3, LargeNumberOfFloat4Parameters)
1902{
1903 const std::string fragmentShaderSource =
1904 "#version 300 es\n"
1905 "precision highp float;\n"
1906 "out vec4 my_FragColor;\n"
1907 "void main()\n"
1908 "{\n"
1909 " my_FragColor = vec4(0.0);\n"
1910 "}";
1911
1912 std::stringstream vertexShaderStream;
1913 const unsigned int paramCount = 1024u;
1914
1915 vertexShaderStream << "#version 300 es\n"
1916 "precision highp float;\n"
1917 "in vec4 a_vec;\n"
1918 "vec4 lotsOfVec4Parameters(";
1919 for (unsigned int i = 0; i < paramCount; ++i)
1920 {
1921 vertexShaderStream << "vec4 a" << i << ", ";
1922 }
1923 vertexShaderStream << "vec4 aLast)\n"
1924 "{\n"
1925 " return ";
1926 for (unsigned int i = 0; i < paramCount; ++i)
1927 {
1928 vertexShaderStream << "a" << i << " + ";
1929 }
1930 vertexShaderStream << "aLast;\n"
1931 "}\n"
1932 "void main()\n"
1933 "{\n"
1934 " gl_Position = lotsOfVec4Parameters(";
1935 for (unsigned int i = 0; i < paramCount; ++i)
1936 {
1937 vertexShaderStream << "a_vec, ";
1938 }
1939 vertexShaderStream << "a_vec);\n"
1940 "}";
1941
1942 GLuint program = CompileProgram(vertexShaderStream.str(), fragmentShaderSource);
1943 EXPECT_NE(0u, program);
1944}
1945
Olli Etuahod4f4c112016-04-15 15:11:24 +03001946// This test was written specifically to stress DeferGlobalInitializers AST transformation.
1947// Test a shader where a global constant array is initialized with an expression containing array
1948// indexing. This initializer is tricky to constant fold, so if it's not constant folded it needs to
1949// be handled in a way that doesn't generate statements in the global scope in HLSL output.
1950// Also includes multiple array initializers in one declaration, where only the second one has
1951// array indexing. This makes sure that the qualifier for the declaration is set correctly if
1952// transformations are applied to the declaration also in the case of ESSL output.
1953TEST_P(GLSLTest_ES3, InitGlobalArrayWithArrayIndexing)
1954{
Yuly Novikov41db2242016-06-25 00:14:28 -04001955 // TODO(ynovikov): re-enable once root cause of http://anglebug.com/1428 is fixed
1956 if (IsAndroid() && IsAdreno() && IsOpenGLES())
1957 {
1958 std::cout << "Test skipped on Adreno OpenGLES on Android." << std::endl;
1959 return;
1960 }
1961
Olli Etuahod4f4c112016-04-15 15:11:24 +03001962 const std::string vertexShaderSource =
1963 "#version 300 es\n"
1964 "precision highp float;\n"
1965 "in vec4 a_vec;\n"
1966 "void main()\n"
1967 "{\n"
1968 " gl_Position = vec4(a_vec);\n"
1969 "}";
1970
1971 const std::string fragmentShaderSource =
1972 "#version 300 es\n"
1973 "precision highp float;\n"
1974 "out vec4 my_FragColor;\n"
1975 "const highp float f[2] = float[2](0.1, 0.2);\n"
1976 "const highp float[2] g = float[2](0.3, 0.4), h = float[2](0.5, f[1]);\n"
1977 "void main()\n"
1978 "{\n"
1979 " my_FragColor = vec4(h[1]);\n"
1980 "}";
1981
1982 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
1983 EXPECT_NE(0u, program);
1984}
1985
Corentin Wallez419bfc92016-06-28 10:54:45 -07001986// Test that index-constant sampler array indexing is supported.
1987TEST_P(GLSLTest, IndexConstantSamplerArrayIndexing)
1988{
1989 if (IsD3D11_FL93()) {
1990 std::cout << "Test skipped on D3D11 FL 9.3." << std::endl;
1991 return;
1992 }
1993
1994 const std::string vertexShaderSource =
1995 "attribute vec4 vPosition;\n"
1996 "void main()\n"
1997 "{\n"
1998 " gl_Position = vPosition;\n"
1999 "}";
2000
2001 const std::string fragmentShaderSource =
2002 "precision mediump float;\n"
2003 "uniform sampler2D uni[2];\n"
2004 "\n"
2005 "float zero(int x)\n"
2006 "{\n"
2007 " return float(x) - float(x);\n"
2008 "}\n"
2009 "\n"
2010 "void main()\n"
2011 "{\n"
2012 " vec4 c = vec4(0,0,0,0);\n"
2013 " for (int ii = 1; ii < 3; ++ii) {\n"
2014 " if (c.x > 255.0) {\n"
2015 " c.x = 255.0 + zero(ii);\n"
2016 " break;\n"
2017 " }\n"
2018 // Index the sampler array with a predictable loop index (index-constant) as opposed to
2019 // a true constant. This is valid in OpenGL ES but isn't in many Desktop OpenGL versions,
2020 // without an extension.
2021 " c += texture2D(uni[ii - 1], vec2(0.5, 0.5));\n"
2022 " }\n"
2023 " gl_FragColor = c;\n"
2024 "}";
2025
2026 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
2027 EXPECT_NE(0u, program);
2028}
2029
Corentin Wallezb00dcee2016-07-11 17:42:58 -04002030// Test that the #pragma directive is supported and doesn't trigger a compilation failure on the
2031// native driver. The only pragma that gets passed to the OpenGL driver is "invariant" but we don't
2032// want to test its behavior, so don't use any varyings.
2033TEST_P(GLSLTest, PragmaDirective)
2034{
2035 const std::string vertexShaderSource =
2036 "#pragma STDGL invariant(all)\n"
2037 "void main()\n"
2038 "{\n"
2039 " gl_Position = vec4(1.0, 0.0, 0.0, 1.0);\n"
2040 "}\n";
2041
2042 const std::string fragmentShaderSource =
2043 "precision mediump float;\n"
2044 "void main()\n"
2045 "{\n"
2046 " gl_FragColor = vec4(1.0);\n"
2047 "}\n";
2048
2049 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
2050 EXPECT_NE(0u, program);
2051}
2052
Olli Etuahoe1d199b2016-07-19 17:14:27 +03002053// Sequence operator evaluates operands from left to right (ESSL 3.00 section 5.9).
2054// The function call that returns the array needs to be evaluated after ++j for the expression to
2055// return the correct value (true).
2056TEST_P(GLSLTest_ES3, SequenceOperatorEvaluationOrderArray)
2057{
2058 const std::string &fragmentShaderSource =
2059 "#version 300 es\n"
2060 "precision mediump float;\n"
2061 "out vec4 my_FragColor; \n"
2062 "int[2] func(int param) {\n"
2063 " return int[2](param, param);\n"
2064 "}\n"
2065 "void main() {\n"
2066 " int a[2]; \n"
2067 " for (int i = 0; i < 2; ++i) {\n"
2068 " a[i] = 1;\n"
2069 " }\n"
2070 " int j = 0; \n"
2071 " bool result = ((++j), (a == func(j)));\n"
2072 " my_FragColor = vec4(0.0, (result ? 1.0 : 0.0), 0.0, 1.0);\n"
2073 "}\n";
2074
2075 GLuint program = CompileProgram(mSimpleVSSource, fragmentShaderSource);
2076 ASSERT_NE(0u, program);
2077
2078 drawQuad(program, "inputAttribute", 0.5f);
2079
2080 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2081}
2082
2083// Sequence operator evaluates operands from left to right (ESSL 3.00 section 5.9).
2084// The short-circuiting expression needs to be evaluated after ++j for the expression to return the
2085// correct value (true).
2086TEST_P(GLSLTest_ES3, SequenceOperatorEvaluationOrderShortCircuit)
2087{
2088 const std::string &fragmentShaderSource =
2089 "#version 300 es\n"
2090 "precision mediump float;\n"
2091 "out vec4 my_FragColor; \n"
2092 "void main() {\n"
2093 " int j = 0; \n"
2094 " bool result = ((++j), (j == 1 ? true : (++j == 3)));\n"
2095 " my_FragColor = vec4(0.0, ((result && j == 1) ? 1.0 : 0.0), 0.0, 1.0);\n"
2096 "}\n";
2097
2098 GLuint program = CompileProgram(mSimpleVSSource, fragmentShaderSource);
2099 ASSERT_NE(0u, program);
2100
2101 drawQuad(program, "inputAttribute", 0.5f);
2102
2103 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2104}
2105
Jamie Madill666f65a2016-08-26 01:34:37 +00002106// Sequence operator evaluates operands from left to right (ESSL 3.00 section 5.9).
2107// Indexing the vector needs to be evaluated after func() for the right result.
2108TEST_P(GLSLTest_ES3, SequenceOperatorEvaluationOrderDynamicVectorIndexingInLValue)
2109{
2110 const std::string &fragmentShaderSource =
2111 "#version 300 es\n"
2112 "precision mediump float;\n"
2113 "out vec4 my_FragColor;\n"
2114 "uniform int u_zero;\n"
2115 "int sideEffectCount = 0;\n"
2116 "float func() {\n"
2117 " ++sideEffectCount;\n"
2118 " return -1.0;\n"
2119 "}\n"
2120 "void main() {\n"
2121 " vec4 v = vec4(0.0, 2.0, 4.0, 6.0); \n"
2122 " float f = (func(), (++v[u_zero + sideEffectCount]));\n"
2123 " bool green = abs(f - 3.0) < 0.01 && abs(v[1] - 3.0) < 0.01 && sideEffectCount == 1;\n"
2124 " my_FragColor = vec4(0.0, (green ? 1.0 : 0.0), 0.0, 1.0);\n"
2125 "}\n";
2126
2127 GLuint program = CompileProgram(mSimpleVSSource, fragmentShaderSource);
2128 ASSERT_NE(0u, program);
2129
2130 drawQuad(program, "inputAttribute", 0.5f);
2131
2132 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2133}
2134
Jamie Madillc9bde922016-07-24 17:58:50 -04002135// Test that using gl_PointCoord with GL_TRIANGLES doesn't produce a link error.
2136// From WebGL test conformance/rendering/point-specific-shader-variables.html
2137// See http://anglebug.com/1380
2138TEST_P(GLSLTest, RenderTrisWithPointCoord)
2139{
2140 const std::string &vert =
2141 "attribute vec2 aPosition;\n"
2142 "void main()\n"
2143 "{\n"
2144 " gl_Position = vec4(aPosition, 0, 1);\n"
2145 " gl_PointSize = 1.0;\n"
2146 "}";
2147 const std::string &frag =
2148 "void main()\n"
2149 "{\n"
2150 " gl_FragColor = vec4(gl_PointCoord.xy, 0, 1);\n"
2151 " gl_FragColor = vec4(0, 1, 0, 1);\n"
2152 "}";
2153
2154 ANGLE_GL_PROGRAM(prog, vert, frag);
2155 drawQuad(prog.get(), "aPosition", 0.5f);
2156 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2157}
2158
Jamie Madill5655b842016-08-02 11:00:07 -04002159// Convers a bug with the integer pow statement workaround.
2160TEST_P(GLSLTest, NestedPowStatements)
2161{
2162 const std::string &vert =
2163 "attribute vec2 position;\n"
2164 "void main()\n"
2165 "{\n"
2166 " gl_Position = vec4(position, 0, 1);\n"
2167 "}";
2168 const std::string &frag =
2169 "precision mediump float;\n"
2170 "float func(float v)\n"
2171 "{\n"
2172 " float f1 = pow(v, 2.0);\n"
2173 " return pow(f1 + v, 2.0);\n"
2174 "}\n"
2175 "void main()\n"
2176 "{\n"
2177 " float v = func(2.0);\n"
2178 " gl_FragColor = abs(v - 36.0) < 0.001 ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);\n"
2179 "}";
2180
2181 ANGLE_GL_PROGRAM(prog, vert, frag);
2182 drawQuad(prog.get(), "position", 0.5f);
2183 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2184}
2185
Qiankun Miaof52fe932016-12-07 13:39:15 +08002186// Test that -float calculation is correct.
2187TEST_P(GLSLTest_ES3, UnaryMinusOperatorFloat)
2188{
Qiankun Miaof52fe932016-12-07 13:39:15 +08002189 const std::string &vert =
2190 "#version 300 es\n"
2191 "in highp vec4 position;\n"
2192 "void main() {\n"
2193 " gl_Position = position;\n"
2194 "}\n";
2195 const std::string &frag =
2196 "#version 300 es\n"
2197 "out highp vec4 o_color;\n"
2198 "void main() {\n"
2199 " highp float f = -1.0;\n"
2200 " // atan(tan(0.5), -f) should be 0.5.\n"
2201 " highp float v = atan(tan(0.5), -f);\n"
2202 " o_color = abs(v - 0.5) < 0.001 ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);\n"
2203 "}\n";
2204
2205 ANGLE_GL_PROGRAM(prog, vert, frag);
2206 drawQuad(prog.get(), "position", 0.5f);
2207 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2208}
2209
Olli Etuahoda9fb092016-12-09 17:32:29 +00002210// Test that atan(vec2, vec2) calculation is correct.
2211TEST_P(GLSLTest_ES3, AtanVec2)
2212{
2213 const std::string &vert =
2214 "#version 300 es\n"
2215 "in highp vec4 position;\n"
2216 "void main() {\n"
2217 " gl_Position = position;\n"
2218 "}\n";
2219 const std::string &frag =
2220 "#version 300 es\n"
2221 "out highp vec4 o_color;\n"
2222 "void main() {\n"
2223 " highp float f = 1.0;\n"
2224 " // atan(tan(0.5), f) should be 0.5.\n"
2225 " highp vec2 v = atan(vec2(tan(0.5)), vec2(f));\n"
2226 " o_color = (abs(v[0] - 0.5) < 0.001 && abs(v[1] - 0.5) < 0.001) ? vec4(0, 1, 0, 1) : "
2227 "vec4(1, 0, 0, 1);\n"
2228 "}\n";
2229
2230 ANGLE_GL_PROGRAM(prog, vert, frag);
2231 drawQuad(prog.get(), "position", 0.5f);
2232 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2233}
2234
Jiawei-Shaoe292e902016-09-07 10:49:01 +08002235// Convers a bug with the unary minus operator on signed integer workaround.
2236TEST_P(GLSLTest_ES3, UnaryMinusOperatorSignedInt)
2237{
2238 const std::string &vert =
2239 "#version 300 es\n"
2240 "in highp vec4 position;\n"
2241 "out mediump vec4 v_color;\n"
2242 "uniform int ui_one;\n"
2243 "uniform int ui_two;\n"
2244 "uniform int ui_three;\n"
2245 "void main() {\n"
2246 " int s[3];\n"
2247 " s[0] = ui_one;\n"
2248 " s[1] = -(-(-ui_two + 1) + 1);\n" // s[1] = -ui_two
2249 " s[2] = ui_three;\n"
2250 " int result = 0;\n"
2251 " for (int i = 0; i < ui_three; i++) {\n"
2252 " result += s[i];\n"
2253 " }\n"
2254 " v_color = (result == 2) ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);\n"
2255 " gl_Position = position;\n"
2256 "}\n";
2257 const std::string &frag =
2258 "#version 300 es\n"
2259 "in mediump vec4 v_color;\n"
2260 "layout(location=0) out mediump vec4 o_color;\n"
2261 "void main() {\n"
2262 " o_color = v_color;\n"
2263 "}\n";
2264
2265 ANGLE_GL_PROGRAM(prog, vert, frag);
2266
Jamie Madille1faacb2016-12-13 12:42:14 -05002267 GLint oneIndex = glGetUniformLocation(prog.get(), "ui_one");
Jiawei-Shaoe292e902016-09-07 10:49:01 +08002268 ASSERT_NE(-1, oneIndex);
Jamie Madille1faacb2016-12-13 12:42:14 -05002269 GLint twoIndex = glGetUniformLocation(prog.get(), "ui_two");
Jiawei-Shaoe292e902016-09-07 10:49:01 +08002270 ASSERT_NE(-1, twoIndex);
Jamie Madille1faacb2016-12-13 12:42:14 -05002271 GLint threeIndex = glGetUniformLocation(prog.get(), "ui_three");
Jiawei-Shaoe292e902016-09-07 10:49:01 +08002272 ASSERT_NE(-1, threeIndex);
2273 glUseProgram(prog.get());
2274 glUniform1i(oneIndex, 1);
2275 glUniform1i(twoIndex, 2);
2276 glUniform1i(threeIndex, 3);
2277
2278 drawQuad(prog.get(), "position", 0.5f);
2279 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2280}
2281
2282// Convers a bug with the unary minus operator on unsigned integer workaround.
2283TEST_P(GLSLTest_ES3, UnaryMinusOperatorUnsignedInt)
2284{
2285 const std::string &vert =
2286 "#version 300 es\n"
2287 "in highp vec4 position;\n"
2288 "out mediump vec4 v_color;\n"
2289 "uniform uint ui_one;\n"
2290 "uniform uint ui_two;\n"
2291 "uniform uint ui_three;\n"
2292 "void main() {\n"
2293 " uint s[3];\n"
2294 " s[0] = ui_one;\n"
2295 " s[1] = -(-(-ui_two + 1u) + 1u);\n" // s[1] = -ui_two
2296 " s[2] = ui_three;\n"
2297 " uint result = 0u;\n"
2298 " for (uint i = 0u; i < ui_three; i++) {\n"
2299 " result += s[i];\n"
2300 " }\n"
2301 " v_color = (result == 2u) ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);\n"
2302 " gl_Position = position;\n"
2303 "}\n";
2304 const std::string &frag =
2305 "#version 300 es\n"
2306 "in mediump vec4 v_color;\n"
2307 "layout(location=0) out mediump vec4 o_color;\n"
2308 "void main() {\n"
2309 " o_color = v_color;\n"
2310 "}\n";
2311
2312 ANGLE_GL_PROGRAM(prog, vert, frag);
2313
Jamie Madille1faacb2016-12-13 12:42:14 -05002314 GLint oneIndex = glGetUniformLocation(prog.get(), "ui_one");
Jiawei-Shaoe292e902016-09-07 10:49:01 +08002315 ASSERT_NE(-1, oneIndex);
Jamie Madille1faacb2016-12-13 12:42:14 -05002316 GLint twoIndex = glGetUniformLocation(prog.get(), "ui_two");
Jiawei-Shaoe292e902016-09-07 10:49:01 +08002317 ASSERT_NE(-1, twoIndex);
Jamie Madille1faacb2016-12-13 12:42:14 -05002318 GLint threeIndex = glGetUniformLocation(prog.get(), "ui_three");
Jiawei-Shaoe292e902016-09-07 10:49:01 +08002319 ASSERT_NE(-1, threeIndex);
2320 glUseProgram(prog.get());
2321 glUniform1ui(oneIndex, 1u);
2322 glUniform1ui(twoIndex, 2u);
2323 glUniform1ui(threeIndex, 3u);
2324
2325 drawQuad(prog.get(), "position", 0.5f);
2326 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2327}
2328
Olli Etuahoab481642016-08-26 12:09:10 +03002329// Test a nested sequence operator with a ternary operator inside. The ternary operator is
2330// intended to be such that it gets converted to an if statement on the HLSL backend.
2331TEST_P(GLSLTest, NestedSequenceOperatorWithTernaryInside)
2332{
2333 const std::string &vert =
2334 "attribute vec2 position;\n"
2335 "void main()\n"
2336 "{\n"
2337 " gl_Position = vec4(position, 0, 1);\n"
2338 "}";
2339
2340 // Note that the uniform keep_flop_positive doesn't need to be set - the test expects it to have
2341 // its default value false.
2342 const std::string &frag =
2343 "precision mediump float;\n"
2344 "uniform bool keep_flop_positive;\n"
2345 "float flop;\n"
2346 "void main() {\n"
2347 " flop = -1.0,\n"
2348 " (flop *= -1.0,\n"
2349 " keep_flop_positive ? 0.0 : flop *= -1.0),\n"
2350 " gl_FragColor = vec4(0, -flop, 0, 1);\n"
2351 "}";
2352
2353 ANGLE_GL_PROGRAM(prog, vert, frag);
2354 drawQuad(prog.get(), "position", 0.5f);
2355 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2356}
2357
Geoff Lang28a97ee2016-09-22 13:01:26 -04002358// Test that using a sampler2D and samplerExternalOES in the same shader works (anglebug.com/1534)
2359TEST_P(GLSLTest, ExternalAnd2DSampler)
2360{
2361 if (!extensionEnabled("GL_OES_EGL_image_external"))
2362 {
2363 std::cout << "Test skipped because GL_OES_EGL_image_external is not available."
2364 << std::endl;
2365 return;
2366 }
2367
2368 const std::string fragmentShader =
2369 "precision mediump float;\n"
2370 "uniform samplerExternalOES tex0;\n"
2371 "uniform sampler2D tex1;\n"
2372 "void main(void)\n"
2373 "{\n"
2374 " vec2 uv = vec2(0.0, 0.0);"
2375 " gl_FragColor = texture2D(tex0, uv) + texture2D(tex1, uv);\n"
2376 "}\n";
2377
2378 ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader);
2379}
2380
Jamie Madill44ebf6b2016-09-22 13:00:02 -04002381// Test that using an invalid constant right-shift produces an error.
2382TEST_P(GLSLTest_ES3, FoldedInvalidRightShift)
2383{
2384 const std::string &fragmentShader =
2385 "#version 300 es\n"
2386 "precision mediump float;\n"
2387 "out vec4 color;\n"
2388 "void main(void)\n"
2389 "{\n"
2390 " int diff = -100 >> -100;\n"
2391 " color = vec4(float(diff));\n"
2392 "}\n";
2393
2394 GLuint program = CompileProgram(mSimpleVSSource, fragmentShader);
2395 EXPECT_EQ(0u, program);
2396 glDeleteProgram(program);
2397}
2398
2399// Test that using an invalid constant left-shift produces an error.
2400TEST_P(GLSLTest_ES3, FoldedInvalidLeftShift)
2401{
2402 const std::string &fragmentShader =
2403 "#version 300 es\n"
2404 "precision mediump float;\n"
2405 "out vec4 color;\n"
2406 "void main(void)\n"
2407 "{\n"
2408 " int diff = -100 << -100;\n"
2409 " color = vec4(float(diff));\n"
2410 "}\n";
2411
2412 GLuint program = CompileProgram(mSimpleVSSource, fragmentShader);
2413 EXPECT_EQ(0u, program);
2414 glDeleteProgram(program);
2415}
2416
Olli Etuaho56a2f952016-12-08 12:16:27 +00002417// Test that literal infinity can be written out from the shader translator.
2418// A similar test can't be made for NaNs, since ESSL 3.00.6 requirements for NaNs are very loose.
2419TEST_P(GLSLTest_ES3, LiteralInfinityOutput)
2420{
2421 const std::string &fragmentShader =
2422 "#version 300 es\n"
2423 "precision highp float;\n"
2424 "out vec4 out_color;\n"
2425 "uniform float u;\n"
2426 "void main()\n"
2427 "{\n"
2428 " float infVar = 1.0e40 - u;\n"
2429 " bool correct = isinf(infVar) && infVar > 0.0;\n"
2430 " out_color = correct ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(1.0, 0.0, 0.0, 1.0);\n"
2431 "}\n";
2432
2433 ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader);
2434 drawQuad(program.get(), "inputAttribute", 0.5f);
2435 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2436}
2437
2438// Test that literal negative infinity can be written out from the shader translator.
2439// A similar test can't be made for NaNs, since ESSL 3.00.6 requirements for NaNs are very loose.
2440TEST_P(GLSLTest_ES3, LiteralNegativeInfinityOutput)
2441{
2442 const std::string &fragmentShader =
2443 "#version 300 es\n"
2444 "precision highp float;\n"
2445 "out vec4 out_color;\n"
2446 "uniform float u;\n"
2447 "void main()\n"
2448 "{\n"
2449 " float infVar = -1.0e40 + u;\n"
2450 " bool correct = isinf(infVar) && infVar < 0.0;\n"
2451 " out_color = correct ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(1.0, 0.0, 0.0, 1.0);\n"
2452 "}\n";
2453
2454 ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader);
2455 drawQuad(program.get(), "inputAttribute", 0.5f);
2456 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2457}
2458
Corentin Wallez36fd1002016-12-08 11:30:44 -05002459// The following MultipleDeclaration* tests are testing TranslatorHLSL specific simplification
2460// passes. Because the interaction of multiple passes must be tested, it is difficult to write
2461// a unittest for them. Instead we add the tests as end2end so will in particular test
2462// TranslatorHLSL when run on Windows.
2463
2464// Test that passes splitting multiple declarations and comma operators are correctly ordered.
2465TEST_P(GLSLTest_ES3, MultipleDeclarationWithCommaOperator)
2466{
2467 const std::string &fragmentShader =
2468 "#version 300 es\n"
2469 "precision mediump float;\n"
2470 "out vec4 color;\n"
2471 "void main(void)\n"
2472 "{\n"
2473 " float a = 0.0, b = ((gl_FragCoord.x < 0.5 ? a : 0.0), 1.0);\n"
2474 " color = vec4(b);\n"
2475 "}\n";
2476
2477 ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader);
2478}
2479
2480// Test that passes splitting multiple declarations and comma operators and for loops are
2481// correctly ordered.
2482TEST_P(GLSLTest_ES3, MultipleDeclarationWithCommaOperatorInForLoop)
2483{
2484 const std::string &fragmentShader =
2485 "#version 300 es\n"
2486 "precision mediump float;\n"
2487 "out vec4 color;\n"
2488 "void main(void)\n"
2489 "{\n"
2490 " for(float a = 0.0, b = ((gl_FragCoord.x < 0.5 ? a : 0.0), 1.0); a < 10.0; a++)\n"
2491 " {\n"
2492 " b += 1.0;\n"
2493 " color = vec4(b);\n"
2494 " }\n"
2495 "}\n";
2496
2497 ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader);
2498}
2499
2500// Test that splitting multiple declaration in for loops works with no loop condition
2501TEST_P(GLSLTest_ES3, MultipleDeclarationInForLoopEmptyCondition)
2502{
2503 const std::string &fragmentShader =
2504 "#version 300 es\n"
2505 "precision mediump float;\n"
2506 "out vec4 color;\n"
2507 "void main(void)\n"
2508 "{\n"
2509 " for(float a = 0.0, b = 1.0;; a++)\n"
2510 " {\n"
2511 " b += 1.0;\n"
2512 " if (a > 10.0) {break;}\n"
2513 " color = vec4(b);\n"
2514 " }\n"
2515 "}\n";
2516
2517 ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader);
2518}
2519
2520// Test that splitting multiple declaration in for loops works with no loop expression
2521TEST_P(GLSLTest_ES3, MultipleDeclarationInForLoopEmptyExpression)
2522{
2523 const std::string &fragmentShader =
2524 "#version 300 es\n"
2525 "precision mediump float;\n"
2526 "out vec4 color;\n"
2527 "void main(void)\n"
2528 "{\n"
2529 " for(float a = 0.0, b = 1.0; a < 10.0;)\n"
2530 " {\n"
2531 " b += 1.0;\n"
2532 " a += 1.0;\n"
2533 " color = vec4(b);\n"
2534 " }\n"
2535 "}\n";
2536
2537 ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader);
2538}
2539
Olli Etuaho8f6eb2a2017-01-12 17:04:58 +00002540// Test that dynamic indexing of a matrix inside a dynamic indexing of a vector in an l-value works
2541// correctly.
2542TEST_P(GLSLTest_ES3, NestedDynamicIndexingInLValue)
2543{
2544 const std::string &fragmentShader =
2545 "#version 300 es\n"
2546 "precision mediump float;\n"
2547 "out vec4 my_FragColor;\n"
2548 "uniform int u_zero;\n"
2549 "void main() {\n"
2550 " mat2 m = mat2(0.0, 0.0, 0.0, 0.0);\n"
2551 " m[u_zero + 1][u_zero + 1] = float(u_zero + 1);\n"
2552 " float f = m[1][1];\n"
2553 " my_FragColor = vec4(1.0 - f, f, 0.0, 1.0);\n"
2554 "}\n";
2555
2556 ANGLE_GL_PROGRAM(program, mSimpleVSSource, fragmentShader);
2557 drawQuad(program.get(), "inputAttribute", 0.5f);
2558 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
2559}
2560
Jamie Madill192745a2016-12-22 15:58:21 -05002561class WebGLGLSLTest : public GLSLTest
2562{
2563 protected:
2564 WebGLGLSLTest() { setWebGLCompatibilityEnabled(true); }
2565};
2566
2567TEST_P(WebGLGLSLTest, MaxVaryingVec4PlusFragCoord)
2568{
2569 GLint maxVaryings = 0;
2570 glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings);
2571
2572 // Generate shader code that uses gl_FragCoord, a special fragment shader variables.
2573 // This test should fail, since we are really using (maxVaryings + 1) varyings.
2574 VaryingTestBase(0, 0, 0, 0, 0, 0, maxVaryings, 0, true, false, false, false);
2575}
2576
2577TEST_P(WebGLGLSLTest, MaxVaryingVec4PlusPointCoord)
2578{
2579 GLint maxVaryings = 0;
2580 glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings);
2581
2582 // Generate shader code that uses gl_FragCoord, a special fragment shader variables.
2583 // This test should fail, since we are really using (maxVaryings + 1) varyings.
2584 VaryingTestBase(0, 0, 0, 0, 0, 0, maxVaryings, 0, false, true, false, false);
2585}
2586
2587TEST_P(WebGLGLSLTest, MaxPlusOneVaryingVec3)
2588{
2589 GLint maxVaryings = 0;
2590 glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings);
2591
2592 VaryingTestBase(0, 0, 0, 0, maxVaryings + 1, 0, 0, 0, false, false, false, false);
2593}
2594
2595TEST_P(WebGLGLSLTest, MaxPlusOneVaryingVec3Array)
2596{
2597 GLint maxVaryings = 0;
2598 glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings);
2599
2600 VaryingTestBase(0, 0, 0, 0, 0, maxVaryings / 2 + 1, 0, 0, false, false, false, false);
2601}
2602
2603TEST_P(WebGLGLSLTest, MaxVaryingVec3AndOneVec2)
2604{
2605 GLint maxVaryings = 0;
2606 glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings);
2607
2608 VaryingTestBase(0, 0, 1, 0, maxVaryings, 0, 0, 0, false, false, false, false);
2609}
2610
2611TEST_P(WebGLGLSLTest, MaxPlusOneVaryingVec2)
2612{
2613 GLint maxVaryings = 0;
2614 glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings);
2615
2616 VaryingTestBase(0, 0, 2 * maxVaryings + 1, 0, 0, 0, 0, 0, false, false, false, false);
2617}
2618
2619TEST_P(WebGLGLSLTest, MaxVaryingVec3ArrayAndMaxPlusOneFloatArray)
2620{
2621 GLint maxVaryings = 0;
2622 glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings);
2623
2624 VaryingTestBase(0, maxVaryings / 2 + 1, 0, 0, 0, 0, 0, maxVaryings / 2, false, false, false,
2625 false);
2626}
2627
Jamie Madill6c9503e2016-08-16 14:06:32 -04002628} // anonymous namespace
2629
Jamie Madillfa05f602015-05-07 13:47:11 -04002630// 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 -05002631ANGLE_INSTANTIATE_TEST(GLSLTest,
2632 ES2_D3D9(),
2633 ES2_D3D11(),
2634 ES2_D3D11_FL9_3(),
2635 ES2_OPENGL(),
2636 ES3_OPENGL(),
2637 ES2_OPENGLES(),
2638 ES3_OPENGLES());
Jamie Madillfa05f602015-05-07 13:47:11 -04002639
2640// 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 -05002641ANGLE_INSTANTIATE_TEST(GLSLTest_ES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());
Jamie Madill192745a2016-12-22 15:58:21 -05002642
2643ANGLE_INSTANTIATE_TEST(WebGLGLSLTest, ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES());