3c2997cacc
We will continue to fold expressions like `10 + 0` or `5 * 1` or `PI * 1` (assuming PI is a const float) because both sides are known, but non-constant-expressions like `x + 0` (assuming x is not a constant) or `foo *= 1` will be left as-is when the optimizer is off. This improves the accuracy of the Viewer shader tab, because a runtime effect expression like `color *= scale` will be preserved in the final output when optimization is off, instead of being replaced with a Nop when scale equals one. Change-Id: I218b327cb0cd12654dca446dee8a5baa96f589b8 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/539197 Commit-Queue: John Stiles <johnstiles@google.com> Auto-Submit: John Stiles <johnstiles@google.com> Reviewed-by: Brian Osman <brianosman@google.com>
66 lines
1.4 KiB
GLSL
66 lines
1.4 KiB
GLSL
|
|
out vec4 sk_FragColor;
|
|
uniform vec4 colorGreen;
|
|
uniform vec4 colorRed;
|
|
bool flatten_compound_constructor_b() {
|
|
ivec4 x = ivec4(ivec3(ivec2(1, 2), 3), 4);
|
|
ivec4 y = ivec4(1, ivec3(2, ivec2(3, 4)));
|
|
return x == y;
|
|
}
|
|
bool flatten_known_if_b() {
|
|
int value;
|
|
if (true) {
|
|
value = 1;
|
|
} else {
|
|
value = 2;
|
|
}
|
|
return value == 1;
|
|
}
|
|
bool eliminate_empty_if_else_b() {
|
|
bool check = false;
|
|
if (check = !check) {
|
|
} else {
|
|
}
|
|
return check;
|
|
}
|
|
bool eliminate_empty_else_b() {
|
|
bool check = true;
|
|
if (check) {
|
|
return true;
|
|
} else {
|
|
}
|
|
return false;
|
|
}
|
|
bool flatten_matching_ternary_b() {
|
|
bool check = true;
|
|
return check ? true : true;
|
|
}
|
|
bool flatten_expr_without_side_effects_b() {
|
|
bool check = true;
|
|
check;
|
|
return check;
|
|
}
|
|
bool eliminate_no_op_arithmetic_b() {
|
|
const int ONE = 1;
|
|
int a1[1];
|
|
int a2[1];
|
|
int x = ONE;
|
|
x = x + 0;
|
|
x *= 1;
|
|
return x == 1;
|
|
}
|
|
bool flatten_switch_b() {
|
|
switch (1) {
|
|
case 0:
|
|
return false;
|
|
case 1:
|
|
return true;
|
|
case 2:
|
|
return false;
|
|
}
|
|
return false;
|
|
}
|
|
vec4 main() {
|
|
return ((((((flatten_compound_constructor_b() && flatten_known_if_b()) && eliminate_empty_if_else_b()) && eliminate_empty_else_b()) && flatten_matching_ternary_b()) && flatten_expr_without_side_effects_b()) && eliminate_no_op_arithmetic_b()) && flatten_switch_b() ? colorGreen : colorRed;
|
|
}
|