EXT_transform_feedback and Vertex Programs

Hi,

I’m making a GPU particle system with the transform feedback buffer. I have combined the particles’ position and time into a single array, so each particle has four-elements (floats).

For my test data, I’m using one particle. The particle’s initial position is [6, 3, 2], and its initial time is -1, leading to a position_time vertex buffer containing: [6.0,3.0,2.0,-1.0].

I can read back the data, and see that the VBO contains this data.

After applying one step iteration, the particle’s position is:
[6.0,6.0,6.0,6.0]. The shader is just for testing, so it’s very simple:

#version 130

in  vec4 position_time_in;
out vec4 position_time_out;

void main() {
	position_time_out.xyzw = position_time_in.wwww;
}

After one pass with the shader the target VBO contains: [6.0,6.0,6.0,6.0], which is clearly not right.

The key lies in “position_time_in”'s swizzle:
Using swizzle “.wwww” -> [6.0,6.0,6.0,6.0]
Using swizzle “.xyzw” -> [6.0,3.0,2.0,-1.0]
Using swizzle “.wzyx” -> [-1.0,2.0,3.0,6.0]
As you can see, when all “w”'s are specified, the first component is used, instead of the last. I’ve also tried the .rgba components instead, with the same result.

I was hoping to use something of this form for debugging, but for some weird reason it’s not. Any ideas, anyone?

Thanks!
-G

Looks like a driver bug. If swizzling isn’t giving you the results you expect for that particular operation, then do not swizzle, i.e. manually assign .w to each component of position_time_out.

position_time_out.x = position_time_in.z;
position_time_out.y = position_time_in.z;
position_time_out.z = position_time_in.z;
position_time_out.w = position_time_in.z;
Gives [6,6,6,6]

position_time_out.x = position_time_in.x;
position_time_out.y = position_time_in.z;
position_time_out.z = position_time_in.z;
position_time_out.w = position_time_in.z;
Gives [6,3,3,3]

position_time_out.x = position_time_in.y;
position_time_out.y = position_time_in.z;
position_time_out.z = position_time_in.z;
position_time_out.w = position_time_in.z;
Gives [2,3,3,3]

position_time_out.x = position_time_in.z;
position_time_out.y = position_time_in.y;
position_time_out.z = position_time_in.z;
position_time_out.w = position_time_in.z;
Gives [3,2,3,3]

So, it seems that at least two different elements of position_time_in need to be accessed, or else the accessed value is the first element . . .

Are u using a single vbo or two different vbos (one for position_time_out and other for position_time)?

Yes.

That sounds like the problem. I’d recommend creating a temporary variable to hold the result of the swizzle before writing it back to the VBO. However, the driver may optimize it and remove the assignment, so you may have to use 2 VBOs.

Er, I meant: “Yes, I am using two VBOs”. My bad.

Is this behaviour the same on both ATI and NVIDIA hardware?

Don’t know; the only computer I own is a NVIDIA laptop. Anyway, I’ve gone back to using three component vectors, which seems to fix it; it’s alright because I have more than 8 attributes to use anyway, so I need three VBO pairs no matter what; I might as well use the ones that are non-buggy.

I think you’re experiencing the problem described in this thread.

  • Chris

Awesome; sounds like exactly it!