NVidia Interface Block Bug?

I’m been experimenting with interface blocks and I’m trying to determine if the following is valid GLSL because it doesn’t work on a NVidia Geforce 480 with 256.53 drivers. If I change both “varOUT” and “varIN” to the same identifier, e.g. “var”, then it works.

Vertex Shader:


#version 330

uniform mat4 ModelView;
uniform mat4 Projection;

struct VaryingStruct
{
 vec4 color;
};

out VaryingIB
{
  VaryingStruct varOUT;
};

in vec3 Position;

void main()
{
  gl_Position = Projection * ModelView * vec4(Position, 1);
  varOUT.color = vec4(1, 0, 0, 1);
}


Fragment Shader:


#version 330

struct VaryingStruct
{
 vec4 color;
};

in VaryingIB
{
  VaryingStruct varIN;
};

out vec4 fragData;

void main()
{
  fragData = varIN.color;
}

This is not valid GLSL. in/out blocks must match completely (names, types, order).

You’re correct. From the spec:

“Matched block names within an interface (as defined above) must match in terms of having the same
number of declarations with the same sequence of types and the same sequence of member names…”

So Alfonse was mistaken.
Interface Block Post

However, the spec also says:
“Any mismatch will generate a link error.”
So, the Nvidia driver should have given me an error. :frowning:

So Alfonse was mistaken.
Interface Block Post

I wasn’t talking about member names. Obviously member names have to match. I was talking about interface block names. And even those have to match. I was specifically saying that you can have two interface blocks in the same shader with the same block name, so long as they have different scope names.

Seems like you contradicted yourself…

So, returning to what I think Sir Hampster was trying to do, does GLSL provide a way to use layout blocks like Cg uses interface blocks?

For example: OUT.color = IN.color, where IN and OUT are interface blocks/layouts/etc. Where you’d call the vertex output varyings by OUT in the vert shader and IN in the frag shader.

Complete (but short) vtx shader example:

Wikipedia:Cg (programming language)#A sample Cg vertex shader


 // input vertex
 struct VertIn {
     float4 pos   : POSITION;
     float4 color : COLOR0;
 };
 
 // output vertex
 struct VertOut {
     float4 pos   : POSITION;
     float4 color : COLOR0;
 };
 
 // vertex shader main entry
 VertOut main(VertIn IN, uniform float4x4 modelViewProj) {
     VertOut OUT;
     OUT.pos     = mul(modelViewProj, IN.pos); // calculate output coords
     OUT.color   = IN.color; // copy input color to output
     OUT.color.z = 1.0f; // blue component of color = 1.0f
     return OUT;
 }

Or do you end up just having to call them by the same name in vtx and frag shader.

Thought I’d ask because I always thought the Cg method was very readable.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.