perf/pixel-rate: new pixel throughput microbenchmark
[piglit.git] / tests / spec / glsl-1.30 / execution / glsl-fs-continue-in-switch-in-do-while.shader_test
blob58dc50de946e316e5616caa68ccfbcb779bd9744
1 # From the GLSL 4.40 spec, section 6.4 (Jumps):
3 #     The continue jump is used only in loops. It skips the remainder
4 #     of the body of the inner most loop of which it is inside. For
5 #     while and do-while loops, this jump is to the next evaluation of
6 #     the loop condition-expression from which the loop continues as
7 #     previously defined.
9 # One way that do-while loops might be implemented is to convert them
10 # to infinite loops that terminate in a conditional break (this is
11 # what Mesa does).  In such an implementation, an easy way to
12 # implement the proper behaviour of "continue" in a do-while loop is
13 # to replicate the conditional break at the site of the "continue".
14 # For example, this code:
16 #     do {
17 #       ...
18 #       if (...) {
19 #         ...
20 #         continue;
21 #       }
22 #       ...
23 #     } while (condition);
25 # would get translated to:
27 #     loop {
28 #       ...
29 #       if (...) {
30 #         ...
31 #         if (!condition)
32 #           break;
33 #         continue;
34 #       }
35 #       ...
36 #       if (!condition)
37 #         break;
38 #     }
40 # However, we must be careful in making this transformation if the
41 # "continue" occurs inside a switch statement, since "break" inside a
42 # switch statement normally exits the switch statement, not the
43 # surrounding loop.
45 # This test verifies that "continue" behaves properly when invoked
46 # inside a switch statement which is itself inside a do-while loop.
48 [require]
49 GLSL >= 1.30
51 [vertex shader]
52 #version 130
53 void main()
55   gl_Position = gl_Vertex;
58 [fragment shader]
59 #version 130
60 void main()
62   int w = 0;
63   int x = 0;
64   int y = 0;
65   int z = 0;
66   do {             // 1st iteration   2nd iteration
67     ++w;           // w <- 1          w <- 2
68     switch (w) {   // Jump to case 1  Jump to case 2
69       case 1:
70         ++x;       // x <- 1
71         break;     // Jump to ++z
72       case 2:
73         continue;  //                 Jump to (w < 2)
74       case 3:
75         ++y;       // (this case is never executed)
76         break;
77     }
78     ++z;           // z <- 1          skipped
79   } while (w < 2); // true            false
81   // The loop should execute for two iterations, so w should be 2.  X
82   // should be incremented on the first iteration only, so it should
83   // be 1.  Y should never be incremented (since w never reaches 3),
84   // so it should be 0.  The "continue" should skip ++z on the second
85   // iteration, so z should be 1.
86   if (w == 2 && x == 1 && y == 0 && z == 1)
87     gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
88   else
89     gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
92 [test]
93 draw rect -1 -1 2 2
94 probe all rgba 0.0 1.0 0.0 1.0