是否可以使用 gl.finish() 在 webgl 中测量渲染时间? [英] Is it possible to measure rendering time in webgl using gl.finish()?

查看:32
本文介绍了是否可以使用 gl.finish() 在 webgl 中测量渲染时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试测量加载 webgl 中的图像所需的时间.

I am trying to measure the time it takes for an image in webgl to load.

我正在考虑使用 gl.finish() 来获取图像加载前后的时间戳,然后将两者相减以获得准确的测量结果,但是我找不到这种用法的好例子.

I was thinking about using gl.finish() to get a timestamp before and after the image has loaded and subtracting the two to get an accurate measurement, however I couldn't find a good example for this kind of usage.

这种事情可能吗,如果可以,有人可以提供示例代码吗?

Is this sort of thing possible, and if so can someone provide a sample code?

推荐答案

不是的.

其实在 Chrome 中 gl.finish 只是一个 gl.flush.查看代码并搜索::结束".

In fact in Chrome gl.finish is just a gl.flush. See the code and search for "::finish".

因为 Chrome 是多进程并且实际上实现了深度安全性,实际的 GL 调用是在另一个进程中从您的 JavaScript 发出的,所以即使 Chrome 确实调用了 gl.finish 它也会发生在另一个进程中并且从 JavaScript 的 POV 以任何形式或形式的时间都不会准确.出于类似的原因,Firefox 显然正在做类似的事情.

Because Chrome is multi-process and actually implements security in depth the actual GL calls are issued in another process from your JavaScript so even if Chrome did call gl.finish it would happen in another process and from the POV of JavaScript would not be accurate for timing in any way shape or form. Firefox is apparently in the process of doing something similar for similar reasons.

即使在 Chrome 之外,每个驱动程序都以不同的方式处理 gl.finish.使用 gl.finish 进行计时并不是有用的信息,因为它不代表实际速度,因为它包括停止 GPU 管道.换句话说,使用 gl.finish 进行计时包含大量实际使用中不会发生的开销,因此不能准确衡量正常情况下执行速度的速度.

Even outside of Chrome, every driver handles gl.finish differently. Using gl.finish for timing is not useful information because it's not representative of actual speed since it includes stalling the GPU pipeline. In other words, timing with gl.finish includes lots of overhead that wouldn't happen in real use and so is not an accurate measurement of how fast something would execute normal circumstances.

在某些 GPU 上有 GL 扩展来获取计时信息.不幸的是,它们 (a) 在 WebGL 中不可用,并且 (b) 不可能永远可用,因为它们不可移植,因为它们不能真正在许多手机中的平铺 GPU 上工作.

There are GL extensions on some GPUs to get timing info. Unfortunately they (a) are not available in WebGL and (b) will not likely ever be as they are not portable as they can't really work on tiled GPUs like those found in many mobile phones.

而不是询问如何为 GL 调用计时,您具体想通过计时来实现什么?也许人们可以提出解决方案.

Instead of asking how to time GL calls what specifically are you trying to achieve by timing them? Maybe people can suggest a solution to that.

这篇关于是否可以使用 gl.finish() 在 webgl 中测量渲染时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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