1/*#pragma settings SkVMDebugTrace*/ 2 3uniform half4 colorRed, colorGreen; 4 5// Should return 5 6const float kZero = 0; 7float return_loop(float five) { 8 for (float i = kZero; i < 10; ++i) { 9 if (i == five) { return i; } 10 } 11 return 0; 12} 13 14// Should return 35 15const float kTen = kZero + 10; 16float continue_loop(float five) { 17 float sum = 0; 18 for (float i = 0; i < kTen; ++i) { 19 if (i < five) { continue; } 20 sum += i; 21 } 22 return sum; 23} 24 25// Should return 15 26float break_loop(float five) { 27 float sum = 0; 28 const float kOne = 1; 29 for (float i = 0; i < 10; i += kOne) { 30 if (i > five) { break; } 31 sum += i; 32 } 33 return sum; 34} 35 36// Should return a value close to zero 37float float_loop() { 38 float sum = 0; 39 for (float i = 0.123; i < 0.6; i += 0.111) { 40 sum += i; 41 } 42 return sum - 1.725; 43} 44 45bool loop_operator_le() { 46 // These loops are inside-out and execute zero times. 47 for (float i = 3; i <= 1; ++i) { return false; } 48 for (float i = 3; i <= 1; --i) { return false; } 49 50 float4 result = float4(9); 51 for (float i = 1; i <= 3; ++i) { 52 result = float4(result.yzw, i); 53 } 54 return result == float4(9, 1, 2, 3); 55} 56 57bool loop_operator_lt() { 58 // These loops are inside-out and execute zero times. 59 for (float i = 4; i < 1; ++i) { return false; } 60 for (float i = 4; i < 1; --i) { return false; } 61 62 float4 result = float4(9); 63 for (float i = 1; i < 4; ++i) { 64 result = float4(result.yzw, i); 65 } 66 return result == float4(9, 1, 2, 3); 67} 68 69bool loop_operator_ge() { 70 // These loops are inside-out and execute zero times. 71 for (float i = 1; i >= 3; ++i) { return false; } 72 for (float i = 1; i >= 3; --i) { return false; } 73 74 float4 result = float4(9); 75 for (float i = 3; i >= 1; --i) { 76 result = float4(result.yzw, i); 77 } 78 return result == float4(9, 3, 2, 1); 79} 80 81bool loop_operator_gt() { 82 // These loops are inside-out and execute zero times. 83 for (float i = 0; i > 3; ++i) { return false; } 84 for (float i = 0; i > 3; --i) { return false; } 85 86 float4 result = float4(9); 87 for (float i = 3; i > 0; --i) { 88 result = float4(result.yzw, i); 89 } 90 return result == float4(9, 3, 2, 1); 91} 92 93bool loop_operator_ne() { 94 // This loop executes zero times. 95 for (int i = 1; i != 1; ++i) { return false; } 96 97 float4 result = float4(9); 98 for (float i = 1; i != 4; ++i) { 99 result = float4(result.yzw, i); 100 } 101 return result == float4(9, 1, 2, 3); 102} 103 104bool loop_operator_eq() { 105 // This loops mismatches and executes zero times. 106 for (float i = 1; i == 2; ++i) { return false; } 107 108 float4 result = float4(9); 109 for (float i = 1; i == 1; ++i) { 110 result = float4(result.yzw, i); 111 } 112 return result == float4(9, 9, 9, 1); 113} 114 115half4 main(float2 pos) { 116 float five = clamp(pos.x, colorGreen.g, colorGreen.a) * 5.0; 117 return (return_loop(five) == 5 && continue_loop(five) == 35 && 118 break_loop(five) == 15 && abs(float_loop()) < 0.025 && 119 loop_operator_le() && loop_operator_lt() && 120 loop_operator_ge() && loop_operator_gt() && 121 loop_operator_eq() && loop_operator_ne()) ? colorGreen : colorRed; 122} 123