javascript 通过网络浏览器访问 GPU

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15213216/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 23:53:16  来源:igfitidea点击:

Accessing GPU via web browser

javascript3dgpugpu-programmingfamo.us

提问by Giles Thompson

I came across this proof of concept earlier today (on TechCrunch.com) and was blown away and intrigued as to how they had managed to accomplish the end result. They state that they don't use webGL or any plugins yet they are able to interact directly with the GPU and render 3D visuals at up to 60 fps using nothing but Javascript. Any ideas how this could be done, or how to access the GPU from Javascript in general without the use of plugins?

我今天早些时候(在 TechCrunch.com 上)遇到了这个概念证明,并对他们如何设法完成最终结果感到震惊和好奇。他们表示他们不使用 webGL 或任何插件,但他们能够直接与 GPU 交互并使用 Javascript 以高达 60 fps 的速度渲染 3D 视觉效果。任何想法如何做到这一点,或者如何在不使用插件的情况下从 Javascript 访问 GPU?

Site Address is: famo.us

网站地址是:famo.us

ps: Try using your arrow keys to shift orientation its far out!!

ps:试着用你的方向键把方向移到很远的地方!!

回答by Halim Qarroum

They're using standard HTML5Javascript APIs to achieve this.

他们使用标准的HTML5Javascript API 来实现这一点。

I saw several references to requestAnimationFramein their code. This method allows one that uses a compatible browser, to display more fluid and optimized animations, with far better frame ratesthan setIntervalbased animations will ever allow you to have. This is certainly achieved by using the GPU and the available hardware background.

requestAnimationFrame在他们的代码中看到了几个引用。这种方法允许使用兼容浏览器的人显示更流畅和优化的动画,帧速率setInterval基于动画的帧速率要好得多。这当然是通过使用 GPU 和可用的硬件背景来实现的。

GPU or every other hardware component cannot be accessed directly using any Javascript routines. Instead, the browser, based on the called JS directives and the execution context, will use the GPU if possibleto optimize some specific treatments, calculus and renderings.

无法使用任何 Javascript 例程直接访问 GPU 或所有其他硬件组件。取而代之的是,浏览器会根据调用的 JS 指令和执行上下文,在可能的情况下使用 GPU来优化一些特定的处理、演算和渲染。

回答by Flavien Volken

Concerning famo.us: they did analysed the bottlenecks of the Webkit rendering pipe and then found a way to bypass them while building the pages. Basically: the DOM tree construction, the Render tree construction, the Layout of Render Tree are bypassed. Take a look on this articlefor a whole explanation.

关于famo.us:他们确实分析了Webkit渲染管道的瓶颈,然后找到了在构建页面时绕过它们的方法。基本上:DOM 树的构建、Render 树的构建、Render Tree 的布局都被绕过了。查看这篇文章以获得完整的解释。

enter image description here

在此处输入图片说明

回答by error

i think the webGL glsl.js library might be good for this, though i havnt seen benchmarks... https://github.com/gre/glsl.js/

我认为 webGL glsl.js 库可能对此有好处,尽管我还没有看到基准测试... https://github.com/gre/glsl.js/

also this approach seems viable;

这种方法似乎也可行;

basically to use the gpu in the way we like to, hardware optimised functions (have a little look into "blas") are used, you do not want to write these! strangely it seems that people still use the old fortran blas.... there is some stuff with compiling via llvm and then using emscripten to turn it into javascript. Use Emscripten with Fortran: LAPACK binding

基本上按照我们喜欢的方式使用gpu,使用硬件优化功能(稍微看看“blas”),你不想写这些!奇怪的是,似乎人们仍然使用旧的 fortran blas .... 有一些东西可以通过 llvm 编译,然后使用 emscripten 将其转换为 javascript。 将 Emscripten 与 Fortran 结合使用:LAPACK 绑定

the emscripten way seems the most versatile, im just about to check it out, but it looks like a mountain, also this topic seems to be somewhat of a call to arms, emscripten only works with fortran if you hack it (see links from the second link). i think what we are looking for is blas support in javascript, this is not a closed issue by any means, and for a few of us out here it is very frustrating! hopefully someone has a link to these blas libraries we cant find... please let me know if i dont quite have my head round this issue, js is new to me.

emscripten 的方式似乎是最通用的,我正要检查一下,但它看起来像一座山,而且这个话题似乎有点像在召唤武器,如果你破解它,emscripten 只适用于 fortran(请参阅来自第二个链接)。我认为我们正在寻找的是 javascript 中的 blas 支持,这无论如何都不是一个封闭的问题,对于我们中的一些人来说,这非常令人沮丧!希望有人有我们找不到的这些 blas 库的链接……如果我不太了解这个问题,请告诉我,js 对我来说是新的。

also, suggesting html5 is sufficiently "optimised" to use the hardware, how can we trust this!? we need gpu optimised blas (basic linear algebra subprograms) e.g. dot product.

此外,建议 html5 已充分“优化”以使用硬件,我们怎么能相信这一点!?我们需要 GPU 优化的 blas(基本线性代数子程序),例如点积。

i think maybe also that these old fortran blas arnt actually the right thing for a modern gpu? node-cuda seems very likely the best thing i have found...

我想也许这些旧的 fortran blas arnt 实际上是现代 gpu 的正确选择?node-cuda 似乎很可能是我发现的最好的东西......

回答by Trevor Dixon

They're using CSS 3D transforms. Web browsers are increasingly using hardware acceleration to do these kinds of CSS3 things.

他们正在使用 CSS 3D 转换。Web 浏览器越来越多地使用硬件加速来做这些 CSS3 的事情。