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 @location attribute not emitted for entry-point varyings #5933

Open
meggsOmatic opened this issue Dec 22, 2024 · 0 comments · May be fixed by #5937
Open

wgsl @location attribute not emitted for entry-point varyings #5933

meggsOmatic opened this issue Dec 22, 2024 · 0 comments · May be fixed by #5937

Comments

@meggsOmatic
Copy link

I'm trying to slang-ify a very simple slang "hello triangle" example flor WebGPU, targeting WGSL. Here's the minimal slang shader:

struct VertexOutput {
    float4 clipPos : SV_POSITION;
    float3 color;
}

[shader("vertex")]
func vertexMain(float3 pos: POSITION, float3 color: COLOR0)->VertexOutput {
    VertexOutput out;
    out.clipPos = float4(pos, 1.0);
    out.color = color;
    return out;
}

I compile it on the 2024.17 release using this command:

.\bin\slangc.exe shaders.slang -target wgsl -entry vertexMain -o ..\src\vertex.wgsl

And then I get this invalid WGSL as the output:

struct VertexOutput_0
{
    @builtin(position) clipPos_0 : vec4<f32>,
    @location(0) color_0 : vec3<f32>,
};

@vertex
fn vertexMain( pos_0 : vec3<f32>,  color_1 : vec3<f32>) -> VertexOutput_0
{
    var out_0 : VertexOutput_0;
    out_0.clipPos_0 = vec4<f32>(pos_0, 1.0f);
    out_0.color_0 = color_1;
    return out_0;
}

This fails to compile in WGSL with the error:

      Entry point vertexMain at Vertex is invalid
        Argument 0 varying error
          Entry point arguments and return values must all have bindings

If I manually edit the WGSL to add @location attributes, it's fine:

fn vertexMain( @location(0) pos_0 : vec3<f32>,  @location(1) color_1 : vec3<f32>) -> VertexOutput_0

Note that if I instead use an input structure instead of entry parameters, the wgsl @location attributes are correctly emitted. The problem is specific to entry parameters. Here's some slang using an input struct:

struct VertexInput {
    float3 pos : POSITION;
    float3 color : COLOR0;
}

struct VertexOutput {
    float4 clipPos : SV_POSITION;
    float3 color;
}

[shader("vertex")]
func vertexMain(VertexInput v)->VertexOutput {
    VertexOutput out;
    out.clipPos = float4(v.pos, 1.0);
    out.color = v.color;
    return out;
}

And here's the valid WGSL it produces. Note the @location attributes correctly applied to the members of VertexInput_0:

struct VertexOutput_0
{
    @builtin(position) clipPos_0 : vec4<f32>,
    @location(0) color_0 : vec3<f32>,
};

struct VertexInput_0
{
    @location(0) pos_0 : vec3<f32>,
    @location(1) color_1 : vec3<f32>,
};

@vertex
fn vertexMain( v_0 : VertexInput_0) -> VertexOutput_0
{
    var out_0 : VertexOutput_0;
    out_0.clipPos_0 = vec4<f32>(v_0.pos_0, 1.0f);
    out_0.color_0 = v_0.color_1;
    return out_0;
}
@fairywreath fairywreath linked a pull request Dec 24, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant