skia2/tests/sksl/intrinsics/Step.metal
John Stiles 017ffd7e05 Implement compile-time optimization for step().
$genType step($genType edge, $genType x);
$genType step(float edge, $genType x);
$genHType step($genHType edge, $genHType x);
$genHType step(half edge, $genHType x);

Change-Id: If52634d7a247772e922cb3fd2e3e8a7c36c275f6
Bug: skia:12034
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/411842
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
2021-05-25 16:59:22 +00:00

23 lines
1.5 KiB
Metal

#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct Uniforms {
float4 testInputs;
float4 colorGreen;
float4 colorRed;
};
struct Inputs {
};
struct Outputs {
float4 sk_FragColor [[color(0)]];
};
fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
Outputs _out;
(void)_out;
const float4 constGreen = float4(0.0, 1.0, 0.0, 1.0);
float4 expectedA = float4(0.0, 0.0, 1.0, 1.0);
float4 expectedB = float4(1.0, 1.0, 0.0, 0.0);
_out.sk_FragColor = ((((((((((((((step(0.5, _uniforms.testInputs.x) == expectedA.x && all(step(0.5, _uniforms.testInputs.xy) == expectedA.xy)) && all(step(0.5, _uniforms.testInputs.xyz) == expectedA.xyz)) && all(step(0.5, _uniforms.testInputs) == expectedA)) && 0.0 == expectedA.x) && all(float2(0.0, 0.0) == expectedA.xy)) && all(float3(0.0, 0.0, 1.0) == expectedA.xyz)) && all(float4(0.0, 0.0, 1.0, 1.0) == expectedA)) && step(_uniforms.testInputs.x, 0.0) == expectedB.x) && all(step(_uniforms.testInputs.xy, float2(0.0, 1.0)) == expectedB.xy)) && all(step(_uniforms.testInputs.xyz, float3(0.0, 1.0, 0.0)) == expectedB.xyz)) && all(step(_uniforms.testInputs, constGreen) == expectedB)) && 1.0 == expectedB.x) && all(float2(1.0, 1.0) == expectedB.xy)) && all(float3(1.0, 1.0, 0.0) == expectedB.xyz)) && all(float4(1.0, 1.0, 0.0, 0.0) == expectedB) ? _uniforms.colorGreen : _uniforms.colorRed;
return _out;
}