2021-01-26 21:28:12 +00:00
|
|
|
uniform half4 colorRed, colorGreen;
|
|
|
|
uniform half unknownInput;
|
|
|
|
|
2021-01-20 17:05:03 +00:00
|
|
|
bool test() {
|
2021-01-26 21:28:12 +00:00
|
|
|
bool expr = unknownInput > 0;
|
2020-09-14 21:30:13 +00:00
|
|
|
|
2021-01-20 17:05:03 +00:00
|
|
|
int ok = 0, bad = 0;
|
2020-09-14 21:30:13 +00:00
|
|
|
|
2021-01-20 17:05:03 +00:00
|
|
|
// Test boolean short-circuiting with constants on the left side.
|
|
|
|
if (true && expr) { ++ok; } else { ++bad; } // -> (expr)
|
|
|
|
if (false && expr) { ++bad; } else { ++ok; } // -> (false) -> block removed
|
|
|
|
if (true ^^ expr) { ++bad; } else { ++ok; } // -> unchanged
|
|
|
|
if (false ^^ expr) { ++ok; } else { ++bad; } // -> (expr)
|
|
|
|
if (true || expr) { ++ok; } else { ++bad; } // -> (true)
|
|
|
|
if (false || expr) { ++ok; } else { ++bad; } // -> (expr)
|
|
|
|
if (true == expr) { ++ok; } else { ++bad; } // -> (expr)
|
|
|
|
if (false == expr) { ++bad; } else { ++ok; } // -> unchanged
|
|
|
|
if (true != expr) { ++bad; } else { ++ok; } // -> unchanged
|
|
|
|
if (false != expr) { ++ok; } else { ++bad; } // -> (expr)
|
|
|
|
|
|
|
|
// Test boolean short-circuiting with constants on the right side.
|
|
|
|
if (expr && true ) { ++ok; } else { ++bad; } // -> (expr)
|
|
|
|
if (expr && false) { ++bad; } else { ++ok; } // -> (false) -> block removed
|
|
|
|
if (expr ^^ true ) { ++bad; } else { ++ok; } // -> unchanged
|
|
|
|
if (expr ^^ false) { ++ok; } else { ++bad; } // -> (expr)
|
|
|
|
if (expr || true ) { ++ok; } else { ++bad; } // -> (true)
|
|
|
|
if (expr || false) { ++ok; } else { ++bad; } // -> (expr)
|
|
|
|
if (expr == true ) { ++ok; } else { ++bad; } // -> (expr)
|
|
|
|
if (expr == false) { ++bad; } else { ++ok; } // -> unchanged
|
|
|
|
if (expr != true ) { ++bad; } else { ++ok; } // -> unchanged
|
|
|
|
if (expr != false) { ++ok; } else { ++bad; } // -> (expr)
|
|
|
|
|
2021-01-20 19:32:33 +00:00
|
|
|
// Test that side-effects in the left-side expression prevent right-side expr elimination.
|
2021-05-24 14:52:23 +00:00
|
|
|
float a = unknownInput + 2, b = unknownInput * 2;
|
2021-01-20 19:32:33 +00:00
|
|
|
|
2021-01-22 14:50:04 +00:00
|
|
|
true || bool(a = b); // -> true
|
2021-01-20 19:32:33 +00:00
|
|
|
if (a == b) { ++bad; } else { ++ok; }
|
|
|
|
|
2021-01-22 14:50:04 +00:00
|
|
|
bool(a = b) || true; // -> unchanged
|
2021-01-20 19:32:33 +00:00
|
|
|
if (a == b) { ++ok; } else { ++bad; }
|
|
|
|
|
|
|
|
return ok == 22 && bad == 0;
|
2021-01-20 17:05:03 +00:00
|
|
|
}
|
|
|
|
|
2021-04-21 18:27:08 +00:00
|
|
|
half4 main(float2 coords) {
|
2021-01-26 21:28:12 +00:00
|
|
|
return test() ? colorGreen : colorRed;
|
2020-09-14 21:30:13 +00:00
|
|
|
}
|