无法读取 null 的属性“requestDevice”

问题描述

我正在尝试在 WebGpu 中渲染 Web GPU 着色器对象

它返回这个错误

未捕获(承诺)类型错误:无法读取 null 的属性“requestDevice” 在cube.html:28

这是我的 requestDevice 代码

(async () => {
 

    const [adapter,glslang] = await Promise.all([
        navigator.gpu.requestAdapter(),import("https://unpkg.com/@webgpu/glslang@0.0.7/web/glslang.js").then(m => m.default())
    ]);

    const device = await adapter.requestDevice();
    
    const canvas = document.getElementById("webgpu-canvas");
    canvas.width = window.innerWidth;
    canvas.height = window.innerHeight;

});

有没有办法解决这个错误??

解决方法

在尝试了很多事情之后,我通过在 about:flags 中重新启用 --enable-unsafe-webgpu 标志来修复它!

在此之前刷新页面几次但后来停止了......现在似乎没问题!