How to know the GPU activity

Is there a way to know if the GPU is busy or not?

What I want to do is to render all (most) at the end of rendering phase (for front to back or states changes sorting purpose), but I need to swap at the begining because some things can’t wait. If I do so, the GPU can be idle during all the rendring phase. My idea is when something to render is avaible i will look if the GPU is busy, if no, I will draw the thing now, and don’t wait, if yes I put it on a list and it will be rendered at the end.

Is it possible?

AFAIK you can’t determine this.

-SirKnight

What about NV_fence ?

nvfence tells you when the GPU has completed a specific task sent earlier. It says nothing about what it is doing now with the stuff you SHOULD have sent in the mean time. The objective is to let you know something is drawn and completed without stalling the pipeline just to be sure.

Thak you for the idea.
NV_fence is probably not the best way, but it’s the only solution for now. I can put a fence after all rendering and before rendering something else just ask if the last fence is still on the GPU queue.

I didn’t implement NV_fence for now, i have some issue to fix before, so I can’t arg it’s a good way or not since fence are not free.

I think you are trying to optimize at the wrong end.

If i understand you right, you want to check if the card is idle and want then to send data to it. If it is busy, you want to queue the tasks and send them later.

But this is, what the driver/card already does automatically. All tasks you send to the card get queued and therefore it will work in parallel with the CPU.

The only thing which can profit from knowing if the card is idle, are commands, which would imply a pipeline-stall. However those commands should be avoided in general, and usually you can easily work around them anyway.

The only command, which will stall the pipeline is the occlusion-query, cause you need to wait until everything is drawn and the result of the query can be evaluated.
But therefore nVidia implemented it in a way which does exactly what you are asking for. It tells you, if the occlusion query has been done yet. So it won´t stall the pipeline, as long as you don´t force it to do so.

And when we are already talking about occlusion query: You could use that extension to do the same thing like NV_fence. Just make an occlusion query (with stuff which will be invisible) and ask if it has been done yet.
The advantage of this extension is, that it is not (really) nVidia specific. I think ATI supports it, too. And it will be included in the 1.5 core.

Hope that helps you.
Jan.

What I want to do at the end is to reorder the tasks in order to avoid states change or avoid overdraw.

e.g.:
If you do
Render with texture 1
Render with texture 2
Render with texture 1

it will be able to reorder and do:
Render with texture 1
Render with texture 1
Render with texture 2
which avoid a texture change.

Your idea for NV_occlusion_query is quite good for supporting ATI GPUs.