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

Use C++ callbacks #8

Open beaufortfrancois opened 1 month ago

beaufortfrancois commented 1 month ago

@kainino0x I'm looking at using C++ callbacks in this app and while it's working natively with Dawn ToT, it fails with Emscripten ToT with the following error:

$ /Users/fbeaufort/github/emscripten/emcmake cmake -B build-web && cmake --build build-web -j100
configure: cmake -B build-web -DCMAKE_TOOLCHAIN_FILE=/Users/fbeaufort/github/emscripten/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_CROSSCOMPILING_EMULATOR=/opt/homebrew/opt/node/bin/node
-- Configuring done (0.4s)
-- Generating done (0.0s)
-- Build files have been written to: /Users/fbeaufort/github/webgpu-cross-platform-app/build-web
[ 50%] Building CXX object CMakeFiles/app.dir/main.cpp.o
/Users/fbeaufort/github/webgpu-cross-platform-app/main.cpp:35:16: error: cannot initialize a parameter of type 'RequestAdapterCallback' (aka 'void (*)(WGPURequestAdapterStatus, WGPUAdapterImpl *, const char *, void *)') with an rvalue of type 'wgpu::CallbackMode'
   35 |       nullptr, wgpu::CallbackMode::AllowSpontaneous,
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/fbeaufort/github/emscripten/cache/sysroot/include/webgpu/webgpu_cpp.h:977:91: note: passing argument to parameter 'callback' here
  977 |         void RequestAdapter(RequestAdapterOptions const * options, RequestAdapterCallback callback, void * userdata) const;
      |                                                                                           ^
/Users/fbeaufort/github/webgpu-cross-platform-app/main.cpp:50:16: error: cannot initialize a parameter of type 'RequestDeviceCallback' (aka 'void (*)(WGPURequestDeviceStatus, WGPUDeviceImpl *, const char *, void *)') with an rvalue of type 'wgpu::CallbackMode'
   50 |       nullptr, wgpu::CallbackMode::AllowSpontaneous,
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/fbeaufort/github/emscripten/cache/sysroot/include/webgpu/webgpu_cpp.h:803:87: note: passing argument to parameter 'callback' here
  803 |         void RequestDevice(DeviceDescriptor const * descriptor, RequestDeviceCallback callback, void * userdata) const;
      |                                                                                       ^
2 errors generated.
make[2]: *** [CMakeFiles/app.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/app.dir/all] Error 2
make: *** [all] Error 2

Do you know what are the steps to fix this issue? Or are you already working on this by any chance?

kainino0x commented 1 month ago

Emscripten doesn't implement any of the Futures-enabled async stuff yet. I'm supposed to implement it but my higher priority right now is temporarily forking the Emscripten bindings so we can deal with the necessary breaking changes without breaking Emscripten users continually.