2021-03-16 14:40:11 +00:00
|
|
|
#include <metal_stdlib>
|
|
|
|
#include <simd/simd.h>
|
|
|
|
using namespace metal;
|
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
|
|
|
struct Uniforms {
|
2021-02-05 21:24:03 +00:00
|
|
|
float4 colorRed;
|
|
|
|
float4 colorGreen;
|
|
|
|
float4 testInputs;
|
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-25 17:35:58 +00:00
|
|
|
struct Inputs {
|
|
|
|
};
|
|
|
|
struct Outputs {
|
|
|
|
float4 sk_FragColor [[color(0)]];
|
|
|
|
};
|
2021-03-22 15:57:41 +00:00
|
|
|
float fn_hh4(float4 v) {
|
2021-02-05 21:24:03 +00:00
|
|
|
for (int x = 1;x <= 2; ++x) {
|
|
|
|
return v.x;
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
|
2021-01-19 18:07:55 +00:00
|
|
|
Outputs _out;
|
2021-01-22 03:24:28 +00:00
|
|
|
(void)_out;
|
2021-02-05 21:24:03 +00:00
|
|
|
float4 v = _uniforms.testInputs;
|
2021-03-04 15:19:48 +00:00
|
|
|
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 = float4(v.xx, 1.0, 1.0);
|
|
|
|
v = v.wzwz;
|
2021-03-22 15:57:41 +00:00
|
|
|
v = float3(fn_hh4(v), 123.0, 456.0).yyzz;
|
|
|
|
v = float3(fn_hh4(v), 123.0, 456.0).yyzz;
|
|
|
|
v = float4(123.0, 456.0, 456.0, fn_hh4(v));
|
|
|
|
v = float4(123.0, 456.0, 456.0, fn_hh4(v));
|
|
|
|
v = float3(fn_hh4(v), 123.0, 456.0).yxxz;
|
|
|
|
v = float3(fn_hh4(v), 123.0, 456.0).yxxz;
|
2021-03-04 15:19:48 +00:00
|
|
|
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);
|
2021-02-05 21:24:03 +00:00
|
|
|
v.wzyx = v;
|
2021-02-19 19:09:38 +00:00
|
|
|
v.xw = v.yz;
|
2021-03-05 18:13:14 +00:00
|
|
|
v.zyx = float3(v.ww, 1.0);
|
2021-02-05 21:24:03 +00:00
|
|
|
_out.sk_FragColor = all(v == float4(1.0)) ? _uniforms.colorGreen : _uniforms.colorRed;
|
2021-01-19 18:07:55 +00:00
|
|
|
return _out;
|
2020-09-25 17:35:58 +00:00
|
|
|
}
|