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

Allow pipeline-overridable constants in structs with fixed sized arrays #7078

Open
shadowcatzero opened this issue Feb 7, 2025 · 3 comments
Labels
area: validation Issues related to validation, diagnostics, and error handling kind: diagnostics Error message should be better type: enhancement New feature or request

Comments

@shadowcatzero
Copy link

Hello, it appears that pipeline-overridable constants cannot be used in structs / type definitions.

Is your feature request related to a problem? Please describe.

Given the following code:

override TEST: u32 = 8;
struct Test {
    test: array<u32, TEST>,
}

The following error is produced:

Shader validation error: Type [10] 'Test' is invalid
    ┌─ compute:300:1
    │  
300 │ ╭ struct Test {
301 │ │     test: array<u32, TEST>,
    │ ╰──────────────────────────^ naga::Type [10]
    │  
    = Expected data type, found [9]


      Type [10] 'Test' is invalid
        Expected data type, found [9]

Describe the solution you'd like
I'd like to be able to use pipeline-overridable constants in struct definitions. I'm not sure if this is expected or not considering I can see it working differently underneath; you'd have to recompile all of the types depending on the "source" type. But it seems to be a bug considering they can be used elsewhere, and I couldn't find any other issues about this. If I declare a constant sized array in a function with a let statement it works as expected.

Describe alternatives you've considered
Find and replacing does work, but it seems weird to only have to do it for struct definitions; this would be more convenient.

Additional context
wgpu version is 24.0.1

Thanks for adding more support for them recently!

@jimblandy
Copy link
Member

We think the WGSL spec doesn't actually support override-sized arrays in structs... right???

Marking "out of scope" for Firefox's purposes, but if you think this is wrong, please let us know.

@cwfitzgerald cwfitzgerald added type: enhancement New feature or request area: api Issues related to API surface naga Shader Translator area: naga front-end lang: WGSL WebGPU Shading Language labels Feb 11, 2025
@shadowcatzero
Copy link
Author

After looking into it, I believe you're correct. It says that arrays in structs must have a "creation-fixed footprint", which means it must have "a size that is fully determined at shader creation time". And override declarations are fixed at pipeline creation time, which is after shader creation time, so later than they'd need to be fixed. Considering that, I think it's perfectly reasonable to leave it as is, it would just be convenient to have a method to recreate the shader to change a struct. Assuming this is not implemented, I think a more clear error would be nice, like "Type array<u32, TEST> does not have a creation-fixed footprint, but is used in a struct". Although it seems like naga's error reporting could use other improvement first. Thanks for the response!

@cwfitzgerald cwfitzgerald added area: validation Issues related to validation, diagnostics, and error handling kind: diagnostics Error message should be better and removed area: api Issues related to API surface naga Shader Translator area: naga front-end lang: WGSL WebGPU Shading Language labels Feb 20, 2025
@cwfitzgerald
Copy link
Member

cwfitzgerald commented Feb 20, 2025

Moving this to a diagnostics issue then :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: validation Issues related to validation, diagnostics, and error handling kind: diagnostics Error message should be better type: enhancement New feature or request
Projects
Status: Todo
Development

No branches or pull requests

3 participants