[英]How to make WebGPU run in Chrome Canary 97?
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.无论哪个 WebGPU 示例(austin-eng、jack1232/WebGPU-Step-By-Step 等),我在启用了不安全 WebGPU 标志的 Chrome Canary 97.0.4686.0 中运行,我在控制台中收到一些错误,表明我的浏览器不支持网络图形处理器。
Example: https://austin-eng.com/webgpu-samples/samples/helloTriangle示例: https://austin-eng.com/webgpu-samples/samples/helloTriangle
Is WebGPU Enabled?
TypeError: Cannot read property 'requestDevice' of null
Can you reproduce this behavior?你能重现这种行为吗?
As https://web.dev/gpu/#enabling-via-about:flags says, to experiment with WebGPU locally, enable the #enable-unsafe-webgpu
flag in about://flags
.正如https://web.dev/gpu/#enabling-via-about:flags所说,要在本地试验 WebGPU,请在
about://flags
启用#enable-unsafe-webgpu
about://flags
。
To check if WebGPU is supported, use:要检查是否支持 WebGPU,请使用:
if ("gpu" in navigator) {
// WebGPU is supported! 🎉
}
Caution: The GPU adapter returned by navigator.gpu.requestAdapter()
may be null
.注意:
navigator.gpu.requestAdapter()
返回的 GPU 适配器可能为null
。
Recently (at least in 96), WebGPU is no longer behind a flag, instead it's now behind an origin trial.最近(至少在 96 年),WebGPU 不再处于标志之后,而是现在处于原始试验之后。 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.这意味着您可以注册一个令牌并将其放在网页的
<head>
中,它将为所有用户启用 WebGPU。
To do this, go to: https://developer.chrome.com/origintrials/#/register_trial/118219490218475521 , fill out the form, and retrieve your token.为此,请访问: https : //developer.chrome.com/origintrials/#/register_trial/118219490218475521 ,填写表格并检索您的令牌。 Note that you can also request a token for
localhost
for development.请注意,您还可以为
localhost
请求令牌以进行开发。 Then simply add <meta httpEquiv="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.然后只需将
<meta httpEquiv="origin-trial" content={ORIGIN_TRIAL_KEY}/>
到您的网页,如果注册正确,WebGPU 不仅会为您启用,还会为访问您网站的每个人启用。
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.如果你用的是canary的chrome,为什么不用最新的canary,据我所知,satable版本已经是108,最新的canary版本是111。当你在最新的canary chrome中启用#enable-unsafe-webgpu时。 you can use ts code
你可以使用 ts 代码
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!祝你好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.