这是indexloc提供的服务,不要输入任何密码
Skip to content

[wgsl] propose switch-case permit multiple literal values per case #630

@dneto0

Description

@dneto0

Right now the case statement allows matching only one literal value:

  const x_9 : u32 = w;
  switch (x_9) {
    default: {
      w = 10;
    }
    case 0: {
      w = 1;
    }
    case 1: {
      w = 2;
    }
    case 5: {
      fallthrough;
    }
    case 6: {
      w = 6;
    }
  }

In this example, both the 5 and 6 cases should do the same thing. I propose that we be able to list multiple values per case statement, like this:

  const x_9 : u32 = w;
  switch (x_9) {
    default: {
      w = 10;
    }
    case 0: {
      w = 1;
    }
    case 1: {
      w = 2;
    }
    case 5, 6: {    // This is the changed line.
      w = 6;
    }
  }

This eliminates the need to write a bunch of boilerplate, namely { fallthrough; }

It's also easier to read, and to preserve in a round-trip with SPIR-V and LLVM. (In SPIR-V and LLVM, you can repeat the target block name for different case values.)

We would still retain the restriction that a case value may not appear in two different case statements for a particular switch construct.

Metadata

Metadata

Assignees

Labels

wgslWebGPU Shading Language Issueswgsl resolvedResolved - waiting for a change to the WGSL specification

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions