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

Support Constants in Enum Cases #2106

Closed
ethereumdegen opened this issue Oct 27, 2022 · 4 comments · Fixed by #2309
Closed

Support Constants in Enum Cases #2106

ethereumdegen opened this issue Oct 27, 2022 · 4 comments · Fixed by #2309
Labels
area: front-end Input formats for conversion kind: feature New feature or request lang: WGSL WebGPU shading language

Comments

@ethereumdegen
Copy link

ethereumdegen commented Oct 27, 2022

This is my shader file:


let TEXTURE_KIND_REGULAR:i32 = 0;
let TEXTURE_KIND_WARP:i32 = 1;
let TEXTURE_KIND_SKY:i32 = 2; 
.....

@fragment
fn main_fs(vertex: VertexOutput) -> FragmentOutput {
   
    var result: FragmentOutput;

       switch (push_constants.texture_kind) {
        case TEXTURE_KIND_REGULAR:
.....

That throws this error:


 case TEXTURE_KIND_REGULAR:
    │              ^^^^^^^^^^^^^^^^^^^^ expected unsigned/signed integer literal


    expected unsigned/signed integer literal, found 'TEXTURE_KIND_REGULAR'

Now.. i could be doing something wrong here but this is VERY confusing and there are not any good docs i can find about this.

my 'let' vars should work for a switch case --- no ?

@ethereumdegen
Copy link
Author

is there a better way to define an immutable constant ?

@cwfitzgerald
Copy link
Member

Right now this isn't possible because we haven't implemented const yet, which is how you would implement this in upstream wgsl. If you want this to work that, you need to put literals right on the cases. A preprocessor could help with that.

@cwfitzgerald cwfitzgerald changed the title expected unsigned/signed integer literal Support Constants in Enum Cases Oct 28, 2022
@cwfitzgerald
Copy link
Member

Dependent on #97

@cwfitzgerald cwfitzgerald added lang: WGSL WebGPU shading language area: front-end Input formats for conversion kind: feature New feature or request labels Oct 28, 2022
@armansito
Copy link
Contributor

Supporting this would be a huge quality of life improvement. In vello, we have to keep multiple files in sync as we can't reference const declarations in switch statements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: front-end Input formats for conversion kind: feature New feature or request lang: WGSL WebGPU shading language
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants