Merge pull request #2976 from jeremy-lunarg/hayes-fix-2975
[platform/upstream/glslang.git] / Test / functionSemantics.frag
1 #version 400\r
2 \r
3 uniform float u;\r
4 \r
5 int foo(int a, const int b, in int c, const in int d, out int e, inout int f)\r
6 {\r
7     int sum = a + b + c + d + f; // no e, it is out only\r
8         // sum should be 47 now\r
9 \r
10         a *= 64;\r
11         // no b, it is read only\r
12         c *= 64;\r
13         // no d, it is read only\r
14         e = 64 * 16; // e starts undefined\r
15         f *= 64;\r
16 \r
17         sum += a + 64 * b + c + 64 * d + e + f; // everything has a value now, totaling of 64(1+2+4+8+16+32) = 64*63 = 4032\r
18         // sum should be 4032 + 47  = 4079\r
19         \r
20         return sum;\r
21 }\r
22 \r
23 int foo2(float a, vec3 b, out int r)\r
24 {\r
25     r = int(3.0 * a);\r
26     return int(5.0 * b.y);\r
27 }\r
28 \r
29 int foo3()\r
30 {\r
31     if (u > 3.2) {\r
32         discard;\r
33         return 1000000;\r
34     }\r
35 \r
36     return 2000000;\r
37 }\r
38 \r
39 void main()\r
40 {\r
41     int e;\r
42         int t = 2;\r
43         struct s {\r
44             ivec4 t;\r
45         } f;\r
46         f.t.y = 32;\r
47 \r
48     // test the different qualifers\r
49     int color = foo(1, 2, t+t, 8, e, f.t.y);\r
50 \r
51         color += 128 * (e + f.t.y); // right side should be 128(64(16 + 32)) = 393216\r
52         // sum should be 4079 + 393216 = 397295\r
53     \r
54     // test conversions\r
55     float arg;\r
56     float ret;\r
57     ret = foo2(4, ivec3(1,2,3), arg);  // ret = 10, param = 12.0\r
58     color += int(ret + arg); // adds 22, for total of 397317\r
59 \r
60     color += foo3();         // theoretically, add 2000000, for total of 2397317\r
61 \r
62     gl_FragColor = vec4(color);\r
63 }\r
64 \r
65 vec3 m(vec2);\r
66 void aggCall()\r
67 {\r
68     float F;\r
69     m(ivec2(F));  // test input conversion of single argument that's an aggregate; other function tests in 120.vert\r
70 }\r
71 \r
72 vec4 badConv()\r
73 {\r
74     return u;     // ERROR, can change scalar to vector\r
75 }