Xfer feedback variable optimized away

hi everyone,

i’m trying to make a little application with transform feedback, i want to capture all (transformed) vertex attributes and want to reuse them the next frame (double-buffered)
capturing variables already works, but i assume the problem is the glsl compiler that “optimizes” the vertex shader and discarts unused variables

the working example:
vertex shader:

#version 450 core

in layout (location = 0) vec3 in_position;
in layout (location = 1) vec4 in_color;

uniform layout (location = 0) mat4 MVP = mat4(1);

layout (xfb_buffer = 0, xfb_offset = 0, xfb_stride = 28) out vec3 position;
layout (xfb_buffer = 0, xfb_offset = 12, xfb_stride = 28) out vec4 color;

void main ()
{
	gl_Position = MVP * vec4(in_position, 1);
	position = (MVP * vec4(in_position, 1)).xyz;
	color = in_color;
}

fragment shader:

#version 450 core

in vec3 position;
in vec4 color;

out layout (location = 0) vec4 out_color;

void main ()
{
	out_color = color + vec4(position, 0);
}

as you can see, the fragment shader does some “weird” stuff, i just added a position to “persuay” the compiler to not discard the variable, but that’s just for testing purposes

of course i want to have this:
fragment shader:

#version 450 core

in vec4 color;

out layout (location = 0) vec4 out_color;

void main ()
{
	out_color = color;
}

but when i do that, the application definitely wont capture the “position” attribute anymore
(i retrieved all transform feedback varyings and the captured data to test this)

what can i do ??
thanks in advance!

[QUOTE=john_connor;1284951]i’m trying to make a little application with transform feedback, i want to capture all (transformed) vertex attributes…

i assume the problem is the glsl compiler that “optimizes” the vertex shader and discarts unused variables …

the working example:
vertex shader:


...
layout (xfb_buffer = 0, xfb_offset = 0, xfb_stride = 28) out vec3 position;
layout (xfb_buffer = 0, xfb_offset = 12, xfb_stride = 28) out vec4 color;
...

fragment shader:


...
    out_color = color + vec4(position, 0);
...

as you can see, the fragment shader does some “weird” stuff, i just added a position to “[persuade]” the compiler to not discard the variable, but that’s just for testing purposes[/QUOTE]

Hmm, ok. Since you’re doing transform feedback, why do you even have a fragment shader? I’d get rid of that (that is, only link a vertex shader into your shader program). See if the linker removes position then.

If so, you might consider using glTransformFeedbackVaryings to set the TF outputs instead of the layout qualifiers. Just be sure to call this “before” you link your program. See this: Transform Feedback (OpenGL Wiki)

Probably not related, but you are setting rasterizer discard, right?

thanks for your reply!

i tried that –> it works!
but the thing is i want to do a kind of “buffer pingponging”
that means WHILE rendering a triangle, i want to capture the transformed vertex in buffer 2
when done, i use buffer 2 as GL_ARRAY_BUFFER and feed the vertices into the same program again, capturing every thing into buffer 1 (ping-pong)
so the point is i need the fragmentshader (beside 2 VAO, 2 VBO, 2 Xfer feedback objects)

glTransformFeedbackVaryings(…) is exactly what i want to avoid :wink:
(used it before, works perfectly)

nope

i also tried to set

#version 450 core

#pragma optimize(off)

in both shaders (vertex / fragment) → doesnt work

by the way:

 doesnt work in my code pieces ?!? why ?

void main() {
int test = 2;
}

You need to use

 [b]instead of[/b] 

, not inside it.

Ok. Well as far as I know what you’re doing is fine. What GPU/driver/OS is this?

I’d suggest that you double-check the spec just to verify that your/my understanding that this is valid is correct. And assuming so, file a bug report with the company/organization that maintains the drivers you’re using.

For now I guess you can continue to use a work-around similar to what you are using, but just change the expression so it can have no real effect on the resulting color, and yet won’t allow the compiler to optimize it away.

a usual desktop pc:
– windows 10 home (x64)
– NVIDIA GeForce GT 640
– driver 369.09 (outdated)
– driver 376.19

OpenGL 4.5 core profile and GLSL 450 core
my driver 369.09 was outdated, but that doesnt matter, my example doesnt work neither with 369.09, nor with 376.19
(i’ve just installed 376.19)

triple-checked it … i dont violate any GLSL 450 core rule

i played around, used interface blocks, etc … nothing worked
(until i pass the “position” attribute to the fragmentshader and use it there anyhow)

i’ll report NVIDIA the bug

[QUOTE=john_connor;1284970]a usual desktop pc:
– windows 10 home (x64)[/QUOTE]

parenthesis_open()

Is this an usual desktop PC ?

parenthesis_close()

From what you’ve indicated, seems pretty typical to me.

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