qining | 9220dbb | 2016-05-04 17:34:38 -0400 | [diff] [blame] | 1 | #version 450 |
| 2 | #extension GL_EXT_tessellation_shader : require |
| 3 | #extension GL_EXT_gpu_shader5 : require |
| 4 | |
| 5 | float minimal() { |
| 6 | precise float result = 5.0; |
| 7 | float a = 10.0; |
| 8 | float b = 20.0; |
| 9 | float c = 30.0; |
| 10 | float d = 40.0; |
| 11 | result = a * b + c * d; // c * d, a * b and rvalue1 + rvalue2 should be 'noContraction'. |
| 12 | return result; |
| 13 | } |
| 14 | |
| 15 | void continuous_assignment() { |
| 16 | precise float result = 5.0; |
qining | 5bec2b5 | 2016-05-06 21:52:28 -0400 | [diff] [blame] | 17 | float a = 10.0; |
| 18 | float b = 20.0; |
qining | 9220dbb | 2016-05-04 17:34:38 -0400 | [diff] [blame] | 19 | result = a = b + 4; // b + 4 should be 'noContraction'. |
| 20 | } |
| 21 | |
| 22 | void convert() { |
qining | 5bec2b5 | 2016-05-06 21:52:28 -0400 | [diff] [blame] | 23 | precise double result; |
| 24 | float a = 10.0; |
| 25 | float b = 20.0; |
qining | 9220dbb | 2016-05-04 17:34:38 -0400 | [diff] [blame] | 26 | b = a + b; // a + b should be 'noContraction'. |
qining | 5bec2b5 | 2016-05-06 21:52:28 -0400 | [diff] [blame] | 27 | result = double(b); // convert operation should not be 'noContraction'. |
qining | 9220dbb | 2016-05-04 17:34:38 -0400 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | float loop_for() { |
| 31 | precise float r1 = 5.0; |
| 32 | precise float r2 = 10.0; |
| 33 | int a = 10; |
| 34 | int b = 20; |
| 35 | int c = 30; |
| 36 | for (int i = 0; i < a; i++) { |
| 37 | r1 += 3.12 + b + i; // 'noContration', this make i++ also 'noContraction' |
| 38 | c += 1; // 'noContration' |
| 39 | } |
| 40 | a += 1; // a + 1 should not be 'noContraction'. |
| 41 | r2 = c; // The calculation of c should be 'noContration'. |
| 42 | return float(r1 + r2); // conversion should not be 'noContration'. |
| 43 | } |
| 44 | |
| 45 | void loop_array(void) { |
qining | 5bec2b5 | 2016-05-06 21:52:28 -0400 | [diff] [blame] | 46 | precise float result; |
qining | 9220dbb | 2016-05-04 17:34:38 -0400 | [diff] [blame] | 47 | |
| 48 | int x = 22; |
| 49 | int y = 33; |
| 50 | |
qining | 5bec2b5 | 2016-05-06 21:52:28 -0400 | [diff] [blame] | 51 | float a0[3]; |
| 52 | result += float(x) + float(y); // x + y should be 'noContraction' also result + rvalue. |
qining | 9220dbb | 2016-05-04 17:34:38 -0400 | [diff] [blame] | 53 | |
| 54 | for (int i = 0; i < 3; ++i) { |
| 55 | // a's dereference + 2 should be 'noContraction'. |
| 56 | result += a0[i] + 2; |
| 57 | // result + 1 and 3 - rvalue should be 'noContraction'. |
| 58 | a0[i] = 3 - result++; |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | void loop_while() { |
| 63 | precise float result = 5.0; |
| 64 | int a = 10; |
| 65 | int b = 20; |
| 66 | while (result < 10) { |
| 67 | result += 3.12 + b; // result + 3.12 should be 'noContraction'. |
| 68 | } |
qining | 5bec2b5 | 2016-05-06 21:52:28 -0400 | [diff] [blame] | 69 | result = a + b + 5; // b + 5 should not be 'noCtraction' because all operands are integers. |
qining | 9220dbb | 2016-05-04 17:34:38 -0400 | [diff] [blame] | 70 | result = 11.1; |
| 71 | } |
| 72 | |
| 73 | float fma_not_decorated() { |
| 74 | precise float result; |
| 75 | float a = 1.0; |
| 76 | float b = 2.0; |
| 77 | float c = 3.0; |
| 78 | b = b + c; // b + c should be decorated with 'noContraction' |
| 79 | result = fma(a, b, c); // fma() should not be decorated with 'noContradtion' |
| 80 | return result; |
| 81 | } |
| 82 | |
| 83 | precise float precise_return_exp_func() { |
| 84 | float a = 1.0; |
| 85 | float b = 2.0; |
| 86 | return a + b; // the ADD operation should be 'noContraction' |
| 87 | } |
| 88 | |
| 89 | precise float precise_return_val_func() { |
| 90 | float a = 1.0; |
| 91 | float b = 2.0; |
| 92 | float result = a + b; // the ADD operation should be 'noContraction' |
| 93 | return result; |
| 94 | } |
| 95 | |
| 96 | float precise_func_parameter(float b, precise out float c) { |
| 97 | float a = 0.5; |
| 98 | c = a + b; // noContration |
| 99 | return a - b; // Not noContraction |
| 100 | } |
| 101 | |
qining | 0c96db5 | 2016-05-06 18:56:33 -0400 | [diff] [blame] | 102 | mat3 matrix (mat2x3 a, mat3x2 b) { |
| 103 | mat2x3 c = mat2x3(1.0, 2.0, 3.0, 4.0, 5.0, 6.0); |
| 104 | precise mat3 result; |
| 105 | result = (a + c) * b; // should be noContraction |
| 106 | return result; |
| 107 | } |
| 108 | |
qining | 9220dbb | 2016-05-04 17:34:38 -0400 | [diff] [blame] | 109 | void main(){} |