wgpu icon indicating copy to clipboard operation
wgpu copied to clipboard

[hlsl-out] "continue cannot be used in a switch" within loop

Open hasali19 opened this issue 1 year ago • 1 comments

WGSL:

@compute
@workgroup_size(1)
fn main() {
    loop {
        switch (0) {
            default: {
                continue;
            }
        }
    }
}

HLSL:

[numthreads(1, 1, 1)]
void main()
{
    while(true) {
        switch(0) {
            default: {
                continue;
            }
        }
    }
    return;
}

The generated HLSL is rejected by FXC with the following error:

error X3708: continue cannot be used in a switch

I guess the continue would need to be compiled down to e.g. a flag that conditionally executes the remainder of the loop.

hasali19 avatar Mar 19 '23 21:03 hasali19

Another variant of this.

WGSL:

    var i = 0;
    loop {
        if i > 4 { break; }
        i = i + 1;
        switch 0 {
            case 0, default {
                continue;
            }
        }
    }

HLSL:

    int i = 0;

    while(true) {
        int _expr2 = i;
        if ((_expr2 > 4)) {
            break;
        }
        int _expr5 = i;
        i = (_expr5 + 1);
        switch(0) {
            case 0:
            default: {
                continue;
            }
        }
    }

will have this error:

 error X3533: non-empty case statements must have break or return

Imberflur avatar Apr 30 '24 05:04 Imberflur