xref: /aosp_15_r20/external/deqp/data/gles3/shaders/conditionals.test (revision 35238bce31c2a825756842865a792f8cf7f89930)
1group if "If Statements"
2
3    case single_statement
4        version 300 es
5        values
6        {
7            input float in0 = [ 0.0 | 1.0 | 2.0 ];
8            output float out0 = [ 0.0 | 1.0 | 1.0 ];
9        }
10
11        both ""
12            #version 300 es
13            precision mediump float;
14            ${DECLARATIONS}
15            void main()
16            {
17                out0 = 0.0;
18                if (in0 >= 1.0)
19                    out0 = 1.0;
20                ${OUTPUT}
21            }
22        ""
23    end
24
25    case compound_statement
26        version 300 es
27        values
28        {
29            input float in0 = [ 0.0 | 1.0 | 2.0 ];
30            output float out0 = [ 0.0 | 1.0 | 1.0 ];
31            output float out1 = [ 1.0 | 0.0 | 0.0 ];
32        }
33
34        both ""
35            #version 300 es
36            precision mediump float;
37            ${DECLARATIONS}
38            void main()
39            {
40                out0 = 0.0;
41                out1 = 1.0;
42                if (in0 >= 1.0)
43                {
44                    out0 = 1.0;
45                    out1 = 0.0;
46                }
47                ${OUTPUT}
48            }
49        ""
50    end
51
52    case sequence_statements
53        version 300 es
54        values
55        {
56            input float in0 = [ 0.0 | 1.0 | 2.0 ];
57            output float out0 = [ 0.0 | 1.0 | 1.0 ];
58            output float out1 = [ 1.0 | 0.0 | 0.0 ];
59        }
60
61        both ""
62            #version 300 es
63            precision mediump float;
64            ${DECLARATIONS}
65            void main()
66            {
67                out0 = 0.0;
68                out1 = 1.0;
69                if (in0 >= 1.0)
70                    out0 = 1.0, out1 = 0.0;
71                ${OUTPUT}
72            }
73        ""
74    end
75
76    case sequence_condition
77        version 300 es
78        values
79        {
80            input float in0 = [ 0.0 | 1.0 | 2.0 ];
81            output float out0 = [ 0.0 | 1.0 | 1.0 ];
82            output float out1 = [ 1.0 | 0.0 | 0.0 ];
83        }
84
85        both ""
86            #version 300 es
87            precision mediump float;
88            ${DECLARATIONS}
89            void main()
90            {
91                out0 = 0.0;
92                out1 = 1.0;
93                if (false, in0 >= 1.0)
94                    out0 = 1.0, out1 = 0.0;
95                ${OUTPUT}
96            }
97        ""
98    end
99
100    case complex_condition
101        version 300 es
102        values
103        {
104            input float in0 = [ 0.0 | 1.0 | 2.0 ];
105            output float out0 = [ 0.0 | 1.0 | 1.0 ];
106            output float out1 = [ 1.0 | 0.0 | 0.0 ];
107        }
108
109        both ""
110            #version 300 es
111            precision mediump float;
112            ${DECLARATIONS}
113            void main()
114            {
115                out0 = 0.0;
116                out1 = 1.0;
117                if (false || (in0 >= 1.0) && (in0 - 2.0*in0 < 0.0))
118                    out0 = 1.0, out1 = 0.0;
119                ${OUTPUT}
120            }
121        ""
122    end
123
124    case if_else
125        version 300 es
126        values
127        {
128            input float in0 = [ 0.0 | 1.0 | 2.0 ];
129            output float out0 = [ 0.0 | 1.0 | 1.0 ];
130        }
131
132        both ""
133            #version 300 es
134            precision mediump float;
135            ${DECLARATIONS}
136            void main()
137            {
138                if (in0 >= 1.0)
139                    out0 = 1.0;
140                else
141                    out0 = 0.0;
142                ${OUTPUT}
143            }
144        ""
145    end
146
147    case if_elseif
148        version 300 es
149        values
150        {
151            input float in0 = [ 0.0 | 1.0 | 2.0 ];
152            output float out0 = [ 0.0 | 1.0 | 2.0 ];
153        }
154
155        both ""
156            #version 300 es
157            precision mediump float;
158            ${DECLARATIONS}
159            void main()
160            {
161                out0 = 0.0;
162                if (in0 >= 2.0)
163                    out0 = 2.0;
164                else if (in0 >= 1.0)
165                    out0 = 1.0;
166                ${OUTPUT}
167            }
168        ""
169    end
170
171    case if_elseif_else
172        version 300 es
173        values
174        {
175            input float in0 = [ 0.0 | 1.0 | 2.0 ];
176            output float out0 = [ 0.0 | 1.0 | 2.0 ];
177        }
178
179        both ""
180            #version 300 es
181            precision mediump float;
182            ${DECLARATIONS}
183            void main()
184            {
185                if (in0 >= 2.0)
186                    out0 = 2.0;
187                else if (in0 >= 1.0)
188                    out0 = 1.0;
189                else
190                    out0 = 0.0;
191                ${OUTPUT}
192            }
193        ""
194    end
195
196    case mixed_if_elseif_else
197        version 300 es
198        values
199        {
200            input float in0 = [ 0.0 | 1.0 | 2.0 ];
201            output float out0 = [ 0.0 | 1.0 | 2.0 ];
202        }
203
204        both ""
205            #version 300 es
206            precision mediump float;
207            ${DECLARATIONS}
208            void main()
209            {
210                if (in0 >= 2.0)
211                {
212                    out0 = 2.0;
213                }
214                else if (in0 >= 1.0)
215                    out0 = 2.0, out0 = 1.0;
216                else
217                    out0 = 0.0;
218                ${OUTPUT}
219            }
220        ""
221    end
222
223    case constant_conditional_assignment_to_matrix
224        version 300 es
225        vertex ""
226            #version 300 es
227                        // This variant doesn't provoke the crash seen in the versions below.
228            ${VERTEX_DECLARATIONS}
229            out mediump float FragVarying;
230            const float in0 = 0.0;
231            void main()
232            {
233                mat2 projectionMatrix = mat2(0.0, 0.0, 0.0, 0.0);
234                if (in0 == 1.0)
235                {
236                    projectionMatrix[0][0] = 1.0;
237                }
238
239                FragVarying = 1.0;
240                gl_Position = dEQP_Position + vec4(projectionMatrix[1][0], 0.0, 0.0, 0.0);
241            }
242        ""
243        fragment ""
244            #version 300 es
245            precision mediump float;
246            ${FRAGMENT_DECLARATIONS}
247            in mediump float FragVarying;
248            void main()
249            {
250                ${FRAG_COLOR} = vec4(FragVarying, 1.0, 1.0, 1.0);
251            }
252        ""
253    end
254
255    case input_conditional_assignment_to_matrix
256        version 300 es
257        values
258        {
259            input float in0 = [ 0.0 ];
260        }
261        vertex ""
262            #version 300 es
263            ${VERTEX_DECLARATIONS}
264            out mediump float FragVarying;  // Necessary to reproduce.
265            void main()
266            {
267                // Crashes with mat4 as well. Does not crash with vectors.
268                mat2 projectionMatrix = mat2(0.0, 0.0, 0.0, 0.0);
269                // Testing a non-constant variable is necessary.
270                if (in0 == 1.0)
271                {
272                    // Using the matrix variable appears necessary.
273                    projectionMatrix[0][0] = 1.0;
274                }
275
276                FragVarying = 1.0;
277                // Referencing the matrix is necessary though clearly the compiler
278                // doesn't realize the assignment is useless.
279                gl_Position = dEQP_Position + vec4(projectionMatrix[1][0], 0.0, 0.0, 0.0);
280            }
281        ""
282        fragment ""
283            #version 300 es
284            precision mediump float;
285            ${FRAGMENT_DECLARATIONS}
286            in mediump float FragVarying;
287            void main()
288            {
289                ${FRAG_COLOR} = vec4(FragVarying, 1.0, 1.0, 1.0);
290            }
291        ""
292    end
293
294    case uniform_conditional_assignment_to_matrix
295        version 300 es
296        values
297        {
298            uniform float uni0 = [ 0.0 ];
299        }
300        vertex ""
301            #version 300 es
302            precision mediump float;
303            ${VERTEX_DECLARATIONS}
304            out mediump float FragVarying;  // Necessary to reproduce.
305            void main()
306            {
307                // Crashes with mat4 as well. Does not crash with vectors.
308                mat2 projectionMatrix = mat2(0.0, 0.0, 0.0, 0.0);
309                // Testing a non-constant variable is necessary.
310                if (uni0 == 1.0)
311                {
312                    // Using the matrix variable appears necessary.
313                    projectionMatrix[0][0] = 1.0;
314                }
315
316                FragVarying = 1.0;
317                // Referencing the matrix is necessary though clearly the compiler
318                // doesn't realize the assignment is useless.
319                gl_Position = dEQP_Position + vec4(projectionMatrix[1][0], 0.0, 0.0, 0.0);
320            }
321        ""
322        fragment ""
323            #version 300 es
324            precision mediump float;
325            ${FRAGMENT_DECLARATIONS}
326            in mediump float FragVarying;
327            void main()
328            {
329                ${FRAG_COLOR} = vec4(FragVarying, 1.0, 1.0, 1.0);
330            }
331        ""
332    end
333
334end # if
335
336group invalid_if "Invalid If Conditionals"
337
338    case missing_parenthesis
339        version 300 es
340        expect compile_fail
341        both ""
342            #version 300 es
343            precision mediump float;
344            ${DECLARATIONS}
345            void main()
346            {
347                if true
348                    ${POSITION_FRAG_COLOR} = vec4(1.0);
349            }
350        ""
351    end
352
353    case unclosed_parenthesis
354        version 300 es
355        expect compile_fail
356        both ""
357            #version 300 es
358            precision mediump float;
359            ${DECLARATIONS}
360            void main()
361            {
362                if (true
363                    ${POSITION_FRAG_COLOR} = vec4(1.0);
364            }
365        ""
366    end
367
368    case int_condition
369        version 300 es
370        expect compile_fail
371        both ""
372            #version 300 es
373            precision mediump float;
374            ${DECLARATIONS}
375            void main()
376            {
377                if (5)
378                    ${POSITION_FRAG_COLOR} = vec4(1.0);
379            }
380        ""
381    end
382
383    case int_zero_condition
384        version 300 es
385        expect compile_fail
386        both ""
387            #version 300 es
388            precision mediump float;
389            ${DECLARATIONS}
390            void main()
391            {
392                if (0)
393                    ${POSITION_FRAG_COLOR} = vec4(1.0);
394            }
395        ""
396    end
397
398    case int_one_condition
399        version 300 es
400        expect compile_fail
401        both ""
402            #version 300 es
403            precision mediump float;
404            ${DECLARATIONS}
405            void main()
406            {
407                if (1)
408                    ${POSITION_FRAG_COLOR} = vec4(1.0);
409            }
410        ""
411    end
412
413    case int_uniform_condition
414        version 300 es
415        expect compile_fail
416
417        both ""
418            #version 300 es
419            precision mediump float;
420            precision mediump int;
421            uniform int u0;
422            ${DECLARATIONS}
423            void main()
424            {
425                if (u0)
426                    ${POSITION_FRAG_COLOR} = vec4(1.0);
427            }
428        ""
429    end
430
431    case float_condition
432        version 300 es
433        expect compile_fail
434        both ""
435            #version 300 es
436            precision mediump float;
437            ${DECLARATIONS}
438            void main()
439            {
440                if (5.0)
441                    ${POSITION_FRAG_COLOR} = vec4(1.0);
442            }
443        ""
444    end
445
446    case float_zero_condition
447        version 300 es
448        expect compile_fail
449        both ""
450            #version 300 es
451            precision mediump float;
452            ${DECLARATIONS}
453            void main()
454            {
455                if (0.0)
456                    ${POSITION_FRAG_COLOR} = vec4(1.0);
457            }
458        ""
459    end
460
461    case float_one_condition
462        version 300 es
463        expect compile_fail
464        both ""
465            #version 300 es
466            precision mediump float;
467            ${DECLARATIONS}
468            void main()
469            {
470                if (1.0)
471                    ${POSITION_FRAG_COLOR} = vec4(1.0);
472            }
473        ""
474    end
475
476    case sampler_condition
477        version 300 es
478        expect compile_fail
479        both ""
480            #version 300 es
481            precision mediump float;
482            uniform sampler2D s0;
483            ${DECLARATIONS}
484            void main()
485            {
486                if (s0)
487                    ${POSITION_FRAG_COLOR} = vec4(1.0);
488            }
489        ""
490    end
491
492end # invalid_if
493