gfx-rs / wgpu

A cross-platform, safe, pure-Rust graphics API.
https://wgpu.rs
Apache License 2.0
11.46k stars 855 forks source link

Naga produces a reserved keyword when translating variable name `packed` to GLSL #5853

Closed kjarosh closed 5 days ago

kjarosh commented 1 week ago

Description

The following fragment of a WGSL shader:

fn unpack_components(packed: u32) -> vec2<u32> {
    return vec2<u32>(packed >> 8u, packed & 15u);
}

(Full shader: https://github.com/ruffle-rs/ruffle/blob/036839fb1f382852711e0c1e270fa3e69a3a540a/render/wgpu/shaders/filter/displacement_map.wgsl)

sometimes fails with error: syntax error, unexpected PACKED_TOK, expecting ')' (Linux) or 'packed' : reserved word ERROR: 0:42: 'packed' : syntax error syntax error (Windows) on Open GL.

Repro steps

Use a variable packed in a WGSL shader and try to compile it using Open GL backend on a device where packed is a reserved keyword (I have no idea when packed is a keyword, it works for some people, for some doesn't).

Expected vs observed behavior

The shader should always work without syntax errors.

Extra materials

Bugs reported for Ruffle with this issue: https://github.com/ruffle-rs/ruffle/issues/12844, https://github.com/ruffle-rs/ruffle/issues/16642.

A screenshot pasted at Ruffle's Discord:

My workaround that turned out to work:

Platform

I personally cannot reproduce it as Open GL does not work on my platform, but platform information is included in the issues referenced above.

cwfitzgerald commented 1 week ago

If you're down for a PR, it just needs to be added to this list: https://github.com/gfx-rs/wgpu/blob/trunk/naga/src/back/glsl/keywords.rs#L1