Update function-type-matching tests to work as Runtime Effects.

Previously, our only test was invoking `sin(1)` which is a pretty
ineffective test. Now, we test args and return types for all the basic
scalars/vectors/matrices.

Change-Id: I7d335303eef8b9c9c6cfef2265a15bbd9bd73e0c
Bug: skia:11246
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/363943
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
This commit is contained in:
John Stiles 2021-02-01 16:36:13 -05:00 committed by Skia Commit-Bot
parent 2bf7d6ff31
commit 931cad1d74
14 changed files with 522 additions and 36 deletions

View File

@ -322,7 +322,8 @@ sksl_shared_tests = [
"/sksl/shared/FragCoordsFlipY.sksl",
"/sksl/shared/FragCoordsNew.sksl",
"/sksl/shared/FragCoordsOld.sksl",
"/sksl/shared/FunctionArgumentMatch.sksl",
"/sksl/shared/FunctionArgTypeMatch.sksl",
"/sksl/shared/FunctionReturnTypeMatch.sksl",
"/sksl/shared/FunctionPrototype.sksl",
"/sksl/shared/Functions.sksl",
"/sksl/shared/GaussianBlur.sksl",

View File

@ -0,0 +1,49 @@
uniform half4 colorGreen, colorRed;
bool takes_float (float x) { return true; }
bool takes_float2 (float2 x) { return true; }
bool takes_float3 (float3 x) { return true; }
bool takes_float4 (float4 x) { return true; }
bool takes_float2x2(float2x2 x) { return true; }
bool takes_float3x3(float3x3 x) { return true; }
bool takes_float4x4(float4x4 x) { return true; }
bool takes_half (half x) { return true; }
bool takes_half2 (half2 x) { return true; }
bool takes_half3 (half3 x) { return true; }
bool takes_half4 (half4 x) { return true; }
bool takes_half2x2 (half2x2 x) { return true; }
bool takes_half3x3 (half3x3 x) { return true; }
bool takes_half4x4 (half4x4 x) { return true; }
bool takes_bool (bool x) { return true; }
bool takes_bool2 (bool2 x) { return true; }
bool takes_bool3 (bool3 x) { return true; }
bool takes_bool4 (bool4 x) { return true; }
bool takes_int (int x) { return true; }
bool takes_int2 (int2 x) { return true; }
bool takes_int3 (int3 x) { return true; }
bool takes_int4 (int4 x) { return true; }
half4 main() {
return takes_float (float (1)) &&
takes_float2 (float2 (2)) &&
takes_float3 (float3 (3)) &&
takes_float4 (float4 (4)) &&
takes_float2x2(float2x2 (2)) &&
takes_float3x3(float3x3 (3)) &&
takes_float4x4(float4x4 (4)) &&
takes_half (half (1)) &&
takes_half2 (half2 (2)) &&
takes_half3 (half3 (3)) &&
takes_half4 (half4 (4)) &&
takes_half2x2 (half2x2 (2)) &&
takes_half3x3 (half3x3 (3)) &&
takes_half4x4 (half4x4 (4)) &&
takes_bool (bool (true)) &&
takes_bool2 (bool2 (true)) &&
takes_bool3 (bool3 (true)) &&
takes_bool4 (bool4 (true)) &&
takes_int (int (1)) &&
takes_int2 (int2 (2)) &&
takes_int3 (int3 (3)) &&
takes_int4 (int4 (4)) ? colorGreen : colorRed;
}

View File

@ -1 +0,0 @@
void main() { float x = sin(1); }

View File

@ -0,0 +1,72 @@
uniform half4 colorGreen, colorRed;
float returns_float() { return float(1); }
float2 returns_float2() { return float2(2); }
float3 returns_float3() { return float3(3); }
float4 returns_float4() { return float4(4); }
float2x2 returns_float2x2() { return float2x2(2); }
float3x3 returns_float3x3() { return float3x3(3); }
float4x4 returns_float4x4() { return float4x4(4); }
half returns_half() { return half(1); }
half2 returns_half2() { return half2(2); }
half3 returns_half3() { return half3(3); }
half4 returns_half4() { return half4(4); }
half2x2 returns_half2x2() { return half2x2(2); }
half3x3 returns_half3x3() { return half3x3(3); }
half4x4 returns_half4x4() { return half4x4(4); }
bool returns_bool() { return bool(true); }
bool2 returns_bool2() { return bool2(true); }
bool3 returns_bool3() { return bool3(true); }
bool4 returns_bool4() { return bool4(true); }
int returns_int() { return int(1); }
int2 returns_int2() { return int2(2); }
int3 returns_int3() { return int3(3); }
int4 returns_int4() { return int4(4); }
half4 main() {
float x1 = returns_float();
float2 x2 = returns_float2();
float3 x3 = returns_float3();
float4 x4 = returns_float4();
float2x2 x5 = returns_float2x2();
float3x3 x6 = returns_float3x3();
float4x4 x7 = returns_float4x4();
half x8 = returns_half();
half2 x9 = returns_half2();
half3 x10 = returns_half3();
half4 x11 = returns_half4();
half2x2 x12 = returns_half2x2();
half3x3 x13 = returns_half3x3();
half4x4 x14 = returns_half4x4();
bool x15 = returns_bool();
bool2 x16 = returns_bool2();
bool3 x17 = returns_bool3();
bool4 x18 = returns_bool4();
int x19 = returns_int();
int2 x20 = returns_int2();
int3 x21 = returns_int3();
int4 x22 = returns_int4();
return x1 == returns_float() &&
x2 == returns_float2() &&
x3 == returns_float3() &&
x4 == returns_float4() &&
x5 == returns_float2x2() &&
x6 == returns_float3x3() &&
x7 == returns_float4x4() &&
x8 == returns_half() &&
x9 == returns_half2() &&
x10 == returns_half3() &&
x11 == returns_half4() &&
x12 == returns_half2x2() &&
x13 == returns_half3x3() &&
x14 == returns_half4x4() &&
x15 == returns_bool() &&
x16 == returns_bool2() &&
x17 == returns_bool3() &&
x18 == returns_bool4() &&
x19 == returns_int() &&
x20 == returns_int2() &&
x21 == returns_int3() &&
x22 == returns_int4() ? colorGreen : colorRed;
}

View File

@ -123,6 +123,8 @@ SKSL_TEST(SkSLDeadStripFunctions, "shared/DeadStripFunctions.sksl")
SKSL_TEST(SkSLDependentInitializers, "shared/DependentInitializers.sksl")
SKSL_TEST(SkSLEmptyBlocksES2, "shared/EmptyBlocksES2.sksl")
SKSL_TEST(SkSLForLoopControlFlow, "shared/ForLoopControlFlow.sksl")
SKSL_TEST(SkSLFunctionArgTypeMatch, "shared/FunctionArgTypeMatch.sksl")
SKSL_TEST(SkSLFunctionReturnTypeMatch, "shared/FunctionReturnTypeMatch.sksl")
SKSL_TEST(SkSLOperatorsES2, "shared/OperatorsES2.sksl")
/*

View File

@ -0,0 +1,53 @@
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %_entrypoint "_entrypoint" %sk_FragColor %sk_Clockwise
OpExecutionMode %_entrypoint OriginUpperLeft
OpName %sk_FragColor "sk_FragColor"
OpName %sk_Clockwise "sk_Clockwise"
OpName %_UniformBuffer "_UniformBuffer"
OpMemberName %_UniformBuffer 0 "colorGreen"
OpMemberName %_UniformBuffer 1 "colorRed"
OpName %_entrypoint "_entrypoint"
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
OpMemberDecorate %_UniformBuffer 0 Offset 0
OpMemberDecorate %_UniformBuffer 0 RelaxedPrecision
OpMemberDecorate %_UniformBuffer 1 Offset 16
OpMemberDecorate %_UniformBuffer 1 RelaxedPrecision
OpDecorate %_UniformBuffer Block
OpDecorate %10 Binding 0
OpDecorate %10 DescriptorSet 0
OpDecorate %24 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
%_UniformBuffer = OpTypeStruct %v4float %v4float
%_ptr_Uniform__UniformBuffer = OpTypePointer Uniform %_UniformBuffer
%10 = OpVariable %_ptr_Uniform__UniformBuffer Uniform
%void = OpTypeVoid
%15 = OpTypeFunction %void
%18 = OpTypeFunction %v4float
%_ptr_Uniform_v4float = OpTypePointer Uniform %v4float
%int = OpTypeInt 32 1
%int_0 = OpConstant %int 0
%_entrypoint = OpFunction %void None %15
%16 = OpLabel
%17 = OpFunctionCall %v4float %main
OpStore %sk_FragColor %17
OpReturn
OpFunctionEnd
%main = OpFunction %v4float None %18
%19 = OpLabel
%20 = OpAccessChain %_ptr_Uniform_v4float %10 %int_0
%24 = OpLoad %v4float %20
OpReturnValue %24
OpFunctionEnd

View File

@ -0,0 +1,29 @@
out vec4 sk_FragColor;
uniform vec4 colorGreen;
uniform vec4 colorRed;
vec4 main() {
return colorGreen;
}

View File

@ -0,0 +1,42 @@
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct Uniforms {
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;
_out.sk_FragColor = _uniforms.colorGreen;
return _out;
}

View File

@ -1,18 +0,0 @@
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %sk_Clockwise
OpExecutionMode %main OriginUpperLeft
OpName %sk_Clockwise "sk_Clockwise"
OpName %main "main"
OpDecorate %sk_Clockwise RelaxedPrecision
OpDecorate %sk_Clockwise BuiltIn FrontFacing
%bool = OpTypeBool
%_ptr_Input_bool = OpTypePointer Input %bool
%sk_Clockwise = OpVariable %_ptr_Input_bool Input
%void = OpTypeVoid
%7 = OpTypeFunction %void
%main = OpFunction %void None %7
%8 = OpLabel
OpReturn
OpFunctionEnd

View File

@ -1,3 +0,0 @@
void main() {
}

View File

@ -1,13 +0,0 @@
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct Inputs {
};
struct Outputs {
float4 sk_FragColor [[color(0)]];
};
fragment Outputs fragmentMain(Inputs _in [[stage_in]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
Outputs _out;
(void)_out;
return _out;
}

View File

@ -0,0 +1,178 @@
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %_entrypoint "_entrypoint" %sk_FragColor %sk_Clockwise
OpExecutionMode %_entrypoint OriginUpperLeft
OpName %sk_FragColor "sk_FragColor"
OpName %sk_Clockwise "sk_Clockwise"
OpName %_UniformBuffer "_UniformBuffer"
OpMemberName %_UniformBuffer 0 "colorGreen"
OpMemberName %_UniformBuffer 1 "colorRed"
OpName %_entrypoint "_entrypoint"
OpName %returns_bool3 "returns_bool3"
OpName %returns_bool4 "returns_bool4"
OpName %returns_int "returns_int"
OpName %returns_int2 "returns_int2"
OpName %returns_int3 "returns_int3"
OpName %returns_int4 "returns_int4"
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
OpMemberDecorate %_UniformBuffer 0 Offset 0
OpMemberDecorate %_UniformBuffer 0 RelaxedPrecision
OpMemberDecorate %_UniformBuffer 1 Offset 16
OpMemberDecorate %_UniformBuffer 1 RelaxedPrecision
OpDecorate %_UniformBuffer Block
OpDecorate %16 Binding 0
OpDecorate %16 DescriptorSet 0
OpDecorate %102 RelaxedPrecision
OpDecorate %104 RelaxedPrecision
OpDecorate %105 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
%_UniformBuffer = OpTypeStruct %v4float %v4float
%_ptr_Uniform__UniformBuffer = OpTypePointer Uniform %_UniformBuffer
%16 = OpVariable %_ptr_Uniform__UniformBuffer Uniform
%void = OpTypeVoid
%21 = OpTypeFunction %void
%v3bool = OpTypeVector %bool 3
%25 = OpTypeFunction %v3bool
%true = OpConstantTrue %bool
%28 = OpConstantComposite %v3bool %true %true %true
%v4bool = OpTypeVector %bool 4
%30 = OpTypeFunction %v4bool
%32 = OpConstantComposite %v4bool %true %true %true %true
%int = OpTypeInt 32 1
%34 = OpTypeFunction %int
%int_1 = OpConstant %int 1
%v2int = OpTypeVector %int 2
%38 = OpTypeFunction %v2int
%int_2 = OpConstant %int 2
%41 = OpConstantComposite %v2int %int_2 %int_2
%v3int = OpTypeVector %int 3
%43 = OpTypeFunction %v3int
%int_3 = OpConstant %int 3
%46 = OpConstantComposite %v3int %int_3 %int_3 %int_3
%v4int = OpTypeVector %int 4
%48 = OpTypeFunction %v4int
%int_4 = OpConstant %int 4
%51 = OpConstantComposite %v4int %int_4 %int_4 %int_4 %int_4
%52 = OpTypeFunction %v4float
%false = OpConstantFalse %bool
%v2bool = OpTypeVector %bool 2
%56 = OpConstantComposite %v2bool %true %true
%_ptr_Function_v4float = OpTypePointer Function %v4float
%_ptr_Uniform_v4float = OpTypePointer Uniform %v4float
%int_0 = OpConstant %int 0
%_entrypoint = OpFunction %void None %21
%22 = OpLabel
%23 = OpFunctionCall %v4float %main
OpStore %sk_FragColor %23
OpReturn
OpFunctionEnd
%returns_bool3 = OpFunction %v3bool None %25
%26 = OpLabel
OpReturnValue %28
OpFunctionEnd
%returns_bool4 = OpFunction %v4bool None %30
%31 = OpLabel
OpReturnValue %32
OpFunctionEnd
%returns_int = OpFunction %int None %34
%35 = OpLabel
OpReturnValue %int_1
OpFunctionEnd
%returns_int2 = OpFunction %v2int None %38
%39 = OpLabel
OpReturnValue %41
OpFunctionEnd
%returns_int3 = OpFunction %v3int None %43
%44 = OpLabel
OpReturnValue %46
OpFunctionEnd
%returns_int4 = OpFunction %v4int None %48
%49 = OpLabel
OpReturnValue %51
OpFunctionEnd
%main = OpFunction %v4float None %52
%53 = OpLabel
%94 = OpVariable %_ptr_Function_v4float Function
%57 = OpLogicalEqual %v2bool %56 %56
%58 = OpAll %bool %57
OpSelectionMerge %60 None
OpBranchConditional %58 %59 %60
%59 = OpLabel
%61 = OpFunctionCall %v3bool %returns_bool3
%62 = OpLogicalEqual %v3bool %28 %61
%63 = OpAll %bool %62
OpBranch %60
%60 = OpLabel
%64 = OpPhi %bool %false %53 %63 %59
OpSelectionMerge %66 None
OpBranchConditional %64 %65 %66
%65 = OpLabel
%67 = OpFunctionCall %v4bool %returns_bool4
%68 = OpLogicalEqual %v4bool %32 %67
%69 = OpAll %bool %68
OpBranch %66
%66 = OpLabel
%70 = OpPhi %bool %false %60 %69 %65
OpSelectionMerge %72 None
OpBranchConditional %70 %71 %72
%71 = OpLabel
%73 = OpFunctionCall %int %returns_int
%74 = OpIEqual %bool %int_1 %73
OpBranch %72
%72 = OpLabel
%75 = OpPhi %bool %false %66 %74 %71
OpSelectionMerge %77 None
OpBranchConditional %75 %76 %77
%76 = OpLabel
%78 = OpFunctionCall %v2int %returns_int2
%79 = OpIEqual %v2bool %41 %78
%80 = OpAll %bool %79
OpBranch %77
%77 = OpLabel
%81 = OpPhi %bool %false %72 %80 %76
OpSelectionMerge %83 None
OpBranchConditional %81 %82 %83
%82 = OpLabel
%84 = OpFunctionCall %v3int %returns_int3
%85 = OpIEqual %v3bool %46 %84
%86 = OpAll %bool %85
OpBranch %83
%83 = OpLabel
%87 = OpPhi %bool %false %77 %86 %82
OpSelectionMerge %89 None
OpBranchConditional %87 %88 %89
%88 = OpLabel
%90 = OpFunctionCall %v4int %returns_int4
%91 = OpIEqual %v4bool %51 %90
%92 = OpAll %bool %91
OpBranch %89
%89 = OpLabel
%93 = OpPhi %bool %false %83 %92 %88
OpSelectionMerge %98 None
OpBranchConditional %93 %96 %97
%96 = OpLabel
%99 = OpAccessChain %_ptr_Uniform_v4float %16 %int_0
%102 = OpLoad %v4float %99
OpStore %94 %102
OpBranch %98
%97 = OpLabel
%103 = OpAccessChain %_ptr_Uniform_v4float %16 %int_1
%104 = OpLoad %v4float %103
OpStore %94 %104
OpBranch %98
%98 = OpLabel
%105 = OpLoad %v4float %94
OpReturnValue %105
OpFunctionEnd

View File

@ -0,0 +1,41 @@
out vec4 sk_FragColor;
uniform vec4 colorGreen;
uniform vec4 colorRed;
bvec3 returns_bool3() {
return bvec3(true);
}
bvec4 returns_bool4() {
return bvec4(true);
}
int returns_int() {
return 1;
}
ivec2 returns_int2() {
return ivec2(2);
}
ivec3 returns_int3() {
return ivec3(3);
}
ivec4 returns_int4() {
return ivec4(4);
}
vec4 main() {
return (((((bvec2(true) == bvec2(true) && bvec3(true) == returns_bool3()) && bvec4(true) == returns_bool4()) && 1 == returns_int()) && ivec2(2) == returns_int2()) && ivec3(3) == returns_int3()) && ivec4(4) == returns_int4() ? colorGreen : colorRed;
}

View File

@ -0,0 +1,54 @@
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct Uniforms {
float4 colorGreen;
float4 colorRed;
};
struct Inputs {
};
struct Outputs {
float4 sk_FragColor [[color(0)]];
};
bool3 returns_bool3() {
return bool3(true);
}
bool4 returns_bool4() {
return bool4(true);
}
int returns_int() {
return 1;
}
int2 returns_int2() {
return int2(2);
}
int3 returns_int3() {
return int3(3);
}
int4 returns_int4() {
return int4(4);
}
fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
Outputs _out;
(void)_out;
_out.sk_FragColor = (((((all(bool2(true) == bool2(true)) && all(bool3(true) == returns_bool3())) && all(bool4(true) == returns_bool4())) && 1 == returns_int()) && all(int2(2) == returns_int2())) && all(int3(3) == returns_int3())) && all(int4(4) == returns_int4()) ? _uniforms.colorGreen : _uniforms.colorRed;
return _out;
}