I'm currently trying to time different parts of my rendering to see how long it takes. I've got the queries working and I'm getting some results.

My question is where should I actually start and end the query?

If the query is wrapped around the ID3D11DeviceContext::VSSetShader function will this tell me how long it took to set the vertex shader? Or will the tell me how long it took to call the function in c++?

I am trying to query the GPU and as far as I know the pipeline isn't executed until I call the ID3D11DeviceContext::DrawIndexed function.

Do I need to do the queries in the shader code?


1 Answer 1


The timestamp queries measure time on the GPU, not the CPU. So if you wrap them around a VSSetShader call it's measuring the time required by whatever that call translates to on the GPU.

The GPU pipeline may not actually start running until you call Present. Doing a draw call probably doesn't make the GPU do anything immediately; it queues up a command into an internal buffer, which is not actually handed off to the GPU until required e.g. by Present. Actually, everything in the ID3D11DeviceContext class works this way, including queries.

The typical way to use queries would be to fire off a bunch of them in one frame and then reap the results two or more frames later. You use multiple sets of queries to get data about all frames (i.e. double-buffering). I actually wrote a detailed article about using GPU queries for timing, which explains all this in detail and includes sample code.

I don't understand what you mean by "do the queries in the shader code".

  • \$\begingroup\$ Your detailed article was great. Thank you. I asked about writing the queries in shader code because shaders are run on the GPU. I now understand queries a lot better after reading your article and understand that that question makes no sence. \$\endgroup\$ Mar 15, 2012 at 21:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .