perf/pixel-rate: new pixel throughput microbenchmark
[piglit.git] / tests / spec / glsl-1.30 / execution / glsl-vs-continue-in-switch-in-do-while.shader_test
blob88fcfb9b397812f13b4b5d8aaefc6ee8c027d1b8
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;
56   int w = 0;
57   int x = 0;
58   int y = 0;
59   int z = 0;
60   do {             // 1st iteration   2nd iteration
61     ++w;           // w <- 1          w <- 2
62     switch (w) {   // Jump to case 1  Jump to case 2
63       case 1:
64         ++x;       // x <- 1
65         break;     // Jump to ++z
66       case 2:
67         continue;  //                 Jump to (w < 2)
68       case 3:
69         ++y;       // (this case is never executed)
70         break;
71     }
72     ++z;           // z <- 1          skipped
73   } while (w < 2); // true            false
75   // The loop should execute for two iterations, so w should be 2.  X
76   // should be incremented on the first iteration only, so it should
77   // be 1.  Y should never be incremented (since w never reaches 3),
78   // so it should be 0.  The "continue" should skip ++z on the second
79   // iteration, so z should be 1.
80   if (w == 2 && x == 1 && y == 0 && z == 1)
81     gl_FrontColor = vec4(0.0, 1.0, 0.0, 1.0);
82   else
83     gl_FrontColor = vec4(1.0, 0.0, 0.0, 1.0);
86 [fragment shader]
87 #version 130
88 void main()
90   gl_FragColor = gl_Color;
93 [test]
94 draw rect -1 -1 2 2
95 probe all rgba 0.0 1.0 0.0 1.0