cwoffenden / hello-webgpu

Cross-platform C++ example for WebGPU and Dawn
272 stars 36 forks source link

Compilation error and runtime error with emscripten 3.0.0 #15

Closed gracicot closed 2 years ago

gracicot commented 2 years ago

Hello! I have a problem running the webgpu example on a web page by compiling the code to wasm using the latest emscripten.

First, in main.cpp at line 345, 346, 347 and 348, I had to change colorDesc.clearValue to colorDesc.clearColor. It wouldn't compile otherwise.

Then after changing those line, running the example on chrome canary (Version 104.0.5092.0 (Official Build) canary (x86_64)).

The error is the following:

Uncaught TypeError: Failed to execute 'setVertexBuffer' on 'GPURenderPassEncoder': Value is outside the 'unsigned long long' value range.
Screen Shot 2022-05-30 at 12 28 22 PM

The error look like it comes from the line 370:

wgpuRenderPassEncoderSetVertexBuffer(pass, 0, vertBuf, 0, WGPU_WHOLE_SIZE);

The argument WGPU_WHOLE_SIZE seems to be transformed to -4294967297 in the javascript side:

Screen Shot 2022-05-30 at 12 30 43 PM

Maybe this is wrong?

I tried to replace the size with a different number. The error goes away but nothing renders. A lot of warnings are generated.

em++ --version

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.0.0-git
Copyright (C) 2014 the Emscripten authors (see AUTHORS.txt)
This is free and open source software under the MIT license.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
cwoffenden commented 2 years ago

Hi! Your Emscripten version is too old. The underlying WebGPU API keeps changing so the only way to keep the C++ version sensibly working is to only support more recent versions. The 3.0.0 release is from November 2021, and there's been far too many changes to the WebGPU implementation in that time.

Does this prebuilt version work for you?

https://wip.numfum.com/2022-04-25/index.html

gracicot commented 2 years ago

Yes, the new emscripten is working, thank you very much.

I've not been able to package emscripten 3.1.9 using nix though, so I used emsdk.