8

im trying to render web GPU shader object in WebGpu

and it returning this error

Uncaught (in promise) TypeError: Cannot read property 'requestDevice' of null at cube.html:28

this is my code to the 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;

});

any idea to fix this error ??

gman
  • 100,619
  • 31
  • 269
  • 393
Buddhika Prasadh
  • 356
  • 1
  • 5
  • 16
  • 1
    Afaik, this isn't generally available yet. Which browser and version are you using? – Ouroborus Dec 19 '20 at 05:12
  • 2
    have you enabled webgpu? It's not shipping yet so you have to turn it on. In Chrome, "about:flags", in firefox "about:config", in Safari you have to turn on the developer menu in preferences and then enable it under experimental features. see: https://github.com/gpuweb/gpuweb/wiki/Implementation-Status The spec for webgpu isn't even done yet so expect things to break. – gman Dec 19 '20 at 05:20
  • yes im using chrome canary Version 89.0.4359.0 and i have enabled webGPU flag – Buddhika Prasadh Dec 19 '20 at 14:34

1 Answers1

0

After trying many things, I fixed it by re-enabling the --enable-unsafe-webgpu flag in about:flags !

Refreshing the page worked before that a couple of times but then stopped... it seems to be fine now!

jeyko
  • 3,093
  • 3
  • 13
  • 16