642cde289d
At IR generation time, this CL limits our optimizations to only @switch statements. A regular switch statement will only be optimized during the optimization phase even if the switch-value is a known compile-time constant. This is done to avoid upsetting our reachability analysis. Most of this CL is moving existing logic from SkSLCompiler into SkSLAnalysis and SkSLSwitchStatement. Although the diffs look large, the actual changes are very small. Change-Id: I90920f41bc386dfa7a980ae7510f6681231a5120 Bug: skia:11340, skia:11342, skia:11319 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/372679 Commit-Queue: John Stiles <johnstiles@google.com> Auto-Submit: John Stiles <johnstiles@google.com> Reviewed-by: Brian Osman <brianosman@google.com>
49 lines
1.8 KiB
Plaintext
49 lines
1.8 KiB
Plaintext
// Declare a user enum.
|
|
enum class E {
|
|
kZero = 0,
|
|
kOne = 1,
|
|
kTwo = 2,
|
|
kThree = 3
|
|
};
|
|
|
|
void main() {
|
|
// Test that the user enum is subject to the same optimizations as a plain int.
|
|
E e = E::kZero;
|
|
if (e == E::kZero) { sk_FragColor = half4(1); }
|
|
@if (e == E::kZero) { sk_FragColor = half4(2); }
|
|
@if (e != E::kZero) { sk_FragColor = half4(3); }
|
|
if (e == E::kOne) { sk_FragColor = half4(4); }
|
|
@if (e == E::kOne) { sk_FragColor = half4(5); }
|
|
@if (e != E::kOne) { sk_FragColor = half4(6); }
|
|
|
|
sk_FragColor = (e == E::kZero) ? half4(7) : half4(-7);
|
|
sk_FragColor = (e != E::kZero) ? half4(8) : half4(-8);
|
|
sk_FragColor = (e == E::kOne) ? half4(9) : half4(-9);
|
|
sk_FragColor = (e != E::kOne) ? half4(10) : half4(-10);
|
|
|
|
switch (e) {
|
|
case E::kZero: sk_FragColor = half4(11); break;
|
|
case E::kOne: sk_FragColor = half4(12); break;
|
|
}
|
|
@switch (E::kZero) {
|
|
case E::kZero: sk_FragColor = half4(13); break;
|
|
case E::kOne: sk_FragColor = half4(14); break;
|
|
}
|
|
|
|
// Test that built-in enums work equally well.
|
|
SkBlendMode m = SkBlendMode::kClear;
|
|
if (m == SkBlendMode::kClear) { sk_FragColor = half4(15); }
|
|
@if (m == SkBlendMode::kClear) { sk_FragColor = half4(16); }
|
|
if (m == SkBlendMode::kSrc) { sk_FragColor = half4(17); }
|
|
@if (m != SkBlendMode::kDst) { sk_FragColor = half4(18); }
|
|
|
|
sk_FragColor = (m == SkBlendMode::kClear) ? half4(19) : half4(-19);
|
|
sk_FragColor = (m != SkBlendMode::kSrc) ? half4(20) : half4(-20);
|
|
|
|
@switch (SkBlendMode::kClear) {
|
|
case SkBlendMode::kClear: sk_FragColor = half4(21); break;
|
|
case SkBlendMode::kSrc: sk_FragColor = half4(22); break;
|
|
case SkBlendMode::kDst: sk_FragColor = half4(23); break;
|
|
}
|
|
}
|