b41d5bb3a7
This lets us use descriptive names like `colorRed` and `colorGreen` instead of `half4(1,0,0,1)` and `half4(0,1,0,1)`. It also lets us use actual unknown values instead of synthesizing sorta-kinda-unknowns by calling sqrt. Change-Id: I61481c33b7ff42182955777b05cfa5fcc13e0efc Reviewed-on: https://skia-review.googlesource.com/c/skia/+/359567 Reviewed-by: Ethan Nicholas <ethannicholas@google.com> Commit-Queue: John Stiles <johnstiles@google.com> Auto-Submit: John Stiles <johnstiles@google.com>
48 lines
2.0 KiB
Plaintext
48 lines
2.0 KiB
Plaintext
uniform half4 colorRed, colorGreen;
|
|
uniform half unknownInput;
|
|
|
|
bool test() {
|
|
bool expr = unknownInput > 0;
|
|
|
|
int ok = 0, bad = 0;
|
|
|
|
// 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)
|
|
|
|
// Test that side-effects in the left-side expression prevent right-side expr elimination.
|
|
float a = sqrt(1), b = sqrt(2);
|
|
|
|
true || bool(a = b); // -> true
|
|
if (a == b) { ++bad; } else { ++ok; }
|
|
|
|
bool(a = b) || true; // -> unchanged
|
|
if (a == b) { ++ok; } else { ++bad; }
|
|
|
|
return ok == 22 && bad == 0;
|
|
}
|
|
|
|
half4 main() {
|
|
return test() ? colorGreen : colorRed;
|
|
}
|