skia2/tests/sksl/shared/golden/SwizzleOpt.glsl
John Stiles f5c1d04ab2 Flatten out constructors nested inside constructors.
- float4(float2(1, 2), 3, 4)   -->  float4(1, 2, 3, 4)
- half3(z, half2(fn(x), y*2))  -->  half3(z, fn(x), y*2)

Single-argument constructors will be ignored by this optimization; these
might be casts or splats.

This had an unexpected side benefit of simplifying some Metal output,
as we need to output fewer Metal matrix construction helper functions
when matrices use more simple scalars for construction.

Change-Id: I0a161db060c107e35247901619291bf83801cb11
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/337400
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2020-11-23 21:29:53 +00:00

36 lines
1.1 KiB
GLSL

out vec4 sk_FragColor;
float fn(float v) {
switch (int(v)) {
case 1:
return 2.0;
default:
return 3.0;
}
}
layout (set = 0) uniform vec3 colRGB;
void main() {
float v = sqrt(1.0);
sk_FragColor = vec4(v);
sk_FragColor = vec4(0.0, vec3(v));
sk_FragColor = vec4(0.0, 0.0, vec2(v));
sk_FragColor = vec4(1.0, 1.0, vec2(v));
sk_FragColor = vec4(vec2(v), 1.0, 1.0);
sk_FragColor = vec4(v);
sk_FragColor = vec4(vec2(v), 1.0, 1.0);
sk_FragColor = vec4(v);
sk_FragColor = vec3(fn(v), 123.0, 456.0).yyzz;
sk_FragColor = vec3(fn(v), 123.0, 456.0).yyzz;
sk_FragColor = vec4(123.0, 456.0, 456.0, fn(v));
sk_FragColor = vec4(123.0, 456.0, 456.0, fn(v));
sk_FragColor = vec3(fn(v), 123.0, 456.0).yxxz;
sk_FragColor = vec3(fn(v), 123.0, 456.0).yxxz;
sk_FragColor = vec4(1.0, 1.0, 2.0, 3.0);
sk_FragColor = vec4(colRGB, 1.0);
sk_FragColor = vec4(colRGB.x, 1.0, colRGB.yz);
sk_FragColor.xyzw = sk_FragColor;
sk_FragColor.wzyx = sk_FragColor;
sk_FragColor.xyzw.xw = sk_FragColor.yz;
sk_FragColor.wzyx.yzw = vec3(sk_FragColor.ww, 1.0);
}