David Neto dffa60ca98 spir-writer: handle break continuing block
The continuing block can exit the loop in very constrained ways:

When a break statement is placed such that it would exit from a loop’s
§ 7.3.8 Continuing Statement, then:

   - The break statement must appear as either:
     - The only statement in the if clause of an if statement that has:
       - no else clause or an empty else clause
       - no elseif clauses
     - The only statement in the else clause of an if statement that has an
       empty if clause and no elseif clauses.
   - That if statement must appear last in the continuing clause.

By design, this allows a lossless round-trip from SPIR-V to WGSL and
back to SPIR-V.  But that requires this special case construct in WGSL
to be translated to an OpBranchConditional with one target being
the loop's megre block (which is where 'break' branches to), and the
other targets the loop header (which is the loop backedge).  That
OpBranchConditional takes the place of the normal case of an
unconditional backedge.

Avoids errors like this:
 continue construct with the continue target X is not
 post dominated by the back-edge block Y

Fixed: 1034
Change-Id: If472a179380b8d77af746a3cd8e279c8a5e56b37
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/59800
Auto-Submit: David Neto <dneto@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
2021-07-27 15:12:27 +00:00

253 lines
10 KiB
Plaintext

; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 151
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %tint_symbol %tint_symbol_2
OpExecutionMode %main OriginUpperLeft
OpName %buf0 "buf0"
OpMemberName %buf0 0 "injectionSwitch"
OpName %x_9 "x_9"
OpName %gl_FragCoord "gl_FragCoord"
OpName %x_GLF_color "x_GLF_color"
OpName %tint_symbol "tint_symbol"
OpName %tint_symbol_2 "tint_symbol_2"
OpName %main_1 "main_1"
OpName %x_43 "x_43"
OpName %x_44 "x_44"
OpName %x_45 "x_45"
OpName %x_46 "x_46"
OpName %zero "zero"
OpName %param "param"
OpName %temp "temp"
OpName %main_out "main_out"
OpMemberName %main_out 0 "x_GLF_color_1"
OpName %tint_symbol_3 "tint_symbol_3"
OpName %tint_symbol_1 "tint_symbol_1"
OpName %main "main"
OpName %alwaysZero_vf2_ "alwaysZero_vf2_"
OpName %coord "coord"
OpName %a "a"
OpName %x_110 "x_110"
OpName %b "b"
OpDecorate %buf0 Block
OpMemberDecorate %buf0 0 Offset 0
OpDecorate %x_9 NonWritable
OpDecorate %x_9 DescriptorSet 0
OpDecorate %x_9 Binding 0
OpDecorate %tint_symbol BuiltIn FragCoord
OpDecorate %tint_symbol_2 Location 0
OpMemberDecorate %main_out 0 Offset 0
%float = OpTypeFloat 32
%v2float = OpTypeVector %float 2
%buf0 = OpTypeStruct %v2float
%_ptr_Uniform_buf0 = OpTypePointer Uniform %buf0
%x_9 = OpVariable %_ptr_Uniform_buf0 Uniform
%v4float = OpTypeVector %float 4
%_ptr_Private_v4float = OpTypePointer Private %v4float
%9 = OpConstantNull %v4float
%gl_FragCoord = OpVariable %_ptr_Private_v4float Private %9
%x_GLF_color = OpVariable %_ptr_Private_v4float Private %9
%_ptr_Input_v4float = OpTypePointer Input %v4float
%tint_symbol = OpVariable %_ptr_Input_v4float Input
%_ptr_Output_v4float = OpTypePointer Output %v4float
%tint_symbol_2 = OpVariable %_ptr_Output_v4float Output %9
%void = OpTypeVoid
%15 = OpTypeFunction %void
%_ptr_Function_float = OpTypePointer Function %float
%21 = OpConstantNull %float
%int = OpTypeInt 32 1
%_ptr_Function_int = OpTypePointer Function %int
%27 = OpConstantNull %int
%_ptr_Function_v2float = OpTypePointer Function %v2float
%31 = OpConstantNull %v2float
%uint = OpTypeInt 32 0
%uint_1 = OpConstant %uint 1
%float_50 = OpConstant %float 50
%bool = OpTypeBool
%uint_0 = OpConstant %uint 0
%_ptr_Uniform_float = OpTypePointer Uniform %float
%float_0 = OpConstant %float 0
%_ptr_Private_float = OpTypePointer Private %float
%float_1 = OpConstant %float 1
%int_0 = OpConstant %int 0
%int_1 = OpConstant %int 1
%false = OpConstantFalse %bool
%74 = OpConstantComposite %v4float %float_0 %float_1 %float_1 %float_1
%uint_2 = OpConstant %uint 2
%main_out = OpTypeStruct %v4float
%113 = OpTypeFunction %void %main_out
%126 = OpTypeFunction %int %_ptr_Function_v2float
%main_1 = OpFunction %void None %15
%18 = OpLabel
%x_43 = OpVariable %_ptr_Function_float Function %21
%x_44 = OpVariable %_ptr_Function_float Function %21
%x_45 = OpVariable %_ptr_Function_float Function %21
%x_46 = OpVariable %_ptr_Function_int Function %27
%zero = OpVariable %_ptr_Function_int Function %27
%param = OpVariable %_ptr_Function_v2float Function %31
%temp = OpVariable %_ptr_Function_v2float Function %31
%33 = OpLoad %v4float %gl_FragCoord
%34 = OpCompositeExtract %float %33 0
%35 = OpCompositeExtract %float %33 1
%36 = OpCompositeConstruct %v2float %34 %35
OpStore %param %36
OpBranch %37
%37 = OpLabel
OpLoopMerge %38 %39 None
OpBranch %40
%40 = OpLabel
%43 = OpAccessChain %_ptr_Function_float %param %uint_1
%44 = OpLoad %float %43
%46 = OpFOrdLessThan %bool %44 %float_50
OpSelectionMerge %48 None
OpBranchConditional %46 %49 %50
%49 = OpLabel
%53 = OpAccessChain %_ptr_Uniform_float %x_9 %uint_0 %uint_1
%54 = OpLoad %float %53
OpStore %x_44 %54
OpBranch %48
%50 = OpLabel
OpStore %x_44 %float_0
OpBranch %48
%48 = OpLabel
%56 = OpLoad %float %x_44
OpStore %x_43 %56
%58 = OpAccessChain %_ptr_Private_float %gl_FragCoord %uint_1
%59 = OpLoad %float %58
%61 = OpFOrdLessThan %bool %59 %float_50
%60 = OpSelect %float %61 %float_1 %float_0
OpStore %x_45 %60
%63 = OpFSub %float %56 %60
%64 = OpFOrdLessThan %bool %63 %float_1
OpSelectionMerge %65 None
OpBranchConditional %64 %66 %65
%66 = OpLabel
OpStore %x_46 %int_0
OpBranch %38
%65 = OpLabel
OpStore %x_46 %int_1
OpBranch %38
%39 = OpLabel
OpBranchConditional %false %37 %38
%38 = OpLabel
%70 = OpLoad %int %x_46
OpStore %zero %70
%71 = OpIEqual %bool %70 %int_1
OpSelectionMerge %72 None
OpBranchConditional %71 %73 %72
%73 = OpLabel
OpReturn
%72 = OpLabel
OpStore %x_GLF_color %74
%75 = OpAccessChain %_ptr_Private_float %gl_FragCoord %uint_0
%76 = OpLoad %float %75
%77 = OpAccessChain %_ptr_Uniform_float %x_9 %uint_0 %uint_0
%78 = OpLoad %float %77
%79 = OpFOrdGreaterThanEqual %bool %76 %78
OpSelectionMerge %80 None
OpBranchConditional %79 %81 %80
%81 = OpLabel
%82 = OpAccessChain %_ptr_Private_float %gl_FragCoord %uint_1
%83 = OpLoad %float %82
%84 = OpFOrdGreaterThanEqual %bool %83 %float_0
OpSelectionMerge %85 None
OpBranchConditional %84 %86 %85
%86 = OpLabel
%87 = OpAccessChain %_ptr_Uniform_float %x_9 %uint_0 %uint_1
%88 = OpLoad %float %87
%89 = OpAccessChain %_ptr_Private_float %x_GLF_color %uint_0
OpStore %89 %88
OpBranch %85
%85 = OpLabel
OpBranch %80
%80 = OpLabel
%90 = OpAccessChain %_ptr_Private_float %gl_FragCoord %uint_1
%91 = OpLoad %float %90
%92 = OpFOrdGreaterThanEqual %bool %91 %float_0
OpSelectionMerge %93 None
OpBranchConditional %92 %94 %93
%94 = OpLabel
%95 = OpAccessChain %_ptr_Uniform_float %x_9 %uint_0 %uint_0
%96 = OpLoad %float %95
%97 = OpAccessChain %_ptr_Private_float %x_GLF_color %uint_1
OpStore %97 %96
OpBranch %93
%93 = OpLabel
%98 = OpLoad %v4float %gl_FragCoord
%99 = OpCompositeExtract %float %98 0
%100 = OpCompositeExtract %float %98 1
%101 = OpCompositeConstruct %v2float %99 %100
%102 = OpCompositeExtract %float %101 0
%103 = OpCompositeExtract %float %101 1
%104 = OpCompositeConstruct %v2float %102 %103
OpStore %temp %104
%105 = OpCompositeExtract %float %104 1
%106 = OpFOrdGreaterThanEqual %bool %105 %float_0
OpSelectionMerge %107 None
OpBranchConditional %106 %108 %107
%108 = OpLabel
%109 = OpAccessChain %_ptr_Uniform_float %x_9 %uint_0 %uint_0
%110 = OpLoad %float %109
%112 = OpAccessChain %_ptr_Private_float %x_GLF_color %uint_2
OpStore %112 %110
OpBranch %107
%107 = OpLabel
OpReturn
OpFunctionEnd
%tint_symbol_3 = OpFunction %void None %113
%tint_symbol_1 = OpFunctionParameter %main_out
%117 = OpLabel
%118 = OpCompositeExtract %v4float %tint_symbol_1 0
OpStore %tint_symbol_2 %118
OpReturn
OpFunctionEnd
%main = OpFunction %void None %15
%120 = OpLabel
%121 = OpLoad %v4float %tint_symbol
OpStore %gl_FragCoord %121
%122 = OpFunctionCall %void %main_1
%124 = OpLoad %v4float %x_GLF_color
%125 = OpCompositeConstruct %main_out %124
%123 = OpFunctionCall %void %tint_symbol_3 %125
OpReturn
OpFunctionEnd
%alwaysZero_vf2_ = OpFunction %int None %126
%coord = OpFunctionParameter %_ptr_Function_v2float
%129 = OpLabel
%a = OpVariable %_ptr_Function_float Function %21
%x_110 = OpVariable %_ptr_Function_float Function %21
%b = OpVariable %_ptr_Function_float Function %21
%134 = OpAccessChain %_ptr_Function_float %coord %uint_1
%135 = OpLoad %float %134
%136 = OpFOrdLessThan %bool %135 %float_50
OpSelectionMerge %137 None
OpBranchConditional %136 %138 %139
%138 = OpLabel
%140 = OpAccessChain %_ptr_Uniform_float %x_9 %uint_0 %uint_1
%141 = OpLoad %float %140
OpStore %x_110 %141
OpBranch %137
%139 = OpLabel
OpStore %x_110 %float_0
OpBranch %137
%137 = OpLabel
%142 = OpLoad %float %x_110
OpStore %a %142
%143 = OpAccessChain %_ptr_Private_float %gl_FragCoord %uint_1
%144 = OpLoad %float %143
%146 = OpFOrdLessThan %bool %144 %float_50
%145 = OpSelect %float %146 %float_1 %float_0
OpStore %b %145
%147 = OpFSub %float %142 %145
%148 = OpFOrdLessThan %bool %147 %float_1
OpSelectionMerge %149 None
OpBranchConditional %148 %150 %149
%150 = OpLabel
OpReturnValue %int_0
%149 = OpLabel
OpReturnValue %int_1
OpFunctionEnd