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>
This commit is contained in:
David Neto
2021-07-27 15:12:27 +00:00
committed by Tint LUCI CQ
parent 97668c8c37
commit dffa60ca98
128 changed files with 14973 additions and 16425 deletions

View File

@@ -1,9 +1,7 @@
SKIP: FAILED
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 63
; Bound: 60
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
@@ -56,9 +54,9 @@ SKIP: FAILED
%_ptr_Private_float = OpTypePointer Private %float
%float_0 = OpConstant %float 0
%false = OpConstantFalse %bool
%49 = OpConstantComposite %v4float %float_1 %float_0 %float_0 %float_1
%46 = OpConstantComposite %v4float %float_1 %float_0 %float_0 %float_1
%main_out = OpTypeStruct %v4float
%50 = OpTypeFunction %void %main_out
%47 = OpTypeFunction %void %main_out
%f_ = OpFunction %void None %15
%18 = OpLabel
OpBranch %19
@@ -86,40 +84,30 @@ SKIP: FAILED
%32 = OpLabel
OpKill
%21 = OpLabel
OpSelectionMerge %43 None
OpBranchConditional %false %44 %45
%44 = OpLabel
OpBranch %43
%45 = OpLabel
OpBranch %20
%43 = OpLabel
OpBranch %19
OpBranchConditional %false %19 %20
%20 = OpLabel
OpReturn
OpFunctionEnd
%main_1 = OpFunction %void None %15
%47 = OpLabel
%48 = OpFunctionCall %void %f_
OpStore %x_GLF_color %49
%44 = OpLabel
%45 = OpFunctionCall %void %f_
OpStore %x_GLF_color %46
OpReturn
OpFunctionEnd
%tint_symbol_3 = OpFunction %void None %50
%tint_symbol_3 = OpFunction %void None %47
%tint_symbol_1 = OpFunctionParameter %main_out
%54 = OpLabel
%55 = OpCompositeExtract %v4float %tint_symbol_1 0
OpStore %tint_symbol_2 %55
%51 = OpLabel
%52 = OpCompositeExtract %v4float %tint_symbol_1 0
OpStore %tint_symbol_2 %52
OpReturn
OpFunctionEnd
%main = OpFunction %void None %15
%57 = OpLabel
%58 = OpLoad %v4float %tint_symbol
OpStore %gl_FragCoord %58
%59 = OpFunctionCall %void %main_1
%61 = OpLoad %v4float %x_GLF_color
%62 = OpCompositeConstruct %main_out %61
%60 = OpFunctionCall %void %tint_symbol_3 %62
%54 = OpLabel
%55 = OpLoad %v4float %tint_symbol
OpStore %gl_FragCoord %55
%56 = OpFunctionCall %void %main_1
%58 = OpLoad %v4float %x_GLF_color
%59 = OpCompositeConstruct %main_out %58
%57 = OpFunctionCall %void %tint_symbol_3 %59
OpReturn
OpFunctionEnd
1:1: The continue construct with the continue target 21[%21] is not post dominated by the back-edge block 43[%43]
%43 = OpLabel

View File

@@ -1,9 +1,7 @@
SKIP: FAILED
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 63
; Bound: 60
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
@@ -56,9 +54,9 @@ SKIP: FAILED
%_ptr_Private_float = OpTypePointer Private %float
%float_0 = OpConstant %float 0
%false = OpConstantFalse %bool
%49 = OpConstantComposite %v4float %float_1 %float_0 %float_0 %float_1
%46 = OpConstantComposite %v4float %float_1 %float_0 %float_0 %float_1
%main_out = OpTypeStruct %v4float
%50 = OpTypeFunction %void %main_out
%47 = OpTypeFunction %void %main_out
%f_ = OpFunction %void None %15
%18 = OpLabel
OpBranch %19
@@ -86,40 +84,30 @@ SKIP: FAILED
%32 = OpLabel
OpKill
%21 = OpLabel
OpSelectionMerge %43 None
OpBranchConditional %false %44 %45
%44 = OpLabel
OpBranch %43
%45 = OpLabel
OpBranch %20
%43 = OpLabel
OpBranch %19
OpBranchConditional %false %19 %20
%20 = OpLabel
OpReturn
OpFunctionEnd
%main_1 = OpFunction %void None %15
%47 = OpLabel
%48 = OpFunctionCall %void %f_
OpStore %x_GLF_color %49
%44 = OpLabel
%45 = OpFunctionCall %void %f_
OpStore %x_GLF_color %46
OpReturn
OpFunctionEnd
%tint_symbol_3 = OpFunction %void None %50
%tint_symbol_3 = OpFunction %void None %47
%tint_symbol_1 = OpFunctionParameter %main_out
%54 = OpLabel
%55 = OpCompositeExtract %v4float %tint_symbol_1 0
OpStore %tint_symbol_2 %55
%51 = OpLabel
%52 = OpCompositeExtract %v4float %tint_symbol_1 0
OpStore %tint_symbol_2 %52
OpReturn
OpFunctionEnd
%main = OpFunction %void None %15
%57 = OpLabel
%58 = OpLoad %v4float %tint_symbol
OpStore %gl_FragCoord %58
%59 = OpFunctionCall %void %main_1
%61 = OpLoad %v4float %x_GLF_color
%62 = OpCompositeConstruct %main_out %61
%60 = OpFunctionCall %void %tint_symbol_3 %62
%54 = OpLabel
%55 = OpLoad %v4float %tint_symbol
OpStore %gl_FragCoord %55
%56 = OpFunctionCall %void %main_1
%58 = OpLoad %v4float %x_GLF_color
%59 = OpCompositeConstruct %main_out %58
%57 = OpFunctionCall %void %tint_symbol_3 %59
OpReturn
OpFunctionEnd
1:1: The continue construct with the continue target 21[%21] is not post dominated by the back-edge block 43[%43]
%43 = OpLabel