skia2/tests/sksl/shared/SwizzleOpt.sksl

47 lines
1.5 KiB
Plaintext
Raw Normal View History

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;
void main() {
half v = half(sqrt(1));
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);
// 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;
sk_FragColor.rgba = sk_FragColor;
sk_FragColor.abgr = sk_FragColor;
sk_FragColor.rgba.ra = sk_FragColor.gb;
sk_FragColor.abgr.gba = sk_FragColor.aa1;
}