mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-20 22:41:07 +01:00
* Fix GLSL output for non-fallthrough switch cases
Partially reverts 02c74b5002 and
fixes #1309.
* Fix indentation of control-flow WGSL code
* Clean up glsl-out switch case fallthrough handling
Only insert a break if needed
and if a case is fallthrough, insert a comment indicating this.
81 lines
1.4 KiB
WebGPU Shading Language
81 lines
1.4 KiB
WebGPU Shading Language
[[stage(compute), workgroup_size(1)]]
|
|
fn main([[builtin(global_invocation_id)]] global_id: vec3<u32>) {
|
|
//TODO: execution-only barrier?
|
|
storageBarrier();
|
|
workgroupBarrier();
|
|
|
|
var pos: i32;
|
|
// switch without cases
|
|
switch (1) {
|
|
default: {
|
|
pos = 1;
|
|
}
|
|
}
|
|
|
|
// non-empty switch *not* in last-statement-in-function position
|
|
// (return statements might be inserted into the switch cases otherwise)
|
|
switch (pos) {
|
|
case 1: {
|
|
pos = 0;
|
|
break;
|
|
}
|
|
case 2: {
|
|
pos = 1;
|
|
}
|
|
case 3: {
|
|
pos = 2;
|
|
fallthrough;
|
|
}
|
|
case 4: {}
|
|
default: {
|
|
pos = 3;
|
|
}
|
|
}
|
|
|
|
// non-empty switch in last-statement-in-function position
|
|
switch (pos) {
|
|
case 1: {
|
|
pos = 0;
|
|
break;
|
|
}
|
|
case 2: {
|
|
pos = 1;
|
|
}
|
|
case 3: {
|
|
pos = 2;
|
|
fallthrough;
|
|
}
|
|
case 4: {}
|
|
default: {
|
|
pos = 3;
|
|
}
|
|
}
|
|
}
|
|
|
|
fn switch_default_break(i: i32) {
|
|
switch (i) {
|
|
default: {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
fn switch_case_break() {
|
|
switch(0) {
|
|
case 0: {
|
|
break;
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
|
|
fn loop_switch_continue(x: i32) {
|
|
loop {
|
|
switch (x) {
|
|
case 1: {
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
}
|