Can I use QueryPerformanceCounter to measure single draw or compute call performance? I know I can use QueryPerformanceCounter for measure time for whole single frame. But can I when it comes to OpenGL draw or compute call?

I always assumed that, as on the diagram, CPU waits for GPU to finish so timer would measure approximate time or am I wrong?



As seen in code:

glBindVertexArray(vertexArrayObject);
timer-&gt;startCounter();      
glDrawElements(GL_TRIANGLE_STRIP, indices.size(), GL_UNSIGNED_INT, 0);
glBindVertexArray(0);
estimatedRenderTime = timer-&gt;getCounter();


or

timer-&gt;startCounter();
glDispatchCompute(width, height, 1);
estimatedRenderTime = timer-&gt;getCounter();
That diagram includes a CPU block titled "wait for GPU". I do not see the part of your code that includes an equivalent command.

Furthermore, even if it did include glFinish/glClientWaitSync/etc, there is no guarantee that the CPU time in any way relates to how much time the GPU spent processing it. glFinish might block on a mutex, thus ending the thread's timeslice. Which means that the thread will start up sometime after that mutex is released. How long after? Who knows, but your QueryPerformanceCounter call will include that time.

If you want to measure GPU time, you should use tools that actually measure GPU time. For example, timer queries. You bracket some commands with glBeginQuery(GL_TIME_ELAPSED, queryObject) and glEndQuery(GL_TIME_ELAPSED). Then you can read the result after some time has elapsed. Like maybe next frame.

And unlike glFinish, this will not absolutely murder your performance ;)