beaufortfrancois / webgpu-cross-platform-app

WebGPU cross-platform app with CMake/Emscripten
https://developer.chrome.com/docs/web-platform/webgpu/build-app
82 stars 6 forks source link

Emscripten compilation error Ubuntu 22.04 #3

Closed pierricgimmig closed 8 months ago

pierricgimmig commented 8 months ago

Running emcmake cmake -B build-web && cmake --build build-web -j4 on Ubuntu 22.04 gives:

pierric@squid:~/git/webgpu-cross-platform-app$ emcmake cmake -B build-web && cmake --build build-web -j4
configure: cmake -B build-web -DCMAKE_TOOLCHAIN_FILE=/usr/share/emscripten/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_CROSSCOMPILING_EMULATOR=/usr/bin/node;--experimental-wasm-threads
-- Configuring done (1.3s)
-- Generating done (0.0s)
-- Build files have been written to: /home/pierric/git/webgpu-cross-platform-app/build-web
[ 50%] Building CXX object CMakeFiles/app.dir/main.cpp.o
/home/pierric/git/webgpu-cross-platform-app/main.cpp:35:11: error: use of undeclared identifier 'exit'
          exit(0);
          ^
/home/pierric/git/webgpu-cross-platform-app/main.cpp:63:12: error: no member named 'code' in 'wgpu::ShaderModuleWGSLDescriptor'
  wgslDesc.code = shaderCode;
  ~~~~~~~~ ^
/home/pierric/git/webgpu-cross-platform-app/main.cpp:97:8: error: no member named 'End' in 'wgpu::RenderPassEncoder'
  pass.End();
  ~~~~ ^
3 errors generated.
em++: error: '/usr/bin/clang++-13 -target wasm32-unknown-emscripten -DEMSCRIPTEN -D__EMSCRIPTEN_major__=3 -D__EMSCRIPTEN_minor__=1 -D__EMSCRIPTEN_tiny__=5 -fignore-exceptions -fvisibility=default -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -D_LIBCPP_ABI_VERSION=2 -fno-threadsafe-statics -Dunix -D__unix -D__unix__ -Werror=implicit-function-declaration -Xclang -iwithsysroot/include/SDL --sysroot=/usr/share/emscripten/cache/sysroot -Xclang -iwithsysroot/include/compat -std=gnu++20 -MD -MT CMakeFiles/app.dir/main.cpp.o -MF CMakeFiles/app.dir/main.cpp.o.d -c /home/pierric/git/webgpu-cross-platform-app/main.cpp -o CMakeFiles/app.dir/main.cpp.o' failed (returned 1)
gmake[2]: *** [CMakeFiles/app.dir/build.make:76: CMakeFiles/app.dir/main.cpp.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/app.dir/all] Error 2
gmake: *** [Makefile:91: all] Error 2
beaufortfrancois commented 8 months ago

Re: error: no member named 'code' in 'wgpu::ShaderModuleWGSLDescriptor', I suspect you're not using the latest version of Emscripten. I use version 3.1.46.

pierricgimmig commented 8 months ago

upgrading to 3.1.47 fixes compilation, however, the web app is a black rectangle, and I get this in the console:

Uncaught RuntimeError: Aborted(TODO: wgpuCreateInstance unimplemented)
    at abort (app.js:1511:11)
    at _wgpuCreateInstance (app.js:6086:7)
    at app.wasm:0x2f99
    at app.wasm:0x2144
    at app.wasm:0x2d94
    at app.js:1556:22
    at callMain (app.js:7111:15)
    at doRun (app.js:7168:23)
    at app.js:7179:7
beaufortfrancois commented 8 months ago

https://github.com/emscripten-core/emscripten/pull/19762 fixed this issue. I wonder if you should remove the build-web folder and try again.

pierricgimmig commented 8 months ago

Thnaks for the suggestion, I removed the build-web folder, tried again, and got:

app.js:6572 Failed to create WebGPU Context Provider

But this was because I hadn't enabled WebGpu in Chrome.

Running google-chrome-unstable --enable-unsafe-webgpu --use-vulkan=true --test-type --enable-features=Vulkan finally gave me that red triangle I was looking for :-)

beaufortfrancois commented 8 months ago

Woohoo!

beaufortfrancois commented 8 months ago

Can you summarize all the steps you made to the original instructions so that others can benefit from you experience on Linux?

pierricgimmig commented 8 months ago

Sure! Here's what I did on Ubuntu 22.04:

image

munrocket commented 8 months ago

Faced with this problem too on Linux.

beaufortfrancois commented 8 months ago

Thank you @pierricgimmig for documenting your steps. Hopefully it will help others in the future.