Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: "enum" support in WGSL #4856

Open
magcius opened this issue Sep 6, 2024 · 2 comments
Open

Feature request: "enum" support in WGSL #4856

magcius opened this issue Sep 6, 2024 · 2 comments
Labels
wgsl WebGPU Shading Language Issues
Milestone

Comments

@magcius
Copy link

magcius commented Sep 6, 2024

This might be supplanted by other features, but it would be helpful to have some form of basic enum syntax to declare integer constants. A very basic strawman is below:

enum BlendMode {
    Normal = 1,
    Add,
    Subtract,
    Multiply,
    Overlay,
    HardLight,
};

struct BlendParams {
    blend_mode: BlendMode, // the same size as a u32,
};

Alternatively, if we had support for user namespaces, we could use const statements to declare u32 variables inside a namespace; this loses the ability to have enums as a separate "type" that can be embedded in structs and passed to functions, but it would be OK to start with.

@dneto0 dneto0 added the wgsl WebGPU Shading Language Issues label Sep 6, 2024
@mwyrzykowski
Copy link

I guess my only question right now is we would need to know the size of the enum. u32 would be fine, if we want to limit the values to u32. Or u32 by default unless the enum uses values exceeding 2^32 - 1 or contains values < 0

@kdashg kdashg added this to the Milestone 3+ milestone Sep 17, 2024
@magcius
Copy link
Author

magcius commented Sep 19, 2024

u32 is the standard lingua franca of GPUs, and I would suggest starting with that as a default; if you want to add support for extending other types, I would be OK with syntax a la enum BlendMode : i8 or something like that. Having the type implicitly decided by value range is a classic C++ footgun that requires people to add MaxValueRange = 0xFFFFFFFF, to all enums to force the size.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wgsl WebGPU Shading Language Issues
Projects
None yet
Development

No branches or pull requests

4 participants