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

Interface type mismatch error while using geometry shader in a graphics pipeline #2049

Open
DiligentGraphics opened this issue Jan 6, 2020 · 3 comments
Labels

Comments

@DiligentGraphics
Copy link

When creating a graphics pipeline with the shaders below, Vulkan validations layers from 1.1.130.0 SDK display the following error:

Vulkan debug message (validation): UNASSIGNED-CoreValidation-Shader-InterfaceTypeMismatch
Number of elements inside builtin block differ between stages (vertex shader 1 vs geometry shader 3).

Vertex shader:

#version 420 core
void main()
{
    vec4 Pos[2];
    Pos[0] = vec4(-0.5, -0.25, 0.0, 1.0);
    Pos[1] = vec4(+0.5, +0.25, 0.0, 1.0);
    gl_Position = Pos[gl_VertexIndex];
}

Geometry shader:

#version 420 core

layout (points) in;
layout (triangle_strip, max_vertices = 3) out;

layout(location = 0) out vec3 out_Color;

void main() {
    vec4 Pos[3];
    Pos[0] = vec4(-1.0, -1.0, 0.0, 1.0);
    Pos[1] = vec4( 0.0, +1.0, 0.0, 1.0);
    Pos[2] = vec4(+1.0, -1.0, 0.0, 1.0);

    vec3 Col[3];
    Col[0] = vec3(1.0, 0.0, 0.0);
    Col[1] = vec3(0.0, 1.0, 0.0);
    Col[2] = vec3(0.0, 0.0, 1.0);
     
    for (int i=0; i < 3; ++i)
    {
        gl_Position = vec4(Pos[i].xy * 0.5 + gl_in[0].gl_Position.xy, gl_in[0].gl_Position.zw);
        out_Color = Col[i];
        EmitVertex();
    }
    EndPrimitive();   
}

Fragment shader:

#version 420 core

layout(location = 0) in  vec3 in_Color;
layout(location = 0) out vec4 out_Color;

void main()
{
    out_Color = vec4(in_Color, 1.0);
}
@johnkslang
Copy link
Member

johnkslang commented Jan 13, 2020

The geometry shader takes a per-vertex array of anything from the vertex shader. You need a gl_Position for each vertex:

in gl_PerVertex {
    vec4 gl_Position;
    float gl_PointSize;
    float gl_ClipDistance[];
    float gl_CullDistance[];
} gl_in[];

(I don't know the exact thing triggering the error, but it does seem this misunderstanding exists in the shaders.)

@DiligentGraphics
Copy link
Author

@johnkslang Redeclaring the gl_in[] in the geometry shader, as well as gl_PerVertex blocks in the vertex shader makes no difference.

Can the error be related to the fact that the primitive topology is points, and the geometry shader expands every point into a triangle?

@johnkslang
Copy link
Member

I actually don't work on that validator, and maybe this bug should move there, but speculating a bit...

It seems like it thinks the geometry shader wants 3 elements per vertex (if you're still getting the same error message), and that implies an input primitive of triangles, which I obviously can't square with points.

I looked at the SPIR-V generated for your original post, and it shows an array of size 1 for the inputs, based on points.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant