Skip to content

flags: support flags that are just combinations of other flags, not taking a new bit. #660

@programmerjake

Description

@programmerjake

This came up in WebAssembly/wasi-webgpu#71 (comment)

where WebGpu has a C definition:
https://github.com/webgpu-native/webgpu-headers/blob/bf8ddb91dc38ea11ec1b727dae1fa965c4207d22/webgpu.h#L1334

/**
 * `Red | Green | Blue | Alpha`.
 */
static const WGPUColorWriteMask WGPUColorWriteMask_All = 0x000000000000000F;

the generated WIT in WebAssembly/wasi-webgpu#71 as of writing is:

flags gpu-color-write {
    red,
    green,
    blue,
    alpha,
    all,
}

which is incorrect in that all shouldn't be a new flag, just a shorthand for a combination of all the other flags.

I think WIT should be changed to allow expressing named flag values that are just combinations of zero or more existing flags by allowing assigning flag values to either 0 or the bitwise or of one or more other named flags:

flags colors {
    black = 0,
    red,
    green,
    yellow = red | green,
    blue,
    magenta = red | blue,
    purple = magenta,
    cyan = green | blue,
    white = red | green | blue,
}

note: I'm not planning on implementing this myself, so whoever's interested feel free to implement it whenever ready.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions