skia2/tests/sksl/intrinsics/RoundEven.metal
John Stiles 368166262a Add trunc/round/roundEven SKSL ES3 public APIs.
Improved tests caught a longstanding bug in the compile-time
optimization logic for round/roundEven. These would *always* round to an
even number even when it didn't make sense to do so. (e.g. 3.1 would
round to 4.)

RoundEven isn't available in lower shader models of Direct3D;
SPIRV-Cross throws if it's unavailable. We may need a caps bit for this.

Change-Id: I3cc50238a2116b8d4e2c4059730d8b5cfb2bb056
Bug: skia:12022, skia:12352
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/441078
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
2021-08-23 15:44:15 +00:00

21 lines
797 B
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 expectedA = float4(-1.0, 0.0, 1.0, 2.0);
_out.sk_FragColor = ((rint(_uniforms.testInputs.x) == -1.0 && all(rint(_uniforms.testInputs.xy) == float2(-1.0, 0.0))) && all(rint(_uniforms.testInputs.xyz) == float3(-1.0, 0.0, 1.0))) && all(rint(_uniforms.testInputs) == expectedA) ? _uniforms.colorGreen : _uniforms.colorRed;
return _out;
}