wgpu: Don't switch on a single constant in output consumed by FXC

glslc emits code like OpSwitch 0 for control flow reasons, for example when one branch ends with a OpKill: 20220604_02h00m28s_grim

this produces the rather dodgy glsl code:

switch(int(0u)) {
        default:
            ...
            if (((_e46.w * _e49.w) < 0.5)) {
                discard;
            } else {
                break;
            }
            break;
    }
}

On certain GPUs I’ve had this not render the fragment at all (need to double check).

Ideally we should check if there’s only one default case and just not produce the switch in that case.

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 1
  • Comments: 18 (18 by maintainers)

Most upvoted comments

oh no there are more switch related bugs in FXC https://bugs.chromium.org/p/tint/issues/detail?id=2126#c4

Is it worth opening an issue to track this?

We absolutely should have execution tests for these cases that force fxc

Seems like people have run into this with SPIRV-Cross as well https://github.com/KhronosGroup/SPIRV-Cross/issues/1402.

I think we should work around these cases in the backends.