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

146 lines
5.6 KiB
Plaintext

; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 88
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %tint_symbol_1
OpExecutionMode %main OriginUpperLeft
OpName %buf0 "buf0"
OpMemberName %buf0 0 "x_GLF_uniform_int_values"
OpName %x_7 "x_7"
OpName %x_GLF_color "x_GLF_color"
OpName %tint_symbol_1 "tint_symbol_1"
OpName %func_ "func_"
OpName %i "i"
OpName %main_1 "main_1"
OpName %main_out "main_out"
OpMemberName %main_out 0 "x_GLF_color_1"
OpName %tint_symbol_2 "tint_symbol_2"
OpName %tint_symbol "tint_symbol"
OpName %main "main"
OpDecorate %buf0 Block
OpMemberDecorate %buf0 0 Offset 0
OpDecorate %_arr_int_uint_3 ArrayStride 16
OpDecorate %x_7 NonWritable
OpDecorate %x_7 DescriptorSet 0
OpDecorate %x_7 Binding 0
OpDecorate %tint_symbol_1 Location 0
OpMemberDecorate %main_out 0 Offset 0
%int = OpTypeInt 32 1
%uint = OpTypeInt 32 0
%uint_3 = OpConstant %uint 3
%_arr_int_uint_3 = OpTypeArray %int %uint_3
%buf0 = OpTypeStruct %_arr_int_uint_3
%_ptr_Uniform_buf0 = OpTypePointer Uniform %buf0
%x_7 = OpVariable %_ptr_Uniform_buf0 Uniform
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%_ptr_Private_v4float = OpTypePointer Private %v4float
%12 = OpConstantNull %v4float
%x_GLF_color = OpVariable %_ptr_Private_v4float Private %12
%_ptr_Output_v4float = OpTypePointer Output %v4float
%tint_symbol_1 = OpVariable %_ptr_Output_v4float Output %12
%15 = OpTypeFunction %int
%_ptr_Function_int = OpTypePointer Function %int
%20 = OpConstantNull %int
%uint_0 = OpConstant %uint 0
%int_0 = OpConstant %int 0
%_ptr_Uniform_int = OpTypePointer Uniform %int
%int_1 = OpConstant %int 1
%bool = OpTypeBool
%true = OpConstantTrue %bool
%int_2 = OpConstant %int 2
%void = OpTypeVoid
%48 = OpTypeFunction %void
%main_out = OpTypeStruct %v4float
%76 = OpTypeFunction %void %main_out
%func_ = OpFunction %int None %15
%17 = OpLabel
%i = OpVariable %_ptr_Function_int Function %20
%24 = OpAccessChain %_ptr_Uniform_int %x_7 %uint_0 %int_0
%25 = OpLoad %int %24
OpStore %i %25
OpBranch %26
%26 = OpLabel
OpLoopMerge %27 %28 None
OpBranch %29
%29 = OpLabel
%30 = OpLoad %int %i
%32 = OpIAdd %int %30 %int_1
OpStore %i %32
OpSelectionMerge %35 None
OpBranchConditional %true %36 %35
%36 = OpLabel
OpSelectionMerge %37 None
OpBranchConditional %true %38 %37
%38 = OpLabel
%40 = OpAccessChain %_ptr_Uniform_int %x_7 %uint_0 %int_2
%41 = OpLoad %int %40
OpReturnValue %41
%37 = OpLabel
OpBranch %35
%35 = OpLabel
OpBranch %28
%28 = OpLabel
%42 = OpLoad %int %i
%43 = OpAccessChain %_ptr_Uniform_int %x_7 %uint_0 %int_1
%44 = OpLoad %int %43
%45 = OpSLessThan %bool %42 %44
OpBranchConditional %45 %26 %27
%27 = OpLabel
%46 = OpAccessChain %_ptr_Uniform_int %x_7 %uint_0 %int_0
%47 = OpLoad %int %46
OpReturnValue %47
OpFunctionEnd
%main_1 = OpFunction %void None %48
%51 = OpLabel
%52 = OpFunctionCall %int %func_
%53 = OpAccessChain %_ptr_Uniform_int %x_7 %uint_0 %int_2
%54 = OpLoad %int %53
%55 = OpIEqual %bool %52 %54
OpSelectionMerge %56 None
OpBranchConditional %55 %57 %58
%57 = OpLabel
%59 = OpAccessChain %_ptr_Uniform_int %x_7 %uint_0 %int_2
%60 = OpLoad %int %59
%61 = OpAccessChain %_ptr_Uniform_int %x_7 %uint_0 %int_0
%62 = OpLoad %int %61
%63 = OpAccessChain %_ptr_Uniform_int %x_7 %uint_0 %int_0
%64 = OpLoad %int %63
%65 = OpAccessChain %_ptr_Uniform_int %x_7 %uint_0 %int_2
%66 = OpLoad %int %65
%67 = OpConvertSToF %float %60
%68 = OpConvertSToF %float %62
%69 = OpConvertSToF %float %64
%70 = OpConvertSToF %float %66
%71 = OpCompositeConstruct %v4float %67 %68 %69 %70
OpStore %x_GLF_color %71
OpBranch %56
%58 = OpLabel
%72 = OpAccessChain %_ptr_Uniform_int %x_7 %uint_0 %int_0
%73 = OpLoad %int %72
%74 = OpConvertSToF %float %73
%75 = OpCompositeConstruct %v4float %74 %74 %74 %74
OpStore %x_GLF_color %75
OpBranch %56
%56 = OpLabel
OpReturn
OpFunctionEnd
%tint_symbol_2 = OpFunction %void None %76
%tint_symbol = OpFunctionParameter %main_out
%80 = OpLabel
%81 = OpCompositeExtract %v4float %tint_symbol 0
OpStore %tint_symbol_1 %81
OpReturn
OpFunctionEnd
%main = OpFunction %void None %48
%83 = OpLabel
%84 = OpFunctionCall %void %main_1
%86 = OpLoad %v4float %x_GLF_color
%87 = OpCompositeConstruct %main_out %86
%85 = OpFunctionCall %void %tint_symbol_2 %87
OpReturn
OpFunctionEnd