summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/glslang/src/Test/precise_struct_block.vert
blob: 279b4b09df50edef274b0cb1414e7133f6dd50d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#version 450

struct T {
  float f1;
  float f2;
};

out B1 {precise T s; float x;} partial_precise_block;
precise out B2 {T s; float x;} all_precise_block;

float struct_member() {
  float a = 1.0;
  float b = 2.0;
  float c = 3.0;
  float d = 4.0;

  precise float result;

  T S, S2, S3;

  S2.f1 = a + 0.2;      // NoContraction
  S2.f2 = b + 0.2;      // NOT NoContraction
  S3.f1 = a + b;        // NOT NoContraction
  S = S2;               // "precise" propagated through parent object nodes
  result = S.f1 + 0.1;  // the ADD operation should be NoContraction

  return result;
}

float complex_array_struct() {
  precise float result;
  struct T1 {
    float t1_array[3];
    float t1_scalar;
  };
  struct T2 {
    T1 t1a[5];
    T1 t1b[6];
    T1 t1c[7];
  };
  struct T3 {float f; T2 t2; vec4 v; int p;};
  T3 t3[10];
  for(int i=0; i<10; i++) {
    t3[i].f = i / 3.0; // Not NoContraction
    t3[i].v = vec4(i * 1.5); // NoContraction
    t3[i].p = i + 1;
    for(int j=0; j<5; j++) {
      for(int k = 0; k<3; k++) {
        t3[i].t2.t1a[j].t1_array[k] = i * j + k; // Not NoContraction
      }
      t3[i].t2.t1a[j].t1_scalar = j * 2.0 / i; // Not NoContration
    }

    for(int j=0; j<6; j++) {
      for(int k = 0; k<3; k++) {
        t3[i].t2.t1b[j].t1_array[k] = i * j + k; // Not NoContraction
      }
      t3[i].t2.t1b[j].t1_scalar = j * 2.0 / i; // NoContraction
    }

    for(int j=0; j<6; j++) {
      for(int k = 0; k<3; k++) {
        t3[i].t2.t1c[j].t1_array[k] = i * j + k; // Not NoContraction because all operands are integers
      }
      t3[i].t2.t1c[j].t1_scalar = j * 2.0 / i; // Not NoContraction
    }
  }
  int i = 2;
  result = t3[5].t2.t1c[6].t1_array[1]
           + t3[2].t2.t1b[1].t1_scalar
           + t3[i - 1].v.xy.x; // NoContraction
  return result;
}

float out_block() {
    float a = 0.1;
    float b = 0.2;
    partial_precise_block.s.f1 = a + b; // NoContraction
    partial_precise_block.s.f2 = a - b; // NoContraction
    partial_precise_block.x = a * b; // Not NoContraction

    all_precise_block.s.f1 = a + b + 1.0; // NoContraction
    all_precise_block.s.f2 = a - b - 1.0; // NoContraction
    all_precise_block.x = a * b * 2.0; // Also NoContraction

    return a + b; // Not NoContraction
}

void main(){}