glsl-array-bounds: set out-of-bounds array index inside shader
[piglit.git] / tests / shaders / glsl-vs-continue-inside-do-while.shader_test
blobaa6d3e634a6145d0ea9e5371bee5abe0577cbe28
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 # As of 1/31/2014 (commit db8b6fb), Mesa handles "continue" inside a
10 # do-while loop incorrectly; instead of jumping to the loop
11 # condition-expression, it jumps to the top of the loop.  This is
12 # particularly problematic because it can lead to infinite loops.
14 # This test verifies correct behaviour of "continue" inside do-while
15 # loops without risking an infinite loop.
17 [require]
18 GLSL >= 1.10
20 [vertex shader]
21 void main()
23   gl_Position = gl_Vertex;
24   int x = 0;
25   int y = 0;
26   do {             // 1st iteration  2nd iteration  3rd iteration
27     ++x;           // x <- 1         x <- 2         x <- 3
28     if (x >= 4)    // false          false          false
29       break;
30     if (x >= 2)    // false          true           true
31       continue;
32     ++y;           // y=1            skipped        skipped
33   } while (x < 3); // true           true           false
35   // The "continue" should skip ++y on all iterations but the first,
36   // so y should now be 1.  The "continue" should not skip (x < 3)
37   // ever, so the loop should terminate when x == 3 (not 4).
38   if (x == 3 && y == 1)
39     gl_FrontColor = vec4(0.0, 1.0, 0.0, 1.0);
40   else
41     gl_FrontColor = vec4(1.0, 0.0, 0.0, 1.0);
44 [fragment shader]
45 void main()
47   gl_FragColor = gl_Color;
50 [test]
51 draw rect -1 -1 2 2
52 probe all rgba 0.0 1.0 0.0 1.0