gfx-rs / wgpu

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

[glsl-in] push constant in fragment shader compile failed #4478

Open Latias94 opened 1 year ago

Latias94 commented 1 year ago

shader.frag

#version 450

layout (location = 0) in vec3 fragColor;

layout (location = 0) out vec4 outColor;

layout (push_constant) uniform PushConstants {
    layout (offset = 64) float opacity;
} pcs;

void main() {
    outColor = vec4(fragColor, pcs.opacity);
}
❯ glslangValidator.exe -V .\shader.frag -o .\shader.frag.spv
.\shader.frag

❯ naga .\shader.frag .\shader.frag.spv
error: Expected Void, Struct or a type, found Layout
  ┌─ shader.frag:8:5
  │
8 │     layout (offset = 64) float opacity;
  │     ^^^^^^

Push constant in vertex shader compile successfully but not in fragment shader.

JCapucho commented 1 year ago

The glsl frontend currently doesn't parse type qualifiers for block declarations members

https://github.com/gfx-rs/naga/blob/0074c68ec4f435c5dc0ba6d62ff567c1f146e9ec/src/front/glsl/parser/declarations.rs#L618-L629

Push constant in vertex shader compile successfully but not in fragment shader.

I assume that the vertex shader doesn't have any decorations otherwise it should also not compile.

Latias94 commented 1 year ago

Is it a low priority TODO?

JCapucho commented 1 year ago

Is it a low priority TODO?

The glsl frontend is something I and others do on our free time, or they contribute to solve their specific needs, so there's no real priority between issues and new features.

But if you or someone else wants to try and fix it I'm happy to provide guidance :)