如何测量计算着色器的时间性能? [英] How to measure time performance of a compute shader?

查看:103
本文介绍了如何测量计算着色器的时间性能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要测量计算着色器的时间.但这当然不是小事.从 OpenGL Wiki - Performance 我得到,在前后使用 glFinish() 很有用着色器调用.但他们也说使用它并不是那么好.是否有可能测量我的着色器的时间?有没有可能测量计算着色器的时间?

i need to measure the time of a compute shader. But of course this is not trivial. From OpenGL Wiki - Performance I got, that it is usefull to use glFinish() before and after the shader call. But they say also that it is not that good to use it. Is there a good possibility to measure the time of my shader? Is there anyways the possibility to measure the time of a compute shader?

我的代码看起来像这样:

My code looks like something like this:

renderloop()
{
  //(1)
  //(2)
  if(updateFunction) //this is done just one time at the beginning
  {
    //update Texture with a compute shader
    //...
    glDispatchCompute();
    glMemoryBarrier(GL_ALL_BARRIER_BITS);
  }
  //(3)
  //(1)

  //use the texture to do some marching cubes rendering
}

我想我必须在位置 (1) 插入 glFinish() 并在 (2) 处启动计时器并在 (3) 处停止.但我不确定它是否真的有效并且会产生正确的计时结果,因为在参考文献中他们谈论的是渲染而计算着色器没有渲染,不是吗?

I guess I have to insert glFinish() at the positions (1) and to start the timer at (2) and to stop it at (3). But i am not sure if it really works and will produce correct timing results, because in the reference they were talking about rendering and a compute shader is no rendering, isn't it?

也存在 OpenGL Timer_Query,但我我不确定它是如何工作的,也不知道它是否对我有用.这个东西对我来说是新的,我不确定我现在是否完全理解它.

There exists the OpenGL Timer_Query too, but I am not sure how it works and don't know whether it is useful for me to use it or not. This stuff is new to me and I am not sure if I fully understand it at the moment.

来自此处的回答说几乎不可能精确测量代码的一部分.最好的方法是测量帧渲染时间,但为了我的目的,我只需要帧渲染时间的计算着色器部分.

The answer from here says that it is nearly impossible to measure precisly a part of the code. The best way is to measure the frame rendering time, but I just need the compute shader part of the frame rendering time for my purposes.

您认为最好的替代方法是什么?只是测量整个帧渲染时间并使用它?或者您是否使用其他测量方法获得了更好的体验?

What do you think is the best alternative to do it? Just measure the whole frame rendering time and use it? Or did you make better experiences with other measurement methods?

推荐答案

定时器查询绝对是要走的路.

Timer queries are definitely the way to go.

一般原则是创建查询对象",并在 GL 函数调用之间插入这些对象.

The general principle is that you create 'query objects' that you insert in between your GL functions calls.

由于 GPU 异步运行,这些查询将被插入到 GPU 命令队列中,并在真正处理命令时填充".

As GPUs run asynchronously, these queries will be inserted in the GPU command queue, and 'filled' when the commands are really processed.

因此,在您的情况下,您需要使用例如 glGenQueries(1, &myQuery);

So, in your case, you need to create a query using, say, glGenQueries(1, &myQuery);

然后,不是启动计时器,而是在 (2) 中使用 glBeginQuery(GL_TIME_ELAPSED, myQuery) 启动查询,然后在 (3) 中使用 glEndQuery '停止'它(GL_TIME_ELAPSED).

Then, instead of starting a timer, you start the query in (2), using glBeginQuery(GL_TIME_ELAPSED, myQuery), and 'stop' it in (3), using glEndQuery(GL_TIME_ELAPSED).

要获得结果,您只需调用 glGetQueryObject 函数即可.

To get the result, you can simply call glGetQueryObject function.

您可以在此处了解更多信息,例如:http://www.lighthouse3d.com/tutorials/opengl-short-tutorials/opengl-timer-query/

You can learn more here for example : http://www.lighthouse3d.com/tutorials/opengl-short-tutorials/opengl-timer-query/

当然,有一些陷阱"——主要是你必须等待计时结果准备好——所以你可以为 GPU &要同步的 CPU,这会减慢您的应用程序速度(但仍会为您提供良好的 GL 计时),或者有多个查询正在进行中.

Of course, there are some 'traps' - the main one is that you have to wait for the timing result to be ready - so you can either for the GPU & CPU to sync, which will slow down you application (but still give you good GL timings), or have multiple queries in-flight.

这篇关于如何测量计算着色器的时间性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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