PDA

View Full Version : NVidia Interface Block Bug?



ViolentHamster
10-13-2010, 12:15 PM
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;
}

randall
10-13-2010, 01:55 PM
This is not valid GLSL. in/out blocks must match completely (names, types, order).

ViolentHamster
10-13-2010, 02:12 PM
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 (http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=283261&Searchpa ge=1&Main=54724&Words=interface+block&Search=true# Post283261)

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

Alfonse Reinheart
10-13-2010, 03:25 PM
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.

ViolentHamster
10-14-2010, 06:46 AM
I renamed some of the variables in the FS block; this is perfectly fine, because GLSL matches input/output blocks by the block name.


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.

Seems like you contradicted yourself...

Dark Photon
10-18-2010, 06:55 AM
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 (http://en.wikipedia.org/wiki/Cg_%28programming_language%29#A_sample_Cg_vertex_s hader)



// 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.