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

[wgsl-in] Parse error for subtraction in array index #4435

Closed
fintelia opened this issue May 22, 2023 · 2 comments · Fixed by #4870
Closed

[wgsl-in] Parse error for subtraction in array index #4435

fintelia opened this issue May 22, 2023 · 2 comments · Fixed by #4870
Labels
area: naga front-end lang: WGSL WebGPU Shading Language naga Shader Translator type: bug Something isn't working

Comments

@fintelia
Copy link
Contributor

This shader:

var<workgroup> a: array<u32, 64>;

fn foo() {
    let x = 1;
    let y = a[x-1];
}

Produces this error:

error: expected ']', found '-1'
  ┌─ a.wgsl:6:16
  │
6 │     let y = a[x-1];
  │                ^^ expected ']'

Could not parse WGSL
@jimblandy
Copy link
Member

The issue here is that Naga treats -1 as a token, not an application of a unary - operator to the literal 1, so the expression is sort of like a[x 7]. This used to be standard behavior, but the WGSL specification changed.

@cwfitzgerald cwfitzgerald transferred this issue from gfx-rs/naga Oct 25, 2023
@cwfitzgerald cwfitzgerald added naga Shader Translator type: bug Something isn't working and removed kind: bug labels Oct 25, 2023
@teoxoy teoxoy added this to the WebGPU Specification V1 milestone Nov 3, 2023
@jimblandy
Copy link
Member

jimblandy commented Dec 13, 2023

This will be fixed by #4870.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: naga front-end lang: WGSL WebGPU Shading Language naga Shader Translator type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants