Files
wgpu/naga/tests/out/msl/control-flow.msl
T
Jamie Nicol 6a61e62f55 [naga wgsl-in] Handle automatic type conversions for switch selector and case expressions (#7250)
This allows abstract-typed expressions to be used for some or all of
the switch selector and case selectors. If these are all not
convertible to the same concrete scalar integer type we return an
error. If all the selector expressions are abstract then they are
concretized to i32.

The note previously provided by the relevant error message, suggesting
adding or removing the `u` suffix from case values, has been
removed. While useful for simple literal values, it was comically
incorrect for more complex case expressions. The error message should
still be useful enough to allow the user to easily identify the
problem.
2025-03-07 03:50:36 +00:00

288 lines
5.9 KiB
Plaintext

// language: metal1.2
#include <metal_stdlib>
#include <simd/simd.h>
using metal::uint;
void switch_default_break(
int i
) {
switch(i) {
default: {
break;
}
}
}
void switch_case_break(
) {
switch(0) {
case 0: {
break;
}
default: {
break;
}
}
return;
}
void switch_selector_type_conversion(
) {
switch(0u) {
case 0u: {
break;
}
default: {
break;
}
}
switch(0u) {
case 0u: {
return;
}
default: {
return;
}
}
}
void switch_const_expr_case_selectors(
) {
switch(0) {
case 0: {
return;
}
case 1: {
return;
}
case 2: {
return;
}
case 3: {
return;
}
case 4: {
return;
}
default: {
return;
}
}
}
void loop_switch_continue(
int x
) {
uint2 loop_bound = uint2(0u);
while(true) {
if (metal::all(loop_bound == uint2(4294967295u))) { break; }
loop_bound += uint2(loop_bound.y == 4294967295u, 1u);
switch(x) {
case 1: {
continue;
}
default: {
break;
}
}
}
return;
}
void loop_switch_continue_nesting(
int x_1,
int y,
int z
) {
uint2 loop_bound_1 = uint2(0u);
while(true) {
if (metal::all(loop_bound_1 == uint2(4294967295u))) { break; }
loop_bound_1 += uint2(loop_bound_1.y == 4294967295u, 1u);
switch(x_1) {
case 1: {
continue;
}
case 2: {
switch(y) {
case 1: {
continue;
}
default: {
uint2 loop_bound_2 = uint2(0u);
while(true) {
if (metal::all(loop_bound_2 == uint2(4294967295u))) { break; }
loop_bound_2 += uint2(loop_bound_2.y == 4294967295u, 1u);
switch(z) {
case 1: {
continue;
}
default: {
break;
}
}
}
break;
}
}
break;
}
default: {
break;
}
}
switch(y) {
default: {
continue;
}
}
}
uint2 loop_bound_3 = uint2(0u);
while(true) {
if (metal::all(loop_bound_3 == uint2(4294967295u))) { break; }
loop_bound_3 += uint2(loop_bound_3.y == 4294967295u, 1u);
switch(y) {
case 1:
default: {
switch(z) {
default: {
continue;
}
}
break;
}
}
}
return;
}
void loop_switch_omit_continue_variable_checks(
int x_2,
int y_1,
int z_1,
int w
) {
int pos_1 = 0;
uint2 loop_bound_4 = uint2(0u);
while(true) {
if (metal::all(loop_bound_4 == uint2(4294967295u))) { break; }
loop_bound_4 += uint2(loop_bound_4.y == 4294967295u, 1u);
switch(x_2) {
case 1: {
pos_1 = 1;
break;
}
default: {
break;
}
}
}
uint2 loop_bound_5 = uint2(0u);
while(true) {
if (metal::all(loop_bound_5 == uint2(4294967295u))) { break; }
loop_bound_5 += uint2(loop_bound_5.y == 4294967295u, 1u);
switch(x_2) {
case 1: {
break;
}
case 2: {
switch(y_1) {
case 1: {
continue;
}
default: {
switch(z_1) {
case 1: {
pos_1 = 2;
break;
}
default: {
break;
}
}
break;
}
}
break;
}
default: {
break;
}
}
}
return;
}
struct main_Input {
};
kernel void main_(
metal::uint3 global_id [[thread_position_in_grid]]
) {
int pos = {};
metal::threadgroup_barrier(metal::mem_flags::mem_device);
metal::threadgroup_barrier(metal::mem_flags::mem_threadgroup);
metal::threadgroup_barrier(metal::mem_flags::mem_texture);
switch(1) {
default: {
pos = 1;
break;
}
}
int _e4 = pos;
switch(_e4) {
case 1: {
pos = 0;
break;
}
case 2: {
pos = 1;
break;
}
case 3:
case 4: {
pos = 2;
break;
}
case 5: {
pos = 3;
break;
}
default:
case 6: {
pos = 4;
break;
}
}
switch(0u) {
case 0u: {
break;
}
default: {
break;
}
}
int _e11 = pos;
switch(_e11) {
case 1: {
pos = 0;
break;
}
case 2: {
pos = 1;
return;
}
case 3: {
pos = 2;
return;
}
case 4: {
return;
}
default: {
pos = 3;
return;
}
}
}