Fix frexp support in Metal.

Our Metal codegen assumes that out params are pointers, but Metal's
built-in frexp actually takes a reference for the exponent, not a
pointer. We now add in a helper function to translate.

Change-Id: I24686347d07151dd99a1ff1c43aff2b35c3181e5
Bug: skia:10762
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/328387
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
This commit is contained in:
John Stiles 2020-10-20 10:24:56 -04:00 committed by Skia Commit-Bot
parent bb9769fb21
commit a80a3dc170
3 changed files with 13 additions and 1 deletions

View File

@ -305,9 +305,9 @@ sksl_settings_tests = [
"$_tests/sksl/glsl/TypePrecision.sksl",
"$_tests/sksl/inliner/InlinerCanBeDisabled.sksl",
"$_tests/sksl/inliner/InlinerWrapsEarlyReturnsWithDoWhileBlock.sksl",
"$_tests/sksl/shared/CrossIntrinsic.sksl",
"$_tests/sksl/shared/Derivatives.sksl",
"$_tests/sksl/shared/DerivativesFlipY.sksl",
"$_tests/sksl/shared/CrossIntrinsic.sksl",
"$_tests/sksl/workarounds/AbsInt.sksl",
"$_tests/sksl/workarounds/BlendGuardedDivide.sksl",
"$_tests/sksl/workarounds/BlendModesAllZeroVec.sksl",

View File

@ -228,6 +228,17 @@ void MetalCodeGenerator::writeFunctionCall(const FunctionCall& c) {
} else if (builtin && name == "inverse") {
SkASSERT(arguments.size() == 1);
this->writeInverseHack(*arguments[0]);
} else if (builtin && name == "frexp") {
// Our Metal codegen assumes that out params are pointers, but Metal's built-in frexp
// actually takes a reference for the exponent, not a pointer. We add in a helper function
// here to translate.
SkASSERT(arguments.size() == 2);
auto [iter, newlyCreated] = fHelpers.insert("frexp");
if (newlyCreated) {
fExtraFunctions.printf(
"float frexp(float arg, thread int* exp) { return frexp(arg, *exp); }\n");
}
this->write("frexp");
} else if (builtin && name == "dFdx") {
this->write("dfdx");
} else if (builtin && name == "dFdy") {

View File

@ -6,6 +6,7 @@ struct Inputs {
struct Outputs {
float4 sk_FragColor [[color(0)]];
};
float frexp(float arg, thread int* exp) { return frexp(arg, *exp); }
fragment Outputs fragmentMain(Inputs _in [[stage_in]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
Outputs _outputStruct;
thread Outputs* _out = &_outputStruct;