View Full Version : Transform feedback issue

02-18-2012, 01:16 PM
I have an interesting problem regarding transform feedback (TFB).

Using a debugger, the following pseudo code runs sucessfully precisely once per frame, on the next and subsequent frames the transform feedback pass generates a general protection fault calling glDrawArrays (nVidia GF 8600GTm). I have also tested on Radeon 4850 - it does not crash but nothing gets rendered.

Pseudo code goes something like this:

pass #1
Bind TFB shader (Gemoetry and vertex shader)
bind VBO for TFB shader containing instance source data
setup and enable TFB
gldrawarrays (GL_POINTS, num instances)
disable TFB
disable VBO

#pass 2
Draw model using transformed VBO

Skipping pass #1 proves that the model does actually draw properly in pass #2 (albeit there is no instance data provided).

This is the code used for pass #1

AsteroidBelt.TransformFeedback.AsteroidCount := AsteroidBelt.NumInstances;
// ---- Pass #1 ----
// Transform feedback - visibility test --- render to vertex buffer
ShaderManager.enableProfile(FXlist[ 7 ].ShaderIndex); //asteroid belt shader Vertex/Gemoetry Shader.
ShaderManager.ApplyAllParameters(FXlist[ 7 ].ShaderIndex);

glBindBuffer(GL_ARRAY_BUFFER, AsteroidBelt.InstanceData.TBO);
glEnableVertexAttribArray(vertexAttribs [7] [vaModelView1]); //instance attribute slot
glVertexAttribPointer(vertexAttribs [7] [vaModelView1], 4, GL_FLOAT, GL_FALSE, 0, pointer(0));

glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, AsteroidBelt.TransformFeedback.BO); //buffer to write into - stream #1
glBeginQuery(GL_PRIMITIVES_GENERATED, AsteroidBelt.TransformFeedback.AsteroidQuery); // query for generated primitive count
glDrawArrays(GL_POINTS, 0, AsteroidBelt.NumInstances); // draw the instance data as points

glDisableVertexAttribArray(vertexAttribs [7] [vaModelView1]); //instance attribute slot
glBindBuffer(GL_ARRAY_BUFFER, 0);

glGetQueryObjectiv(AsteroidBelt.TransformFeedback. AsteroidQuery, GL_QUERY_RESULT, @AsteroidBelt.TransformFeedback.AsteroidCount);

As I said, what I don't get is that if I put a flag in pass #1 to only fill the contents of the feedback VBO once, pass #2 sucessfully draws the asteroids. As soon as I remove the 'once-only' flag from pass #1 I get a general protecton fault.

Any ideas?

02-20-2012, 03:16 AM
Problem solved.
It turns out that some state from a previous object was still active and affects the TFB in some odd way.
Specifically, the issue lies when using the following:

glInterleavedArrays(GL_C4UB_V3F, 0, @stars.StarArray[0].color[0]);
glDrawArrays (GL_POINTS,0,len);

it looks like I needed to wrap the above glInterleavedArrays with:
glPopClientAttrib ;

...which I should have done anyway, but did not because it just seemed to 'work' OK until now (driver updates, etc).

02-20-2012, 04:03 PM
Wouldn't it be time to get rid of deprecated stuff? Exactly how old is this code, anyway?-)

02-21-2012, 10:08 AM
Yes I could replace it with modern vbo arrays. The thing is I used that code because it was soooo easy to setup and use. 1 line of source is equivalent to about 10 lines.

02-24-2012, 06:34 AM
Just tested the Transform Feedback on ATI Radeon 4850.
The asteroids are not being rendered at all, although they are correctly rendering on GeForce 8600mGT.
Stepping through the Transform Feeback code posted in post #1, I can see the Query object returns a sensible number for the number of instances/vertices rendered to vertex buffer.
So, I'm inclined to think that the TFB rendering is working but using the output buffer objects as a source to the next stage is somehow wrong.

Anyone else seen this kind of Transform Feedback issue on AMD/ATI hardware?

02-26-2012, 09:33 PM
Can you send your sample code to daniel.rakos (at) amd.com? I'll take a look at it.

02-27-2012, 09:55 AM
Many thanks. I'll send you the code and shaders I use. You won't be able to compile it however as it's written in Delphi.
However you should be able to follow what it's doing (I hope).
Any issues, please email me back with questions etc.

02-27-2012, 07:50 PM
No problem, I'm very familiar with Delphi (I used it for about a decade before moving to C++). The source, however, should be enough to reproduce the issue.

02-28-2012, 02:28 AM
Source code snippets and shaders on its way....