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

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

问题描述

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

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

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

解决方案

不是.

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

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

即使在Chrome之外,每个驱动程序对gl.finish的处理方式也不同.使用gl.finish进行计时不是有用的信息,因为它不代表实际速度,因为它包括使GPU管线停顿.换句话说,使用gl.finish进行计时会包含很多在实际使用中不会发生的开销,因此无法准确地衡量某些事物在正常情况下执行的速度.

某些GPU上有GL扩展以获取时序信息.不幸的是,它们(a)在WebGL中不可用,并且(b)由于它们不可移植,因为它们不能像在许多移动电话中那样在平铺的GPU上真正工作,因此不可能出现.

您不是在问GL通话的时间,而是要通过计时来具体实现什么?也许人们可以提出解决方案.

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

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?

解决方案

No it is not.

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

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.

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.

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.

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天全站免登陆