問題描述
使用在瀏覽器中運行的 webgl 創建 GPU 密集型 Web 應用程序是否現實? (Is it realistic to create gpu‑intensive web apps using webgl running in the browser?)
我一直在考慮使用在瀏覽器中運行的 webgl 創建一款時髦的遊戲,但我注意到儘管擁有 3gb 的 vram 的 NVIDIA GeForce GTX 1060,但我最多只能使用 512mb 的 vram一次。我相信這是因為瀏覽器使用的是我的集成 gpu 而不是我的專用 gpu。我讀過幾個人有同樣的問題並通過重新配置來糾正它,但我不希望我的 web 應用程序的用戶也有類似的問題並且需要更多的 vram 來擔心這個問題運行應用程序。
有沒有簡單的“修復”?允許瀏覽器使用專用 GPU 而無需進行任何技術重新配置?這只是在瀏覽器中使用 gpu 的不幸問題嗎?還是我不了解有關使用 gpu 的基本知識?
參考解法
方法 1:
In WebGL you can ask the browser to use the discrete gpu by passing in powerPreference: 'high‑performance'
to getContext
as in
const gl = someCanvas.getContext('webgl', {powerPreference: 'high‑performance'});
You can check if it worked by using the WEBGL_debug_renderer_info
extension if it exists
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');
}
If you don't pass in a powerPerformance
setting it defaults to whatever the browser chooses. Most browsers choose the integrated GPU by default to save power.
As for GPU intensive, I'd say Google Earth is fairly intense?
update
So as of 2020‑07 the powerPreference
option really only works on Dual GPU Macs. The good news is apparently Microsoft is adding support to Chromium for Dual GPU Windows.
(by therealguy、gman)