Add break-if support.

This CL adds support for `break-if` to Tint.

Bug: tint:1633, tint:1451
Change-Id: I30dfd62a3e09255624ff76ebe0cdd3a3c7cf9c5f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/106420
Auto-Submit: Dan Sinclair <dsinclair@chromium.org>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: dan sinclair <dsinclair@google.com>
This commit is contained in:
dan sinclair
2022-10-20 22:45:50 +00:00
committed by Dawn LUCI CQ
parent f8c07d4753
commit b8b0c21918
49 changed files with 983 additions and 74 deletions

View File

@@ -1,3 +1,7 @@
bug/tint/1064.wgsl:12:9 warning: use of deprecated language feature: `break` must not be used to exit from a continuing block. Use break-if instead.
break;
^^^^^
void main() {
while (true) {
if (false) {

View File

@@ -1,3 +1,7 @@
bug/tint/1064.wgsl:12:9 warning: use of deprecated language feature: `break` must not be used to exit from a continuing block. Use break-if instead.
break;
^^^^^
void main() {
while (true) {
if (false) {

View File

@@ -1,3 +1,7 @@
bug/tint/1064.wgsl:12:9 warning: use of deprecated language feature: `break` must not be used to exit from a continuing block. Use break-if instead.
break;
^^^^^
#version 310 es
precision mediump float;

View File

@@ -1,3 +1,7 @@
bug/tint/1064.wgsl:12:9 warning: use of deprecated language feature: `break` must not be used to exit from a continuing block. Use break-if instead.
break;
^^^^^
#include <metal_stdlib>
using namespace metal;

View File

@@ -1,3 +1,7 @@
bug/tint/1064.wgsl:12:9 warning: use of deprecated language feature: `break` must not be used to exit from a continuing block. Use break-if instead.
break;
^^^^^
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0

View File

@@ -1,3 +1,7 @@
bug/tint/1064.wgsl:12:9 warning: use of deprecated language feature: `break` must not be used to exit from a continuing block. Use break-if instead.
break;
^^^^^
@fragment
fn main() {
loop {

View File

@@ -0,0 +1,14 @@
fn f() -> i32 {
var i : i32;
loop {
if (i > 4) {
return i;
}
continuing {
i = i + 1;
break if i == 4;
}
}
return i;
}

View File

@@ -0,0 +1,18 @@
[numthreads(1, 1, 1)]
void unused_entry_point() {
return;
}
int f() {
int i = 0;
while (true) {
if ((i > 4)) {
return i;
}
{
i = (i + 1);
if ((i == 4)) { break; }
}
}
return i;
}

View File

@@ -0,0 +1,18 @@
[numthreads(1, 1, 1)]
void unused_entry_point() {
return;
}
int f() {
int i = 0;
while (true) {
if ((i > 4)) {
return i;
}
{
i = (i + 1);
if ((i == 4)) { break; }
}
}
return i;
}

View File

@@ -0,0 +1,20 @@
#version 310 es
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void unused_entry_point() {
return;
}
int f() {
int i = 0;
while (true) {
if ((i > 4)) {
return i;
}
{
i = (i + 1);
if ((i == 4)) { break; }
}
}
return i;
}

View File

@@ -0,0 +1,17 @@
#include <metal_stdlib>
using namespace metal;
int f() {
int i = 0;
while (true) {
if ((i > 4)) {
return i;
}
{
i = as_type<int>((as_type<uint>(i) + as_type<uint>(1)));
if ((i == 4)) { break; }
}
}
return i;
}

View File

@@ -0,0 +1,53 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 29
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
OpExecutionMode %unused_entry_point LocalSize 1 1 1
OpName %unused_entry_point "unused_entry_point"
OpName %f "f"
OpName %i "i"
%void = OpTypeVoid
%1 = OpTypeFunction %void
%int = OpTypeInt 32 1
%5 = OpTypeFunction %int
%_ptr_Function_int = OpTypePointer Function %int
%11 = OpConstantNull %int
%int_4 = OpConstant %int 4
%bool = OpTypeBool
%int_1 = OpConstant %int 1
%unused_entry_point = OpFunction %void None %1
%4 = OpLabel
OpReturn
OpFunctionEnd
%f = OpFunction %int None %5
%8 = OpLabel
%i = OpVariable %_ptr_Function_int Function %11
OpBranch %12
%12 = OpLabel
OpLoopMerge %13 %14 None
OpBranch %15
%15 = OpLabel
%16 = OpLoad %int %i
%18 = OpSGreaterThan %bool %16 %int_4
OpSelectionMerge %20 None
OpBranchConditional %18 %21 %20
%21 = OpLabel
%22 = OpLoad %int %i
OpReturnValue %22
%20 = OpLabel
OpBranch %14
%14 = OpLabel
%23 = OpLoad %int %i
%25 = OpIAdd %int %23 %int_1
OpStore %i %25
%26 = OpLoad %int %i
%27 = OpIEqual %bool %26 %int_4
OpBranchConditional %27 %13 %12
%13 = OpLabel
%28 = OpLoad %int %i
OpReturnValue %28
OpFunctionEnd

View File

@@ -0,0 +1,14 @@
fn f() -> i32 {
var i : i32;
loop {
if ((i > 4)) {
return i;
}
continuing {
i = (i + 1);
break if (i == 4);
}
}
return i;
}