skia2/tests/sksl/shared/SwizzleOpt.metal
John Stiles c2c1b0c460 Migrate some SkSL swizzle tests to dm.
Change-Id: I2bd6bf9c368359a2b21861c1b6f621040d335111
Bug: skia:11009
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/367056
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
2021-02-08 16:16:28 +00:00

50 lines
1.3 KiB
Metal

#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct Uniforms {
float4 colorRed;
float4 colorGreen;
float4 testInputs;
};
struct Inputs {
};
struct Outputs {
float4 sk_FragColor [[color(0)]];
};
float fn(float4 v) {
for (int x = 1;x <= 2; ++x) {
return v.x;
}
}
fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
Outputs _out;
(void)_out;
float4 v = _uniforms.testInputs;
v = v;
v = float4(0.0, v.zyx);
v = float4(0.0, 0.0, v.xw);
v = float4(1.0, 1.0, v.wx);
v = float4(v.zy, 1.0, 1.0);
v = v;
v = float4(v.xx, 1.0, 1.0);
v = v.wzwz;
v = float3(fn(v), 123.0, 456.0).yyzz;
v = float3(fn(v), 123.0, 456.0).yyzz;
v = float4(123.0, 456.0, 456.0, fn(v));
v = float4(123.0, 456.0, 456.0, fn(v));
v = float3(fn(v), 123.0, 456.0).yxxz;
v = float3(fn(v), 123.0, 456.0).yxxz;
v = float4(1.0, 1.0, 2.0, 3.0);
v = float4(_uniforms.colorRed.xyz, 1.0);
v = float4(_uniforms.colorRed.x, 1.0, _uniforms.colorRed.yz);
v.xyzw = v;
v.wzyx = v;
v.xyzw.xw = v.yz;
v.wzyx.yzw = float3(v.ww, 1.0);
_out.sk_FragColor = all(v == float4(1.0)) ? _uniforms.colorGreen : _uniforms.colorRed;
return _out;
}