skia2/resources/sksl/folding/SwizzleFolding.sksl
John Stiles fb7d378a1a Add test demonstrating swizzled constant folding.
At present, this is a missed optimization opportunity. These will be
optimized in a followup CL.

Change-Id: I8882058900cdc12c8ab0df03e36ebfb9d8022f01
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/402580
Commit-Queue: John Stiles <johnstiles@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
2021-04-29 15:59:37 +00:00

30 lines
988 B
Plaintext

uniform half4 colorRed, colorGreen;
bool test() {
const half4 colorWhite = half4(1);
const half2 point = half2(40, 60);
bool ok = true;
// Comparisons on swizzled constants should fold
ok = ok && (point.x >= 0 && point.x <= 100 && point.y >= 0 && point.y <= 100);
// Arithmetic on swizzled constants should fold
ok = ok && (colorWhite.x == 1);
ok = ok && (colorWhite.x + colorWhite.y == 2);
ok = ok && (colorWhite.x + colorWhite.y + colorWhite.z == 3);
ok = ok && (colorWhite.x + colorWhite.y + colorWhite.z + colorWhite.w == 4);
// No-op arithmetic using swizzled constants should fold away
ok = ok && ((colorGreen * colorWhite.x) != (colorRed * colorWhite.y));
// Folding on swizzles with more than one component should be optimized.
const half2 pointOffset = point.yx + colorWhite.xz;
ok = ok && (pointOffset == half2(61, 41));
return ok;
}
half4 main(float2 coords) {
return test() ? colorGreen : colorRed;
}