Pass-through geometry shader warning

Hello,

I am using the following geometry shader:


#version 150 

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

void main()
{
    for(int i = 0; i < gl_in.length(); ++i)
    {
        gl_Position = gl_in[i].gl_Position;
        EmitVertex();
    }
    EndPrimitive();
}

It compiles and links without error, and runs correctly. When I query the log, using glGetProgramInfoLog, it contains the following warning:

Geometry info

0(21) : warning C7050: “gl_Position” might be used before being initialized

It is referring to the gl_Position on the left-hand side of the equals operator, since if I replace that with “vec4 foo”, there are no warnings. I am using gl_Position in the same manner as every geometry shader example I’ve come across. Do you know what I’m doing wrong or any workarounds?

I am running on NVIDIA GeoForce 8 with 195.62 drivers.

Thanks,
Patrick

The same warning…Someone can help?

Not certain, but what if you declare “i” outside the forloop and change ++i to i++, as in


    int i;
    for(i = 0; i < gl_in.length(); i++)
    {

Probably a non-issue but worth a try :wink:

Note, I saw this change based on the geometry shader tutorial here.

As you expected, this change doesn’t help.

Regards,
Patrick

Perhaps I should ask if anyone can share a pass-through geometry shader that doesn’t have this warning in glGetProgramInfoLog? Maybe this is only present on NVIDIA?

Thanks,
Patrick

What appears to me might be the issue is that if gl_in.length() == 0, gl_Position will never be set.
As a blindfold shot over the shoulder, might try initializing gl_Position “before” the loop.

That is a pretty good blindfold shot. Adding “gl_Position = vec4(0);” before the for loop eliminates the warning. I bet the optimizer will be able to get rid of this line since gl_Position is written again before the first call to EmitVertex(), making this assignment to gl_Position unnecessary.

I’m not thrilled with this but it gets the job done. Thanks again!

Regards,
Patrick

Is it actually possible for gl_in.length() to be zero in a geometry shader? Wouldn’t that mean a glDraw call with 0 elements, and thus no need to invoke the pipeline?