Optimize swizzled multiple-argument constructors.
This will reorder constructors with swizzles applied, such as
`half4(1, 2, 3, 4).xxyz` --> `half4(1, 1, 2, 3)`
`half4(1, colRGB).yzwx` --> `half4(colRGB.x, colRGB.y, colRGB.z, 1)`
Note that, depending on the swizzle components, some elements of the
constructor may be duplicated and others may be eliminated. The
optimizer makes sure to leave the swizzle alone if it would duplicate
anything non-trivial, or if it would eliminate anything with a side
effect.
Change-Id: I470fda217ae8cf5828406b89a5696ca6aebf608d
Bug: skia:10954
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/335860
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2020-11-19 16:06:47 +00:00
|
|
|
half fn(half v) {
|
|
|
|
// Add an un-inlinable construct to ensure that fn() remains a standalone function.
|
|
|
|
switch (int(v)) {
|
|
|
|
case 1: return 2;
|
|
|
|
default: return 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
layout(set=0) uniform half3 colRGB;
|
|
|
|
|
2020-09-16 17:40:35 +00:00
|
|
|
void main() {
|
|
|
|
half v = half(sqrt(1));
|
Optimize swizzled multiple-argument constructors.
This will reorder constructors with swizzles applied, such as
`half4(1, 2, 3, 4).xxyz` --> `half4(1, 1, 2, 3)`
`half4(1, colRGB).yzwx` --> `half4(colRGB.x, colRGB.y, colRGB.z, 1)`
Note that, depending on the swizzle components, some elements of the
constructor may be duplicated and others may be eliminated. The
optimizer makes sure to leave the swizzle alone if it would duplicate
anything non-trivial, or if it would eliminate anything with a side
effect.
Change-Id: I470fda217ae8cf5828406b89a5696ca6aebf608d
Bug: skia:10954
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/335860
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2020-11-19 16:06:47 +00:00
|
|
|
|
2020-09-16 17:40:35 +00:00
|
|
|
sk_FragColor = half4(v).rgba;
|
|
|
|
sk_FragColor = half4(v).rgb0.abgr;
|
|
|
|
sk_FragColor = half4(v).rgba.00ra;
|
|
|
|
sk_FragColor = half4(v).rgba.rrra.00ra.11ab;
|
|
|
|
sk_FragColor = half4(v).abga.gb11;
|
|
|
|
sk_FragColor = half4(v).abgr.abgr;
|
|
|
|
sk_FragColor = half4(half4(v).rrrr.bb, 1, 1);
|
|
|
|
sk_FragColor = half4(half4(v).ba.grgr);
|
2020-09-28 18:03:25 +00:00
|
|
|
|
Optimize swizzled multiple-argument constructors.
This will reorder constructors with swizzles applied, such as
`half4(1, 2, 3, 4).xxyz` --> `half4(1, 1, 2, 3)`
`half4(1, colRGB).yzwx` --> `half4(colRGB.x, colRGB.y, colRGB.z, 1)`
Note that, depending on the swizzle components, some elements of the
constructor may be duplicated and others may be eliminated. The
optimizer makes sure to leave the swizzle alone if it would duplicate
anything non-trivial, or if it would eliminate anything with a side
effect.
Change-Id: I470fda217ae8cf5828406b89a5696ca6aebf608d
Bug: skia:10954
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/335860
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2020-11-19 16:06:47 +00:00
|
|
|
// The swizzle will not be optimized away to avoid eliminating fn().
|
|
|
|
sk_FragColor = half3(fn(v), 123, 456).yyzz;
|
|
|
|
sk_FragColor = half3(fn(v), half2(123, 456)).yyzz;
|
|
|
|
|
|
|
|
// The swizzle will be optimized away because fn() can be reordered.
|
|
|
|
sk_FragColor = half3(fn(v), 123, 456).yzzx;
|
|
|
|
sk_FragColor = half3(fn(v), half2(123, 456)).yzzx;
|
|
|
|
|
|
|
|
// The swizzle will not be optimized away to avoid duplicating fn().
|
|
|
|
sk_FragColor = half3(fn(v), 123, 456).yxxz;
|
|
|
|
sk_FragColor = half3(fn(v), half2(123, 456)).yxxz;
|
|
|
|
|
|
|
|
// Swizzled constants.
|
|
|
|
sk_FragColor = half4(1, 2, 3, 4).xxyz;
|
|
|
|
|
|
|
|
// Swizzled uniforms mixed with constants.
|
|
|
|
sk_FragColor = half4(1, colRGB).yzwx;
|
|
|
|
sk_FragColor = half4(1, colRGB).yxzw;
|
|
|
|
|
2020-09-28 18:03:25 +00:00
|
|
|
sk_FragColor.rgba = sk_FragColor;
|
|
|
|
sk_FragColor.abgr = sk_FragColor;
|
|
|
|
sk_FragColor.rgba.ra = sk_FragColor.gb;
|
|
|
|
sk_FragColor.abgr.gba = sk_FragColor.aa1;
|
2020-09-16 17:40:35 +00:00
|
|
|
}
|