在浏览器中使用 webgl 运行 创建 gpu 密集型 Web 应用程序是否现实?

Is it realistic to create gpu-intensive web apps using webgl running in the browser?

我一直在考虑在浏览器中使用 运行s 的 webgl 创建一个时髦的游戏,但我注意到尽管有一个带有 3gb 显存的 NVIDIA GeForce GTX 1060,我只能一次最多使用 512mb 的 vram。我相信这是因为浏览器正在使用我的集成 gpu 而不是我的专用 gpu。我读过几个人有同样的问题并通过重新配置来纠正它,但我不希望我的网络应用程序的用户如果也有类似的问题并且需要更多的 vram 来担心这个运行 应用程序。

是否有一种简单的“修复方法”可以让浏览器无需进行任何技术重新配置即可使用专用 GPU?这只是在浏览器中使用 gpu 的不幸问题吗?还是我不了解使用 gpu 的一些基本知识?

在 WebGL 中,您可以通过将 powerPreference: 'high-performance' 传递给 getContext 来要求浏览器使用离散 gpu,如

const gl = someCanvas.getContext('webgl', {powerPreference: 'high-performance'});

您可以使用 WEBGL_debug_renderer_info 扩展来检查它是否有效

const canvas = document.createElement('canvas');
const gl = canvas.getContext('webgl', {powerPreference: 'high-performance'});
const ext = gl.getExtension('WEBGL_debug_renderer_info');
if (ext) {
  console.log(gl.getParameter(ext.UNMASKED_VENDOR_WEBGL));
  console.log(gl.getParameter(ext.UNMASKED_RENDERER_WEBGL));
} else {
  console.log('this browser does not support WEBGL_debug_renderer_info');
}

如果您不传入 powerPerformance 设置,它将默认为浏览器选择的任何内容。大多数浏览器默认选择集成GPU以节省电量。

至于 GPU 密集型,我会说 Google Earth 相当密集?


更新

因此,从 2020 年 7 月开始,powerPreference 选项实际上仅适用于双 GPU Mac。好消息显然是Microsoft is adding support to Chromium for Dual GPU Windows