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

Can't redeclare gl_perVertex (for gl_ClipDistance as a passthrough) #1441

Closed
tfiner opened this issue Jul 12, 2018 · 9 comments
Closed

Can't redeclare gl_perVertex (for gl_ClipDistance as a passthrough) #1441

tfiner opened this issue Jul 12, 2018 · 9 comments

Comments

@tfiner
Copy link

tfiner commented Jul 12, 2018

Using glslangValidator, version 7.7.2776 and 7.8.2801 I get the following results:

Reproduction:

a.vert:

#version 150
out gl_PerVertex {
   vec4 gl_Position;
   float gl_ClipDistance[4];
};

b.geom:

#version 150
in gl_PerVertex {
   vec4 gl_Position;
   float gl_ClipDistance[4];
} gl_in[];

Observation:
The error is:

'built-in block redeclaration' : not supported for this version or the enabled extensions

Expectation:
My understanding is that redeclaring the gl_PerVertex is necessary to define the size of gl_ClipDistance, so I think that the code is correct and the compiler's error message is not. Further, the code does actually work on at least one system. ;)

Lastly, I see in the code with the error message that there's a call to profileRequires what looks like versions 320 and 410 of ES? I didn't see that in the documentation for gl_ClipDistance. Shouldn't it be version 130 for the vertex and 150 for the geometry?

@johnkslang
Copy link
Member

Redeclaring blocks needs GL_ARB_separate_shader_objects or #version 410.

@tfiner
Copy link
Author

tfiner commented Jul 12, 2018

I don't understand, it says on the documentation page for gl_ClipDistance that you need to redeclare it:
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/gl_ClipDistance.xhtml

Is there a way to pass through gl_ClipDistance in a geometry shader in 150?

From the 150 spec is says:

The gl_ClipDistance array is predeclared as unsized and must be sized by the shader either redeclaring it
with a size or indexing it only with integral constant expressions.

This implies a redeclaring of the interface block in order for the geometry shader to see the gl_ClipDistance array.

@johnkslang
Copy link
Member

I don't think you can redeclare blocks in base #version 150. This might work:

out float gl_ClipDistance[4];

Or, going to a higher #version, or using extensions.

Do you need #version 150? #version 150 was a complex juncture between blocks, redeclarations, SSO, extensions, and profiles in this space. If it is possible to get away from it, it would probably save time.

@tfiner
Copy link
Author

tfiner commented Jul 12, 2018

I found a workaround, by taking advantage of that other half of that clause "or indexing with integral constant expressions". It isn't ideal, but it works and compiles without warning or errors.

Your suggestion works fine in a vertex shader, but... there's an array for the geometry shader. That's the part that is causing me problems. Yeah I can't bump the version number.

@HorstBaerbel
Copy link

HorstBaerbel commented Mar 28, 2019

I have this for a 330 core shader:

#version 330 core
const int nrOfClipPlanes = 6;
uniform vec4 clipPlaneEquation[nrOfClipPlanes];
uniform bool clipPlaneEnabled[nrOfClipPlanes];

out gl_PerVertex {
	vec4 gl_Position;
	float gl_ClipDistance[nrOfClipPlanes];
};

void calculateClipDistances(vec4 position) {
	for (int i = 0; i < nrOfClipPlanes; i++) {
		gl_ClipDistance[i] = clipPlaneEnabled[i] ? dot(position, clipPlaneEquation[i]) : 1.0;
	}
}

uniform mat4 modelViewMatrix;
uniform mat4 projectionMatrix;
uniform mat3 normalMatrix;
uniform vec2 scalarRange;

in vec3 vertex0;
in float color0;
in vec3 normal0;

out float colorCoord;
out vec3 normal;
out vec3 vertexPos;

void main() {
	vec4 position = vec4(vertex0, 1.0);
	vec4 worldPos4 = modelViewMatrix * position;
	gl_Position = projectionMatrix * worldPos4;
	vertexPos = vec3(worldPos4) / worldPos4.w;
	colorCoord = (color0 - scalarRange.x) / (scalarRange.y - scalarRange.x);
	normal = normalize(normalMatrix * normal0);
	calculateClipDistances(position);
} 

Is the way of redeclaring gl_ClipDistance wrong? I'm using version 7.11.3170 btw.

@johnkslang
Copy link
Member

Going to #version 410 lets you redeclare blocks.

For #version 330, I think you can just say out float gl_ClipDistance[nrOfClipPlanes]; without a block.

@HorstBaerbel
Copy link

HorstBaerbel commented Mar 29, 2019

I forgot to say that this is a vertex shader. The wiki page does not state a specific version requirement btw. The reference page and the built-in wiki page doesn't either.
The GLSL 3.3 specs say redeclaring built in variables it forbidden unless specifically allowed for certain variables, so that probably covers it, but is easy to miss...

@johnkslang
Copy link
Member

GLSL issues outside of glslang can be raised at https://github.com/KhronosGroup/GLSL.

@Yusuf-EMU
Copy link

z

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

No branches or pull requests

4 participants