使用查询测量片段着色器的时间 [英] Measuring the time of the fragment shader with queries

查看:29
本文介绍了使用查询测量片段着色器的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用查询系统来检索片段着色器的执行时间.

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

我正在创建一个带有两个时间戳查询的查询池,我正在使用 vkCmdWriteTimestamp.

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 在所有之前的命令执行到指定的流水线阶段时锁存计时器的值,并将时间戳值写入内存.写入时间戳值时,查询的可用性状态设置为可用.

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.

这是否包括指定的流水线阶段?例如,如果我指定 VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,它会在片段着色器完成之前还是之后锁存计时器?

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?

我什么时候需要调用 vkCmdWriteTimestamp?我注意到,如果对 vkCmdWriteTimestamp 的两个调用直接在彼此之上,则产生的增量将接近 0.最初我认为调用它们时应该无关紧要,因为我指定了管道阶段.

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.

推荐答案

您似乎误解了这些函数的作用.他们没有检测到这些阶段执行所需的时间.它们检测系统在命令流中那个点到达那个阶段需要多长时间.

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.

也就是说,如果您使用EARLY_FRAGMENT_TESTS_BIT",那么您要问的问题是所有先前命令完成执行到完成早期片段测试的时间是什么时候."FRAGMENT_SHADER_BIT"也是如此.这意味着它们之间的时间差实际上是不存在的;这将是最后一个渲染命令的最后几个图元执行其片段着色器所花费的时间.

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.

请记住:渲染命令是流水线化的.虽然一些原语正在做早期片段测试,但其他人正在运行片段着色器,而其他人仍在运行后 FS 的东西.等等.

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.

这篇关于使用查询测量片段着色器的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆