Implement roundEven intrinsic in Metal (as rint).

Change-Id: Ieb7698d357c9be05ca1f17de84215add54553f84
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/349065
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
John Stiles 2020-12-30 18:12:48 -05:00 committed by Skia Commit-Bot
parent dc435fa60d
commit 2345653898
3 changed files with 9 additions and 2 deletions

View File

@ -68,6 +68,7 @@ void MetalCodeGenerator::setupIntrinsics() {
fIntrinsicMap[String("radians")] = kRadians_IntrinsicKind;
fIntrinsicMap[String("reflect")] = kReflect_IntrinsicKind;
fIntrinsicMap[String("refract")] = kRefract_IntrinsicKind;
fIntrinsicMap[String("roundEven")] = kRoundEven_IntrinsicKind;
fIntrinsicMap[String("sample")] = kTexture_IntrinsicKind;
}
@ -722,6 +723,11 @@ void MetalCodeGenerator::writeIntrinsicCall(const FunctionCall& c, IntrinsicKind
}
break;
}
case kRoundEven_IntrinsicKind: {
this->write("rint");
this->writeArgumentList(c.arguments());
break;
}
case kBitCount_IntrinsicKind: {
this->write("popcount(");
this->writeExpression(*arguments[0], kSequence_Precedence);

View File

@ -80,7 +80,7 @@ public:
MetalCodeGenerator(const Context* context, const Program* program, ErrorReporter* errors,
OutputStream* out)
: INHERITED(program, errors, out)
, fReservedWords({"atan2", "rsqrt", "dfdx", "dfdy", "vertex", "fragment"})
, fReservedWords({"atan2", "rsqrt", "rint", "dfdx", "dfdy", "vertex", "fragment"})
, fLineEnding("\n")
, fContext(*context) {
this->setupIntrinsics();
@ -124,6 +124,7 @@ protected:
kRadians_IntrinsicKind,
kReflect_IntrinsicKind,
kRefract_IntrinsicKind,
kRoundEven_IntrinsicKind,
kTexture_IntrinsicKind,
};

View File

@ -11,6 +11,6 @@ struct Outputs {
fragment Outputs fragmentMain(Inputs _in [[stage_in]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
Outputs _outputStruct;
thread Outputs* _out = &_outputStruct;
_out->sk_FragColor.x = roundEven(_in.a);
_out->sk_FragColor.x = rint(_in.a);
return *_out;
}