naga icon indicating copy to clipboard operation
naga copied to clipboard

[hlsl-out] Can't fall through case/default unless case/default has no code

Open hasali19 opened this issue 2 years ago • 1 comments

WGSL:

@group(0)
@binding(0)
var<uniform> u: i32;

@compute
@workgroup_size(1)
fn main() {
    switch (u) {
        case 0: {
            switch (u) {
                case 0: {}
                default: {}
            }
        }
        default: {}
    }
}

HLSL:

cbuffer u : register(b0) { int u; }

[numthreads(1, 1, 1)]
void main()
{
    int _expr1 = u;
    switch(_expr1) {
        case 0: {
            int _expr2 = u;
            switch(_expr2) {
                case 0: {
                    return;
                }
                default: {
                    return;
                }
            }
            break;
        }
        default: {
            return;
        }
    }
}

This gives an interesting error:

 error X8000: D3D11 Internal Compiler Error: Invalid Bytecode: Can't fall through case/default unless case/default has no code. Opcode #12 (count 1-based). Aborting validation.
error X8000: D3D11 Internal Compiler Error: Invalid Bytecode: Can't continue validation - aborting.

Might be a weird FXC issue.

hasali19 avatar Jun 06 '22 16:06 hasali19

Looks like another weird FXC error. If you replace the return with a break then it stops complaining...

cbuffer u : register(b0) { int u; }

[numthreads(1, 1, 1)]
void main()
{
    int _expr1 = u;
    switch(_expr1) {
        case 0: {
            int _expr2 = u;
            switch(_expr2) {
                case 0: {
                    return; // <- here
                }
                default: {
                    return;
                }
            }
            break;
        }
        default: {
            return;
        }
    }
}

teoxoy avatar Jun 13 '22 14:06 teoxoy