Update switch-fallthrough test to run in dm.

Also, removed "switch containing dead code" test. This wasn't testing
anything meaningful. (When we had full CFG analysis, we could have
eliminated some of the assignments inside the switch body, but this is
not something we do anymore.)

Change-Id: Iaeb74ebee41a7f368113ede9a4e30c033b9de8ac
Bug: skia:12450
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/450985
Commit-Queue: John Stiles <johnstiles@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
This commit is contained in:
John Stiles 2021-09-21 10:56:31 -04:00 committed by SkCQ
parent 408f38ea05
commit e32309d771
10 changed files with 189 additions and 178 deletions

View File

@ -397,7 +397,6 @@ sksl_shared_tests = [
"/sksl/shared/StructsInFunctions.sksl",
"/sksl/shared/StructMaxDepth.sksl",
"/sksl/shared/Switch.sksl",
"/sksl/shared/SwitchContainingDeadCode.sksl",
"/sksl/shared/SwitchDefaultOnly.sksl",
"/sksl/shared/SwitchWithFallthrough.sksl",
"/sksl/shared/SwizzleBoolConstants.sksl",

View File

@ -1,14 +0,0 @@
uniform int unknownInput;
void main() {
half value;
switch (unknownInput) {
case 0:
value = 0.0;
case 1:
value = 1.0;
default:
value = 2.0;
}
sk_FragColor = value.xxxx;
}

View File

@ -1,12 +1,25 @@
uniform float unknownInput;
uniform half4 colorGreen, colorRed;
void main() {
half value = 0.0;
switch (int(unknownInput)) {
case 0:
value = 0.0;
bool switch_fallthrough(int value) {
switch (value) {
case 2: return false;
case 1:
value = 1.0;
case 0: return true;
default: return false;
}
sk_FragColor = value.xxxx;
}
bool switch_fallthrough_twice(int value) {
switch (value) {
case 0: return false;
case 1:
case 2:
case 3: return true;
default: return false;
}
}
half4 main(float2 coords) {
int x = int(colorGreen.g);
return (switch_fallthrough(x) && switch_fallthrough_twice(x)) ? colorGreen : colorRed;
}

View File

@ -325,6 +325,7 @@ SKSL_TEST(SkSLStructArrayFollowedByScalar, "shared/StructArrayFollowedByScal
SKSL_TEST(SkSLStructsInFunctions, "shared/StructsInFunctions.sksl")
SKSL_TEST_ES3(SkSLSwitch, "shared/Switch.sksl")
SKSL_TEST_ES3(SkSLSwitchDefaultOnly, "shared/SwitchDefaultOnly.sksl")
SKSL_TEST_ES3(SkSLSwitchWithFallthrough, "shared/SwitchWithFallthrough.sksl")
SKSL_TEST(SkSLSwizzleBoolConstants, "shared/SwizzleBoolConstants.sksl")
SKSL_TEST(SkSLSwizzleByConstantIndex, "shared/SwizzleByConstantIndex.sksl")
SKSL_TEST(SkSLSwizzleConstants, "shared/SwizzleConstants.sksl")

View File

@ -1,63 +0,0 @@
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %sk_FragColor %sk_Clockwise
OpExecutionMode %main OriginUpperLeft
OpName %sk_FragColor "sk_FragColor"
OpName %sk_Clockwise "sk_Clockwise"
OpName %_UniformBuffer "_UniformBuffer"
OpMemberName %_UniformBuffer 0 "unknownInput"
OpName %main "main"
OpName %value "value"
OpDecorate %sk_FragColor RelaxedPrecision
OpDecorate %sk_FragColor Location 0
OpDecorate %sk_FragColor Index 0
OpDecorate %sk_Clockwise BuiltIn FrontFacing
OpMemberDecorate %_UniformBuffer 0 Offset 0
OpDecorate %_UniformBuffer Block
OpDecorate %10 Binding 0
OpDecorate %10 DescriptorSet 0
OpDecorate %value RelaxedPrecision
OpDecorate %30 RelaxedPrecision
OpDecorate %31 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
%int = OpTypeInt 32 1
%_UniformBuffer = OpTypeStruct %int
%_ptr_Uniform__UniformBuffer = OpTypePointer Uniform %_UniformBuffer
%10 = OpVariable %_ptr_Uniform__UniformBuffer Uniform
%void = OpTypeVoid
%15 = OpTypeFunction %void
%_ptr_Function_float = OpTypePointer Function %float
%_ptr_Uniform_int = OpTypePointer Uniform %int
%int_0 = OpConstant %int 0
%float_0 = OpConstant %float 0
%float_1 = OpConstant %float 1
%float_2 = OpConstant %float 2
%main = OpFunction %void None %15
%16 = OpLabel
%value = OpVariable %_ptr_Function_float Function
%19 = OpAccessChain %_ptr_Uniform_int %10 %int_0
%22 = OpLoad %int %19
OpSelectionMerge %23 None
OpSwitch %22 %26 0 %24 1 %25
%24 = OpLabel
OpStore %value %float_0
OpBranch %25
%25 = OpLabel
OpStore %value %float_1
OpBranch %26
%26 = OpLabel
OpStore %value %float_2
OpBranch %23
%23 = OpLabel
%30 = OpLoad %float %value
%31 = OpCompositeConstruct %v4float %30 %30 %30 %30
OpStore %sk_FragColor %31
OpReturn
OpFunctionEnd

View File

@ -1,15 +0,0 @@
out vec4 sk_FragColor;
uniform int unknownInput;
void main() {
float value;
switch (unknownInput) {
case 0:
value = 0.0;
case 1:
value = 1.0;
default:
value = 2.0;
}
sk_FragColor = vec4(value);
}

View File

@ -1,26 +0,0 @@
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct Uniforms {
int unknownInput;
};
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;
float value;
switch (_uniforms.unknownInput) {
case 0:
value = 0.0;
case 1:
value = 1.0;
default:
value = 2.0;
}
_out.sk_FragColor = float4(value);
return _out;
}

View File

@ -1,25 +1,34 @@
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %sk_FragColor %sk_Clockwise
OpExecutionMode %main OriginUpperLeft
OpEntryPoint Fragment %_entrypoint_v "_entrypoint" %sk_FragColor %sk_Clockwise
OpExecutionMode %_entrypoint_v OriginUpperLeft
OpName %sk_FragColor "sk_FragColor"
OpName %sk_Clockwise "sk_Clockwise"
OpName %_UniformBuffer "_UniformBuffer"
OpMemberName %_UniformBuffer 0 "unknownInput"
OpMemberName %_UniformBuffer 0 "colorGreen"
OpMemberName %_UniformBuffer 1 "colorRed"
OpName %_entrypoint_v "_entrypoint_v"
OpName %switch_fallthrough_bi "switch_fallthrough_bi"
OpName %switch_fallthrough_twice_bi "switch_fallthrough_twice_bi"
OpName %main "main"
OpName %value "value"
OpName %x "x"
OpDecorate %sk_FragColor RelaxedPrecision
OpDecorate %sk_FragColor Location 0
OpDecorate %sk_FragColor Index 0
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 %value RelaxedPrecision
OpDecorate %29 RelaxedPrecision
OpDecorate %30 RelaxedPrecision
OpDecorate %12 Binding 0
OpDecorate %12 DescriptorSet 0
OpDecorate %54 RelaxedPrecision
OpDecorate %55 RelaxedPrecision
OpDecorate %72 RelaxedPrecision
OpDecorate %75 RelaxedPrecision
OpDecorate %76 RelaxedPrecision
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%_ptr_Output_v4float = OpTypePointer Output %v4float
@ -27,35 +36,106 @@ OpDecorate %30 RelaxedPrecision
%bool = OpTypeBool
%_ptr_Input_bool = OpTypePointer Input %bool
%sk_Clockwise = OpVariable %_ptr_Input_bool Input
%_UniformBuffer = OpTypeStruct %float
%_UniformBuffer = OpTypeStruct %v4float %v4float
%_ptr_Uniform__UniformBuffer = OpTypePointer Uniform %_UniformBuffer
%10 = OpVariable %_ptr_Uniform__UniformBuffer Uniform
%12 = OpVariable %_ptr_Uniform__UniformBuffer Uniform
%void = OpTypeVoid
%14 = OpTypeFunction %void
%_ptr_Function_float = OpTypePointer Function %float
%17 = OpTypeFunction %void
%v2float = OpTypeVector %float 2
%float_0 = OpConstant %float 0
%_ptr_Uniform_float = OpTypePointer Uniform %float
%21 = OpConstantComposite %v2float %float_0 %float_0
%_ptr_Function_v2float = OpTypePointer Function %v2float
%int = OpTypeInt 32 1
%_ptr_Function_int = OpTypePointer Function %int
%26 = OpTypeFunction %bool %_ptr_Function_int
%false = OpConstantFalse %bool
%true = OpConstantTrue %bool
%47 = OpTypeFunction %v4float %_ptr_Function_v2float
%_ptr_Uniform_v4float = OpTypePointer Uniform %v4float
%int_0 = OpConstant %int 0
%float_1 = OpConstant %float 1
%main = OpFunction %void None %14
%15 = OpLabel
%value = OpVariable %_ptr_Function_float Function
OpStore %value %float_0
%19 = OpAccessChain %_ptr_Uniform_float %10 %int_0
%23 = OpLoad %float %19
%24 = OpConvertFToS %int %23
OpSelectionMerge %25 None
OpSwitch %24 %25 0 %26 1 %27
%26 = OpLabel
OpStore %value %float_0
OpBranch %27
%27 = OpLabel
OpStore %value %float_1
OpBranch %25
%25 = OpLabel
%29 = OpLoad %float %value
%30 = OpCompositeConstruct %v4float %29 %29 %29 %29
OpStore %sk_FragColor %30
%_ptr_Function_v4float = OpTypePointer Function %v4float
%int_1 = OpConstant %int 1
%_entrypoint_v = OpFunction %void None %17
%18 = OpLabel
%22 = OpVariable %_ptr_Function_v2float Function
OpStore %22 %21
%24 = OpFunctionCall %v4float %main %22
OpStore %sk_FragColor %24
OpReturn
OpFunctionEnd
%switch_fallthrough_bi = OpFunction %bool None %26
%28 = OpFunctionParameter %_ptr_Function_int
%29 = OpLabel
%30 = OpLoad %int %28
OpSelectionMerge %31 None
OpSwitch %30 %35 2 %32 1 %33 0 %34
%32 = OpLabel
OpReturnValue %false
%33 = OpLabel
OpBranch %34
%34 = OpLabel
OpReturnValue %true
%35 = OpLabel
OpReturnValue %false
%31 = OpLabel
OpUnreachable
OpFunctionEnd
%switch_fallthrough_twice_bi = OpFunction %bool None %26
%38 = OpFunctionParameter %_ptr_Function_int
%39 = OpLabel
%40 = OpLoad %int %38
OpSelectionMerge %41 None
OpSwitch %40 %46 0 %42 1 %43 2 %44 3 %45
%42 = OpLabel
OpReturnValue %false
%43 = OpLabel
OpBranch %44
%44 = OpLabel
OpBranch %45
%45 = OpLabel
OpReturnValue %true
%46 = OpLabel
OpReturnValue %false
%41 = OpLabel
OpUnreachable
OpFunctionEnd
%main = OpFunction %v4float None %47
%48 = OpFunctionParameter %_ptr_Function_v2float
%49 = OpLabel
%x = OpVariable %_ptr_Function_int Function
%58 = OpVariable %_ptr_Function_int Function
%63 = OpVariable %_ptr_Function_int Function
%66 = OpVariable %_ptr_Function_v4float Function
%51 = OpAccessChain %_ptr_Uniform_v4float %12 %int_0
%54 = OpLoad %v4float %51
%55 = OpCompositeExtract %float %54 1
%56 = OpConvertFToS %int %55
OpStore %x %56
%57 = OpLoad %int %x
OpStore %58 %57
%59 = OpFunctionCall %bool %switch_fallthrough_bi %58
OpSelectionMerge %61 None
OpBranchConditional %59 %60 %61
%60 = OpLabel
%62 = OpLoad %int %x
OpStore %63 %62
%64 = OpFunctionCall %bool %switch_fallthrough_twice_bi %63
OpBranch %61
%61 = OpLabel
%65 = OpPhi %bool %false %49 %64 %60
OpSelectionMerge %70 None
OpBranchConditional %65 %68 %69
%68 = OpLabel
%71 = OpAccessChain %_ptr_Uniform_v4float %12 %int_0
%72 = OpLoad %v4float %71
OpStore %66 %72
OpBranch %70
%69 = OpLabel
%73 = OpAccessChain %_ptr_Uniform_v4float %12 %int_1
%75 = OpLoad %v4float %73
OpStore %66 %75
OpBranch %70
%70 = OpLabel
%76 = OpLoad %v4float %66
OpReturnValue %76
OpFunctionEnd

View File

@ -1,13 +1,31 @@
out vec4 sk_FragColor;
uniform float unknownInput;
void main() {
float value = 0.0;
switch (int(unknownInput)) {
case 0:
value = 0.0;
uniform vec4 colorGreen;
uniform vec4 colorRed;
bool switch_fallthrough_bi(int value) {
switch (value) {
case 2:
return false;
case 1:
value = 1.0;
case 0:
return true;
default:
return false;
}
sk_FragColor = vec4(value);
}
bool switch_fallthrough_twice_bi(int value) {
switch (value) {
case 0:
return false;
case 1:
case 2:
case 3:
return true;
default:
return false;
}
}
vec4 main() {
int x = int(colorGreen.y);
return switch_fallthrough_bi(x) && switch_fallthrough_twice_bi(x) ? colorGreen : colorRed;
}

View File

@ -2,23 +2,41 @@
#include <simd/simd.h>
using namespace metal;
struct Uniforms {
float unknownInput;
float4 colorGreen;
float4 colorRed;
};
struct Inputs {
};
struct Outputs {
float4 sk_FragColor [[color(0)]];
};
bool switch_fallthrough_bi(int value) {
switch (value) {
case 2:
return false;
case 1:
case 0:
return true;
default:
return false;
}
}
bool switch_fallthrough_twice_bi(int value) {
switch (value) {
case 0:
return false;
case 1:
case 2:
case 3:
return true;
default:
return false;
}
}
fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
Outputs _out;
(void)_out;
float value = 0.0;
switch (int(_uniforms.unknownInput)) {
case 0:
value = 0.0;
case 1:
value = 1.0;
}
_out.sk_FragColor = float4(value);
int x = int(_uniforms.colorGreen.y);
_out.sk_FragColor = switch_fallthrough_bi(x) && switch_fallthrough_twice_bi(x) ? _uniforms.colorGreen : _uniforms.colorRed;
return _out;
}