Merge pull request #2865 from alan-baker/update-license
[platform/upstream/glslang.git] / Test / precise_struct_block.vert
1 #version 450
2
3 struct T {
4   float f1;
5   float f2;
6 };
7
8 out B1 {precise T s; float x;} partial_precise_block;
9 precise out B2 {T s; float x;} all_precise_block;
10
11 float struct_member() {
12   float a = 1.0;
13   float b = 2.0;
14   float c = 3.0;
15   float d = 4.0;
16
17   precise float result;
18
19   T S, S2, S3;
20
21   S2.f1 = a + 0.2;      // NoContraction
22   S2.f2 = b + 0.2;      // NOT NoContraction
23   S3.f1 = a + b;        // NOT NoContraction
24   S = S2;               // "precise" propagated through parent object nodes
25   result = S.f1 + 0.1;  // the ADD operation should be NoContraction
26
27   return result;
28 }
29
30 float complex_array_struct() {
31   precise float result;
32   struct T1 {
33     float t1_array[3];
34     float t1_scalar;
35   };
36   struct T2 {
37     T1 t1a[5];
38     T1 t1b[6];
39     T1 t1c[7];
40   };
41   struct T3 {float f; T2 t2; vec4 v; int p;};
42   T3 t3[10];
43   for(int i=0; i<10; i++) {
44     t3[i].f = i / 3.0; // Not NoContraction
45     t3[i].v = vec4(i * 1.5); // NoContraction
46     t3[i].p = i + 1;
47     for(int j=0; j<5; j++) {
48       for(int k = 0; k<3; k++) {
49         t3[i].t2.t1a[j].t1_array[k] = i * j + k; // Not NoContraction
50       }
51       t3[i].t2.t1a[j].t1_scalar = j * 2.0 / i; // Not NoContration
52     }
53
54     for(int j=0; j<6; j++) {
55       for(int k = 0; k<3; k++) {
56         t3[i].t2.t1b[j].t1_array[k] = i * j + k; // Not NoContraction
57       }
58       t3[i].t2.t1b[j].t1_scalar = j * 2.0 / i; // NoContraction
59     }
60
61     for(int j=0; j<6; j++) {
62       for(int k = 0; k<3; k++) {
63         t3[i].t2.t1c[j].t1_array[k] = i * j + k; // Not NoContraction because all operands are integers
64       }
65       t3[i].t2.t1c[j].t1_scalar = j * 2.0 / i; // Not NoContraction
66     }
67   }
68   int i = 2;
69   result = t3[5].t2.t1c[6].t1_array[1]
70            + t3[2].t2.t1b[1].t1_scalar
71            + t3[i - 1].v.xy.x; // NoContraction
72   return result;
73 }
74
75 float out_block() {
76     float a = 0.1;
77     float b = 0.2;
78     partial_precise_block.s.f1 = a + b; // NoContraction
79     partial_precise_block.s.f2 = a - b; // NoContraction
80     partial_precise_block.x = a * b; // Not NoContraction
81
82     all_precise_block.s.f1 = a + b + 1.0; // NoContraction
83     all_precise_block.s.f2 = a - b - 1.0; // NoContraction
84     all_precise_block.x = a * b * 2.0; // Also NoContraction
85
86     return a + b; // Not NoContraction
87 }
88
89 void main(){}