blob: 5423d8993414d02346603dfa7719fcc34262c1c1 [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 Madill55def582015-05-04 11:24:57 -04009#include "libANGLE/Context.h"
10#include "libANGLE/Program.h"
11
Jamie Madillfa05f602015-05-07 13:47:11 -040012using namespace angle;
Austin Kinross18b931d2014-09-29 12:58:31 -070013
Jamie Madill2bf8b372014-06-16 17:18:51 -040014class GLSLTest : public ANGLETest
Jamie Madill96509e42014-05-29 14:33:27 -040015{
Jamie Madillfa05f602015-05-07 13:47:11 -040016 protected:
17 GLSLTest()
Jamie Madill96509e42014-05-29 14:33:27 -040018 {
19 setWindowWidth(128);
20 setWindowHeight(128);
21 setConfigRedBits(8);
22 setConfigGreenBits(8);
23 setConfigBlueBits(8);
24 setConfigAlphaBits(8);
25 }
Jamie Madillbfa91f42014-06-05 15:45:18 -040026
27 virtual void SetUp()
28 {
29 ANGLETest::SetUp();
30
Jamie Madill2bf8b372014-06-16 17:18:51 -040031 mSimpleVSSource = SHADER_SOURCE
Jamie Madillbfa91f42014-06-05 15:45:18 -040032 (
33 attribute vec4 inputAttribute;
34 void main()
35 {
36 gl_Position = inputAttribute;
37 }
38 );
39 }
40
Austin Kinrossaf875522014-08-25 21:06:07 -070041 std::string GenerateVaryingType(GLint vectorSize)
42 {
43 char varyingType[10];
44
45 if (vectorSize == 1)
46 {
47 sprintf(varyingType, "float");
48 }
49 else
50 {
51 sprintf(varyingType, "vec%d", vectorSize);
52 }
53
54 return std::string(varyingType);
55 }
56
57 std::string GenerateVectorVaryingDeclaration(GLint vectorSize, GLint arraySize, GLint id)
58 {
59 char buff[100];
60
61 if (arraySize == 1)
62 {
63 sprintf(buff, "varying %s v%d;\n", GenerateVaryingType(vectorSize).c_str(), id);
64 }
65 else
66 {
67 sprintf(buff, "varying %s v%d[%d];\n", GenerateVaryingType(vectorSize).c_str(), id, arraySize);
68 }
69
70 return std::string(buff);
71 }
72
73 std::string GenerateVectorVaryingSettingCode(GLint vectorSize, GLint arraySize, GLint id)
74 {
75 std::string returnString;
76 char buff[100];
77
78 if (arraySize == 1)
79 {
80 sprintf(buff, "\t v%d = %s(1.0);\n", id, GenerateVaryingType(vectorSize).c_str());
81 returnString += buff;
82 }
83 else
84 {
85 for (int i = 0; i < arraySize; i++)
86 {
87 sprintf(buff, "\t v%d[%d] = %s(1.0);\n", id, i, GenerateVaryingType(vectorSize).c_str());
88 returnString += buff;
89 }
90 }
91
92 return returnString;
93 }
94
95 std::string GenerateVectorVaryingUseCode(GLint arraySize, GLint id)
96 {
97 if (arraySize == 1)
98 {
99 char buff[100];
100 sprintf(buff, "v%d + ", id);
101 return std::string(buff);
102 }
103 else
104 {
105 std::string returnString;
106 for (int i = 0; i < arraySize; i++)
107 {
108 char buff[100];
109 sprintf(buff, "v%d[%d] + ", id, i);
110 returnString += buff;
111 }
112 return returnString;
113 }
114 }
115
Austin Kinross8b695ee2015-03-12 13:12:20 -0700116 void GenerateGLSLWithVaryings(GLint floatCount, GLint floatArrayCount, GLint vec2Count, GLint vec2ArrayCount, GLint vec3Count, GLint vec3ArrayCount,
117 GLint vec4Count, GLint vec4ArrayCount, bool useFragCoord, bool usePointCoord, bool usePointSize,
118 std::string* fragmentShader, std::string* vertexShader)
Austin Kinrossaf875522014-08-25 21:06:07 -0700119 {
120 // Generate a string declaring the varyings, to share between the fragment shader and the vertex shader.
121 std::string varyingDeclaration;
122
123 unsigned int varyingCount = 0;
124
125 for (GLint i = 0; i < floatCount; i++)
126 {
127 varyingDeclaration += GenerateVectorVaryingDeclaration(1, 1, varyingCount);
128 varyingCount += 1;
129 }
130
131 for (GLint i = 0; i < floatArrayCount; i++)
132 {
133 varyingDeclaration += GenerateVectorVaryingDeclaration(1, 2, varyingCount);
134 varyingCount += 1;
135 }
136
137 for (GLint i = 0; i < vec2Count; i++)
138 {
139 varyingDeclaration += GenerateVectorVaryingDeclaration(2, 1, varyingCount);
140 varyingCount += 1;
141 }
142
143 for (GLint i = 0; i < vec2ArrayCount; i++)
144 {
145 varyingDeclaration += GenerateVectorVaryingDeclaration(2, 2, varyingCount);
146 varyingCount += 1;
147 }
148
149 for (GLint i = 0; i < vec3Count; i++)
150 {
151 varyingDeclaration += GenerateVectorVaryingDeclaration(3, 1, varyingCount);
152 varyingCount += 1;
153 }
154
155 for (GLint i = 0; i < vec3ArrayCount; i++)
156 {
157 varyingDeclaration += GenerateVectorVaryingDeclaration(3, 2, varyingCount);
158 varyingCount += 1;
159 }
160
Austin Kinross8b695ee2015-03-12 13:12:20 -0700161 for (GLint i = 0; i < vec4Count; i++)
162 {
163 varyingDeclaration += GenerateVectorVaryingDeclaration(4, 1, varyingCount);
164 varyingCount += 1;
165 }
166
167 for (GLint i = 0; i < vec4ArrayCount; i++)
168 {
169 varyingDeclaration += GenerateVectorVaryingDeclaration(4, 2, varyingCount);
170 varyingCount += 1;
171 }
172
Austin Kinrossaf875522014-08-25 21:06:07 -0700173 // Generate the vertex shader
174 vertexShader->clear();
175 vertexShader->append(varyingDeclaration);
176 vertexShader->append("\nvoid main()\n{\n");
177
178 unsigned int currentVSVarying = 0;
179
180 for (GLint i = 0; i < floatCount; i++)
181 {
182 vertexShader->append(GenerateVectorVaryingSettingCode(1, 1, currentVSVarying));
183 currentVSVarying += 1;
184 }
185
186 for (GLint i = 0; i < floatArrayCount; i++)
187 {
188 vertexShader->append(GenerateVectorVaryingSettingCode(1, 2, currentVSVarying));
189 currentVSVarying += 1;
190 }
191
192 for (GLint i = 0; i < vec2Count; i++)
193 {
194 vertexShader->append(GenerateVectorVaryingSettingCode(2, 1, currentVSVarying));
195 currentVSVarying += 1;
196 }
197
198 for (GLint i = 0; i < vec2ArrayCount; i++)
199 {
200 vertexShader->append(GenerateVectorVaryingSettingCode(2, 2, currentVSVarying));
201 currentVSVarying += 1;
202 }
203
204 for (GLint i = 0; i < vec3Count; i++)
205 {
206 vertexShader->append(GenerateVectorVaryingSettingCode(3, 1, currentVSVarying));
207 currentVSVarying += 1;
208 }
209
210 for (GLint i = 0; i < vec3ArrayCount; i++)
211 {
212 vertexShader->append(GenerateVectorVaryingSettingCode(3, 2, currentVSVarying));
213 currentVSVarying += 1;
214 }
215
Austin Kinross8b695ee2015-03-12 13:12:20 -0700216 for (GLint i = 0; i < vec4Count; i++)
217 {
218 vertexShader->append(GenerateVectorVaryingSettingCode(4, 1, currentVSVarying));
219 currentVSVarying += 1;
220 }
221
222 for (GLint i = 0; i < vec4ArrayCount; i++)
223 {
224 vertexShader->append(GenerateVectorVaryingSettingCode(4, 2, currentVSVarying));
225 currentVSVarying += 1;
226 }
227
228 if (usePointSize)
229 {
230 vertexShader->append("gl_PointSize = 1.0;\n");
231 }
232
Austin Kinrossaf875522014-08-25 21:06:07 -0700233 vertexShader->append("}\n");
234
235 // Generate the fragment shader
236 fragmentShader->clear();
237 fragmentShader->append("precision highp float;\n");
238 fragmentShader->append(varyingDeclaration);
239 fragmentShader->append("\nvoid main() \n{ \n\tvec4 retColor = vec4(0,0,0,0);\n");
240
241 unsigned int currentFSVarying = 0;
242
243 // Make use of the float varyings
244 fragmentShader->append("\tretColor += vec4(");
245
246 for (GLint i = 0; i < floatCount; i++)
247 {
248 fragmentShader->append(GenerateVectorVaryingUseCode(1, currentFSVarying));
249 currentFSVarying += 1;
250 }
251
252 for (GLint i = 0; i < floatArrayCount; i++)
253 {
254 fragmentShader->append(GenerateVectorVaryingUseCode(2, currentFSVarying));
255 currentFSVarying += 1;
256 }
257
258 fragmentShader->append("0.0, 0.0, 0.0, 0.0);\n");
259
260 // Make use of the vec2 varyings
261 fragmentShader->append("\tretColor += vec4(");
262
263 for (GLint i = 0; i < vec2Count; i++)
264 {
265 fragmentShader->append(GenerateVectorVaryingUseCode(1, currentFSVarying));
266 currentFSVarying += 1;
267 }
268
269 for (GLint i = 0; i < vec2ArrayCount; i++)
270 {
271 fragmentShader->append(GenerateVectorVaryingUseCode(2, currentFSVarying));
272 currentFSVarying += 1;
273 }
274
275 fragmentShader->append("vec2(0.0, 0.0), 0.0, 0.0);\n");
276
277 // Make use of the vec3 varyings
278 fragmentShader->append("\tretColor += vec4(");
279
280 for (GLint i = 0; i < vec3Count; i++)
281 {
282 fragmentShader->append(GenerateVectorVaryingUseCode(1, currentFSVarying));
283 currentFSVarying += 1;
284 }
285
286 for (GLint i = 0; i < vec3ArrayCount; i++)
287 {
288 fragmentShader->append(GenerateVectorVaryingUseCode(2, currentFSVarying));
289 currentFSVarying += 1;
290 }
291
292 fragmentShader->append("vec3(0.0, 0.0, 0.0), 0.0);\n");
Austin Kinross8b695ee2015-03-12 13:12:20 -0700293
294 // Make use of the vec4 varyings
295 fragmentShader->append("\tretColor += ");
296
297 for (GLint i = 0; i < vec4Count; i++)
298 {
299 fragmentShader->append(GenerateVectorVaryingUseCode(1, currentFSVarying));
300 currentFSVarying += 1;
301 }
302
303 for (GLint i = 0; i < vec4ArrayCount; i++)
304 {
305 fragmentShader->append(GenerateVectorVaryingUseCode(2, currentFSVarying));
306 currentFSVarying += 1;
307 }
308
309 fragmentShader->append("vec4(0.0, 0.0, 0.0, 0.0);\n");
310
311 // Set gl_FragColor, and use special variables if requested
312 fragmentShader->append("\tgl_FragColor = retColor");
313
314 if (useFragCoord)
315 {
316 fragmentShader->append(" + gl_FragCoord");
317 }
318
319 if (usePointCoord)
320 {
321 fragmentShader->append(" + vec4(gl_PointCoord, 0.0, 0.0)");
322 }
323
324 fragmentShader->append(";\n}");
325 }
326
327 void VaryingTestBase(GLint floatCount, GLint floatArrayCount, GLint vec2Count, GLint vec2ArrayCount, GLint vec3Count, GLint vec3ArrayCount,
328 GLint vec4Count, GLint vec4ArrayCount, bool useFragCoord, bool usePointCoord, bool usePointSize, bool expectSuccess)
329 {
330 std::string fragmentShaderSource;
331 std::string vertexShaderSource;
332
333 GenerateGLSLWithVaryings(floatCount, floatArrayCount, vec2Count, vec2ArrayCount, vec3Count, vec3ArrayCount,
334 vec4Count, vec4ArrayCount, useFragCoord, usePointCoord, usePointSize,
335 &fragmentShaderSource, &vertexShaderSource);
336
337 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
338
339 if (expectSuccess)
340 {
341 EXPECT_NE(0u, program);
342 }
343 else
344 {
345 EXPECT_EQ(0u, program);
346 }
Austin Kinrossaf875522014-08-25 21:06:07 -0700347 }
348
Austin Kinross7a3e8e22015-10-08 15:50:06 -0700349 void CompileGLSLWithUniformsAndSamplers(GLint vertexUniformCount,
350 GLint fragmentUniformCount,
351 GLint vertexSamplersCount,
352 GLint fragmentSamplersCount,
353 bool expectSuccess)
354 {
355 std::stringstream vertexShader;
356 std::stringstream fragmentShader;
357
358 // Generate the vertex shader
359 vertexShader << "precision mediump float;\n";
360
361 for (int i = 0; i < vertexUniformCount; i++)
362 {
363 vertexShader << "uniform vec4 v" << i << ";\n";
364 }
365
366 for (int i = 0; i < vertexSamplersCount; i++)
367 {
368 vertexShader << "uniform sampler2D s" << i << ";\n";
369 }
370
371 vertexShader << "void main()\n{\n";
372
373 for (int i = 0; i < vertexUniformCount; i++)
374 {
375 vertexShader << " gl_Position += v" << i << ";\n";
376 }
377
378 for (int i = 0; i < vertexSamplersCount; i++)
379 {
380 vertexShader << " gl_Position += texture2D(s" << i << ", vec2(0.0, 0.0));\n";
381 }
382
383 if (vertexUniformCount == 0 && vertexSamplersCount == 0)
384 {
385 vertexShader << " gl_Position = vec4(0.0);\n";
386 }
387
388 vertexShader << "}\n";
389
390 // Generate the fragment shader
391 fragmentShader << "precision mediump float;\n";
392
393 for (int i = 0; i < fragmentUniformCount; i++)
394 {
395 fragmentShader << "uniform vec4 v" << i << ";\n";
396 }
397
398 for (int i = 0; i < fragmentSamplersCount; i++)
399 {
400 fragmentShader << "uniform sampler2D s" << i << ";\n";
401 }
402
403 fragmentShader << "void main()\n{\n";
404
405 for (int i = 0; i < fragmentUniformCount; i++)
406 {
407 fragmentShader << " gl_FragColor += v" << i << ";\n";
408 }
409
410 for (int i = 0; i < fragmentSamplersCount; i++)
411 {
412 fragmentShader << " gl_FragColor += texture2D(s" << i << ", vec2(0.0, 0.0));\n";
413 }
414
415 if (fragmentUniformCount == 0 && fragmentSamplersCount == 0)
416 {
417 fragmentShader << " gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);\n";
418 }
419
420 fragmentShader << "}\n";
421
422 GLuint program = CompileProgram(vertexShader.str(), fragmentShader.str());
423
424 if (expectSuccess)
425 {
426 EXPECT_NE(0u, program);
427 }
428 else
429 {
430 EXPECT_EQ(0u, program);
431 }
432 }
433
Jamie Madill2bf8b372014-06-16 17:18:51 -0400434 std::string mSimpleVSSource;
Jamie Madill96509e42014-05-29 14:33:27 -0400435};
436
Jamie Madillfa05f602015-05-07 13:47:11 -0400437class GLSLTest_ES3 : public GLSLTest
Gregoire Payen de La Garanderieb3dced22015-01-12 14:54:55 +0000438{
439};
440
Jamie Madillfa05f602015-05-07 13:47:11 -0400441TEST_P(GLSLTest, NamelessScopedStructs)
Jamie Madill96509e42014-05-29 14:33:27 -0400442{
Jamie Madillbfa91f42014-06-05 15:45:18 -0400443 const std::string fragmentShaderSource = SHADER_SOURCE
Jamie Madill96509e42014-05-29 14:33:27 -0400444 (
Jamie Madillbfa91f42014-06-05 15:45:18 -0400445 precision mediump float;
446
Jamie Madill96509e42014-05-29 14:33:27 -0400447 void main()
448 {
Jamie Madillbfa91f42014-06-05 15:45:18 -0400449 struct
450 {
451 float q;
452 } b;
453
454 gl_FragColor = vec4(1, 0, 0, 1);
455 gl_FragColor.a += b.q;
Jamie Madill96509e42014-05-29 14:33:27 -0400456 }
457 );
458
Jamie Madill5599c8f2014-08-26 13:16:39 -0400459 GLuint program = CompileProgram(mSimpleVSSource, fragmentShaderSource);
Jamie Madillbfa91f42014-06-05 15:45:18 -0400460 EXPECT_NE(0u, program);
461}
Austin Kinross18b931d2014-09-29 12:58:31 -0700462
Jamie Madillfa05f602015-05-07 13:47:11 -0400463TEST_P(GLSLTest, ScopedStructsOrderBug)
Jamie Madillbfa91f42014-06-05 15:45:18 -0400464{
Geoff Lange0cc2a42016-01-20 10:58:17 -0500465 // TODO(geofflang): Find out why this doesn't compile on Apple OpenGL drivers
466 // (http://anglebug.com/1292)
Geoff Lang5103f4c2016-01-26 11:40:18 -0500467 // TODO(geofflang): Find out why this doesn't compile on AMD OpenGL drivers
Geoff Lange0cc2a42016-01-20 10:58:17 -0500468 // (http://anglebug.com/1291)
Jamie Madill518b9fa2016-03-02 11:26:02 -0500469 if (isOpenGL() && (IsOSX() || !IsNVIDIA()))
Geoff Lange0cc2a42016-01-20 10:58:17 -0500470 {
Jamie Madill518b9fa2016-03-02 11:26:02 -0500471 std::cout << "Test disabled on this OpenGL configuration." << std::endl;
Geoff Lange0cc2a42016-01-20 10:58:17 -0500472 return;
473 }
Geoff Lange0cc2a42016-01-20 10:58:17 -0500474
Jamie Madillbfa91f42014-06-05 15:45:18 -0400475 const std::string fragmentShaderSource = SHADER_SOURCE
476 (
477 precision mediump float;
478
479 struct T
480 {
481 float f;
482 };
483
484 void main()
485 {
486 T a;
487
488 struct T
489 {
490 float q;
491 };
492
493 T b;
494
495 gl_FragColor = vec4(1, 0, 0, 1);
496 gl_FragColor.a += a.f;
497 gl_FragColor.a += b.q;
498 }
499 );
500
Jamie Madill5599c8f2014-08-26 13:16:39 -0400501 GLuint program = CompileProgram(mSimpleVSSource, fragmentShaderSource);
Jamie Madillbfa91f42014-06-05 15:45:18 -0400502 EXPECT_NE(0u, program);
503}
504
Jamie Madillfa05f602015-05-07 13:47:11 -0400505TEST_P(GLSLTest, ScopedStructsBug)
Jamie Madillbfa91f42014-06-05 15:45:18 -0400506{
Jamie Madill96509e42014-05-29 14:33:27 -0400507 const std::string fragmentShaderSource = SHADER_SOURCE
508 (
509 precision mediump float;
510
511 struct T_0
512 {
513 float f;
514 };
515
516 void main()
517 {
518 gl_FragColor = vec4(1, 0, 0, 1);
519
520 struct T
521 {
522 vec2 v;
523 };
524
525 T_0 a;
526 T b;
527
528 gl_FragColor.a += a.f;
529 gl_FragColor.a += b.v.x;
530 }
531 );
532
Jamie Madill5599c8f2014-08-26 13:16:39 -0400533 GLuint program = CompileProgram(mSimpleVSSource, fragmentShaderSource);
Jamie Madill2bf8b372014-06-16 17:18:51 -0400534 EXPECT_NE(0u, program);
535}
536
Jamie Madillfa05f602015-05-07 13:47:11 -0400537TEST_P(GLSLTest, DxPositionBug)
Jamie Madill2bf8b372014-06-16 17:18:51 -0400538{
539 const std::string &vertexShaderSource = SHADER_SOURCE
540 (
541 attribute vec4 inputAttribute;
542 varying float dx_Position;
543 void main()
544 {
545 gl_Position = vec4(inputAttribute);
546 dx_Position = 0.0;
547 }
548 );
549
550 const std::string &fragmentShaderSource = SHADER_SOURCE
551 (
552 precision mediump float;
553
554 varying float dx_Position;
555
556 void main()
557 {
558 gl_FragColor = vec4(dx_Position, 0, 0, 1);
559 }
560 );
561
Jamie Madill5599c8f2014-08-26 13:16:39 -0400562 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
Jamie Madill96509e42014-05-29 14:33:27 -0400563 EXPECT_NE(0u, program);
564}
Jamie Madill4836d222014-07-24 06:55:51 -0400565
Jamie Madillfa05f602015-05-07 13:47:11 -0400566TEST_P(GLSLTest, ElseIfRewriting)
Jamie Madill4836d222014-07-24 06:55:51 -0400567{
568 const std::string &vertexShaderSource =
569 "attribute vec4 a_position;\n"
570 "varying float v;\n"
571 "void main() {\n"
572 " gl_Position = a_position;\n"
573 " v = 1.0;\n"
574 " if (a_position.x <= 0.5) {\n"
575 " v = 0.0;\n"
576 " } else if (a_position.x >= 0.5) {\n"
577 " v = 2.0;\n"
578 " }\n"
579 "}\n";
580
581 const std::string &fragmentShaderSource =
582 "precision highp float;\n"
583 "varying float v;\n"
584 "void main() {\n"
585 " vec4 color = vec4(1.0, 0.0, 0.0, 1.0);\n"
586 " if (v >= 1.0) color = vec4(0.0, 1.0, 0.0, 1.0);\n"
587 " if (v >= 2.0) color = vec4(0.0, 0.0, 1.0, 1.0);\n"
588 " gl_FragColor = color;\n"
589 "}\n";
590
Jamie Madill5599c8f2014-08-26 13:16:39 -0400591 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
Jamie Madill4836d222014-07-24 06:55:51 -0400592 ASSERT_NE(0u, program);
593
594 drawQuad(program, "a_position", 0.5f);
Jamie Madill4836d222014-07-24 06:55:51 -0400595
596 EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255);
597 EXPECT_PIXEL_EQ(getWindowWidth()-1, 0, 0, 255, 0, 255);
598}
599
Jamie Madillfa05f602015-05-07 13:47:11 -0400600TEST_P(GLSLTest, TwoElseIfRewriting)
Jamie Madill4836d222014-07-24 06:55:51 -0400601{
602 const std::string &vertexShaderSource =
603 "attribute vec4 a_position;\n"
604 "varying float v;\n"
605 "void main() {\n"
606 " gl_Position = a_position;\n"
Jamie Madill778d5272014-08-04 13:13:25 -0400607 " if (a_position.x == 0.0) {\n"
Jamie Madill4836d222014-07-24 06:55:51 -0400608 " v = 1.0;\n"
609 " } else if (a_position.x > 0.5) {\n"
610 " v = 0.0;\n"
611 " } else if (a_position.x > 0.75) {\n"
612 " v = 0.5;\n"
613 " }\n"
614 "}\n";
615
616 const std::string &fragmentShaderSource =
617 "precision highp float;\n"
618 "varying float v;\n"
619 "void main() {\n"
620 " gl_FragColor = vec4(v, 0.0, 0.0, 1.0);\n"
621 "}\n";
622
Jamie Madill5599c8f2014-08-26 13:16:39 -0400623 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
Jamie Madill4836d222014-07-24 06:55:51 -0400624 EXPECT_NE(0u, program);
625}
Jamie Madill1c28e1f2014-08-04 11:37:54 -0400626
Jamie Madillfa05f602015-05-07 13:47:11 -0400627TEST_P(GLSLTest, FrontFacingAndVarying)
Jamie Madille6256f82014-09-17 10:31:15 -0400628{
Geoff Langdd323e92015-06-09 15:16:31 -0400629 EGLPlatformParameters platform = GetParam().eglParameters;
Austin Kinross8b695ee2015-03-12 13:12:20 -0700630
Jamie Madille6256f82014-09-17 10:31:15 -0400631 const std::string vertexShaderSource = SHADER_SOURCE
632 (
633 attribute vec4 a_position;
634 varying float v_varying;
635 void main()
636 {
637 v_varying = a_position.x;
638 gl_Position = a_position;
639 }
640 );
641
642 const std::string fragmentShaderSource = SHADER_SOURCE
643 (
644 precision mediump float;
645 varying float v_varying;
646 void main()
647 {
648 vec4 c;
649
650 if (gl_FrontFacing)
651 {
652 c = vec4(v_varying, 0, 0, 1.0);
653 }
654 else
655 {
656 c = vec4(0, v_varying, 0, 1.0);
657 }
658 gl_FragColor = c;
659 }
660 );
661
662 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
Austin Kinross02df7962015-07-01 10:03:42 -0700663
664 // Compilation should fail on D3D11 feature level 9_3, since gl_FrontFacing isn't supported.
665 if (platform.renderer == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE)
666 {
667 if (platform.majorVersion == 9 && platform.minorVersion == 3)
668 {
669 EXPECT_EQ(0u, program);
670 return;
671 }
672 }
673
674 // Otherwise, compilation should succeed
Jamie Madille6256f82014-09-17 10:31:15 -0400675 EXPECT_NE(0u, program);
676}
677
Yuly Novikova1f6dc92016-06-15 23:27:04 -0400678// Verify that linking shaders declaring different shading language versions fails.
679TEST_P(GLSLTest_ES3, VersionMismatch)
680{
681 const std::string fragmentShaderSource100 =
682 "precision mediump float;\n"
683 "varying float v_varying;\n"
684 "void main() { gl_FragColor = vec4(v_varying, 0, 0, 1.0); }\n";
685
686 const std::string vertexShaderSource100 =
687 "attribute vec4 a_position;\n"
688 "varying float v_varying;\n"
689 "void main() { v_varying = a_position.x; gl_Position = a_position; }\n";
690
691 const std::string fragmentShaderSource300 =
692 "#version 300 es\n"
693 "precision mediump float;\n"
694 "in float v_varying;\n"
695 "out vec4 my_FragColor;\n"
696 "void main() { my_FragColor = vec4(v_varying, 0, 0, 1.0); }\n";
697
698 const std::string vertexShaderSource300 =
699 "#version 300 es\n"
700 "in vec4 a_position;\n"
701 "out float v_varying;\n"
702 "void main() { v_varying = a_position.x; gl_Position = a_position; }\n";
703
704 GLuint program = CompileProgram(vertexShaderSource300, fragmentShaderSource100);
705 EXPECT_EQ(0u, program);
706
707 program = CompileProgram(vertexShaderSource100, fragmentShaderSource300);
708 EXPECT_EQ(0u, program);
709}
710
711// Verify that declaring varying as invariant only in vertex shader fails in ESSL 1.00.
712TEST_P(GLSLTest, InvariantVaryingOut)
713{
714 const std::string fragmentShaderSource =
715 "precision mediump float;\n"
716 "varying float v_varying;\n"
717 "void main() { gl_FragColor = vec4(v_varying, 0, 0, 1.0); }\n";
718
719 const std::string vertexShaderSource =
720 "attribute vec4 a_position;\n"
721 "invariant varying float v_varying;\n"
722 "void main() { v_varying = a_position.x; gl_Position = a_position; }\n";
723
724 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
725 EXPECT_EQ(0u, program);
726}
727
728// Verify that declaring varying as invariant only in vertex shader succeeds in ESSL 3.00.
729TEST_P(GLSLTest_ES3, InvariantVaryingOut)
730{
731 // TODO: ESSL 3.00 -> GLSL 1.20 translation should add "invariant" in fragment shader
732 // for varyings which are invariant in vertex shader (http://anglebug.com/1293)
733 if (isOpenGL())
734 {
735 std::cout << "Test disabled on OpenGL." << std::endl;
736 return;
737 }
738
739 const std::string fragmentShaderSource =
740 "#version 300 es\n"
741 "precision mediump float;\n"
742 "in float v_varying;\n"
743 "out vec4 my_FragColor;\n"
744 "void main() { my_FragColor = vec4(v_varying, 0, 0, 1.0); }\n";
745
746 const std::string vertexShaderSource =
747 "#version 300 es\n"
748 "in vec4 a_position;\n"
749 "invariant out float v_varying;\n"
750 "void main() { v_varying = a_position.x; gl_Position = a_position; }\n";
751
752 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
753 EXPECT_NE(0u, program);
754}
755
756// Verify that declaring varying as invariant only in fragment shader fails in ESSL 1.00.
Jamie Madillfa05f602015-05-07 13:47:11 -0400757TEST_P(GLSLTest, InvariantVaryingIn)
Jamie Madill1c28e1f2014-08-04 11:37:54 -0400758{
Yuly Novikova1f6dc92016-06-15 23:27:04 -0400759 const std::string fragmentShaderSource =
760 "precision mediump float;\n"
761 "invariant varying float v_varying;\n"
762 "void main() { gl_FragColor = vec4(v_varying, 0, 0, 1.0); }\n";
Geoff Lange0cc2a42016-01-20 10:58:17 -0500763
Yuly Novikova1f6dc92016-06-15 23:27:04 -0400764 const std::string vertexShaderSource =
765 "attribute vec4 a_position;\n"
766 "varying float v_varying;\n"
767 "void main() { v_varying = a_position.x; gl_Position = a_position; }\n";
Jamie Madill1c28e1f2014-08-04 11:37:54 -0400768
Jamie Madill5599c8f2014-08-26 13:16:39 -0400769 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
Yuly Novikova1f6dc92016-06-15 23:27:04 -0400770 EXPECT_EQ(0u, program);
Jamie Madill1c28e1f2014-08-04 11:37:54 -0400771}
772
Yuly Novikova1f6dc92016-06-15 23:27:04 -0400773// Verify that declaring varying as invariant only in fragment shader fails in ESSL 3.00.
774TEST_P(GLSLTest_ES3, InvariantVaryingIn)
775{
776 const std::string fragmentShaderSource =
777 "#version 300 es\n"
778 "precision mediump float;\n"
779 "invariant in float v_varying;\n"
780 "out vec4 my_FragColor;\n"
781 "void main() { my_FragColor = vec4(v_varying, 0, 0, 1.0); }\n";
782
783 const std::string vertexShaderSource =
784 "#version 300 es\n"
785 "in vec4 a_position;\n"
786 "out float v_varying;\n"
787 "void main() { v_varying = a_position.x; gl_Position = a_position; }\n";
788
789 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
790 EXPECT_EQ(0u, program);
791}
792
793// Verify that declaring varying as invariant in both shaders succeeds in ESSL 1.00.
Jamie Madillfa05f602015-05-07 13:47:11 -0400794TEST_P(GLSLTest, InvariantVaryingBoth)
Jamie Madill1c28e1f2014-08-04 11:37:54 -0400795{
Yuly Novikova1f6dc92016-06-15 23:27:04 -0400796 const std::string fragmentShaderSource =
797 "precision mediump float;\n"
798 "invariant varying float v_varying;\n"
799 "void main() { gl_FragColor = vec4(v_varying, 0, 0, 1.0); }\n";
Jamie Madill1c28e1f2014-08-04 11:37:54 -0400800
Yuly Novikova1f6dc92016-06-15 23:27:04 -0400801 const std::string vertexShaderSource =
802 "attribute vec4 a_position;\n"
803 "invariant varying float v_varying;\n"
804 "void main() { v_varying = a_position.x; gl_Position = a_position; }\n";
Jamie Madill1c28e1f2014-08-04 11:37:54 -0400805
Jamie Madill5599c8f2014-08-26 13:16:39 -0400806 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
Jamie Madill1c28e1f2014-08-04 11:37:54 -0400807 EXPECT_NE(0u, program);
808}
809
Yuly Novikova1f6dc92016-06-15 23:27:04 -0400810// Verify that declaring varying as invariant in both shaders fails in ESSL 3.00.
811TEST_P(GLSLTest_ES3, InvariantVaryingBoth)
812{
813 const std::string fragmentShaderSource =
814 "#version 300 es\n"
815 "precision mediump float;\n"
816 "invariant in float v_varying;\n"
817 "out vec4 my_FragColor;\n"
818 "void main() { my_FragColor = vec4(v_varying, 0, 0, 1.0); }\n";
819
820 const std::string vertexShaderSource =
821 "#version 300 es\n"
822 "in vec4 a_position;\n"
823 "invariant out float v_varying;\n"
824 "void main() { v_varying = a_position.x; gl_Position = a_position; }\n";
825
826 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
827 EXPECT_EQ(0u, program);
828}
829
830// Verify that declaring gl_Position as invariant succeeds in ESSL 1.00.
Jamie Madillfa05f602015-05-07 13:47:11 -0400831TEST_P(GLSLTest, InvariantGLPosition)
Jamie Madill1c28e1f2014-08-04 11:37:54 -0400832{
Yuly Novikova1f6dc92016-06-15 23:27:04 -0400833 const std::string fragmentShaderSource =
834 "precision mediump float;\n"
835 "varying float v_varying;\n"
836 "void main() { gl_FragColor = vec4(v_varying, 0, 0, 1.0); }\n";
Jamie Madill1c28e1f2014-08-04 11:37:54 -0400837
Yuly Novikova1f6dc92016-06-15 23:27:04 -0400838 const std::string vertexShaderSource =
839 "attribute vec4 a_position;\n"
840 "invariant gl_Position;\n"
841 "varying float v_varying;\n"
842 "void main() { v_varying = a_position.x; gl_Position = a_position; }\n";
Jamie Madill1c28e1f2014-08-04 11:37:54 -0400843
Jamie Madill5599c8f2014-08-26 13:16:39 -0400844 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
Jamie Madill1c28e1f2014-08-04 11:37:54 -0400845 EXPECT_NE(0u, program);
846}
847
Yuly Novikova1f6dc92016-06-15 23:27:04 -0400848// Verify that declaring gl_Position as invariant succeeds in ESSL 3.00.
849TEST_P(GLSLTest_ES3, InvariantGLPosition)
Jamie Madill1c28e1f2014-08-04 11:37:54 -0400850{
Yuly Novikova1f6dc92016-06-15 23:27:04 -0400851 const std::string fragmentShaderSource =
852 "#version 300 es\n"
853 "precision mediump float;\n"
854 "in float v_varying;\n"
855 "out vec4 my_FragColor;\n"
856 "void main() { my_FragColor = vec4(v_varying, 0, 0, 1.0); }\n";
857
858 const std::string vertexShaderSource =
859 "#version 300 es\n"
860 "in vec4 a_position;\n"
861 "invariant gl_Position;\n"
862 "out float v_varying;\n"
863 "void main() { v_varying = a_position.x; gl_Position = a_position; }\n";
864
865 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
866 EXPECT_NE(0u, program);
867}
868
869// Verify that using invariant(all) in both shaders succeeds in ESSL 1.00.
870TEST_P(GLSLTest, InvariantAllBoth)
871{
872 // TODO: ESSL 1.00 -> GLSL 1.20 translation should add "invariant" in fragment shader
873 // for varyings which are invariant in vertex shader individually,
874 // and remove invariant(all) from fragment shader (http://anglebug.com/1293)
875 if (isOpenGL())
Geoff Lange0cc2a42016-01-20 10:58:17 -0500876 {
877 std::cout << "Test disabled on OpenGL." << std::endl;
878 return;
879 }
880
Yuly Novikova1f6dc92016-06-15 23:27:04 -0400881 const std::string fragmentShaderSource =
882 "#pragma STDGL invariant(all)\n"
883 "precision mediump float;\n"
884 "varying float v_varying;\n"
885 "void main() { gl_FragColor = vec4(v_varying, 0, 0, 1.0); }\n";
Jamie Madill1c28e1f2014-08-04 11:37:54 -0400886
887 const std::string vertexShaderSource =
888 "#pragma STDGL invariant(all)\n"
889 "attribute vec4 a_position;\n"
890 "varying float v_varying;\n"
891 "void main() { v_varying = a_position.x; gl_Position = a_position; }\n";
892
Jamie Madill5599c8f2014-08-26 13:16:39 -0400893 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
Jamie Madill1c28e1f2014-08-04 11:37:54 -0400894 EXPECT_NE(0u, program);
895}
Austin Kinrossaf875522014-08-25 21:06:07 -0700896
Yuly Novikova1f6dc92016-06-15 23:27:04 -0400897// Verify that using invariant(all) in both shaders fails in ESSL 3.00.
898TEST_P(GLSLTest_ES3, InvariantAllBoth)
899{
900 const std::string fragmentShaderSource =
901 "#version 300 es\n"
902 "#pragma STDGL invariant(all)\n"
903 "precision mediump float;\n"
904 "in float v_varying;\n"
905 "out vec4 my_FragColor;\n"
906 "void main() { my_FragColor = vec4(v_varying, 0, 0, 1.0); }\n";
907
908 const std::string vertexShaderSource =
909 "#version 300 es\n"
910 "#pragma STDGL invariant(all)\n"
911 "in vec4 a_position;\n"
912 "out float v_varying;\n"
913 "void main() { v_varying = a_position.x; gl_Position = a_position; }\n";
914
915 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
916 EXPECT_EQ(0u, program);
917}
918
919// Verify that using invariant(all) only in fragment shader fails in ESSL 1.00.
920TEST_P(GLSLTest, InvariantAllIn)
921{
922 const std::string fragmentShaderSource =
923 "#pragma STDGL invariant(all)\n"
924 "precision mediump float;\n"
925 "varying float v_varying;\n"
926 "void main() { gl_FragColor = vec4(v_varying, 0, 0, 1.0); }\n";
927
928 const std::string vertexShaderSource =
929 "attribute vec4 a_position;\n"
930 "varying float v_varying;\n"
931 "void main() { v_varying = a_position.x; gl_Position = a_position; }\n";
932
933 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
934 EXPECT_EQ(0u, program);
935}
936
937// Verify that using invariant(all) only in fragment shader fails in ESSL 3.00.
938TEST_P(GLSLTest_ES3, InvariantAllIn)
939{
940 const std::string fragmentShaderSource =
941 "#version 300 es\n"
942 "#pragma STDGL invariant(all)\n"
943 "precision mediump float;\n"
944 "in float v_varying;\n"
945 "out vec4 my_FragColor;\n"
946 "void main() { my_FragColor = vec4(v_varying, 0, 0, 1.0); }\n";
947
948 const std::string vertexShaderSource =
949 "#version 300 es\n"
950 "in vec4 a_position;\n"
951 "out float v_varying;\n"
952 "void main() { v_varying = a_position.x; gl_Position = a_position; }\n";
953
954 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
955 EXPECT_EQ(0u, program);
956}
957
958// Verify that using invariant(all) only in vertex shader fails in ESSL 1.00.
959TEST_P(GLSLTest, InvariantAllOut)
960{
961 const std::string fragmentShaderSource =
962 "precision mediump float;\n"
963 "varying float v_varying;\n"
964 "void main() { gl_FragColor = vec4(v_varying, 0, 0, 1.0); }\n";
965
966 const std::string vertexShaderSource =
967 "#pragma STDGL invariant(all)\n"
968 "attribute vec4 a_position;\n"
969 "varying float v_varying;\n"
970 "void main() { v_varying = a_position.x; gl_Position = a_position; }\n";
971
972 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
973 EXPECT_EQ(0u, program);
974}
975
976// Verify that using invariant(all) only in vertex shader succeeds in ESSL 3.00.
977TEST_P(GLSLTest_ES3, InvariantAllOut)
978{
979 // TODO: ESSL 3.00 -> GLSL 1.20 translation should add "invariant" in fragment shader
980 // for varyings which are invariant in vertex shader,
981 // because of invariant(all) being used in vertex shader (http://anglebug.com/1293)
982 if (isOpenGL())
983 {
984 std::cout << "Test disabled on OpenGL." << std::endl;
985 return;
986 }
987
988 const std::string fragmentShaderSource =
989 "#version 300 es\n"
990 "precision mediump float;\n"
991 "in float v_varying;\n"
992 "out vec4 my_FragColor;\n"
993 "void main() { my_FragColor = vec4(v_varying, 0, 0, 1.0); }\n";
994
995 const std::string vertexShaderSource =
996 "#version 300 es\n"
997 "#pragma STDGL invariant(all)\n"
998 "in vec4 a_position;\n"
999 "out float v_varying;\n"
1000 "void main() { v_varying = a_position.x; gl_Position = a_position; }\n";
1001
1002 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
1003 EXPECT_NE(0u, program);
1004}
1005
Jamie Madillfa05f602015-05-07 13:47:11 -04001006TEST_P(GLSLTest, MaxVaryingVec4)
Austin Kinross8b695ee2015-03-12 13:12:20 -07001007{
Geoff Lang69accbd2016-01-25 16:22:32 -05001008#if defined(__APPLE__)
1009 // TODO(geofflang): Find out why this doesn't compile on Apple AND OpenGL drivers
1010 // (http://anglebug.com/1291)
Jamie Madill518b9fa2016-03-02 11:26:02 -05001011 if (IsAMD() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Geoff Lang69accbd2016-01-25 16:22:32 -05001012 {
1013 std::cout << "Test disabled on Apple AMD OpenGL." << std::endl;
1014 return;
1015 }
1016#endif
1017
Austin Kinross8b695ee2015-03-12 13:12:20 -07001018 GLint maxVaryings = 0;
1019 glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings);
1020
1021 VaryingTestBase(0, 0, 0, 0, 0, 0, maxVaryings, 0, false, false, false, true);
1022}
1023
Jamie Madillfa05f602015-05-07 13:47:11 -04001024TEST_P(GLSLTest, MaxMinusTwoVaryingVec4PlusTwoSpecialVariables)
Austin Kinross8b695ee2015-03-12 13:12:20 -07001025{
1026 GLint maxVaryings = 0;
1027 glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings);
1028
1029 // Generate shader code that uses gl_FragCoord and gl_PointCoord, two special fragment shader variables.
1030 VaryingTestBase(0, 0, 0, 0, 0, 0, maxVaryings - 2, 0, true, true, false, true);
1031}
1032
Jamie Madillfa05f602015-05-07 13:47:11 -04001033TEST_P(GLSLTest, MaxMinusTwoVaryingVec4PlusThreeSpecialVariables)
Austin Kinross8b695ee2015-03-12 13:12:20 -07001034{
Geoff Lange0cc2a42016-01-20 10:58:17 -05001035 // TODO(geofflang): Figure out why this fails on OpenGL AMD (http://anglebug.com/1291)
Jamie Madill518b9fa2016-03-02 11:26:02 -05001036 if (IsAMD() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Geoff Lange0cc2a42016-01-20 10:58:17 -05001037 {
1038 std::cout << "Test disabled on OpenGL." << std::endl;
1039 return;
1040 }
1041
Austin Kinross8b695ee2015-03-12 13:12:20 -07001042 GLint maxVaryings = 0;
1043 glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings);
1044
1045 // Generate shader code that uses gl_FragCoord, gl_PointCoord and gl_PointSize.
1046 VaryingTestBase(0, 0, 0, 0, 0, 0, maxVaryings - 2, 0, true, true, true, true);
1047}
1048
Geoff Lange0cc2a42016-01-20 10:58:17 -05001049// Disabled because drivers are allowed to successfully compile shaders that have more than the
1050// maximum number of varyings. (http://anglebug.com/1296)
1051TEST_P(GLSLTest, DISABLED_MaxVaryingVec4PlusFragCoord)
Austin Kinross8b695ee2015-03-12 13:12:20 -07001052{
1053 GLint maxVaryings = 0;
1054 glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings);
1055
1056 // Generate shader code that uses gl_FragCoord, a special fragment shader variables.
1057 // This test should fail, since we are really using (maxVaryings + 1) varyings.
1058 VaryingTestBase(0, 0, 0, 0, 0, 0, maxVaryings, 0, true, false, false, false);
1059}
1060
Geoff Lange0cc2a42016-01-20 10:58:17 -05001061// Disabled because drivers are allowed to successfully compile shaders that have more than the
1062// maximum number of varyings. (http://anglebug.com/1296)
1063TEST_P(GLSLTest, DISABLED_MaxVaryingVec4PlusPointCoord)
Austin Kinross8b695ee2015-03-12 13:12:20 -07001064{
1065 GLint maxVaryings = 0;
1066 glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings);
1067
1068 // Generate shader code that uses gl_FragCoord, a special fragment shader variables.
1069 // This test should fail, since we are really using (maxVaryings + 1) varyings.
1070 VaryingTestBase(0, 0, 0, 0, 0, 0, maxVaryings, 0, false, true, false, false);
1071}
1072
Jamie Madillfa05f602015-05-07 13:47:11 -04001073TEST_P(GLSLTest, MaxVaryingVec3)
Austin Kinrossaf875522014-08-25 21:06:07 -07001074{
1075 GLint maxVaryings = 0;
1076 glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings);
1077
Austin Kinross8b695ee2015-03-12 13:12:20 -07001078 VaryingTestBase(0, 0, 0, 0, maxVaryings, 0, 0, 0, false, false, false, true);
Austin Kinrossaf875522014-08-25 21:06:07 -07001079}
1080
Jamie Madillfa05f602015-05-07 13:47:11 -04001081TEST_P(GLSLTest, MaxVaryingVec3Array)
Austin Kinrossaf875522014-08-25 21:06:07 -07001082{
1083 GLint maxVaryings = 0;
1084 glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings);
1085
Austin Kinross8b695ee2015-03-12 13:12:20 -07001086 VaryingTestBase(0, 0, 0, 0, 0, maxVaryings / 2, 0, 0, false, false, false, true);
Austin Kinrossaf875522014-08-25 21:06:07 -07001087}
1088
Jamie Madillbee59e02014-10-02 10:44:18 -04001089// Disabled because of a failure in D3D9
Jamie Madill9fc36822015-11-18 13:08:07 -05001090TEST_P(GLSLTest, MaxVaryingVec3AndOneFloat)
Austin Kinrossaf875522014-08-25 21:06:07 -07001091{
Jamie Madill518b9fa2016-03-02 11:26:02 -05001092 if (IsD3D9())
Jamie Madill9fc36822015-11-18 13:08:07 -05001093 {
1094 std::cout << "Test disabled on D3D9." << std::endl;
1095 return;
1096 }
1097
Austin Kinrossaf875522014-08-25 21:06:07 -07001098 GLint maxVaryings = 0;
1099 glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings);
1100
Austin Kinross8b695ee2015-03-12 13:12:20 -07001101 VaryingTestBase(1, 0, 0, 0, maxVaryings, 0, 0, 0, false, false, false, true);
Austin Kinrossaf875522014-08-25 21:06:07 -07001102}
1103
Jamie Madillbee59e02014-10-02 10:44:18 -04001104// Disabled because of a failure in D3D9
Jamie Madill9fc36822015-11-18 13:08:07 -05001105TEST_P(GLSLTest, MaxVaryingVec3ArrayAndOneFloatArray)
Austin Kinrossaf875522014-08-25 21:06:07 -07001106{
Jamie Madill518b9fa2016-03-02 11:26:02 -05001107 if (IsD3D9())
Jamie Madill9fc36822015-11-18 13:08:07 -05001108 {
1109 std::cout << "Test disabled on D3D9." << std::endl;
1110 return;
1111 }
1112
Austin Kinrossaf875522014-08-25 21:06:07 -07001113 GLint maxVaryings = 0;
1114 glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings);
1115
Austin Kinross8b695ee2015-03-12 13:12:20 -07001116 VaryingTestBase(0, 1, 0, 0, 0, maxVaryings / 2, 0, 0, false, false, false, true);
Austin Kinrossaf875522014-08-25 21:06:07 -07001117}
1118
Jamie Madillbee59e02014-10-02 10:44:18 -04001119// Disabled because of a failure in D3D9
Jamie Madill9fc36822015-11-18 13:08:07 -05001120TEST_P(GLSLTest, TwiceMaxVaryingVec2)
Austin Kinrossaf875522014-08-25 21:06:07 -07001121{
Jamie Madill518b9fa2016-03-02 11:26:02 -05001122 if (IsD3D9())
Jamie Madill9fc36822015-11-18 13:08:07 -05001123 {
1124 std::cout << "Test disabled on D3D9." << std::endl;
1125 return;
1126 }
1127
Geoff Lange0cc2a42016-01-20 10:58:17 -05001128 if (getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE)
1129 {
1130 // TODO(geofflang): Figure out why this fails on NVIDIA's GLES driver
1131 std::cout << "Test disabled on OpenGL ES." << std::endl;
1132 return;
1133 }
1134
Geoff Lang69accbd2016-01-25 16:22:32 -05001135#if defined(__APPLE__)
1136 // TODO(geofflang): Find out why this doesn't compile on Apple AND OpenGL drivers
1137 // (http://anglebug.com/1291)
Jamie Madill518b9fa2016-03-02 11:26:02 -05001138 if (IsAMD() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Geoff Lang69accbd2016-01-25 16:22:32 -05001139 {
1140 std::cout << "Test disabled on Apple AMD OpenGL." << std::endl;
1141 return;
1142 }
1143#endif
1144
Austin Kinrossaf875522014-08-25 21:06:07 -07001145 GLint maxVaryings = 0;
1146 glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings);
1147
Austin Kinross8b695ee2015-03-12 13:12:20 -07001148 VaryingTestBase(0, 0, 2 * maxVaryings, 0, 0, 0, 0, 0, false, false, false, true);
Austin Kinrossaf875522014-08-25 21:06:07 -07001149}
1150
Jamie Madillbee59e02014-10-02 10:44:18 -04001151// Disabled because of a failure in D3D9
Jamie Madill9fc36822015-11-18 13:08:07 -05001152TEST_P(GLSLTest, MaxVaryingVec2Arrays)
Austin Kinrossaf875522014-08-25 21:06:07 -07001153{
Jamie Madill518b9fa2016-03-02 11:26:02 -05001154 if (IsD3DSM3())
Jamie Madill9fc36822015-11-18 13:08:07 -05001155 {
1156 std::cout << "Test disabled on SM3." << std::endl;
1157 return;
1158 }
1159
Geoff Lange0cc2a42016-01-20 10:58:17 -05001160 if (getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE)
1161 {
1162 // TODO(geofflang): Figure out why this fails on NVIDIA's GLES driver
1163 std::cout << "Test disabled on OpenGL ES." << std::endl;
1164 return;
1165 }
1166
Geoff Lang69accbd2016-01-25 16:22:32 -05001167#if defined(__APPLE__)
1168 // TODO(geofflang): Find out why this doesn't compile on Apple AND OpenGL drivers
1169 // (http://anglebug.com/1291)
Jamie Madill518b9fa2016-03-02 11:26:02 -05001170 if (IsAMD() && getPlatformRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE)
Geoff Lang69accbd2016-01-25 16:22:32 -05001171 {
1172 std::cout << "Test disabled on Apple AMD OpenGL." << std::endl;
1173 return;
1174 }
1175#endif
1176
Austin Kinrossaf875522014-08-25 21:06:07 -07001177 GLint maxVaryings = 0;
1178 glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings);
1179
Austin Kinross8b695ee2015-03-12 13:12:20 -07001180 VaryingTestBase(0, 0, 0, maxVaryings, 0, 0, 0, 0, false, false, false, true);
Austin Kinrossaf875522014-08-25 21:06:07 -07001181}
1182
Geoff Lange0cc2a42016-01-20 10:58:17 -05001183// Disabled because drivers are allowed to successfully compile shaders that have more than the
1184// maximum number of varyings. (http://anglebug.com/1296)
1185TEST_P(GLSLTest, DISABLED_MaxPlusOneVaryingVec3)
Austin Kinrossaf875522014-08-25 21:06:07 -07001186{
1187 GLint maxVaryings = 0;
1188 glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings);
1189
Austin Kinross8b695ee2015-03-12 13:12:20 -07001190 VaryingTestBase(0, 0, 0, 0, maxVaryings + 1, 0, 0, 0, false, false, false, false);
Austin Kinrossaf875522014-08-25 21:06:07 -07001191}
1192
Geoff Lange0cc2a42016-01-20 10:58:17 -05001193// Disabled because drivers are allowed to successfully compile shaders that have more than the
1194// maximum number of varyings. (http://anglebug.com/1296)
1195TEST_P(GLSLTest, DISABLED_MaxPlusOneVaryingVec3Array)
Austin Kinrossaf875522014-08-25 21:06:07 -07001196{
1197 GLint maxVaryings = 0;
1198 glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings);
1199
Austin Kinross8b695ee2015-03-12 13:12:20 -07001200 VaryingTestBase(0, 0, 0, 0, 0, maxVaryings / 2 + 1, 0, 0, false, false, false, false);
Austin Kinrossaf875522014-08-25 21:06:07 -07001201}
1202
Geoff Lange0cc2a42016-01-20 10:58:17 -05001203// Disabled because drivers are allowed to successfully compile shaders that have more than the
1204// maximum number of varyings. (http://anglebug.com/1296)
1205TEST_P(GLSLTest, DISABLED_MaxVaryingVec3AndOneVec2)
Austin Kinrossaf875522014-08-25 21:06:07 -07001206{
1207 GLint maxVaryings = 0;
1208 glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings);
1209
Austin Kinross8b695ee2015-03-12 13:12:20 -07001210 VaryingTestBase(0, 0, 1, 0, maxVaryings, 0, 0, 0, false, false, false, false);
Austin Kinrossaf875522014-08-25 21:06:07 -07001211}
1212
Geoff Lange0cc2a42016-01-20 10:58:17 -05001213// Disabled because drivers are allowed to successfully compile shaders that have more than the
1214// maximum number of varyings. (http://anglebug.com/1296)
1215TEST_P(GLSLTest, DISABLED_MaxPlusOneVaryingVec2)
Austin Kinrossaf875522014-08-25 21:06:07 -07001216{
1217 GLint maxVaryings = 0;
1218 glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings);
1219
Austin Kinross8b695ee2015-03-12 13:12:20 -07001220 VaryingTestBase(0, 0, 2 * maxVaryings + 1, 0, 0, 0, 0, 0, false, false, false, false);
Austin Kinrossaf875522014-08-25 21:06:07 -07001221}
1222
Geoff Lange0cc2a42016-01-20 10:58:17 -05001223// Disabled because drivers are allowed to successfully compile shaders that have more than the
1224// maximum number of varyings. (http://anglebug.com/1296)
1225TEST_P(GLSLTest, DISABLED_MaxVaryingVec3ArrayAndMaxPlusOneFloatArray)
Austin Kinrossaf875522014-08-25 21:06:07 -07001226{
1227 GLint maxVaryings = 0;
1228 glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryings);
1229
Austin Kinross8b695ee2015-03-12 13:12:20 -07001230 VaryingTestBase(0, maxVaryings / 2 + 1, 0, 0, 0, 0, 0, maxVaryings / 2, false, false, false, false);
Austin Kinrossaf875522014-08-25 21:06:07 -07001231}
Geoff Langf60fab62014-11-24 11:21:20 -05001232
1233// Verify shader source with a fixed length that is less than the null-terminated length will compile.
Jamie Madillfa05f602015-05-07 13:47:11 -04001234TEST_P(GLSLTest, FixedShaderLength)
Geoff Langf60fab62014-11-24 11:21:20 -05001235{
1236 GLuint shader = glCreateShader(GL_FRAGMENT_SHADER);
1237
1238 const std::string appendGarbage = "abcasdfasdfasdfasdfasdf";
1239 const std::string source = "void main() { gl_FragColor = vec4(0, 0, 0, 0); }" + appendGarbage;
1240 const char *sourceArray[1] = { source.c_str() };
Corentin Wallez973402f2015-05-11 13:42:22 -04001241 GLint lengths[1] = { static_cast<GLint>(source.length() - appendGarbage.length()) };
Cooper Partin4d61f7e2015-08-12 10:56:50 -07001242 glShaderSource(shader, static_cast<GLsizei>(ArraySize(sourceArray)), sourceArray, lengths);
Geoff Langf60fab62014-11-24 11:21:20 -05001243 glCompileShader(shader);
1244
1245 GLint compileResult;
1246 glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult);
1247 EXPECT_NE(compileResult, 0);
1248}
1249
1250// Verify that a negative shader source length is treated as a null-terminated length.
Jamie Madillfa05f602015-05-07 13:47:11 -04001251TEST_P(GLSLTest, NegativeShaderLength)
Geoff Langf60fab62014-11-24 11:21:20 -05001252{
1253 GLuint shader = glCreateShader(GL_FRAGMENT_SHADER);
1254
1255 const char *sourceArray[1] = { "void main() { gl_FragColor = vec4(0, 0, 0, 0); }" };
1256 GLint lengths[1] = { -10 };
Cooper Partin4d61f7e2015-08-12 10:56:50 -07001257 glShaderSource(shader, static_cast<GLsizei>(ArraySize(sourceArray)), sourceArray, lengths);
Geoff Langf60fab62014-11-24 11:21:20 -05001258 glCompileShader(shader);
1259
1260 GLint compileResult;
1261 glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult);
1262 EXPECT_NE(compileResult, 0);
1263}
1264
Corentin Wallez9a9c0482016-04-12 10:36:25 -04001265// Check that having an invalid char after the "." doesn't cause an assert.
1266TEST_P(GLSLTest, InvalidFieldFirstChar)
1267{
1268 GLuint shader = glCreateShader(GL_VERTEX_SHADER);
1269 const char *source = "void main() {vec4 x; x.}";
1270 glShaderSource(shader, 1, &source, 0);
1271 glCompileShader(shader);
1272
1273 GLint compileResult;
1274 glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult);
1275 EXPECT_EQ(0, compileResult);
1276}
1277
Geoff Langf60fab62014-11-24 11:21:20 -05001278// Verify that a length array with mixed positive and negative values compiles.
Jamie Madillfa05f602015-05-07 13:47:11 -04001279TEST_P(GLSLTest, MixedShaderLengths)
Geoff Langf60fab62014-11-24 11:21:20 -05001280{
1281 GLuint shader = glCreateShader(GL_FRAGMENT_SHADER);
1282
1283 const char *sourceArray[] =
1284 {
1285 "void main()",
1286 "{",
1287 " gl_FragColor = vec4(0, 0, 0, 0);",
1288 "}",
1289 };
1290 GLint lengths[] =
1291 {
1292 -10,
1293 1,
Corentin Wallez973402f2015-05-11 13:42:22 -04001294 static_cast<GLint>(strlen(sourceArray[2])),
Geoff Langf60fab62014-11-24 11:21:20 -05001295 -1,
1296 };
1297 ASSERT_EQ(ArraySize(sourceArray), ArraySize(lengths));
1298
Cooper Partin4d61f7e2015-08-12 10:56:50 -07001299 glShaderSource(shader, static_cast<GLsizei>(ArraySize(sourceArray)), sourceArray, lengths);
Geoff Langf60fab62014-11-24 11:21:20 -05001300 glCompileShader(shader);
1301
1302 GLint compileResult;
1303 glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult);
1304 EXPECT_NE(compileResult, 0);
1305}
1306
1307// Verify that zero-length shader source does not affect shader compilation.
Jamie Madillfa05f602015-05-07 13:47:11 -04001308TEST_P(GLSLTest, ZeroShaderLength)
Geoff Langf60fab62014-11-24 11:21:20 -05001309{
1310 GLuint shader = glCreateShader(GL_FRAGMENT_SHADER);
1311
1312 const char *sourceArray[] =
1313 {
1314 "adfasdf",
1315 "34534",
1316 "void main() { gl_FragColor = vec4(0, 0, 0, 0); }",
1317 "",
1318 "asdfasdfsdsdf",
1319 };
1320 GLint lengths[] =
1321 {
1322 0,
1323 0,
1324 -1,
1325 0,
1326 0,
1327 };
1328 ASSERT_EQ(ArraySize(sourceArray), ArraySize(lengths));
1329
Cooper Partin4d61f7e2015-08-12 10:56:50 -07001330 glShaderSource(shader, static_cast<GLsizei>(ArraySize(sourceArray)), sourceArray, lengths);
Geoff Langf60fab62014-11-24 11:21:20 -05001331 glCompileShader(shader);
1332
1333 GLint compileResult;
1334 glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult);
1335 EXPECT_NE(compileResult, 0);
1336}
Jamie Madill21c1e452014-12-29 11:33:41 -05001337
1338// Tests that bad index expressions don't crash ANGLE's translator.
1339// https://code.google.com/p/angleproject/issues/detail?id=857
Jamie Madillfa05f602015-05-07 13:47:11 -04001340TEST_P(GLSLTest, BadIndexBug)
Jamie Madill21c1e452014-12-29 11:33:41 -05001341{
1342 const std::string &fragmentShaderSourceVec =
1343 "precision mediump float;\n"
1344 "uniform vec4 uniformVec;\n"
1345 "void main()\n"
1346 "{\n"
1347 " gl_FragColor = vec4(uniformVec[int()]);\n"
1348 "}";
1349
1350 GLuint shader = CompileShader(GL_FRAGMENT_SHADER, fragmentShaderSourceVec);
1351 EXPECT_EQ(0u, shader);
1352
1353 if (shader != 0)
1354 {
1355 glDeleteShader(shader);
1356 }
1357
1358 const std::string &fragmentShaderSourceMat =
1359 "precision mediump float;\n"
1360 "uniform mat4 uniformMat;\n"
1361 "void main()\n"
1362 "{\n"
1363 " gl_FragColor = vec4(uniformMat[int()]);\n"
1364 "}";
1365
1366 shader = CompileShader(GL_FRAGMENT_SHADER, fragmentShaderSourceMat);
1367 EXPECT_EQ(0u, shader);
1368
1369 if (shader != 0)
1370 {
1371 glDeleteShader(shader);
1372 }
1373
1374 const std::string &fragmentShaderSourceArray =
1375 "precision mediump float;\n"
1376 "uniform vec4 uniformArray;\n"
1377 "void main()\n"
1378 "{\n"
1379 " gl_FragColor = vec4(uniformArray[int()]);\n"
1380 "}";
1381
1382 shader = CompileShader(GL_FRAGMENT_SHADER, fragmentShaderSourceArray);
1383 EXPECT_EQ(0u, shader);
1384
1385 if (shader != 0)
1386 {
1387 glDeleteShader(shader);
1388 }
Jamie Madill37997142015-01-28 10:06:34 -05001389}
1390
Jamie Madill2e295e22015-04-29 10:41:33 -04001391// Test that structs defined in uniforms are translated correctly.
Jamie Madillfa05f602015-05-07 13:47:11 -04001392TEST_P(GLSLTest, StructSpecifiersUniforms)
Jamie Madill2e295e22015-04-29 10:41:33 -04001393{
1394 const std::string fragmentShaderSource = SHADER_SOURCE
1395 (
1396 precision mediump float;
1397
1398 uniform struct S { float field;} s;
1399
1400 void main()
1401 {
1402 gl_FragColor = vec4(1, 0, 0, 1);
1403 gl_FragColor.a += s.field;
1404 }
1405 );
1406
1407 GLuint program = CompileProgram(mSimpleVSSource, fragmentShaderSource);
1408 EXPECT_NE(0u, program);
1409}
Jamie Madill55def582015-05-04 11:24:57 -04001410
1411// Test that gl_DepthRange is not stored as a uniform location. Since uniforms
1412// beginning with "gl_" are filtered out by our validation logic, we must
1413// bypass the validation to test the behaviour of the implementation.
1414// (note this test is still Impl-independent)
Jamie Madillfa05f602015-05-07 13:47:11 -04001415TEST_P(GLSLTest, DepthRangeUniforms)
Jamie Madill55def582015-05-04 11:24:57 -04001416{
1417 const std::string fragmentShaderSource = SHADER_SOURCE
1418 (
1419 precision mediump float;
1420
1421 void main()
1422 {
1423 gl_FragColor = vec4(gl_DepthRange.near, gl_DepthRange.far, gl_DepthRange.diff, 1);
1424 }
1425 );
1426
1427 GLuint program = CompileProgram(mSimpleVSSource, fragmentShaderSource);
1428 EXPECT_NE(0u, program);
1429
1430 // dive into the ANGLE internals, so we can bypass validation.
1431 gl::Context *context = reinterpret_cast<gl::Context *>(getEGLWindow()->getContext());
1432 gl::Program *glProgram = context->getProgram(program);
1433 GLint nearIndex = glProgram->getUniformLocation("gl_DepthRange.near");
1434 EXPECT_EQ(-1, nearIndex);
1435
1436 // Test drawing does not throw an exception.
1437 drawQuad(program, "inputAttribute", 0.5f);
1438
1439 EXPECT_GL_NO_ERROR();
1440
1441 glDeleteProgram(program);
1442}
Jamie Madill4052dfc2015-05-06 15:18:49 -04001443
1444// Covers the WebGL test 'glsl/bugs/pow-of-small-constant-in-user-defined-function'
1445// See https://code.google.com/p/angleproject/issues/detail?id=851
1446// TODO(jmadill): ANGLE constant folding can fix this
Jamie Madillfa05f602015-05-07 13:47:11 -04001447TEST_P(GLSLTest, DISABLED_PowOfSmallConstant)
Jamie Madill4052dfc2015-05-06 15:18:49 -04001448{
1449 const std::string &fragmentShaderSource = SHADER_SOURCE
1450 (
1451 precision highp float;
1452
1453 float fun(float arg)
1454 {
1455 // These values are still easily within the highp range.
1456 // The minimum range in terms of 10's exponent is around -19 to 19, and IEEE-754 single precision range is higher than that.
1457 return pow(arg, 2.0);
1458 }
1459
1460 void main()
1461 {
1462 // Note that the bug did not reproduce if an uniform was passed to the function instead of a constant,
1463 // or if the expression was moved outside the user-defined function.
1464 const float a = 1.0e-6;
1465 float b = 1.0e12 * fun(a);
1466 if (abs(b - 1.0) < 0.01)
1467 {
1468 gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0); // green
1469 }
1470 else
1471 {
1472 gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); // red
1473 }
1474 }
1475 );
1476
1477 GLuint program = CompileProgram(mSimpleVSSource, fragmentShaderSource);
1478 EXPECT_NE(0u, program);
1479
1480 drawQuad(program, "inputAttribute", 0.5f);
1481 EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
1482 EXPECT_GL_NO_ERROR();
1483}
Jamie Madillfa05f602015-05-07 13:47:11 -04001484
Cooper Partina5ef8d82015-08-19 14:52:21 -07001485// Test that fragment shaders which contain non-constant loop indexers and compiled for FL9_3 and
1486// below
1487// fail with a specific error message.
1488// Additionally test that the same fragment shader compiles successfully with feature levels greater
1489// than FL9_3.
1490TEST_P(GLSLTest, LoopIndexingValidation)
1491{
1492 const std::string fragmentShaderSource = SHADER_SOURCE
1493 (
1494 precision mediump float;
1495
1496 uniform float loopMax;
1497
1498 void main()
1499 {
1500 gl_FragColor = vec4(1, 0, 0, 1);
1501 for (float l = 0.0; l < loopMax; l++)
1502 {
1503 if (loopMax > 3.0)
1504 {
1505 gl_FragColor.a += 0.1;
1506 }
1507 }
1508 }
1509 );
1510
1511 GLuint shader = glCreateShader(GL_FRAGMENT_SHADER);
1512
1513 const char *sourceArray[1] = {fragmentShaderSource.c_str()};
1514 glShaderSource(shader, 1, sourceArray, nullptr);
1515 glCompileShader(shader);
1516
1517 GLint compileResult;
1518 glGetShaderiv(shader, GL_COMPILE_STATUS, &compileResult);
1519
1520 // If the test is configured to run limited to Feature Level 9_3, then it is
1521 // assumed that shader compilation will fail with an expected error message containing
1522 // "Loop index cannot be compared with non-constant expression"
Olli Etuaho814a54d2015-08-27 16:23:09 +03001523 if ((GetParam() == ES2_D3D11_FL9_3() || GetParam() == ES2_D3D9()))
Cooper Partina5ef8d82015-08-19 14:52:21 -07001524 {
1525 if (compileResult != 0)
1526 {
1527 FAIL() << "Shader compilation succeeded, expected failure";
1528 }
1529 else
1530 {
1531 GLint infoLogLength;
1532 glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);
1533
1534 std::string infoLog;
1535 infoLog.resize(infoLogLength);
1536 glGetShaderInfoLog(shader, static_cast<GLsizei>(infoLog.size()), NULL, &infoLog[0]);
1537
1538 if (infoLog.find("Loop index cannot be compared with non-constant expression") ==
1539 std::string::npos)
1540 {
1541 FAIL() << "Shader compilation failed with unexpected error message";
1542 }
1543 }
1544 }
1545 else
1546 {
1547 EXPECT_NE(0, compileResult);
1548 }
1549
1550 if (shader != 0)
1551 {
1552 glDeleteShader(shader);
1553 }
1554}
1555
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001556// Tests that the maximum uniforms count returned from querying GL_MAX_VERTEX_UNIFORM_VECTORS
1557// can actually be used.
1558TEST_P(GLSLTest, VerifyMaxVertexUniformVectors)
1559{
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001560 int maxUniforms = 10000;
1561 glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, &maxUniforms);
1562 EXPECT_GL_NO_ERROR();
1563 std::cout << "Validating GL_MAX_VERTEX_UNIFORM_VECTORS = " << maxUniforms << std::endl;
1564
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001565 CompileGLSLWithUniformsAndSamplers(maxUniforms, 0, 0, 0, true);
1566}
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001567
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001568// Tests that the maximum uniforms count returned from querying GL_MAX_VERTEX_UNIFORM_VECTORS
1569// can actually be used along with the maximum number of texture samplers.
1570TEST_P(GLSLTest, VerifyMaxVertexUniformVectorsWithSamplers)
1571{
Geoff Lange0cc2a42016-01-20 10:58:17 -05001572 if (GetParam().eglParameters.renderer == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE ||
1573 GetParam().eglParameters.renderer == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE)
1574 {
1575 std::cout << "Test disabled on OpenGL." << std::endl;
1576 return;
1577 }
1578
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001579 int maxUniforms = 10000;
1580 glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, &maxUniforms);
1581 EXPECT_GL_NO_ERROR();
1582 std::cout << "Validating GL_MAX_VERTEX_UNIFORM_VECTORS = " << maxUniforms << std::endl;
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001583
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001584 int maxTextureImageUnits = 0;
1585 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &maxTextureImageUnits);
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001586
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001587 CompileGLSLWithUniformsAndSamplers(maxUniforms, 0, maxTextureImageUnits, 0, true);
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001588}
1589
1590// Tests that the maximum uniforms count + 1 from querying GL_MAX_VERTEX_UNIFORM_VECTORS
1591// fails shader compilation.
1592TEST_P(GLSLTest, VerifyMaxVertexUniformVectorsExceeded)
1593{
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001594 int maxUniforms = 10000;
1595 glGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, &maxUniforms);
1596 EXPECT_GL_NO_ERROR();
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001597 std::cout << "Validating GL_MAX_VERTEX_UNIFORM_VECTORS + 1 = " << maxUniforms + 1 << std::endl;
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001598
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001599 CompileGLSLWithUniformsAndSamplers(maxUniforms + 1, 0, 0, 0, false);
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001600}
1601
1602// Tests that the maximum uniforms count returned from querying GL_MAX_FRAGMENT_UNIFORM_VECTORS
1603// can actually be used.
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001604TEST_P(GLSLTest, VerifyMaxFragmentUniformVectors)
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001605{
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001606 int maxUniforms = 10000;
1607 glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, &maxUniforms);
1608 EXPECT_GL_NO_ERROR();
1609 std::cout << "Validating GL_MAX_FRAGMENT_UNIFORM_VECTORS = " << maxUniforms << std::endl;
1610
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001611 CompileGLSLWithUniformsAndSamplers(0, maxUniforms, 0, 0, true);
1612}
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001613
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001614// Tests that the maximum uniforms count returned from querying GL_MAX_FRAGMENT_UNIFORM_VECTORS
1615// can actually be used along with the maximum number of texture samplers.
1616TEST_P(GLSLTest, VerifyMaxFragmentUniformVectorsWithSamplers)
1617{
Geoff Lange0cc2a42016-01-20 10:58:17 -05001618 if (GetParam().eglParameters.renderer == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE ||
1619 GetParam().eglParameters.renderer == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE)
1620 {
1621 std::cout << "Test disabled on OpenGL." << std::endl;
1622 return;
1623 }
1624
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001625 int maxUniforms = 10000;
1626 glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, &maxUniforms);
1627 EXPECT_GL_NO_ERROR();
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001628
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001629 int maxTextureImageUnits = 0;
1630 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureImageUnits);
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001631
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001632 CompileGLSLWithUniformsAndSamplers(0, maxUniforms, 0, maxTextureImageUnits, true);
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001633}
1634
1635// Tests that the maximum uniforms count + 1 from querying GL_MAX_FRAGMENT_UNIFORM_VECTORS
1636// fails shader compilation.
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001637TEST_P(GLSLTest, VerifyMaxFragmentUniformVectorsExceeded)
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001638{
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001639 int maxUniforms = 10000;
1640 glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, &maxUniforms);
1641 EXPECT_GL_NO_ERROR();
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001642 std::cout << "Validating GL_MAX_FRAGMENT_UNIFORM_VECTORS + 1 = " << maxUniforms + 1
1643 << std::endl;
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001644
Austin Kinross7a3e8e22015-10-08 15:50:06 -07001645 CompileGLSLWithUniformsAndSamplers(0, maxUniforms + 1, 0, 0, false);
Cooper Partin69f9b2c2015-08-20 13:25:41 -07001646}
1647
Olli Etuahobe59c2f2016-03-07 11:32:34 +02001648// Test that two constructors which have vec4 and mat2 parameters get disambiguated (issue in
1649// HLSL).
1650TEST_P(GLSLTest_ES3, AmbiguousConstructorCall2x2)
1651{
1652 const std::string fragmentShaderSource =
1653 "#version 300 es\n"
1654 "precision highp float;\n"
1655 "out vec4 my_FragColor;\n"
1656 "void main()\n"
1657 "{\n"
1658 " my_FragColor = vec4(0.0);\n"
1659 "}";
1660
1661 const std::string vertexShaderSource =
1662 "#version 300 es\n"
1663 "precision highp float;\n"
1664 "in vec4 a_vec;\n"
1665 "in mat2 a_mat;\n"
1666 "void main()\n"
1667 "{\n"
1668 " gl_Position = vec4(a_vec) + vec4(a_mat);\n"
1669 "}";
1670
1671 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
1672 EXPECT_NE(0u, program);
1673}
1674
1675// Test that two constructors which have mat2x3 and mat3x2 parameters get disambiguated.
1676// This was suspected to be an issue in HLSL, but HLSL seems to be able to natively choose between
1677// the function signatures in this case.
1678TEST_P(GLSLTest_ES3, AmbiguousConstructorCall2x3)
1679{
1680 const std::string fragmentShaderSource =
1681 "#version 300 es\n"
1682 "precision highp float;\n"
1683 "out vec4 my_FragColor;\n"
1684 "void main()\n"
1685 "{\n"
1686 " my_FragColor = vec4(0.0);\n"
1687 "}";
1688
1689 const std::string vertexShaderSource =
1690 "#version 300 es\n"
1691 "precision highp float;\n"
1692 "in mat3x2 a_matA;\n"
1693 "in mat2x3 a_matB;\n"
1694 "void main()\n"
1695 "{\n"
1696 " gl_Position = vec4(a_matA) + vec4(a_matB);\n"
1697 "}";
1698
1699 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
1700 EXPECT_NE(0u, program);
1701}
1702
1703// Test that two functions which have vec4 and mat2 parameters get disambiguated (issue in HLSL).
1704TEST_P(GLSLTest_ES3, AmbiguousFunctionCall2x2)
1705{
1706 const std::string fragmentShaderSource =
1707 "#version 300 es\n"
1708 "precision highp float;\n"
1709 "out vec4 my_FragColor;\n"
1710 "void main()\n"
1711 "{\n"
1712 " my_FragColor = vec4(0.0);\n"
1713 "}";
1714
1715 const std::string vertexShaderSource =
1716 "#version 300 es\n"
1717 "precision highp float;\n"
1718 "in vec4 a_vec;\n"
1719 "in mat2 a_mat;\n"
1720 "vec4 foo(vec4 a)\n"
1721 "{\n"
1722 " return a;\n"
1723 "}\n"
1724 "vec4 foo(mat2 a)\n"
1725 "{\n"
1726 " return vec4(a[0][0]);\n"
1727 "}\n"
1728 "void main()\n"
1729 "{\n"
1730 " gl_Position = foo(a_vec) + foo(a_mat);\n"
1731 "}";
1732
1733 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
1734 EXPECT_NE(0u, program);
1735}
1736
1737// Test that an user-defined function with a large number of float4 parameters doesn't fail due to
1738// the function name being too long.
1739TEST_P(GLSLTest_ES3, LargeNumberOfFloat4Parameters)
1740{
1741 const std::string fragmentShaderSource =
1742 "#version 300 es\n"
1743 "precision highp float;\n"
1744 "out vec4 my_FragColor;\n"
1745 "void main()\n"
1746 "{\n"
1747 " my_FragColor = vec4(0.0);\n"
1748 "}";
1749
1750 std::stringstream vertexShaderStream;
1751 const unsigned int paramCount = 1024u;
1752
1753 vertexShaderStream << "#version 300 es\n"
1754 "precision highp float;\n"
1755 "in vec4 a_vec;\n"
1756 "vec4 lotsOfVec4Parameters(";
1757 for (unsigned int i = 0; i < paramCount; ++i)
1758 {
1759 vertexShaderStream << "vec4 a" << i << ", ";
1760 }
1761 vertexShaderStream << "vec4 aLast)\n"
1762 "{\n"
1763 " return ";
1764 for (unsigned int i = 0; i < paramCount; ++i)
1765 {
1766 vertexShaderStream << "a" << i << " + ";
1767 }
1768 vertexShaderStream << "aLast;\n"
1769 "}\n"
1770 "void main()\n"
1771 "{\n"
1772 " gl_Position = lotsOfVec4Parameters(";
1773 for (unsigned int i = 0; i < paramCount; ++i)
1774 {
1775 vertexShaderStream << "a_vec, ";
1776 }
1777 vertexShaderStream << "a_vec);\n"
1778 "}";
1779
1780 GLuint program = CompileProgram(vertexShaderStream.str(), fragmentShaderSource);
1781 EXPECT_NE(0u, program);
1782}
1783
Olli Etuahod4f4c112016-04-15 15:11:24 +03001784// This test was written specifically to stress DeferGlobalInitializers AST transformation.
1785// Test a shader where a global constant array is initialized with an expression containing array
1786// indexing. This initializer is tricky to constant fold, so if it's not constant folded it needs to
1787// be handled in a way that doesn't generate statements in the global scope in HLSL output.
1788// Also includes multiple array initializers in one declaration, where only the second one has
1789// array indexing. This makes sure that the qualifier for the declaration is set correctly if
1790// transformations are applied to the declaration also in the case of ESSL output.
1791TEST_P(GLSLTest_ES3, InitGlobalArrayWithArrayIndexing)
1792{
1793 const std::string vertexShaderSource =
1794 "#version 300 es\n"
1795 "precision highp float;\n"
1796 "in vec4 a_vec;\n"
1797 "void main()\n"
1798 "{\n"
1799 " gl_Position = vec4(a_vec);\n"
1800 "}";
1801
1802 const std::string fragmentShaderSource =
1803 "#version 300 es\n"
1804 "precision highp float;\n"
1805 "out vec4 my_FragColor;\n"
1806 "const highp float f[2] = float[2](0.1, 0.2);\n"
1807 "const highp float[2] g = float[2](0.3, 0.4), h = float[2](0.5, f[1]);\n"
1808 "void main()\n"
1809 "{\n"
1810 " my_FragColor = vec4(h[1]);\n"
1811 "}";
1812
1813 GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
1814 EXPECT_NE(0u, program);
1815}
1816
Jamie Madillfa05f602015-05-07 13:47:11 -04001817// 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 -05001818ANGLE_INSTANTIATE_TEST(GLSLTest,
1819 ES2_D3D9(),
1820 ES2_D3D11(),
1821 ES2_D3D11_FL9_3(),
1822 ES2_OPENGL(),
1823 ES3_OPENGL(),
1824 ES2_OPENGLES(),
1825 ES3_OPENGLES());
Jamie Madillfa05f602015-05-07 13:47:11 -04001826
1827// 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 -05001828ANGLE_INSTANTIATE_TEST(GLSLTest_ES3, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES());