1# Tests todo:
2# - inout with varyings, attributes, uniforms (and arrays of 'em)
3# - inout with arrays, array elements
4# - inout with array elements
5# - inout by-value semantics (arrays & elements & structs)
6
7# Done:
8# - control flow: return, return in loop, etc.
9
10group datatypes "Function Parameter Data Types"
11
12	case float_float
13		values
14		{
15			input float in0		= [ 0.0 | 1.0 | -2.0 | 2.5 ];
16			output float out0	= [ 0.0 | -1.0 | 2.0 | -2.5 ];
17		}
18
19		both ""
20			precision mediump float;
21			${DECLARATIONS}
22
23			float func (float a)
24			{
25				return -a;
26			}
27
28			void main()
29			{
30				out0 = func(in0);
31				${OUTPUT}
32			}
33		""
34	end
35
36	case float_vec2
37		values
38		{
39			input vec2 in0		= [ vec2(0.0, 1.0) | vec2(2.0, 2.5) ];
40			output float out0	= [ -1.0 | -4.5 ];
41		}
42
43		both ""
44			precision mediump float;
45			${DECLARATIONS}
46
47			float func (vec2 a)
48			{
49				return -(a.x + a.y);
50			}
51
52			void main()
53			{
54				out0 = func(in0);
55				${OUTPUT}
56			}
57		""
58	end
59
60	case float_vec3
61		values
62		{
63			input vec3 in0		= [ vec3(0.0, 1.0, -2.0) | vec3(2.0, 2.5, -4.0) ];
64			output float out0	= [ 1.0 | -0.5 ];
65		}
66
67		both ""
68			precision mediump float;
69			${DECLARATIONS}
70
71			float func (vec3 a)
72			{
73				return -(a.x + a.y + a.z);
74			}
75
76			void main()
77			{
78				out0 = func(in0);
79				${OUTPUT}
80			}
81		""
82	end
83
84	case float_vec4
85		values
86		{
87			input vec4 in0		= [ vec4(0.0, 1.0, -2.0, 0.5) | vec4(2.0, 2.5, 4.0, -7.0) ];
88			output float out0	= [ 0.5 | -1.5 ];
89		}
90
91		both ""
92			precision mediump float;
93			${DECLARATIONS}
94
95			float func (vec4 a)
96			{
97				return -(a.x + a.y + a.z + a.w);
98			}
99
100			void main()
101			{
102				out0 = func(in0);
103				${OUTPUT}
104			}
105		""
106	end
107
108	case float_mat2
109		values
110		{
111			input mat2 in0		= [ mat2(0.0, 1.0, -2.0, 0.5) | mat2(2.0, 2.5, 4.0, -7.0) ];
112			output float out0	= [ 0.5 | -1.5 ];
113		}
114
115		both ""
116			precision mediump float;
117			${DECLARATIONS}
118
119			float func (mat2 a)
120			{
121				return -(a[0][0] + a[0][1] + a[1][0] + a[1][1]);
122			}
123
124			void main()
125			{
126				out0 = func(in0);
127				${OUTPUT}
128			}
129		""
130	end
131
132	case float_mat3
133		values
134		{
135			input mat3 in0		= [ mat3(0.0, 1.0, -2.0, 0.5, 1.0, -1.0, 2.0, 4.0, -1.0) | mat3(2.0, 2.5, 4.0, -7.0, 2.5, 3.0, 0.5, -3.5, 1.0) ];
136			output float out0	= [ -4.5 | -5.0 ];
137		}
138
139		both ""
140			precision mediump float;
141			${DECLARATIONS}
142
143			float func (mat3 a)
144			{
145				return -(a[0][0] + a[0][1] + a[0][2] + a[1][0] + a[1][1] + a[1][2] + a[2][0] + a[2][1] + a[2][2]);
146			}
147
148			void main()
149			{
150				out0 = func(in0);
151				${OUTPUT}
152			}
153		""
154	end
155
156	case float_mat4
157		values
158		{
159			input mat4 in0		= [ mat4(0.0, 1.0, -2.0, 0.5, 1.0, -1.0, 2.0, 4.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -2.0, -2.0) | mat4(2.0, 2.5, 4.0, -7.0, 2.5, 3.0, 0.5, -3.5, 1.0, 0.0, 2.0, -1.0, 1.0, 0.0, -1.0, 3.0) ];
160			output float out0	= [ -5.5 | -9.0 ];
161		}
162
163		both ""
164			precision mediump float;
165			${DECLARATIONS}
166
167			float func (mat4 a)
168			{
169				return -(a[0][0] + a[0][1] + a[0][2] + a[0][3] + a[1][0] + a[1][1] + a[1][2] + a[1][3] + a[2][0] + a[2][1] + a[2][2] + a[2][3] + a[3][0] + a[3][1] + a[3][2] + a[3][3]);
170			}
171
172			void main()
173			{
174				out0 = func(in0);
175				${OUTPUT}
176			}
177		""
178	end
179
180	case int_int
181		values
182		{
183			input int in0		= [ -1 | 0 | 1 | 4 ];
184			output int out0		= [ 1 | 0 | -1 | -4 ];
185		}
186
187		both ""
188			precision mediump float;
189			precision mediump int;
190			${DECLARATIONS}
191
192			int func (int a)
193			{
194				return -a;
195			}
196
197			void main()
198			{
199				${SETUP}
200				out0 = func(in0);
201				${OUTPUT}
202			}
203		""
204	end
205
206	case int_ivec2
207		values
208		{
209			input ivec2 in0		= [ ivec2(-1, 0) | ivec2(1, 4) ];
210			output int out0		= [ 1 | -5 ];
211		}
212
213		both ""
214			precision mediump float;
215			precision mediump int;
216			${DECLARATIONS}
217
218			int func (ivec2 a)
219			{
220				return -(a.x + a.y);
221			}
222
223			void main()
224			{
225				${SETUP}
226				out0 = func(in0);
227				${OUTPUT}
228			}
229		""
230	end
231
232	case int_ivec3
233		values
234		{
235			input ivec3 in0		= [ ivec3(-1, 0, 2) | ivec3(1, 4, -8) ];
236			output int out0		= [ -1 | 3 ];
237		}
238
239		both ""
240			precision mediump float;
241			precision mediump int;
242			${DECLARATIONS}
243
244			int func (ivec3 a)
245			{
246				return -(a.x + a.y + a.z);
247			}
248
249			void main()
250			{
251				${SETUP}
252				out0 = func(in0);
253				${OUTPUT}
254			}
255		""
256	end
257
258	case int_ivec4
259		values
260		{
261			input ivec4 in0		= [ ivec4(-1, 0, 2, 2) | ivec4(1, 4, -8, 2) ];
262			output int out0		= [ -3 | 1 ];
263		}
264
265		both ""
266			precision mediump float;
267			precision mediump int;
268			${DECLARATIONS}
269
270			int func (ivec4 a)
271			{
272				return -(a.x + a.y + a.z + a.w);
273			}
274
275			void main()
276			{
277				${SETUP}
278				out0 = func(in0);
279				${OUTPUT}
280			}
281		""
282	end
283
284	case bool_bool
285		values
286		{
287			input bool in0		= [ true | false ];
288			output bool out0	= [ false | true ];
289		}
290
291		both ""
292			precision mediump float;
293			${DECLARATIONS}
294
295			bool func (bool a)
296			{
297				return !a;
298			}
299
300			void main()
301			{
302				${SETUP}
303				out0 = func(in0);
304				${OUTPUT}
305			}
306		""
307	end
308
309	case bool_bvec2
310		values
311		{
312			input bvec2 in0		= [ bvec2(true, true) | bvec2(false, true) ];
313			output bool out0	= [ false | true ];
314		}
315
316		both ""
317			precision mediump float;
318			${DECLARATIONS}
319
320			bool func (bvec2 a)
321			{
322				return !(a.x == a.y);
323			}
324
325			void main()
326			{
327				${SETUP}
328				out0 = func(in0);
329				${OUTPUT}
330			}
331		""
332	end
333
334	case bool_bvec3
335		values
336		{
337			input bvec3 in0		= [ bvec3(true, true, false) | bvec3(true, false, false) ];
338			output bool out0	= [ false | true ];
339		}
340
341		both ""
342			precision mediump float;
343			${DECLARATIONS}
344
345			bool func (bvec3 a)
346			{
347				return (a.x == a.y) == a.z;
348			}
349
350			void main()
351			{
352				${SETUP}
353				out0 = func(in0);
354				${OUTPUT}
355			}
356		""
357	end
358
359	case bool_bvec4
360		values
361		{
362			input bvec4 in0		= [ bvec4(true, true, true, false) | bvec4(false, false, true, true) | bvec4(true, false, false, true) ];
363			output bool out0	= [ false | true | true ];
364		}
365
366		both ""
367			precision mediump float;
368			${DECLARATIONS}
369
370			bool func (bvec4 a)
371			{
372				return ((a.x == a.y) == (a.z == a.w));
373			}
374
375			void main()
376			{
377				${SETUP}
378				out0 = func(in0);
379				${OUTPUT}
380			}
381		""
382	end
383
384	case mat2
385		values
386		{
387			input mat2 in0	= [ mat2(-2.0, 0.5, -1.0, 1.0) | mat2(1.0, -3.5, -3.5, 2.5) | mat2(-2.0, -2.0, 3.5, 0.0) ];
388			output mat2 out0	= [ mat2(4.0, -1.0, 2.0, -2.0) | mat2(-2.0, 7.0, 7.0, -5.0) | mat2(4.0, 4.0, -7.0, -0.0) ];
389		}
390
391		both ""
392			precision mediump float;
393			${DECLARATIONS}
394
395			mat2 func (mat2 a)
396			{
397				return -2.0*a;
398			}
399
400			void main()
401			{
402				${SETUP}
403				out0 = func(in0);
404				${OUTPUT}
405			}
406		""
407	end
408
409
410	case mat3
411		values
412		{
413			input mat3 in0	= [ mat3(2.5, 0.0, 1.0, -2.5, 1.0, 3.0, 0.0, 2.0, 1.5) | mat3(-3.5, 2.0, 0.5, -1.5, -3.5, 2.5, 0.0, 1.5, 3.0) | mat3(1.5, 3.0, -1.0, 2.5, -0.5, 3.5, 3.0, -3.0, -2.5) ];
414			output mat3 out0	= [ mat3(-5.0, -0.0, -2.0, 5.0, -2.0, -6.0, -0.0, -4.0, -3.0) | mat3(7.0, -4.0, -1.0, 3.0, 7.0, -5.0, -0.0, -3.0, -6.0) | mat3(-3.0, -6.0, 2.0, -5.0, 1.0, -7.0, -6.0, 6.0, 5.0) ];
415		}
416
417		both ""
418			precision mediump float;
419			${DECLARATIONS}
420
421			mat3 func (mat3 a)
422			{
423				return -2.0*a;
424			}
425
426			void main()
427			{
428				${SETUP}
429				out0 = func(in0);
430				${OUTPUT}
431			}
432		""
433	end
434
435
436	case mat4
437		values
438		{
439			input mat4 in0	= [ mat4(-2.0, 3.5, -0.5, 1.0, -1.5, 0.0, -1.0, -1.0, 0.5, 0.5, 3.0, 1.5, 3.0, 2.5, 3.5, 1.5) | mat4(-2.5, 2.5, 3.5, 3.0, 0.5, 1.5, -2.0, 2.5, 0.5, -1.5, -3.5, 2.5, 3.5, -3.0, 2.5, -0.5) | mat4(-2.5, -1.5, 2.0, 3.0, -3.5, 1.0, -3.5, 1.5, -1.5, 3.0, 3.5, 0.0, 3.5, -1.5, -3.0, 0.5) ];
440			output mat4 out0	= [ mat4(4.0, -7.0, 1.0, -2.0, 3.0, -0.0, 2.0, 2.0, -1.0, -1.0, -6.0, -3.0, -6.0, -5.0, -7.0, -3.0) | mat4(5.0, -5.0, -7.0, -6.0, -1.0, -3.0, 4.0, -5.0, -1.0, 3.0, 7.0, -5.0, -7.0, 6.0, -5.0, 1.0) | mat4(5.0, 3.0, -4.0, -6.0, 7.0, -2.0, 7.0, -3.0, 3.0, -6.0, -7.0, -0.0, -7.0, 3.0, 6.0, -1.0) ];
441		}
442
443		both ""
444			precision mediump float;
445			${DECLARATIONS}
446
447			mat4 func (mat4 a)
448			{
449				return -2.0*a;
450			}
451
452			void main()
453			{
454				${SETUP}
455				out0 = func(in0);
456				${OUTPUT}
457			}
458		""
459	end
460
461	case float_struct
462		values
463		{
464			input vec3 in0		= [ vec3(0.0, 1.0, -2.0) | vec3(2.0, 2.5, -4.0) ];
465			output float out0	= [ 1.0 | -0.5 ];
466		}
467
468		both ""
469			precision mediump float;
470			${DECLARATIONS}
471
472			struct Pos { float a, b, c; };
473
474			float func (Pos p)
475			{
476				return -(p.a + p.b + p.c);
477			}
478
479			void main()
480			{
481				Pos p = Pos(in0.x, in0.y, in0.z);
482				out0 = func(p);
483				${OUTPUT}
484			}
485		""
486	end
487
488	case struct_struct
489		values
490		{
491			input vec3 in0		= [ vec3(0.0, 1.0, -2.0) | vec3(2.0, 2.5, -4.0) ];
492			output float out0	= [ 1.0 | -0.5 ];
493		}
494
495		both ""
496			precision mediump float;
497			${DECLARATIONS}
498
499			struct Pos { float a, b, c; };
500
501			Pos func (Pos p)
502			{
503				return Pos(-p.a, -p.b, -p.c);
504			}
505
506			void main()
507			{
508				Pos p = Pos(in0.x, in0.y, in0.z);
509				p = func(p);
510				out0 = p.a + p.b + p.c;
511				${OUTPUT}
512			}
513		""
514	end
515
516	case struct_nested_struct
517		values
518		{
519			input vec3 in0		= [ vec3(0.0, 1.0, -2.0) | vec3(2.0, 2.5, -4.0) ];
520			output float out0	= [ 1.0 | -0.5 ];
521		}
522
523		both ""
524			precision mediump float;
525			${DECLARATIONS}
526
527			struct Pos { float a, b, c; };
528			struct Line { Pos start, end; };
529
530			Line func (Pos p)
531			{
532				return Line(p, Pos(-p.a, -p.b, -p.c));
533			}
534
535			float sum (Pos p)
536			{
537				return (p.a + p.b + p.c);
538			}
539
540			void main()
541			{
542				Pos p = Pos(in0.x, in0.y, in0.z);
543				Line line = func(p);
544				out0 = sum(line.start) + (2.0 * sum(line.end));
545				${OUTPUT}
546			}
547		""
548	end
549
550
551end # datatypes
552
553group qualifiers "Function Parameter Qualifiers"
554
555	case in_float
556		values
557		{
558			input float in0		= [ 0.0 | 1.0 | -2.0 | 2.5 ];
559			output float out0	= [ 0.0 | -1.0 | 2.0 | -2.5 ];
560		}
561
562		both ""
563			precision mediump float;
564			precision mediump int;
565			${DECLARATIONS}
566
567			float func (in float a)
568			{
569				a = -a;
570				return 2.0 * a;
571			}
572
573			void main()
574			{
575				${SETUP}
576				float f = in0;
577				float g = func(f);
578				out0 = f + g;
579				${OUTPUT}
580			}
581		""
582	end
583
584	case out_float
585		values
586		{
587			input float in0		= [ 0.0 | 1.0 | -2.0 | 2.5 ];
588			output float out0	= [ 0.0 | -1.0 | 2.0 | -2.5 ];
589		}
590
591		both ""
592			precision mediump float;
593			precision mediump int;
594			${DECLARATIONS}
595
596			void func (out float a)
597			{
598				a = -1.0;
599			}
600
601			void main()
602			{
603				${SETUP}
604				float f = 1.0;
605				func(f);
606				out0 = f * in0;
607				${OUTPUT}
608			}
609		""
610	end
611
612	case inout_float
613		values
614		{
615			input float in0		= [ 0.0 | 1.0 | -2.0 | 2.5 ];
616			output float out0	= [ 0.0 | -1.0 | 2.0 | -2.5 ];
617		}
618
619		both ""
620			precision mediump float;
621			precision mediump int;
622			${DECLARATIONS}
623
624			void func (inout float a)
625			{
626				a = -a;
627			}
628
629			void main()
630			{
631				${SETUP}
632				float f = 1.0;
633				func(f);
634				out0 = f * in0;
635				${OUTPUT}
636			}
637		""
638	end
639
640	case in_lowp_float
641		values
642		{
643			input float in0		= [ 0.0 | 1.0 | -2.0 | 2.5 ];
644			output float out0	= [ 0.0 | -1.0 | 2.0 | -2.5 ];
645		}
646
647		both ""
648			precision mediump float;
649			precision mediump int;
650			${DECLARATIONS}
651
652			float func (in lowp float a)
653			{
654				a = -a;
655				return 2.0 * a;
656			}
657
658			void main()
659			{
660				${SETUP}
661				float f = in0;
662				float g = func(f);
663				out0 = f + g;
664				${OUTPUT}
665			}
666		""
667	end
668
669	case out_lowp_float
670		values
671		{
672			input float in0		= [ 0.0 | 1.0 | -2.0 | 2.5 ];
673			output float out0	= [ 0.0 | -1.0 | 2.0 | -2.5 ];
674		}
675
676		both ""
677			precision mediump float;
678			precision mediump int;
679			${DECLARATIONS}
680
681			void func (out lowp float a)
682			{
683				a = -1.0;
684			}
685
686			void main()
687			{
688				${SETUP}
689				float f = 1.0;
690				func(f);
691				out0 = f * in0;
692				${OUTPUT}
693			}
694		""
695	end
696
697	case inout_lowp_float
698		values
699		{
700			input float in0		= [ 0.0 | 1.0 | -2.0 | 2.5 ];
701			output float out0	= [ 0.0 | -1.0 | 2.0 | -2.5 ];
702		}
703
704		both ""
705			precision mediump float;
706			precision mediump int;
707			${DECLARATIONS}
708
709			void func (inout lowp float a)
710			{
711				a = -a;
712			}
713
714			void main()
715			{
716				${SETUP}
717				float f = 1.0;
718				func(f);
719				out0 = f * in0;
720				${OUTPUT}
721			}
722		""
723	end
724
725	case in_highp_float
726		values
727		{
728			input float in0		= [ 0.0 | 1.0 | -2.0 | 2.5 ];
729			output float out0	= [ 0.0 | -1.0 | 2.0 | -2.5 ];
730		}
731
732		both ""
733			precision mediump float;
734			precision mediump int;
735			${DECLARATIONS}
736
737			float func (in highp float a)
738			{
739				a = -a;
740				return 2.0 * a;
741			}
742
743			void main()
744			{
745				${SETUP}
746				float f = in0;
747				float g = func(f);
748				out0 = f + g;
749				${OUTPUT}
750			}
751		""
752	end
753
754	case out_highp_float
755		values
756		{
757			input float in0		= [ 0.0 | 1.0 | -2.0 | 2.5 ];
758			output float out0	= [ 0.0 | -1.0 | 2.0 | -2.5 ];
759		}
760
761		both ""
762			precision mediump float;
763			precision mediump int;
764			${DECLARATIONS}
765
766			void func (out highp float a)
767			{
768				a = -1.0;
769			}
770
771			void main()
772			{
773				${SETUP}
774				float f = 1.0;
775				func(f);
776				out0 = f * in0;
777				${OUTPUT}
778			}
779		""
780	end
781
782	case inout_highp_float
783		values
784		{
785			input float in0		= [ 0.0 | 1.0 | -2.0 | 2.5 ];
786			output float out0	= [ 0.0 | -1.0 | 2.0 | -2.5 ];
787		}
788
789		both ""
790			precision mediump float;
791			precision mediump int;
792			${DECLARATIONS}
793
794			void func (inout highp float a)
795			{
796				a = -a;
797			}
798
799			void main()
800			{
801				${SETUP}
802				float f = 1.0;
803				func(f);
804				out0 = f * in0;
805				${OUTPUT}
806			}
807		""
808	end
809
810	case const_float
811		values
812		{
813			input float in0		= [ 0.0 | 1.0 | -2.0 | 2.5 ];
814			output float out0	= [ 0.0 | -1.0 | 2.0 | -2.5 ];
815		}
816
817		both ""
818			precision mediump float;
819			precision mediump int;
820			${DECLARATIONS}
821
822			float func (const float a)
823			{
824				float b = -a;
825				return 2.0 * b;
826			}
827
828			void main()
829			{
830				${SETUP}
831				float f = in0;
832				float g = func(f);
833				out0 = f + g;
834				${OUTPUT}
835			}
836		""
837	end
838
839	case const_in_float
840		values
841		{
842			input float in0		= [ 0.0 | 1.0 | -2.0 | 2.5 ];
843			output float out0	= [ 0.0 | -1.0 | 2.0 | -2.5 ];
844		}
845
846		both ""
847			precision mediump float;
848			precision mediump int;
849			${DECLARATIONS}
850
851			float func (const in float a)
852			{
853				float b = -a;
854				return 2.0 * b;
855			}
856
857			void main()
858			{
859				${SETUP}
860				float f = in0;
861				float g = func(f);
862				out0 = f + g;
863				${OUTPUT}
864			}
865		""
866	end
867
868	case in_int
869		values
870		{
871			input int in0		= [ 0 | 1 | -2 | 4 ];
872			output int out0		= [ 0 | -1 | 2 | -4 ];
873		}
874
875		both ""
876			precision mediump float;
877			precision mediump int;
878			${DECLARATIONS}
879
880			int func (in int a)
881			{
882				a = -a;
883				return 2 * a;
884			}
885
886			void main()
887			{
888				${SETUP}
889				int f = in0;
890				int g = func(f);
891				out0 = f + g;
892				${OUTPUT}
893			}
894		""
895	end
896
897	case out_int
898		values
899		{
900			input int in0		= [ 0 | 1 | -2 | 6 ];
901			output int out0		= [ 0 | -1 | 2 | -6 ];
902		}
903
904		both ""
905			precision mediump float;
906			precision mediump int;
907			${DECLARATIONS}
908
909			void func (out int a)
910			{
911				a = -1;
912			}
913
914			void main()
915			{
916				${SETUP}
917				int f = 1;
918				func(f);
919				out0 = f * in0;
920				${OUTPUT}
921			}
922		""
923	end
924
925	case inout_int
926		values
927		{
928			input int in0		= [ 0 | 1 | -2 | 6 ];
929			output int out0		= [ 0 | -1 | 2 | -6 ];
930		}
931
932		both ""
933			precision mediump float;
934			precision mediump int;
935			${DECLARATIONS}
936
937			void func (inout int a)
938			{
939				a = -a;
940			}
941
942			void main()
943			{
944				${SETUP}
945				int f = 1;
946				func(f);
947				out0 = f * in0;
948				${OUTPUT}
949			}
950		""
951	end
952
953	case in_lowp_int
954		values
955		{
956			input int in0		= [ 0 | 1 | -2 | 4 ];
957			output int out0		= [ 0 | -1 | 2 | -4 ];
958		}
959
960		both ""
961			precision mediump float;
962			precision mediump int;
963			${DECLARATIONS}
964
965			int func (in lowp int a)
966			{
967				a = -a;
968				return 2 * a;
969			}
970
971			void main()
972			{
973				${SETUP}
974				int f = in0;
975				int g = func(f);
976				out0 = f + g;
977				${OUTPUT}
978			}
979		""
980	end
981
982	case out_lowp_int
983		values
984		{
985			input int in0		= [ 0 | 1 | -2 | 6 ];
986			output int out0		= [ 0 | -1 | 2 | -6 ];
987		}
988
989		both ""
990			precision mediump float;
991			precision mediump int;
992			${DECLARATIONS}
993
994			void func (out lowp int a)
995			{
996				a = -1;
997			}
998
999			void main()
1000			{
1001				${SETUP}
1002				int f = 1;
1003				func(f);
1004				out0 = f * in0;
1005				${OUTPUT}
1006			}
1007		""
1008	end
1009
1010	case inout_lowp_int
1011		values
1012		{
1013			input int in0		= [ 0 | 1 | -2 | 6 ];
1014			output int out0		= [ 0 | -1 | 2 | -6 ];
1015		}
1016
1017		both ""
1018			precision mediump float;
1019			precision mediump int;
1020			${DECLARATIONS}
1021
1022			void func (inout lowp int a)
1023			{
1024				a = -a;
1025			}
1026
1027			void main()
1028			{
1029				${SETUP}
1030				int f = 1;
1031				func(f);
1032				out0 = f * in0;
1033				${OUTPUT}
1034			}
1035		""
1036	end
1037
1038	case in_highp_int
1039		values
1040		{
1041			input int in0		= [ 0 | 1 | -2 | 4 ];
1042			output int out0		= [ 0 | -1 | 2 | -4 ];
1043		}
1044
1045		both ""
1046			precision mediump float;
1047			precision mediump int;
1048			${DECLARATIONS}
1049
1050			int func (in highp int a)
1051			{
1052				a = -a;
1053				return 2 * a;
1054			}
1055
1056			void main()
1057			{
1058				${SETUP}
1059				int f = in0;
1060				int g = func(f);
1061				out0 = f + g;
1062				${OUTPUT}
1063			}
1064		""
1065	end
1066
1067	case out_highp_int
1068		values
1069		{
1070			input int in0		= [ 0 | 1 | -2 | 6 ];
1071			output int out0		= [ 0 | -1 | 2 | -6 ];
1072		}
1073
1074		both ""
1075			precision mediump float;
1076			precision mediump int;
1077			${DECLARATIONS}
1078
1079			void func (out highp int a)
1080			{
1081				a = -1;
1082			}
1083
1084			void main()
1085			{
1086				${SETUP}
1087				int f = 1;
1088				func(f);
1089				out0 = f * in0;
1090				${OUTPUT}
1091			}
1092		""
1093	end
1094
1095	case inout_highp_int
1096		values
1097		{
1098			input int in0		= [ 0 | 1 | -2 | 6 ];
1099			output int out0		= [ 0 | -1 | 2 | -6 ];
1100		}
1101
1102		both ""
1103			precision mediump float;
1104			precision mediump int;
1105			${DECLARATIONS}
1106
1107			void func (inout highp int a)
1108			{
1109				a = -a;
1110			}
1111
1112			void main()
1113			{
1114				${SETUP}
1115				int f = 1;
1116				func(f);
1117				out0 = f * in0;
1118				${OUTPUT}
1119			}
1120		""
1121	end
1122
1123	case const_int
1124		values
1125		{
1126			input int in0		= [ 0 | 1 | -2 | 4 ];
1127			output int out0		= [ 0 | -1 | 2 | -4 ];
1128		}
1129
1130		both ""
1131			precision mediump float;
1132			precision mediump int;
1133			${DECLARATIONS}
1134
1135			int func (const int a)
1136			{
1137				int b = -a;
1138				return 2 * b;
1139			}
1140
1141			void main()
1142			{
1143				${SETUP}
1144				int f = in0;
1145				int g = func(f);
1146				out0 = f + g;
1147				${OUTPUT}
1148			}
1149		""
1150	end
1151
1152	case const_in_int
1153		values
1154		{
1155			input int in0		= [ 0 | 1 | -2 | 4 ];
1156			output int out0		= [ 0 | -1 | 2 | -4 ];
1157		}
1158
1159		both ""
1160			precision mediump float;
1161			precision mediump int;
1162			${DECLARATIONS}
1163
1164			int func (const in int a)
1165			{
1166				int b = -a;
1167				return 2 * b;
1168			}
1169
1170			void main()
1171			{
1172				${SETUP}
1173				int f = in0;
1174				int g = func(f);
1175				out0 = f + g;
1176				${OUTPUT}
1177			}
1178		""
1179	end
1180
1181	case in_bool
1182		values
1183		{
1184			input bool in0		= [ true | false ];
1185			output bool out0	= [ true | true ];
1186		}
1187
1188		both ""
1189			precision mediump float;
1190			${DECLARATIONS}
1191
1192			bool func (in bool a)
1193			{
1194				a = !a;
1195				return a;
1196			}
1197
1198			void main()
1199			{
1200				${SETUP}
1201				bool f = in0;
1202				bool g = func(f);
1203				out0 = (f != g);
1204				${OUTPUT}
1205			}
1206		""
1207	end
1208
1209	case out_bool
1210		values
1211		{
1212			input bool in0		= [ true | false ];
1213			output bool out0	= [ false | true ];
1214		}
1215
1216		both ""
1217			precision mediump float;
1218			${DECLARATIONS}
1219
1220			void func (out bool a)
1221			{
1222				a = false;
1223			}
1224
1225			void main()
1226			{
1227				${SETUP}
1228				bool f = true;
1229				func(f);
1230				out0 = (in0 == f);
1231				${OUTPUT}
1232			}
1233		""
1234	end
1235
1236	case inout_bool
1237		values
1238		{
1239			input bool in0		= [ true | false ];
1240			output bool out0	= [ false | true ];
1241		}
1242
1243		both ""
1244			precision mediump float;
1245			${DECLARATIONS}
1246
1247			void func (inout bool a)
1248			{
1249				a = !a;
1250			}
1251
1252			void main()
1253			{
1254				${SETUP}
1255				bool f = true;
1256				func(f);
1257				out0 = (in0 == f);
1258				${OUTPUT}
1259			}
1260		""
1261	end
1262
1263end # qualifiers
1264
1265group declarations "Function Declarations"
1266
1267	case void_vs_no_void
1268		values
1269		{
1270			input float in0		= [ 0.0 | 1.0 | -2.0 | 2.5 ];
1271			output float out0	= [ 0.0 | -1.0 | 2.0 | -2.5 ];
1272		}
1273
1274		both ""
1275			precision mediump float;
1276			${DECLARATIONS}
1277
1278			float func ();
1279
1280			void main()
1281			{
1282				out0 = func() * in0;
1283				${OUTPUT}
1284			}
1285
1286			float func (void)
1287			{
1288				return -1.0;
1289			}
1290		""
1291	end
1292
1293	case in_vs_no_in
1294		values
1295		{
1296			input float in0		= [ 0.0 | 1.0 | -2.0 | 2.5 ];
1297			output float out0	= [ 0.0 | -1.0 | 2.0 | -2.5 ];
1298		}
1299
1300		both ""
1301			precision mediump float;
1302			${DECLARATIONS}
1303
1304			float func (float f);
1305
1306			void main()
1307			{
1308				out0 = func(in0);
1309				${OUTPUT}
1310			}
1311
1312			float func (in float f)
1313			{
1314				return -f;
1315			}
1316		""
1317	end
1318
1319	case default_vs_explicit_precision
1320		values
1321		{
1322			input float in0		= [ 0.0 | 1.0 | -2.0 | 2.5 ];
1323			output float out0	= [ 0.0 | -1.0 | 2.0 | -2.5 ];
1324		}
1325
1326		both ""
1327			precision mediump float;
1328			${DECLARATIONS}
1329
1330			float func (float f);
1331
1332			void main()
1333			{
1334				out0 = func(in0);
1335				${OUTPUT}
1336			}
1337
1338			float func (mediump float f)
1339			{
1340				return -f;
1341			}
1342		""
1343	end
1344
1345end # declarations
1346
1347group overloading "Function Overloading"
1348
1349	case user_func_arg_type_simple
1350		values
1351		{
1352			input float in0		= [ 0.0 | 1.0 | -2.0 | 2.5 ];
1353			output float out0	= [ 0.0 | -1.0 | 2.0 | -2.5 ];
1354		}
1355
1356		both ""
1357			precision mediump float;
1358			precision mediump int;
1359			${DECLARATIONS}
1360
1361			float func (float a)
1362			{
1363				return -a;
1364			}
1365
1366			int func (int a)
1367			{
1368				return -a;
1369			}
1370
1371			void main()
1372			{
1373				out0 = func(in0) * float(func(-1));
1374				${OUTPUT}
1375			}
1376		""
1377	end
1378
1379	case user_func_arg_float_types
1380		values
1381		{
1382			input float in0		= [ 0.0 | 1.0 | -2.0 | 2.5 ];
1383			output float out0	= [ 0.0 | -1.0 | 2.0 | -2.5 ];
1384		}
1385
1386		both ""
1387			precision mediump float;
1388			precision mediump int;
1389			${DECLARATIONS}
1390
1391			float func (float a) { return -a; }
1392			vec2 func (vec2 a) { return a.yx; }
1393			vec3 func (vec3 a) { return a.xxx; }
1394			vec4 func (vec4 a) { return a.wwww; }
1395
1396			void main()
1397			{
1398				out0 = func(func(func(func(vec4(in0)).xyz).xy).x);
1399				${OUTPUT}
1400			}
1401		""
1402	end
1403
1404	case user_func_arg_int_types
1405		values
1406		{
1407			input int in0		= [ 0 | 1 | -2 | 6 ];
1408			output int out0		= [ 0 | -1 | 2 | -6 ];
1409		}
1410
1411		both ""
1412			precision mediump float;
1413			precision mediump int;
1414			${DECLARATIONS}
1415
1416			int func (int a) { return -a; }
1417			ivec2 func (ivec2 a) { return a.yx; }
1418			ivec3 func (ivec3 a) { return a.xxx; }
1419			ivec4 func (ivec4 a) { return a.wwww; }
1420
1421			void main()
1422			{
1423				${SETUP}
1424				out0 = func(func(func(func(ivec4(in0)).xyz).xy).x);
1425				${OUTPUT}
1426			}
1427		""
1428	end
1429
1430	case user_func_arg_bool_types
1431		values
1432		{
1433			input bool in0		= [ true | false ];
1434			output bool out0	= [ false | true ];
1435		}
1436
1437		both ""
1438			precision mediump float;
1439			${DECLARATIONS}
1440
1441			bool func (bool a) { return !a; }
1442			bvec2 func (bvec2 a) { return a.yx; }
1443			bvec3 func (bvec3 a) { return a.xxx; }
1444			bvec4 func (bvec4 a) { return a.wwww; }
1445
1446			void main()
1447			{
1448				${SETUP}
1449				out0 = func(func(func(func(bvec4(in0)).xyz).xy).x);
1450				${OUTPUT}
1451			}
1452		""
1453	end
1454
1455	case user_func_arg_basic_types
1456		values
1457		{
1458			input float in0		= [ 0.0 | 1.0 | -2.0 | 2.5 ];
1459			output float out0	= [ 0.0 | -1.0 | 2.0 | -2.5 ];
1460		}
1461
1462		both ""
1463			precision mediump float;
1464			precision mediump int;
1465			${DECLARATIONS}
1466
1467			float func (float a) { return -a; }
1468			vec2 func (vec2 a) { return a.yx; }
1469			vec3 func (vec3 a) { return a.xxx; }
1470			vec4 func (vec4 a) { return a.wwww; }
1471			int func (int a) { return -a; }
1472			ivec2 func (ivec2 a) { return a.yx; }
1473			ivec3 func (ivec3 a) { return a.xxx; }
1474			ivec4 func (ivec4 a) { return a.wwww; }
1475			bool func (bool a) { return !a; }
1476			bvec2 func (bvec2 a) { return a.yx; }
1477			bvec3 func (bvec3 a) { return a.xxx; }
1478			bvec4 func (bvec4 a) { return a.wwww; }
1479
1480			void main()
1481			{
1482				${SETUP}
1483				if (func(func(bvec4(false)).x))
1484					out0 = func(in0) * float(func(-1));
1485				else
1486					out0 = float(func(func(ivec4(func(func(func(vec4(0.5)).xyz).xy).xxxx)).xy).x);
1487				${OUTPUT}
1488			}
1489		""
1490	end
1491
1492	case user_func_arg_complex_types
1493		values
1494		{
1495			input float in0		= [ 0.0 | 1.0 | -2.0 | 2.5 ];
1496			output float out0	= [ 0.0 | -1.0 | 2.0 | -2.5 ];
1497		}
1498
1499		both ""
1500			precision mediump float;
1501			precision mediump int;
1502			${DECLARATIONS}
1503
1504			struct Pos { float a, b, c; };
1505			struct Line { Pos start, end; };
1506
1507			float func (float a) { return -a; }
1508			float func (float a[4]) { return a[0] + a[3]; }
1509			vec2 func (vec2 a) { return a.yx; }
1510			vec3 func (vec3 a) { return a.xxx; }
1511			vec4 func (vec4 a) { return a.wwww; }
1512			vec4 func (vec4 a[4]) { return a[1] + a[2]; }
1513			int func (int a) { return -a; }
1514			ivec2 func (ivec2 a) { return a.yx; }
1515			ivec3 func (ivec3 a) { return a.xxx; }
1516			ivec4 func (ivec4 a) { return a.wwww; }
1517			bool func (bool a) { return !a; }
1518			bvec2 func (bvec2 a) { return a.yx; }
1519			bvec3 func (bvec3 a) { return a.xxx; }
1520			bvec4 func (bvec4 a) { return a.wwww; }
1521			Pos func (Pos a) { return a; }
1522			Line func (Line a) { return Line(a.end, a.start); }
1523
1524			void main()
1525			{
1526				${SETUP}
1527				float arr[4];
1528				vec4 arr2[4];
1529				out0 = func(arr) + func(arr2).x;
1530				if (func(func(bvec4(false)).x))
1531					out0 = func(in0) * float(func(-1));
1532				else
1533					out0 = float(func(func(ivec4(func(func(func(vec4(0.5)).xyz).xy).xxxx)).xy).x);
1534				${OUTPUT}
1535			}
1536		""
1537	end
1538
1539	case user_func_arguments
1540		values
1541		{
1542			input float in0		= [ 0.0 | 1.0 | -2.0 | 2.5 ];
1543			output float out0	= [ 0.0 | -1.0 | 2.0 | -2.5 ];
1544		}
1545
1546		both ""
1547			precision mediump float;
1548			${DECLARATIONS}
1549
1550			float func (float a)
1551			{
1552				return -a;
1553			}
1554
1555			float func (float a, float b)
1556			{
1557				return a * b;
1558			}
1559
1560			void main()
1561			{
1562				out0 = func(in0) * func(-0.5, -2.0);
1563				${OUTPUT}
1564			}
1565		""
1566	end
1567
1568	case builtin_sin
1569		values
1570		{
1571			input int in0		= [ -1 | 0 | 1 | 4 ];
1572			output int out0		= [ 1 | 0 | -1 | -4 ];
1573		}
1574
1575		both ""
1576			precision mediump float;
1577			precision mediump int;
1578			${DECLARATIONS}
1579
1580			int sin(int a) { return -a; }
1581
1582			void main()
1583			{
1584				${SETUP}
1585				out0 = sin(in0);
1586				${OUTPUT}
1587			}
1588		""
1589	end
1590
1591	case builtin_step
1592		values
1593		{
1594			input int in0		= [ -1 | 0 | 1 | 4 ];
1595			output int out0		= [ 1 | 0 | -1 | -4 ];
1596		}
1597
1598		both ""
1599			precision mediump float;
1600			precision mediump int;
1601			${DECLARATIONS}
1602
1603			int step (float i, float j, int a) { return -a; }
1604
1605			void main()
1606			{
1607				${SETUP}
1608				out0 = step(0.0, 1.0, in0);
1609				${OUTPUT}
1610			}
1611		""
1612	end
1613
1614	case array_size
1615		values
1616		{
1617			output float out0	= [ 1.0 ];
1618		}
1619
1620		both ""
1621			precision mediump float;
1622			${DECLARATIONS}
1623
1624			float func (float f[3])
1625			{
1626				return f[0];
1627			}
1628
1629			float func (float f[4])
1630			{
1631				return f[1];
1632			}
1633
1634			void main ()
1635			{
1636				${SETUP}
1637				float x[4];
1638				x[0] = -1.0;
1639				x[1] = 1.0;
1640				x[2] = x[3] = 0.0;
1641				out0 = func(x);
1642				${OUTPUT}
1643			}
1644		""
1645	end
1646
1647end # overloading
1648
1649group array_arguments "Arrays as Arguments"
1650
1651	case local_in_float
1652		values
1653		{
1654			input vec4 in0		= [ vec4(0.0, 1.0, 2.0, -4.0) | vec4(-7.5, 12.125, -0.25, 16.0) ];
1655			output vec4 out0	= [ vec4(0.0, -1.0, -2.0, 4.0) | vec4(7.5, -12.125, 0.25, -16.0) ];
1656		}
1657
1658		both ""
1659			precision mediump float;
1660			${DECLARATIONS}
1661
1662			float func (in float a[4])
1663			{
1664				a[0] = -1.0;
1665				a[2] = -4.0;
1666				a[3] = -3.0 * a[1];
1667				return a[0];
1668			}
1669
1670			void main()
1671			{
1672				float arr[4];
1673				arr[0] = in0.x;
1674				arr[1] = in0.y;
1675				arr[2] = in0.z;
1676				arr[3] = in0.w;
1677				float f = func(arr);
1678				out0 = f * vec4(arr[0], arr[1], arr[2], arr[3]);
1679				${OUTPUT}
1680			}
1681		""
1682	end
1683
1684	case global_in_float
1685		values
1686		{
1687			input vec4 in0		= [ vec4(0.0, 1.0, 2.0, -4.0) | vec4(-7.5, 12.125, -0.25, 16.0) ];
1688			output vec4 out0	= [ vec4(0.0, -1.0, -2.0, 4.0) | vec4(7.5, -12.125, 0.25, -16.0) ];
1689		}
1690
1691		both ""
1692			precision mediump float;
1693			${DECLARATIONS}
1694
1695			float func (in float a[4])
1696			{
1697				a[0] = -1.0;
1698				a[2] = -4.0;
1699				a[3] = -3.0 * a[1];
1700				return a[0];
1701			}
1702
1703			float arr[4];
1704
1705			void main()
1706			{
1707				arr[0] = in0.x;
1708				arr[1] = in0.y;
1709				arr[2] = in0.z;
1710				arr[3] = in0.w;
1711				float f = func(arr);
1712				out0 = f * vec4(arr[0], arr[1], arr[2], arr[3]);
1713				${OUTPUT}
1714			}
1715		""
1716	end
1717
1718	case local_in_int
1719		values
1720		{
1721			input ivec4 in0		= [ ivec4(0, 1, 2, -4) | ivec4(-7, -11, 13, 19) ];
1722			output ivec4 out0	= [ ivec4(0, -1, -2, 4) | ivec4(7, 11, -13, -19) ];
1723		}
1724
1725		both ""
1726			precision mediump float;
1727			precision mediump int;
1728			${DECLARATIONS}
1729
1730			int func (in int a[4])
1731			{
1732				a[0] = -1;
1733				a[2] = -4;
1734				a[3] = -3 * a[1];
1735				return a[0];
1736			}
1737
1738			void main()
1739			{
1740				${SETUP}
1741				int arr[4];
1742				arr[0] = in0.x;
1743				arr[1] = in0.y;
1744				arr[2] = in0.z;
1745				arr[3] = in0.w;
1746				int f = func(arr);
1747				out0 = f * ivec4(arr[0], arr[1], arr[2], arr[3]);
1748				${OUTPUT}
1749			}
1750		""
1751	end
1752
1753	case global_in_int
1754		values
1755		{
1756			input ivec4 in0		= [ ivec4(0, 1, 2, 4) | ivec4(-7, -11, 13, 19) ];
1757			output ivec4 out0	= [ ivec4(0, -1, -2, -4) | ivec4(7, 11, -13, -19) ];
1758		}
1759
1760		both ""
1761			precision mediump float;
1762			precision mediump int;
1763			${DECLARATIONS}
1764
1765			int func (in int a[4])
1766			{
1767				a[0] = -1;
1768				a[2] = -4;
1769				a[3] = -3 * a[1];
1770				return a[0];
1771			}
1772
1773			int arr[4];
1774
1775			void main()
1776			{
1777				${SETUP}
1778				arr[0] = in0.x;
1779				arr[1] = in0.y;
1780				arr[2] = in0.z;
1781				arr[3] = in0.w;
1782				int f = func(arr);
1783				out0 = f * ivec4(arr[0], arr[1], arr[2], arr[3]);
1784				${OUTPUT}
1785			}
1786
1787		""
1788	end
1789
1790	case local_in_bool
1791		values
1792		{
1793			input bvec4 in0		= [ bvec4(true, true, false, true) | bvec4(false, false, false, false) ];
1794			output bvec4 out0	= [ bvec4(false, false, true, false) | bvec4(true, true, true, true) ];
1795		}
1796
1797		both ""
1798			precision mediump float;
1799			${DECLARATIONS}
1800
1801			bool func (in bool a[4])
1802			{
1803				a[0] = false;
1804				a[2] = true;
1805				a[3] = !a[1];
1806				return a[0];
1807			}
1808
1809			void main()
1810			{
1811				${SETUP}
1812				bool arr[4];
1813				arr[0] = !in0.x;
1814				arr[1] = !in0.y;
1815				arr[2] = !in0.z;
1816				arr[3] = !in0.w;
1817				func(arr);
1818				out0 = bvec4(arr[0], arr[1], arr[2], arr[3]);
1819				${OUTPUT}
1820			}
1821		""
1822	end
1823
1824	case global_in_bool
1825		values
1826		{
1827			input bvec4 in0		= [ bvec4(true, true, false, true) | bvec4(false, false, false, false) ];
1828			output bvec4 out0	= [ bvec4(false, false, true, false) | bvec4(true, true, true, true) ];
1829		}
1830
1831		both ""
1832			precision mediump float;
1833			${DECLARATIONS}
1834
1835			bool func (in bool a[4])
1836			{
1837				a[0] = false;
1838				a[2] = true;
1839				a[3] = !a[1];
1840				return a[0];
1841			}
1842
1843			bool arr[4];
1844
1845			void main()
1846			{
1847				${SETUP}
1848				arr[0] = !in0.x;
1849				arr[1] = !in0.y;
1850				arr[2] = !in0.z;
1851				arr[3] = !in0.w;
1852				func(arr);
1853				out0 = bvec4(arr[0], arr[1], arr[2], arr[3]);
1854				${OUTPUT}
1855			}
1856		""
1857	end
1858
1859	case test_helpers
1860		desc "Check that helper functions are supported properly."
1861		values
1862		{
1863			input vec4 in0		= [ vec4(0.0, 1.0, 2.0, -4.0) | vec4(-7.5, 12.125, -0.25, 16.0) ];
1864			output float out0	= [ 1.0 | 1.0 ];
1865		}
1866
1867		both ""
1868			precision mediump float;
1869			${DECLARATIONS}
1870
1871			vec4 get (in float arr[4]);
1872			void set (out float arr[4], vec4 val);
1873			void negate (inout float arr[4]);
1874			bool test (in float arr[4], vec4 ref);
1875			bool isEqual (in float a[4], in float b[4]);
1876
1877			void main()
1878			{
1879				float arr[4];
1880				set(arr, in0);
1881				negate(arr);
1882				out0 = float(test(arr, -in0));
1883				${OUTPUT}
1884			}
1885
1886			float absDiff (vec4 a, vec4 b) { vec4 d = abs(a - b); return max(max(d.x, d.y), max(d.z, d.w)); }
1887			vec4 get (in float arr[4]) { return vec4(arr[0], arr[1], arr[2], arr[3]); }
1888			void set (out float arr[4], vec4 val) { arr[0] = val.x; arr[1] = val.y; arr[2] = val.z; arr[3] = val.w; }
1889			void negate (inout float arr[4]) { set(arr, -get(arr)); }
1890			bool test (in float arr[4], vec4 ref) { return (absDiff(get(arr), ref) < 0.1); }
1891			bool isEqual (in float a[4], in float b[4]) { return (absDiff(get(a), get(b)) < 0.1); }
1892		""
1893	end
1894
1895	case copy_local_in_on_call
1896		desc "Check that local 'in' arguments are copied on call and don't alias."
1897		values
1898		{
1899			input vec4 in0		= [ vec4(0.0, 1.0, 2.0, -4.0) | vec4(-7.5, 12.125, -0.25, 16.0) ];
1900			output vec4 out0	= [ vec4(0.0, -1.0, -2.0, 4.0) | vec4(7.5, -12.125, 0.25, -16.0) ];
1901		}
1902
1903		both ""
1904			precision mediump float;
1905			${DECLARATIONS}
1906
1907			vec4 get (in float arr[4]);
1908			void set (out float arr[4], vec4 val);
1909			void negate (inout float arr[4]);
1910			bool test (in float arr[4], vec4 ref);
1911			bool isEqual (in float a[4], in float b[4]);
1912
1913			float func (in float a[4], in float b[4])
1914			{
1915				a[0] = 2.123;
1916				a[2] = -4.123;
1917				return isEqual(a, b) ? 1.0 : -1.0;
1918			}
1919
1920			void main()
1921			{
1922				float arr[4];
1923				set(arr, in0);
1924				out0 = in0 * func(arr, arr);
1925				${OUTPUT}
1926			}
1927
1928			float absDiff (vec4 a, vec4 b) { vec4 d = abs(a - b); return max(max(d.x, d.y), max(d.z, d.w)); }
1929			vec4 get (in float arr[4]) { return vec4(arr[0], arr[1], arr[2], arr[3]); }
1930			void set (out float arr[4], vec4 val) { arr[0] = val.x; arr[1] = val.y; arr[2] = val.z; arr[3] = val.w; }
1931			void negate (inout float arr[4]) { set(arr, -get(arr)); }
1932			bool test (in float arr[4], vec4 ref) { return (absDiff(get(arr), ref) < 0.1); }
1933			bool isEqual (in float a[4], in float b[4]) { return (absDiff(get(a), get(b)) < 0.1); }
1934		""
1935	end
1936
1937	case copy_global_in_on_call
1938		desc "Check that global 'in' arguments are copied on call and don't alias."
1939		values
1940		{
1941			input vec4 in0		= [ vec4(0.0, 1.0, 2.0, -4.0) | vec4(-7.5, 12.125, -0.25, 16.0) ];
1942			output vec4 out0	= [ vec4(0.0, -1.0, -2.0, 4.0) | vec4(7.5, -12.125, 0.25, -16.0) ];
1943		}
1944
1945		both ""
1946			precision mediump float;
1947			${DECLARATIONS}
1948
1949			vec4 get (in float arr[4]);
1950			void set (out float arr[4], vec4 val);
1951			void negate (inout float arr[4]);
1952			bool test (in float arr[4], vec4 ref);
1953			bool isEqual (in float a[4], in float b[4]);
1954
1955			float func (in float a[4], in float b[4])
1956			{
1957				a[0] = 2.123;
1958				a[2] = -4.123;
1959				return isEqual(a, b) ? 1.0 : -1.0;
1960			}
1961
1962			float arr[4];
1963
1964			void main()
1965			{
1966				set(arr, in0);
1967				out0 = in0 * func(arr, arr);
1968				${OUTPUT}
1969			}
1970
1971			float absDiff (vec4 a, vec4 b) { vec4 d = abs(a - b); return max(max(d.x, d.y), max(d.z, d.w)); }
1972			vec4 get (in float arr[4]) { return vec4(arr[0], arr[1], arr[2], arr[3]); }
1973			void set (out float arr[4], vec4 val) { arr[0] = val.x; arr[1] = val.y; arr[2] = val.z; arr[3] = val.w; }
1974			void negate (inout float arr[4]) { set(arr, -get(arr)); }
1975			bool test (in float arr[4], vec4 ref) { return (absDiff(get(arr), ref) < 0.1); }
1976			bool isEqual (in float a[4], in float b[4]) { return (absDiff(get(a), get(b)) < 0.1); }
1977		""
1978	end
1979
1980	case copy_local_inout_on_call
1981		desc "Check that local 'in' arguments are copied on call and don't alias."
1982		values
1983		{
1984			input vec4 in0		= [ vec4(0.0, 1.0, 2.0, -4.0) | vec4(-7.5, 12.125, -0.25, 16.0) ];
1985			output vec4 out0	= [ vec4(0.0, -1.0, -2.0, 4.0) | vec4(7.5, -12.125, 0.25, -16.0) ];
1986		}
1987
1988		both ""
1989			precision mediump float;
1990			${DECLARATIONS}
1991
1992			vec4 get (in float arr[4]);
1993			void set (out float arr[4], vec4 val);
1994			void negate (inout float arr[4]);
1995			bool test (in float arr[4], vec4 ref);
1996			bool isEqual (in float a[4], in float b[4]);
1997
1998			float func (inout float a[4], inout float b[4])
1999			{
2000				negate(a);
2001				return isEqual(a, b) ? 1.0 : -1.0;
2002			}
2003
2004			void main()
2005			{
2006				float arr[4];
2007				set(arr, in0);
2008				float m = func(arr, arr); // returns -1.0
2009				float n = float(test(arr, in0) || test(arr, -in0));
2010				out0 = in0 * m * n;
2011				${OUTPUT}
2012			}
2013
2014			float absDiff (vec4 a, vec4 b) { vec4 d = abs(a - b); return max(max(d.x, d.y), max(d.z, d.w)); }
2015			vec4 get (in float arr[4]) { return vec4(arr[0], arr[1], arr[2], arr[3]); }
2016			void set (out float arr[4], vec4 val) { arr[0] = val.x; arr[1] = val.y; arr[2] = val.z; arr[3] = val.w; }
2017			void negate (inout float arr[4]) { set(arr, -get(arr)); }
2018			bool test (in float arr[4], vec4 ref) { return (absDiff(get(arr), ref) < 0.1); }
2019			bool isEqual (in float a[4], in float b[4]) { return (absDiff(get(a), get(b)) < 0.1); }
2020		""
2021	end
2022
2023	case copy_global_inout_on_call
2024		desc "Check that global 'in' arguments are copied on call and don't alias."
2025		values
2026		{
2027			input vec4 in0		= [ vec4(0.0, 1.0, 2.0, -4.0) | vec4(-7.5, 12.125, -0.25, 16.0) ];
2028			output vec4 out0	= [ vec4(0.0, -1.0, -2.0, 4.0) | vec4(7.5, -12.125, 0.25, -16.0) ];
2029		}
2030
2031		both ""
2032			precision mediump float;
2033			${DECLARATIONS}
2034
2035			vec4 get (in float arr[4]);
2036			void set (out float arr[4], vec4 val);
2037			void negate (inout float arr[4]);
2038			bool test (in float arr[4], vec4 ref);
2039			bool isEqual (in float a[4], in float b[4]);
2040
2041			float func (in float a[4], in float b[4])
2042			{
2043				negate(a);
2044				return isEqual(a, b) ? 1.0 : -1.0;
2045			}
2046
2047			float arr[4];
2048
2049			void main()
2050			{
2051				set(arr, in0);
2052				float m = func(arr, arr); // returns -1.0
2053				float n = float(test(arr, in0) || test(arr, -in0));
2054				out0 = in0 * m * n;
2055				${OUTPUT}
2056			}
2057
2058			float absDiff (vec4 a, vec4 b) { vec4 d = abs(a - b); return max(max(d.x, d.y), max(d.z, d.w)); }
2059			vec4 get (in float arr[4]) { return vec4(arr[0], arr[1], arr[2], arr[3]); }
2060			void set (out float arr[4], vec4 val) { arr[0] = val.x; arr[1] = val.y; arr[2] = val.z; arr[3] = val.w; }
2061			void negate (inout float arr[4]) { set(arr, -get(arr)); }
2062			bool test (in float arr[4], vec4 ref) { return (absDiff(get(arr), ref) < 0.1); }
2063			bool isEqual (in float a[4], in float b[4]) { return (absDiff(get(a), get(b)) < 0.1); }
2064		""
2065	end
2066
2067#			vec4 get (in float arr[4]);
2068#			void set (out float arr[4], vec4 val);
2069#			void negate (inout float arr[4]);
2070#			bool test (in float arr[4], vec4 ref);
2071#			bool isEqual (in float a[4], in float b[4]);
2072
2073#			float absDiff (vec4 a, vec4 b) { vec4 d = abs(a - b); return max(max(d.x, d.y), max(d.z, d.w)); }
2074#			vec4 get (in float arr[4]) { return vec4(arr[0], arr[1], arr[2], arr[3]); }
2075#			void set (out float arr[4], vec4 val) { arr[0] = val.x; arr[1] = val.y; arr[2] = val.z; arr[3] = val.w; }
2076#			void negate (inout float arr[4]) { set(arr, -get(arr)); }
2077#			bool test (in float arr[4], vec4 ref) { return (absDiff(get(arr), ref) < 0.1); }
2078#			bool isEqual (in float a[4], in float b[4]) { return (absDiff(get(a), get(b)) < 0.1); }
2079
2080end # array_arguments
2081
2082#group qualifiers "Function Parameter Qualifiers"
2083#
2084#end # qualifiers
2085
2086group control_flow "Control Flow In Functions"
2087
2088	case simple_return
2089		values
2090		{
2091			input float in0		= [ -0.5 | 1.5 ];
2092			output float out0	= [ 0.5 | -1.5 ];
2093		}
2094
2095		both ""
2096			precision mediump float;
2097			${DECLARATIONS}
2098
2099			float func (float a)
2100			{
2101				return -a;
2102				a = a * -1.0;
2103				return 1.0;
2104			}
2105
2106			void main()
2107			{
2108				${SETUP}
2109				out0 = func(in0);
2110				${OUTPUT}
2111			}
2112		""
2113	end
2114
2115	case return_in_if
2116		values
2117		{
2118			input float in0		= [ -0.5 | 1.5 ];
2119			output float out0	= [ 0.5 | -1.5 ];
2120		}
2121
2122		both ""
2123			precision mediump float;
2124			${DECLARATIONS}
2125
2126			float func (float a)
2127			{
2128				if (a != 0.0)
2129					return -a;
2130				return 1.0;
2131			}
2132
2133			void main()
2134			{
2135				${SETUP}
2136				out0 = func(in0);
2137				${OUTPUT}
2138			}
2139		""
2140	end
2141
2142	case return_in_else
2143		values
2144		{
2145			input float in0		= [ -0.5 | 1.5 ];
2146			output float out0	= [ 0.5 | -1.5 ];
2147		}
2148
2149		both ""
2150			precision mediump float;
2151			${DECLARATIONS}
2152
2153			float func (float a)
2154			{
2155				if (a == 0.0)
2156					return 1.0;
2157				else
2158					return -a;
2159				return 1.0;
2160			}
2161
2162			void main()
2163			{
2164				${SETUP}
2165				out0 = func(in0);
2166				${OUTPUT}
2167			}
2168		""
2169	end
2170
2171	case return_in_loop
2172		values
2173		{
2174			input float in0		= [ -0.5 | 1.5 ];
2175			output float out0	= [ 0.5 | -1.5 ];
2176		}
2177
2178		both ""
2179			precision mediump float;
2180			${DECLARATIONS}
2181
2182			float func (float a)
2183			{
2184				for (int i = 0; i < 1; i++)
2185					return -a;
2186				return 1.0;
2187			}
2188
2189			void main()
2190			{
2191				${SETUP}
2192				out0 = func(in0);
2193				${OUTPUT}
2194			}
2195		""
2196	end
2197
2198	case return_in_loop_if
2199		values
2200		{
2201			input float in0		= [ -0.5 | 1.5 ];
2202			output float out0	= [ 0.5 | -1.5 ];
2203		}
2204
2205		both ""
2206			precision mediump float;
2207			${DECLARATIONS}
2208
2209			float func (float a)
2210			{
2211				for (int i = 0; i < 3; i++)
2212				{
2213					if (i == 1)
2214						return a;
2215					else if (i > 1)
2216						return -1.0;
2217					a = -a;
2218				}
2219				return 1.0;
2220			}
2221
2222			void main()
2223			{
2224				${SETUP}
2225				out0 = func(in0);
2226				${OUTPUT}
2227			}
2228		""
2229	end
2230
2231	case return_after_loop
2232		values
2233		{
2234			input float in0		= [ -0.5 | 1.5 ];
2235			output float out0	= [ 0.5 | -1.5 ];
2236		}
2237
2238		both ""
2239			precision mediump float;
2240			${DECLARATIONS}
2241
2242			float func (float a)
2243			{
2244				for (int i = 0; i < 5; i++)
2245					a = -a;
2246				return a;
2247			}
2248
2249			void main()
2250			{
2251				${SETUP}
2252				out0 = func(in0);
2253				${OUTPUT}
2254			}
2255		""
2256	end
2257
2258	case return_after_break
2259		values
2260		{
2261			input float in0		= [ -0.5 | 1.5 ];
2262			output float out0	= [ 0.5 | -1.5 ];
2263		}
2264
2265		both ""
2266			precision mediump float;
2267			${DECLARATIONS}
2268
2269			float func (float a)
2270			{
2271				for (int i = 0; i < 6; i++)
2272				{
2273					a = -a;
2274					if (i == 4)
2275						break;
2276				}
2277				return a;
2278			}
2279
2280			void main()
2281			{
2282				${SETUP}
2283				out0 = func(in0);
2284				${OUTPUT}
2285			}
2286		""
2287	end
2288
2289	case return_after_continue
2290		values
2291		{
2292			input float in0		= [ -0.5 | 1.5 ];
2293			output float out0	= [ 0.5 | -1.5 ];
2294		}
2295
2296		both ""
2297			precision mediump float;
2298			${DECLARATIONS}
2299
2300			float func (float a)
2301			{
2302				for (int i = 0; i < 6; i++)
2303				{
2304					if (i == 4)
2305						continue;
2306					a = -a;
2307				}
2308				return a;
2309			}
2310
2311			void main()
2312			{
2313				${SETUP}
2314				out0 = func(in0);
2315				${OUTPUT}
2316			}
2317		""
2318	end
2319
2320	case return_in_nested_loop
2321		values
2322		{
2323			input float in0		= [ -0.5 | 1.5 ];
2324			output float out0	= [ 0.5 | -1.5 ];
2325		}
2326
2327		both ""
2328			precision mediump float;
2329			${DECLARATIONS}
2330
2331			float func (float a)
2332			{
2333				for (int i = 0; i < 6; i++)
2334				{
2335					a = -a;
2336					for (int j = 0; j < 4; j++)
2337					{
2338						a = -a;
2339						if (i == 1)
2340							return a;
2341					}
2342					if (i == 4)
2343						return 1.0;
2344				}
2345				return 1.0;
2346			}
2347
2348			void main()
2349			{
2350				${SETUP}
2351				out0 = func(in0);
2352				${OUTPUT}
2353			}
2354		""
2355	end
2356
2357	case return_after_loop_sequence
2358		values
2359		{
2360			input float in0		= [ -0.5 | 1.5 ];
2361			output float out0	= [ 0.5 | -1.5 ];
2362		}
2363
2364		both ""
2365			precision mediump float;
2366			${DECLARATIONS}
2367
2368			float func (float a)
2369			{
2370				int i;
2371				for (i = 0; i < 6; i++) // negate a
2372				{
2373					a = -a;
2374					if (i == 4)
2375						a = -a;
2376				}
2377
2378				for (; i < 10; i++) // keep a
2379				{
2380					if (i == 8)
2381						continue;
2382					else if (i == 9)
2383						break;
2384					a = -a;
2385				}
2386
2387				return a;
2388			}
2389
2390			void main()
2391			{
2392				${SETUP}
2393				out0 = func(in0);
2394				${OUTPUT}
2395			}
2396		""
2397	end
2398
2399	case mixed_return_break_continue
2400		values
2401		{
2402			input float in0		= [ -0.5 | 1.5 ];
2403			output float out0	= [ 0.5 | -1.5 ];
2404		}
2405
2406		both ""
2407			precision mediump float;
2408			${DECLARATIONS}
2409
2410			float func (float a)
2411			{
2412				int i;
2413				for (i = 0; i < 6; i++)
2414				{
2415					if (i == 0)
2416						continue;
2417					else if (i == 1)
2418					{
2419					}
2420					else if (i == 3)
2421						break;
2422					else
2423						return a;
2424					a = -a;
2425				}
2426
2427				return 1.0;
2428			}
2429
2430			void main()
2431			{
2432				${SETUP}
2433				out0 = func(in0);
2434				${OUTPUT}
2435			}
2436		""
2437	end
2438
2439end # control_flow
2440
2441group misc "Miscellaneous"
2442
2443	case multi_arg_float
2444		values
2445		{
2446			input vec4 in0		= [ vec4(0.0, 1.0, -2.0, 0.5) | vec4(2.0, 2.5, 4.0, -7.0) ];
2447			output float out0	= [ 0.5 | -1.5 ]; # -sum(in0)
2448		}
2449
2450		both ""
2451			precision mediump float;
2452			${DECLARATIONS}
2453
2454			float sum(vec4 v) { return (v.x + v.y + v.z + v.w); }
2455
2456			float func (float a, vec3 b, vec2 c, vec2 d, vec4 e)
2457			{
2458				return -sum(vec4(a, b) + vec4(c, d)) + sum(e);
2459			}
2460
2461			void main()
2462			{
2463				${SETUP}
2464				out0 = func(in0.y, in0.xzw, in0.wz, in0.yx, in0);
2465				${OUTPUT}
2466			}
2467		""
2468	end
2469
2470	case multi_arg_int
2471		values
2472		{
2473			input ivec4 in0		= [ ivec4(-1, 0, 2, 2) | ivec4(1, 4, -8, 2) ];
2474			output int out0		= [ -3 | 1 ];
2475		}
2476
2477		both ""
2478			precision mediump float;
2479			precision mediump int;
2480			${DECLARATIONS}
2481
2482			int sum(ivec4 v) { return (v.x + v.y + v.z + v.w); }
2483
2484			int func (int a, ivec3 b, ivec2 c, ivec2 d, ivec4 e)
2485			{
2486				return -sum(ivec4(a, b) + ivec4(c, d)) + sum(e);
2487			}
2488
2489			void main()
2490			{
2491				${SETUP}
2492				out0 = func(in0.y, in0.xzw, in0.wz, in0.yx, in0);
2493				${OUTPUT}
2494			}
2495		""
2496	end
2497
2498	case argument_eval_order_1
2499		values
2500		{
2501			input int in0	= [  0 | 1 | 3 | 5 ];
2502			output int out0	= [ -1 | 5 | 11 | 17 ];
2503		}
2504
2505		both ""
2506			precision mediump float;
2507			${DECLARATIONS}
2508
2509			int func (float a, int b, bool c, int d)
2510			{
2511				if (c)
2512					return b + int(a) + d;
2513				else
2514					return -1;
2515			}
2516
2517			void main ()
2518			{
2519				${SETUP}
2520				float v0 = float(in0);
2521				int v1 = in0;
2522				out0 = func((v0 += 1.0), v1++, (v0 > 1.5), v1);
2523				${OUTPUT}
2524			}
2525		""
2526	end
2527
2528	case argument_eval_order_2
2529		values
2530		{
2531			input int in0	= [ 0 | -1 | 3 | 5 ];
2532			output int out0	= [ 3 | -1 | 9 | 13 ];
2533		}
2534
2535		both ""
2536			precision mediump float;
2537			${DECLARATIONS}
2538
2539			int g;
2540
2541			int modG (int v)
2542			{
2543				g += v;
2544				return v;
2545			}
2546
2547			int func (float a, int b, bool c, int d)
2548			{
2549				if (c)
2550					return b + int(a) + d;
2551				else
2552					return -1;
2553			}
2554
2555			void main ()
2556			{
2557				${SETUP}
2558				out0 = func(float(g = in0), modG(2), --g > 0, g);
2559				${OUTPUT}
2560			}
2561		""
2562	end
2563
2564	case missing_returns
2565		values
2566		{
2567			input float in0 = [ 1.0 | 2.0 | 3.0 ];
2568			output float out0 = [ -1.0 | -2.0 | -3.0 ];
2569		}
2570		both ""
2571			// Note specification says that returned value is undefined if no return
2572			// statement has been executed. In this case func() is called only with
2573			// positive values.
2574			precision mediump float;
2575			${DECLARATIONS}
2576
2577			float func (float f)
2578			{
2579				if (f > 0.0)
2580					return -f;
2581			}
2582
2583			void main ()
2584			{
2585				${SETUP}
2586				out0 = func(in0);
2587				${OUTPUT}
2588			}
2589		""
2590	end
2591
2592end # misc
2593
2594group invalid "Invalid Functions"
2595	case break_in_body
2596		expect compile_fail
2597		both ""
2598			precision mediump float;
2599
2600			void func ()
2601			{
2602				break;
2603			}
2604
2605			void main ()
2606			{
2607				${POSITION_FRAG_COLOR} = vec4(1.0);
2608			}
2609		""
2610	end
2611
2612	case continue_in_body
2613		expect compile_fail
2614		both ""
2615			precision mediump float;
2616
2617			void func ()
2618			{
2619				continue;
2620			}
2621
2622			void main ()
2623			{
2624				${POSITION_FRAG_COLOR} = vec4(1.0);
2625			}
2626		""
2627	end
2628
2629	case return_value_from_void_function
2630		expect compile_fail
2631		both ""
2632			precision mediump float;
2633
2634			void func ()
2635			{
2636				return 1.0;
2637			}
2638
2639			void main ()
2640			{
2641				${POSITION_FRAG_COLOR} = vec4(1.0);
2642			}
2643		""
2644	end
2645
2646	case extra_arguments
2647		expect compile_fail
2648		both ""
2649			precision mediump float;
2650
2651			void func (float f)
2652			{
2653			}
2654
2655			void main ()
2656			{
2657				func(1.0, 2.0);
2658				${POSITION_FRAG_COLOR} = vec4(1.0);
2659			}
2660		""
2661	end
2662
2663	case missing_arguments
2664		expect compile_fail
2665		both ""
2666			precision mediump float;
2667
2668			void func (float f)
2669			{
2670			}
2671
2672			void main ()
2673			{
2674				func();
2675				${POSITION_FRAG_COLOR} = vec4(1.0);
2676			}
2677		""
2678	end
2679
2680	case missing_argument_type
2681		expect compile_fail
2682		both ""
2683			precision mediump float;
2684
2685			void func (in f)
2686			{
2687			}
2688
2689			void main ()
2690			{
2691				${POSITION_FRAG_COLOR} = vec4(1.0);
2692			}
2693		""
2694	end
2695
2696	case argument_basetype_mismatch
2697		expect compile_fail
2698		both ""
2699			precision mediump float;
2700			precision mediump int;
2701
2702			void func (float f)
2703			{
2704			}
2705
2706			void main ()
2707			{
2708				func(2);
2709				${POSITION_FRAG_COLOR} = vec4(1.0);
2710			}
2711		""
2712	end
2713
2714	case argument_scalar_vector_mismatch
2715		expect compile_fail
2716		both ""
2717			precision mediump float;
2718
2719			void func (vec2 f)
2720			{
2721			}
2722
2723			void main ()
2724			{
2725				func(2.0);
2726				${POSITION_FRAG_COLOR} = vec4(1.0);
2727			}
2728		""
2729	end
2730
2731	case argument_vector_size_mismatch
2732		expect compile_fail
2733		both ""
2734			precision mediump float;
2735
2736			void func (vec3 f)
2737			{
2738			}
2739
2740			void main ()
2741			{
2742				func(vec2(2.0));
2743				${POSITION_FRAG_COLOR} = vec4(1.0);
2744			}
2745		""
2746	end
2747
2748	case duplicate_function
2749		expect compile_fail
2750		both ""
2751			precision mediump float;
2752
2753			void func (vec3 f);
2754
2755			void func (vec3 f)
2756			{
2757			}
2758
2759			void func (vec3 f)
2760			{
2761			}
2762
2763			void main ()
2764			{
2765				${POSITION_FRAG_COLOR} = vec4(1.0);
2766			}
2767		""
2768	end
2769
2770	case prototype_mismatch_return_type
2771		expect compile_fail
2772		both ""
2773			precision mediump float;
2774
2775			void func (vec3 f);
2776
2777			void main ()
2778			{
2779				${POSITION_FRAG_COLOR} = vec4(1.0);
2780			}
2781
2782			float func (vec3 f)
2783			{
2784				return f.x;
2785			}
2786		""
2787	end
2788
2789	case prototype_unspecified_array_size
2790		expect compile_fail
2791		both ""
2792			precision mediump float;
2793
2794			void func (vec3 f[]);
2795
2796			void main ()
2797			{
2798				${POSITION_FRAG_COLOR} = vec4(1.0);
2799			}
2800		""
2801	end
2802
2803	case call_mismatch_argument_array_size
2804		expect compile_fail
2805		both ""
2806			precision mediump float;
2807
2808			void func (vec3 f[3]);
2809			void func (vec3 f[3])
2810			{
2811			}
2812
2813			void main ()
2814			{
2815				vec3 array[4];
2816				func(array);
2817				${POSITION_FRAG_COLOR} = vec4(1.0);
2818			}
2819		""
2820	end
2821
2822	case prototype_mismatch_argument_const
2823		expect compile_fail
2824		both ""
2825			precision mediump float;
2826
2827			void func (vec3 f);
2828			void func (const vec3 f)
2829			{
2830			}
2831
2832			void main ()
2833			{
2834				${POSITION_FRAG_COLOR} = vec4(1.0);
2835			}
2836		""
2837	end
2838
2839	case prototype_mismatch_argument_array_const
2840		expect compile_fail
2841		both ""
2842			precision mediump float;
2843
2844			void func (vec3 f[3]);
2845			void func (const vec3 f[3])
2846			{
2847			}
2848
2849			void main ()
2850			{
2851				${POSITION_FRAG_COLOR} = vec4(1.0);
2852			}
2853		""
2854	end
2855
2856	case prototype_mismatch_array_inout
2857		expect compile_fail
2858		both ""
2859			precision mediump float;
2860
2861			void func (out vec3 f);
2862			void func (inout vec3 f)
2863			{
2864			}
2865
2866			void main ()
2867			{
2868				${POSITION_FRAG_COLOR} = vec4(1.0);
2869			}
2870		""
2871	end
2872
2873	case missing_return_type
2874		expect compile_fail
2875		both ""
2876			precision mediump float;
2877
2878			func (float f);
2879			func (inout vec3 f[3])
2880			{
2881			}
2882
2883			void main ()
2884			{
2885				${POSITION_FRAG_COLOR} = vec4(1.0);
2886			}
2887		""
2888	end
2889
2890	case call_before_definition
2891		expect compile_fail
2892		both ""
2893			precision mediump float;
2894
2895			void main ()
2896			{
2897				func(1.0);
2898				${POSITION_FRAG_COLOR} = vec4(1.0);
2899			}
2900
2901			void func (float f)
2902			{
2903			}
2904
2905		""
2906	end
2907
2908	case return_array_in_struct
2909		expect compile_fail
2910		both ""
2911			precision mediump float;
2912
2913			struct Foo
2914			{
2915				float f;
2916				float arr[2];
2917			};
2918
2919			Foo func ()
2920			{
2921				Foo f;
2922				f.f = 1.0;
2923				f.arr[0] = 2.0;
2924				return f;
2925			}
2926
2927			void main ()
2928			{
2929				${POSITION_FRAG_COLOR} = vec4(1.0);
2930			}
2931		""
2932	end
2933
2934	case argument_precision_overload
2935		expect compile_fail
2936		both ""
2937			precision mediump float;
2938
2939			float func (lowp float f)
2940			{
2941				return f;
2942			}
2943
2944			float func (mediump float f)
2945			{
2946				return f;
2947			}
2948
2949			void main ()
2950			{
2951				${POSITION_FRAG_COLOR} = vec4(1.0);
2952			}
2953		""
2954	end
2955
2956	case argument_in_out_overload
2957		expect compile_fail
2958		both ""
2959			precision mediump float;
2960
2961			void func (in float f)
2962			{
2963			}
2964
2965			void func (out float f)
2966			{
2967				f = 1.0;
2968			}
2969
2970			void main ()
2971			{
2972				${POSITION_FRAG_COLOR} = vec4(1.0);
2973			}
2974		""
2975	end
2976
2977	case argument_in_inout_overload
2978		expect compile_fail
2979		both ""
2980			precision mediump float;
2981
2982			void func (in float f)
2983			{
2984			}
2985
2986			void func (inout float f)
2987			{
2988				f = -f;
2989			}
2990
2991			void main ()
2992			{
2993				${POSITION_FRAG_COLOR} = vec4(1.0);
2994			}
2995		""
2996	end
2997
2998	case argument_out_inout_overload
2999		expect compile_fail
3000		both ""
3001			precision mediump float;
3002
3003			void func (out float f)
3004			{
3005				f = -1.0;
3006			}
3007
3008			void func (inout float f)
3009			{
3010				f = -f;
3011			}
3012
3013			void main ()
3014			{
3015				${POSITION_FRAG_COLOR} = vec4(1.0);
3016			}
3017		""
3018	end
3019
3020	case return_type_overload
3021		expect compile_fail
3022		both ""
3023			precision mediump float;
3024
3025			float func (float f)
3026			{
3027				return f;
3028			}
3029
3030			int func (float f)
3031			{
3032				return int(f);
3033			}
3034
3035			void main ()
3036			{
3037				${POSITION_FRAG_COLOR} = vec4(1.0);
3038			}
3039		""
3040	end
3041
3042	case return_type_precision_overload
3043		expect compile_fail
3044		both ""
3045			precision mediump float;
3046
3047			lowp float func (float f)
3048			{
3049				return f;
3050			}
3051
3052			mediump float func (float f)
3053			{
3054				return f;
3055			}
3056
3057			void main ()
3058			{
3059				${POSITION_FRAG_COLOR} = vec4(1.0);
3060			}
3061		""
3062	end
3063
3064	case return_type_const_overload
3065		expect compile_fail
3066		both ""
3067			precision mediump float;
3068
3069			float func (float f)
3070			{
3071				return f;
3072			}
3073
3074			const float func (float f)
3075			{
3076				return f;
3077			}
3078
3079			void main ()
3080			{
3081				${POSITION_FRAG_COLOR} = vec4(1.0);
3082			}
3083		""
3084	end
3085
3086	case return_without_value
3087		expect compile_fail
3088		both ""
3089			precision mediump float;
3090
3091			float func (float f)
3092			{
3093				return;
3094				return 1.0;
3095			}
3096
3097			void main ()
3098			{
3099				${POSITION_FRAG_COLOR} = vec4(1.0);
3100			}
3101		""
3102	end
3103
3104	case local_function_prototype
3105		expect compile_fail
3106		both ""
3107			precision mediump float;
3108
3109			void main ()
3110			{
3111				float func (float f);
3112
3113				${POSITION_FRAG_COLOR} = vec4(1.0);
3114			}
3115		""
3116	end
3117
3118	case local_function_definition
3119		expect compile_fail
3120		both ""
3121			precision mediump float;
3122
3123			void main ()
3124			{
3125				float func (float f)
3126				{
3127					return 1.0;
3128				}
3129
3130				${POSITION_FRAG_COLOR} = vec4(1.0);
3131			}
3132		""
3133	end
3134
3135	case name_type_conflict
3136		expect compile_fail
3137		both ""
3138			precision mediump float;
3139
3140			struct foo { float a; }
3141
3142			float foo (float f)
3143			{
3144				return 1.0;
3145			}
3146
3147			void main ()
3148			{
3149				${POSITION_FRAG_COLOR} = vec4(1.0);
3150			}
3151		""
3152	end
3153
3154	case const_overload
3155		expect compile_fail
3156		both ""
3157			precision mediump float;
3158
3159			void func (vec3 f)
3160			{
3161			}
3162
3163			void func (const vec3 f)
3164			{
3165			}
3166
3167			void main ()
3168			{
3169				${POSITION_FRAG_COLOR} = vec4(1.0);
3170			}
3171		""
3172	end
3173
3174	case uniform_local
3175		expect compile_fail
3176		both ""
3177			precision mediump float;
3178
3179			void func (vec3 f)
3180			{
3181				uniform float u;
3182			}
3183
3184			void main ()
3185			{
3186				${POSITION_FRAG_COLOR} = vec4(1.0);
3187			}
3188		""
3189	end
3190
3191	case varying_local
3192		expect compile_fail
3193		both ""
3194			precision mediump float;
3195
3196			void func (vec3 f)
3197			{
3198				varying float v;
3199			}
3200
3201			void main ()
3202			{
3203				${POSITION_FRAG_COLOR} = vec4(1.0);
3204			}
3205		""
3206	end
3207
3208	case attribute_local
3209		expect compile_fail
3210		both ""
3211			precision mediump float;
3212
3213			void func (vec3 f)
3214			{
3215				attribute float a;
3216			}
3217
3218			void main ()
3219			{
3220				${POSITION_FRAG_COLOR} = vec4(1.0);
3221			}
3222		""
3223	end
3224
3225	case uniform_argument
3226		expect compile_fail
3227		both ""
3228			precision mediump float;
3229
3230			void func (uniform vec3 f)
3231			{
3232			}
3233
3234			void main ()
3235			{
3236				${POSITION_FRAG_COLOR} = vec4(1.0);
3237			}
3238		""
3239	end
3240
3241	case varying_argument
3242		expect compile_fail
3243		both ""
3244			precision mediump float;
3245
3246			void func (varying vec3 f)
3247			{
3248			}
3249
3250			void main ()
3251			{
3252				${POSITION_FRAG_COLOR} = vec4(1.0);
3253			}
3254		""
3255	end
3256
3257	case attribute_argument
3258		expect compile_fail
3259		both ""
3260			precision mediump float;
3261
3262			void func (attribute vec3 f)
3263			{
3264			}
3265
3266			void main ()
3267			{
3268				${POSITION_FRAG_COLOR} = vec4(1.0);
3269			}
3270		""
3271	end
3272
3273	case uniform_return_type
3274		expect compile_fail
3275		both ""
3276			precision mediump float;
3277
3278			uniform float func (vec3 f)
3279			{
3280				return f.x;
3281			}
3282
3283			void main ()
3284			{
3285				${POSITION_FRAG_COLOR} = vec4(1.0);
3286			}
3287		""
3288	end
3289
3290	case varying_return_type
3291		expect compile_fail
3292		both ""
3293			precision mediump float;
3294
3295			varying float func (vec3 f)
3296			{
3297				return f.x;
3298			}
3299
3300			void main ()
3301			{
3302				${POSITION_FRAG_COLOR} = vec4(1.0);
3303			}
3304		""
3305	end
3306
3307	case attribute_return_type
3308		expect compile_fail
3309		both ""
3310			precision mediump float;
3311
3312			attribute float func (vec3 f)
3313			{
3314				return f.x;
3315			}
3316
3317			void main ()
3318			{
3319				${POSITION_FRAG_COLOR} = vec4(1.0);
3320			}
3321		""
3322	end
3323
3324	case main_invalid_return_type
3325		expect compile_fail
3326		both ""
3327			precision mediump float;
3328
3329			float main ()
3330			{
3331				${POSITION_FRAG_COLOR} = vec4(1.0);
3332			}
3333		""
3334	end
3335
3336	case main_has_arguments
3337		expect compile_fail
3338		both ""
3339			precision mediump float;
3340
3341			void main (float f)
3342			{
3343				${POSITION_FRAG_COLOR} = vec4(1.0);
3344			}
3345		""
3346	end
3347
3348	case main_missing_return_type
3349		expect compile_fail
3350		both ""
3351			precision mediump float;
3352
3353			main ()
3354			{
3355				${POSITION_FRAG_COLOR} = vec4(1.0);
3356			}
3357		""
3358	end
3359
3360	case write_const_arg
3361		expect compile_fail
3362		both ""
3363			precision mediump float;
3364
3365			func (const float f)
3366			{
3367				f = 1.0;
3368			}
3369
3370			main ()
3371			{
3372				${POSITION_FRAG_COLOR} = vec4(1.0);
3373			}
3374		""
3375	end
3376
3377	case write_const_array_arg
3378		expect compile_fail
3379		both ""
3380			precision mediump float;
3381
3382			func (const float f[3])
3383			{
3384				f[0] = 1.0;
3385			}
3386
3387			main ()
3388			{
3389				${POSITION_FRAG_COLOR} = vec4(1.0);
3390			}
3391		""
3392	end
3393
3394	case modify_const_arg
3395		expect compile_fail
3396		both ""
3397			precision mediump float;
3398			precision mediump int;
3399			${DECLARATIONS}
3400
3401			int func (const int a)
3402			{
3403				a = -a;
3404				return 2 * a;
3405			}
3406
3407			void main()
3408			{
3409				${POSITION_FRAG_COLOR} = vec4(func(3));
3410			}
3411		""
3412	end
3413
3414	case init_const_local_from_const_arg
3415		expect compile_fail
3416		both ""
3417			precision mediump float;
3418			precision mediump int;
3419			${DECLARATIONS}
3420
3421			int func (const int a)
3422			{
3423				const int b = -a;
3424				return 2 * b;
3425			}
3426
3427			void main()
3428			{
3429				${POSITION_FRAG_COLOR} = vec4(func(3));
3430			}
3431		""
3432	end
3433
3434	case array_size_from_const_arg
3435		expect compile_fail
3436		both ""
3437			precision mediump float;
3438			precision mediump int;
3439			${DECLARATIONS}
3440
3441			int func (const int a)
3442			{
3443				int arr[a];
3444				arr[1] = 3;
3445				return arr[1];
3446			}
3447
3448			void main()
3449			{
3450				${POSITION_FRAG_COLOR} = vec4(func(3));
3451			}
3452		""
3453	end
3454
3455	case double_declare
3456		expect compile_fail
3457		both ""
3458			precision mediump float;
3459			${DECLARATIONS}
3460
3461			float func (float f);
3462			float func (float f);
3463
3464			float func (float f)
3465			{
3466				return -f;
3467			}
3468
3469			void main()
3470			{
3471				${POSITION_FRAG_COLOR} = vec4(func(1.0));
3472			}
3473		""
3474	end
3475
3476end # invalid
3477