Sign in to follow this  
UfoZ

primitives generated glQuery

Recommended Posts

Still playing around with geometry shaders. Is it possible to use the GL_PRIMITIVES_GENERATED_NV query even if transform feedback isn't active? Right now, I get a result of 0 when trying to use it, but it works properly elsewhere in the same program (during the same frame even) when feedback is on. I'd just like to get the number of triangles output by the geometry shader. Am I doing this wrong, or is there something I missed? (another way to do this maybe?)
	glBeginQuery(GL_PRIMITIVES_GENERATED_NV, q);
	glDrawArrays(GL_TRIANGLES, 0, num);
	glEndQuery(GL_PRIMITIVES_GENERATED_NV);

	int gen=-1;
	glGetQueryObjectiv(q, GL_QUERY_RESULT, &gen); // gen is now 0 (no errors)

Share this post


Link to post
Share on other sites
Quote:
Original post by UfoZ
Is it possible to use the GL_PRIMITIVES_GENERATED_NV query even if transform feedback isn't active?

Looks like it should!
Quote:
From NV_transform_feedback
When BeginQuery is called with a <target> of PRIMITIVES_GENERATED_NV, the primitives-generated count maintained by the GL is set to zero. When the generated primitive query is active, the primitives-generated count is incremented every time a primitive reaches the Discarding Rasterization stage (see Section 3.x) right before rasterization. This counter counts the number of primitives emitted by a geometry shader, if active, possibly further tessellated into separate primitives during the transform-feedback stage, if active.

Quote:
From NV_transform_feedback
20. Why does TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN_NV have a TRANSFORM_FEEDBACK prefix but PRIMITIVES_GENERATED_NV doesn't?
RESOLVED: The number of primitives generated is independent of any feedback that is active. The number of primitives that are written is only valid for transform feedback - another extension could conceivably have a different way of writing out primitives that would require a similar but distinct token.


Are you sure the two distinct code paths in which you're executing the query to be really equivalent (beside SO)? Maybe the query generation didn't work as expected.

Share this post


Link to post
Share on other sites
Yeah, pretty much equivalent. I'm just moving data back and forth between two buffers, but in the last step the result gets rasterized and rendered instead of being written back to a buffer and discarded. But it'd be nice to know how many triangles were output without having to save them...

I tried turning on transform feedback into an unused buffer, and it works fine that way.

glBindBufferBaseNV(GL_TRANSFORM_FEEDBACK_BUFFER_NV, 0, dummy);
glBeginTransformFeedbackNV(GL_TRIANGLES);

glBeginQuery(GL_PRIMITIVES_GENERATED_NV, q);
glDrawArrays(GL_TRIANGLES, 0, num);
glEndQuery(GL_PRIMITIVES_GENERATED_NV);

glEndTransformFeedbackNV();

int gen=-1;
glGetQueryObjectiv(q, GL_QUERY_RESULT, &gen); // correct result




But obviously, I don't want to save any data, just to get it on the screen.

Weird, especially because the spec that you quoted does address this issue, yet it doesn't state clearly whether or not the two functionalities are interdependent.

Share this post


Link to post
Share on other sites
I suppose you already checked for NO_ERROR.

I was thinking at why BeginQuery could fail, but there's little rationale for this if no error is reported.
I have scratched my head a few minutes trying to understand if it is possible for a Draw-call to fail (for some reason) without giving an error but I still don't get any way for this to happen.
Is it possible the Draw-call is a nop? I suppose num comes from a previous SO/XF pass: is it being set to the expected value? I suppose it is since you say it works fine with SO enabled.

There's the obvious stuff about vertex sources but I don't think this is the problem.

You said you've tried:
1- Render to FB - it didn't work
2- Render to FB with a SO buffer - it works

Have you tried rendering to the FB with disabled rasterization and no SO? (ok, I know it doesn't make much sense in the first place)

Quote:
Original post by UfoZ
Weird, especially because the spec that you quoted does address this issue, yet it doesn't state clearly whether or not the two functionalities are interdependent.

I admit I am also not so confident with GS and SO but if I remember well (notice the bold if) "...the primitives-generated count is incremented every time a primitive reaches the Discarding Rasterization stage" is rather accurate (being SO a pass-thuru stage).
I'll try to have another read at the specs in the next few days.

Share this post


Link to post
Share on other sites
Quote:
Original post by Krohm
You said you've tried:
1- Render to FB - it didn't work
2- Render to FB with a SO buffer - it works

Have you tried rendering to the FB with disabled rasterization and no SO? (ok, I know it doesn't make much sense in the first place)


I just tried with rasterization off, same thing. The query runs correctly only if SO is on.

And yeah, no errors, and I am drawing a nonzero number of triangles :)

So, I guess it is a mystery. Might be a driver thing or whatever. All of this sm 4.0 stuff is pretty new, so I guess the spec isn't set in stone either.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this