Reputation: 53
Whichever WebGPU example (austin-eng, jack1232/WebGPU-Step-By-Step, etc...) I run in Chrome Canary 97.0.4686.0 with unsafe WebGPU flag enabled I get some errors in console that indicate that my browser does not support WebGPU.
Example: https://austin-eng.com/webgpu-samples/samples/helloTriangle
Is WebGPU Enabled?
TypeError: Cannot read property 'requestDevice' of null
Can you reproduce this behavior?
Upvotes: 2
Views: 9015
Reputation: 31
if you use chrome of canary, why not use the latest canary, as far as I know, satable version is already 108, the latest canary version is 111. when you enable #enable-unsafe-webgpu in the lastest canary chrome. you can use ts code
let adapter: GPUAdapter;
let device: GPUDevice;
export async function getGpuDevice() {
if (device) {
return { adapter, device }
} else {
try {
adapter = (await navigator.gpu.requestAdapter())!;
device = (await adapter!.requestDevice())!;
} catch (e) {
alert('your browser don‘t support webgpu\n你的浏览器不支持 webgpu');
}
return { adapter, device };
}
}
good luck!
Upvotes: 0
Reputation: 1674
Recently (at least in 96), WebGPU is no longer behind a flag, instead it's now behind an origin trial. This means that you can register for a token and put it in the <head>
of your webpage and it will enable WebGPU for all users.
To do this, go to: https://developer.chrome.com/origintrials/#/register_trial/118219490218475521, fill out the form, and retrieve your token. Note that you can also request a token for localhost
for development. Then simply add <meta http-equiv="origin-trial" content={ORIGIN_TRIAL_KEY}/>
to your webpage and if registered correctly, WebGPU will be enabled for not only you but everyone that visits your site.
If you are using JSX
/React
, use this: <meta httpEquiv="origin-trial" content={ORIGIN_TRIAL_KEY}/>
The difference is http-equiv
vs httpEquiv
.
Upvotes: 4
Reputation: 5659
As https://web.dev/gpu/#enabling-via-about:flags says, to experiment with WebGPU locally, enable the #enable-unsafe-webgpu
flag in about://flags
.
To check if WebGPU is supported, use:
if ("gpu" in navigator) {
// WebGPU is supported! 🎉
}
Caution: The GPU adapter returned by navigator.gpu.requestAdapter()
may be null
.
At the time of writing, WebGPU is available on select devices on Chrome OS, macOS, and Windows 10 in Chrome 94 with more devices being supported in the future. Linux experimental support is available by running Chrome with --enable-features=Vulkan
. More support for more platforms will follow.
Upvotes: 1