skia2/tests/sksl/shared/golden/SwizzleOpt.metal
John Stiles 3d921f1b2c Add unit test to demonstrate lack of SkSL swizzle optimization.
The right side of assignments will collapse redundant swizzles, but the
left side does not. Code like this can actually cause the ByteCode-
Generator to assert if it is run (it asserts in `swizzle_is_simple`
during code generation).

Change-Id: I891912fe0b5de2670dfa95f6702a86d5c42bb2ec
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/320296
Commit-Queue: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2020-09-28 19:02:03 +00:00

27 lines
1.0 KiB
Metal

#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct Inputs {
};
struct Outputs {
float4 sk_FragColor [[color(0)]];
};
fragment Outputs fragmentMain(Inputs _in [[stage_in]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
Outputs _outputStruct;
thread Outputs* _out = &_outputStruct;
float v = sqrt(1.0);
_out->sk_FragColor = float4(v);
_out->sk_FragColor = float4(float4(v).xyz, 0.0).wzyx;
_out->sk_FragColor = float3(float4(v).xw, 0.0).zzxy;
_out->sk_FragColor = float3(float3(float4(v).xw, 0.0).yx, 1.0).zzxy;
_out->sk_FragColor = float3(float4(v).zy, 1.0).xyzz;
_out->sk_FragColor = float4(v);
_out->sk_FragColor = float4(float4(v).xx, 1.0, 1.0);
_out->sk_FragColor = float4(v).wzwz;
_out->sk_FragColor.xyzw = _out->sk_FragColor;
_out->sk_FragColor.wzyx = _out->sk_FragColor;
_out->sk_FragColor.xyzw.xw = _out->sk_FragColor.yz;
_out->sk_FragColor.wzyx.yzw = float3(_out->sk_FragColor.ww, 1.0);
return *_out;
}