Add SPIR-V support for modf intrinsic.

Change-Id: I887e700a7bf11bf2d5359c9721798f72f00e53f3
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/342756
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
This commit is contained in:
John Stiles 2020-12-09 17:14:47 -05:00 committed by Skia Commit-Bot
parent a3b8ac76e5
commit 01957273e7
6 changed files with 75 additions and 0 deletions

View File

@ -245,6 +245,7 @@ sksl_shared_tests = [
"$_tests/sksl/intrinsics/Min.sksl",
"$_tests/sksl/intrinsics/Mix.sksl",
"$_tests/sksl/intrinsics/Mod.sksl",
"$_tests/sksl/intrinsics/Modf.sksl",
"$_tests/sksl/intrinsics/Normalize.sksl",
"$_tests/sksl/intrinsics/Not.sksl",
"$_tests/sksl/intrinsics/NotEqual.sksl",

View File

@ -72,6 +72,7 @@ void SPIRVCodeGenerator::setupIntrinsics() {
fIntrinsicMap[String("determinant")] = ALL_GLSL(Determinant);
fIntrinsicMap[String("matrixInverse")] = ALL_GLSL(MatrixInverse);
fIntrinsicMap[String("mod")] = SPECIAL(Mod);
fIntrinsicMap[String("modf")] = ALL_GLSL(Modf);
fIntrinsicMap[String("min")] = SPECIAL(Min);
fIntrinsicMap[String("max")] = SPECIAL(Max);
fIntrinsicMap[String("clamp")] = SPECIAL(Clamp);

View File

@ -0,0 +1 @@
in half a, b; void main() { sk_FragColor.x = modf(a, b); }

View File

@ -0,0 +1,41 @@
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %sk_FragColor %sk_Clockwise %a %b
OpExecutionMode %main OriginUpperLeft
OpName %sk_FragColor "sk_FragColor"
OpName %sk_Clockwise "sk_Clockwise"
OpName %a "a"
OpName %b "b"
OpName %main "main"
OpDecorate %sk_FragColor RelaxedPrecision
OpDecorate %sk_FragColor Location 0
OpDecorate %sk_FragColor Index 0
OpDecorate %sk_Clockwise RelaxedPrecision
OpDecorate %sk_Clockwise BuiltIn FrontFacing
OpDecorate %a RelaxedPrecision
OpDecorate %b RelaxedPrecision
OpDecorate %17 RelaxedPrecision
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%_ptr_Output_v4float = OpTypePointer Output %v4float
%sk_FragColor = OpVariable %_ptr_Output_v4float Output
%bool = OpTypeBool
%_ptr_Input_bool = OpTypePointer Input %bool
%sk_Clockwise = OpVariable %_ptr_Input_bool Input
%_ptr_Input_float = OpTypePointer Input %float
%a = OpVariable %_ptr_Input_float Input
%b = OpVariable %_ptr_Input_float Input
%void = OpTypeVoid
%14 = OpTypeFunction %void
%_ptr_Output_float = OpTypePointer Output %float
%int = OpTypeInt 32 1
%int_0 = OpConstant %int 0
%main = OpFunction %void None %14
%15 = OpLabel
%17 = OpLoad %float %a
%16 = OpExtInst %float %1 Modf %17 %b
%18 = OpAccessChain %_ptr_Output_float %sk_FragColor %int_0
OpStore %18 %16
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,7 @@
out vec4 sk_FragColor;
in float a;
in float b;
void main() {
sk_FragColor.x = modf(a, b);
}

View File

@ -0,0 +1,24 @@
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct Inputs {
float a;
float b;
};
struct Outputs {
float4 sk_FragColor [[color(0)]];
};
float _skOutParamHelper0_modf(float _var0, thread float& b) {
float _var1;
float _skResult = modf(_var0, _var1);
b = _var1;
return _skResult;
}
fragment Outputs fragmentMain(Inputs _in [[stage_in]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
Outputs _outputStruct;
thread Outputs* _out = &_outputStruct;
_out->sk_FragColor.x = _skOutParamHelper0_modf(_in.a, _in.b);
return *_out;
}