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

struct <fun>Output conflicts with fn <fun> on Metal #6439

Closed
Jengamon opened this issue Oct 22, 2024 · 2 comments · Fixed by #6438
Closed

struct <fun>Output conflicts with fn <fun> on Metal #6439

Jengamon opened this issue Oct 22, 2024 · 2 comments · Fixed by #6438
Assignees

Comments

@Jengamon
Copy link

Description
Naga fails to rename a shader variable named "vsOutput", causing failures in shaders that use the name.

Repro steps
(at least, this works on latest MacOS, and does not repro on WASM)
(taken from https://webgpufundamentals.org/webgpu/lessons/webgpu-inter-stage-variables.html)

struct VertexOutput {
    @builtin(position) position: vec4f,
    @location(0) color: vec4f,
};

@vertex fn vs(
    @builtin(vertex_index) vertexIndex : u32
) -> VertexOutput {
    var pos = array(
        vec2f( 0.0,  0.5), // top center
        vec2f(-0.5, -0.5), // bottom left
        vec2f( 0.5, -0.5)  // bottom right
    );
    var color = array<vec4f, 3>(
        vec4f(1, 0, 0, 1), // red
        vec4f(0, 1, 0, 1), // green
        vec4f(0, 0, 1, 1), // blue
    );

    var vsOutput: VertexOutput;
    vsOutput.position = vec4f(pos[vertexIndex], 0.0, 1.0);
    vsOutput.color = color[vertexIndex];
    return vsOutput;
}

@fragment fn fs(fsInput: VertexOutput) -> @location(0) vec4f {
    return fsInput.color;
}
  1. setup a program using the above shader
  2. attempt to run the program and observe the crash

Expected vs observed behavior
Expected for the shader to compile and run.

Observed an error due to invalid types in shader.

Extra materials
cwfitzgerald told me to make this issue so here I am.

Platform
OS: MacOS 15.0.1
wgpu: 22.1.0

@Jengamon
Copy link
Author

After a bit more investigation, I've found that the actual thing problematic variable name is <function name>Output, and vsOutput is only problematic inside a function named vs (vsyOutput is problematic in function vsy, etc.)

@ErichDonGubler
Copy link
Member

ErichDonGubler commented Oct 22, 2024

Literally just barely solved this in #6438. 🙌🏻😤

Also, welcome the community! Thanks for taking the time to file. 🙂

@github-project-automation github-project-automation bot moved this from Todo to Done in WebGPU for Firefox Oct 22, 2024
@ErichDonGubler ErichDonGubler self-assigned this Oct 22, 2024
@ErichDonGubler ErichDonGubler changed the title vsOutput needs to be added to the list of excluded names struct <fun>Output conflicts with fn <fun> on Metal Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants