skia2/tests/sksl/shared/ShortCircuitBoolFolding.sksl
John Stiles ab4ab20fcf Migrate most SkSL tests currently in /glsl/ to /shared/.
These tests will also be used for Metal and SPIR-V testing. A small
handful of GLSL-specific stragglers (#version-specific or type-precision
related) will remain in /glsl/.

Change-Id: I7f2b2bd92825c327922c8ce74e438d2daa440dff
Bug: skia:10649
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/319408
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
2020-09-25 17:13:53 +00:00

38 lines
1.3 KiB
Plaintext

void main() {
bool expr1 = sk_FragCoord.x > 0;
bool expr2 = sk_FragCoord.y > 0;
if (true && expr1) { // -> if (expr1)
sk_FragColor.r = 1;
} else if (false && expr1) { // -> if (false) -> block removed
sk_FragColor.r = -2;
} else if (true ^^ expr1) { // -> if (!expr1)
sk_FragColor.r = 3;
} else if (false ^^ expr2) { // -> if (expr2)
sk_FragColor.r = 4;
} else if (false || expr2) { // -> if (expr2)
sk_FragColor.r = 5;
} else if (true || expr2) { // -> if (true) -> replaces unreachable else
sk_FragColor.r = 6;
} else { // removed
sk_FragColor.r = -7;
}
// Test short-circuiting of right hand side boolean literals
if (expr1 && true) { // -> if (expr1)
sk_FragColor.r = 1;
} else if (expr1 && false) { // -> if (false) -> block removed
sk_FragColor.r = -2;
} else if (expr1 ^^ true) { // -> if (!expr1)
sk_FragColor.r = 3;
} else if (expr2 ^^ false) { // -> if (expr2)
sk_FragColor.r = 4;
} else if (expr2 || false) { // -> if (expr2)
sk_FragColor.r = 5;
} else if (expr2 || true) { // -> if (true) -> replaces unreachable else
sk_FragColor.r = 6;
} else { // removed
sk_FragColor.r = -7;
}
}