1

I want to use the query system to retrieve the execution time of the fragment shader.

I am creating a query pool with two timestamp queries and I am using vkCmdWriteTimestamp.

device.cmd_draw_indexed(draw_command_buffer, 6, 1, 0, 0, 1);
device.cmd_write_timestamp(
    draw_command_buffer,
    vk::PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT,
    query_pool,
    0,
);
device.cmd_write_timestamp(
    draw_command_buffer,
    vk::PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
    query_pool,
    1,
);
device.cmd_end_render_pass(draw_command_buffer);

Which pipeline stages do I need to specify to only track the time for the fragment shader?

vkCmdWriteTimestamp latches the value of the timer when all previous commands have completed executing as far as the specified pipeline stage, and writes the timestamp value to memory. When the timestamp value is written, the availability status of the query is set to available.

Does this include the specified pipeline stage? For example if I specify VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, will it latch the timer before or after the fragment shader has finished?

When do I need to call vkCmdWriteTimestamp? I have noticed that if both calls to vkCmdWriteTimestamp are directly on top of each other, the resulting delta will be close to 0. Initially I thought it shouldn't matter when I call them because I specify the pipeline stage.

Maik Klein
  • 15,548
  • 27
  • 101
  • 197

1 Answers1

3

You seem to misunderstand what these functions are doing. They don't detect the time it takes for those stages to execute. They detect how long it takes for the system to reach that stage at that point in the command stream.

That is, if you use "EARLY_FRAGMENT_TESTS_BIT", the question you're asking is "what is the time when all prior commands have finished executing up to the point when they're done with early fragment tests." The same goes for "FRAGMENT_SHADER_BIT". Which means the time delta between these will effectively be non-existent; it'll be the time it took for the last primitives few of the last rendering command to execute its fragment shader.

Or worse, the time between the execution of the two query commands. They're not free, after all.

Remember: rendering commands are pipelined. While some primitives are doing early fragment tests, others are running the fragment shader, and others still are running post-FS stuff. And so on.

Timestamps, as the standard says, are for "timing the execution of commands", not the execution of pipeline stages. There is no way to measure the execution time of a pipeline stage.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982