eliemichel / LearnWebGPU-Code

The accompanying code of the Learn WebGPU C++ programming guide
https://eliemichel.github.io/LearnWebGPU
MIT License
114 stars 30 forks source link

step095-emscripten webgpu.hpp errors when building for web #44

Closed aagrawal05 closed 4 months ago

aagrawal05 commented 4 months ago

Hi, fresh build on M1 has this log:

[output after commands]

  1. emcmake cmake -B build/web -DWEBGPU_BACKEND=EMSCRIPTEN
  2. cmake --build build/web
[ 53%] Built target imgui
[ 66%] Built target glfw3webgpu
[ 73%] Building CXX object CMakeFiles/App.dir/main.cpp.o
In file included from /Users/aagrawal05/Projects/LearnWebGPU-Code/main.cpp:27:
In file included from /Users/aagrawal05/Projects/LearnWebGPU-Code/Application.h:29:
/Users/aagrawal05/Projects/LearnWebGPU-Code/build/web/_deps/webgpu-backend-emscripten-src/include/webgpu/webgpu.hpp:226:1: error: unknown type name 'WGPUComputePassTimestampLocation'; did you mean 'ComputePassTimestampLocation'?
  226 | ENUM(ComputePassTimestampLocation)
      | ^
/Users/aagrawal05/Projects/LearnWebGPU-Code/build/web/_deps/webgpu-backend-emscripten-src/include/webgpu/webgpu.hpp:104:10: note: expanded from macro 'ENUM'
  104 |         typedef WGPU ## Type W; /* W == WGPU Type */ \
      |                 ^
<scratch space>:29:1: note: expanded from here
   29 | WGPUComputePassTimestampLocation
      | ^
/Users/aagrawal05/Projects/LearnWebGPU-Code/build/web/_deps/webgpu-backend-emscripten-src/include/webgpu/webgpu.hpp:226:6: note: 'ComputePassTimestampLocation' declared here
  226 | ENUM(ComputePassTimestampLocation)
      |      ^
/Users/aagrawal05/Projects/LearnWebGPU-Code/build/web/_deps/webgpu-backend-emscripten-src/include/webgpu/webgpu.hpp:226:1: error: conversion function converting 'wgpu::ComputePassTimestampLocation' to itself will never be used [-Werror,-Wclass-conversion]
  226 | ENUM(ComputePassTimestampLocation)
      | ^
/Users/aagrawal05/Projects/LearnWebGPU-Code/build/web/_deps/webgpu-backend-emscripten-src/include/webgpu/webgpu.hpp:106:2: note: expanded from macro 'ENUM'
  106 |         operator W() { return m_raw; } \
      |         ^
/Users/aagrawal05/Projects/LearnWebGPU-Code/build/web/_deps/webgpu-backend-emscripten-src/include/webgpu/webgpu.hpp:226:1: error: field has incomplete type 'W' (aka 'wgpu::ComputePassTimestampLocation')
/Users/aagrawal05/Projects/LearnWebGPU-Code/build/web/_deps/webgpu-backend-emscripten-src/include/webgpu/webgpu.hpp:108:4: note: expanded from macro 'ENUM'
  108 |         W m_raw; \
      |           ^
/Users/aagrawal05/Projects/LearnWebGPU-Code/build/web/_deps/webgpu-backend-emscripten-src/include/webgpu/webgpu.hpp:226:6: note: definition of 'wgpu::ComputePassTimestampLocation' is not complete until the closing '}'
  226 | ENUM(ComputePassTimestampLocation)
      |      ^
/Users/aagrawal05/Projects/LearnWebGPU-Code/build/web/_deps/webgpu-backend-emscripten-src/include/webgpu/webgpu.hpp:227:13: error: constexpr variable cannot have non-literal type 'const W' (aka 'const wgpu::ComputePassTimestampLocation')
  227 |         ENUM_ENTRY(Beginning, 0x00000000)
      |                    ^
/Users/aagrawal05/Projects/LearnWebGPU-Code/build/web/_deps/webgpu-backend-emscripten-src/include/webgpu/webgpu.hpp:228:13: error: constexpr variable cannot have non-literal type 'const W' (aka 'const wgpu::ComputePassTimestampLocation')
  228 |         ENUM_ENTRY(End, 0x00000001)
      |                    ^
/Users/aagrawal05/Projects/LearnWebGPU-Code/build/web/_deps/webgpu-backend-emscripten-src/include/webgpu/webgpu.hpp:229:13: error: constexpr variable cannot have non-literal type 'const W' (aka 'const wgpu::ComputePassTimestampLocation')
  229 |         ENUM_ENTRY(Force32, 0x7FFFFFFF)
      |                    ^
/Users/aagrawal05/Projects/LearnWebGPU-Code/build/web/_deps/webgpu-backend-emscripten-src/include/webgpu/webgpu.hpp:309:1: error: unknown type name 'WGPUPipelineStatisticName'; did you mean 'PipelineStatisticName'?
  309 | ENUM(PipelineStatisticName)
      | ^
/Users/aagrawal05/Projects/LearnWebGPU-Code/build/web/_deps/webgpu-backend-emscripten-src/include/webgpu/webgpu.hpp:104:10: note: expanded from macro 'ENUM'
  104 |         typedef WGPU ## Type W; /* W == WGPU Type */ \
      |                 ^
<scratch space>:41:1: note: expanded from here
   41 | WGPUPipelineStatisticName
      | ^
/Users/aagrawal05/Projects/LearnWebGPU-Code/build/web/_deps/webgpu-backend-emscripten-src/include/webgpu/webgpu.hpp:309:6: note: 'PipelineStatisticName' declared here
  309 | ENUM(PipelineStatisticName)
      |      ^
/Users/aagrawal05/Projects/LearnWebGPU-Code/build/web/_deps/webgpu-backend-emscripten-src/include/webgpu/webgpu.hpp:309:1: error: conversion function converting 'wgpu::PipelineStatisticName' to itself will never be used [-Werror,-Wclass-conversion]
  309 | ENUM(PipelineStatisticName)
      | ^
/Users/aagrawal05/Projects/LearnWebGPU-Code/build/web/_deps/webgpu-backend-emscripten-src/include/webgpu/webgpu.hpp:106:2: note: expanded from macro 'ENUM'
  106 |         operator W() { return m_raw; } \
      |         ^
/Users/aagrawal05/Projects/LearnWebGPU-Code/build/web/_deps/webgpu-backend-emscripten-src/include/webgpu/webgpu.hpp:309:1: error: field has incomplete type 'W' (aka 'wgpu::PipelineStatisticName')
/Users/aagrawal05/Projects/LearnWebGPU-Code/build/web/_deps/webgpu-backend-emscripten-src/include/webgpu/webgpu.hpp:108:4: note: expanded from macro 'ENUM'
  108 |         W m_raw; \
      |           ^
/Users/aagrawal05/Projects/LearnWebGPU-Code/build/web/_deps/webgpu-backend-emscripten-src/include/webgpu/webgpu.hpp:309:6: note: definition of 'wgpu::PipelineStatisticName' is not complete until the closing '}'
  309 | ENUM(PipelineStatisticName)
      |      ^
/Users/aagrawal05/Projects/LearnWebGPU-Code/build/web/_deps/webgpu-backend-emscripten-src/include/webgpu/webgpu.hpp:310:13: error: constexpr variable cannot have non-literal type 'const W' (aka 'const wgpu::PipelineStatisticName')
  310 |         ENUM_ENTRY(VertexShaderInvocations, 0x00000000)
      |                    ^
/Users/aagrawal05/Projects/LearnWebGPU-Code/build/web/_deps/webgpu-backend-emscripten-src/include/webgpu/webgpu.hpp:311:13: error: constexpr variable cannot have non-literal type 'const W' (aka 'const wgpu::PipelineStatisticName')
  311 |         ENUM_ENTRY(ClipperInvocations, 0x00000001)
      |                    ^
/Users/aagrawal05/Projects/LearnWebGPU-Code/build/web/_deps/webgpu-backend-emscripten-src/include/webgpu/webgpu.hpp:312:13: error: constexpr variable cannot have non-literal type 'const W' (aka 'const wgpu::PipelineStatisticName')
  312 |         ENUM_ENTRY(ClipperPrimitivesOut, 0x00000002)
      |                    ^
/Users/aagrawal05/Projects/LearnWebGPU-Code/build/web/_deps/webgpu-backend-emscripten-src/include/webgpu/webgpu.hpp:313:13: error: constexpr variable cannot have non-literal type 'const W' (aka 'const wgpu::PipelineStatisticName')
  313 |         ENUM_ENTRY(FragmentShaderInvocations, 0x00000003)
      |                    ^
/Users/aagrawal05/Projects/LearnWebGPU-Code/build/web/_deps/webgpu-backend-emscripten-src/include/webgpu/webgpu.hpp:314:13: error: constexpr variable cannot have non-literal type 'const W' (aka 'const wgpu::PipelineStatisticName')
  314 |         ENUM_ENTRY(ComputeShaderInvocations, 0x00000004)
      |                    ^
/Users/aagrawal05/Projects/LearnWebGPU-Code/build/web/_deps/webgpu-backend-emscripten-src/include/webgpu/webgpu.hpp:315:13: error: constexpr variable cannot have non-literal type 'const W' (aka 'const wgpu::PipelineStatisticName')
  315 |         ENUM_ENTRY(Force32, 0x7FFFFFFF)
      |                    ^
/Users/aagrawal05/Projects/LearnWebGPU-Code/build/web/_deps/webgpu-backend-emscripten-src/include/webgpu/webgpu.hpp:350:1: error: unknown type name 'WGPURenderPassTimestampLocation'; did you mean 'RenderPassTimestampLocation'?
  350 | ENUM(RenderPassTimestampLocation)
      | ^
/Users/aagrawal05/Projects/LearnWebGPU-Code/build/web/_deps/webgpu-backend-emscripten-src/include/webgpu/webgpu.hpp:104:10: note: expanded from macro 'ENUM'
  104 |         typedef WGPU ## Type W; /* W == WGPU Type */ \
      |                 ^
<scratch space>:47:1: note: expanded from here
   47 | WGPURenderPassTimestampLocation
      | ^
/Users/aagrawal05/Projects/LearnWebGPU-Code/build/web/_deps/webgpu-backend-emscripten-src/include/webgpu/webgpu.hpp:350:6: note: 'RenderPassTimestampLocation' declared here
  350 | ENUM(RenderPassTimestampLocation)
      |      ^
/Users/aagrawal05/Projects/LearnWebGPU-Code/build/web/_deps/webgpu-backend-emscripten-src/include/webgpu/webgpu.hpp:350:1: error: conversion function converting 'wgpu::RenderPassTimestampLocation' to itself will never be used [-Werror,-Wclass-conversion]
  350 | ENUM(RenderPassTimestampLocation)
      | ^
/Users/aagrawal05/Projects/LearnWebGPU-Code/build/web/_deps/webgpu-backend-emscripten-src/include/webgpu/webgpu.hpp:106:2: note: expanded from macro 'ENUM'
  106 |         operator W() { return m_raw; } \
      |         ^
/Users/aagrawal05/Projects/LearnWebGPU-Code/build/web/_deps/webgpu-backend-emscripten-src/include/webgpu/webgpu.hpp:350:1: error: field has incomplete type 'W' (aka 'wgpu::RenderPassTimestampLocation')
/Users/aagrawal05/Projects/LearnWebGPU-Code/build/web/_deps/webgpu-backend-emscripten-src/include/webgpu/webgpu.hpp:108:4: note: expanded from macro 'ENUM'
  108 |         W m_raw; \
      |           ^
/Users/aagrawal05/Projects/LearnWebGPU-Code/build/web/_deps/webgpu-backend-emscripten-src/include/webgpu/webgpu.hpp:350:6: note: definition of 'wgpu::RenderPassTimestampLocation' is not complete until the closing '}'
  350 | ENUM(RenderPassTimestampLocation)
      |      ^
/Users/aagrawal05/Projects/LearnWebGPU-Code/build/web/_deps/webgpu-backend-emscripten-src/include/webgpu/webgpu.hpp:351:13: error: constexpr variable cannot have non-literal type 'const W' (aka 'const wgpu::RenderPassTimestampLocation')
  351 |         ENUM_ENTRY(Beginning, 0x00000000)
      |                    ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make[2]: *** [CMakeFiles/App.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/App.dir/all] Error 2
make: *** [all] Error 2

The example builds perfectly on native. The issue (from the log) seems to be local to the webgpu.hpp header. Is there some sort of version mismatch or other error?

eliemichel commented 4 months ago

This branch uses a version of WebGPU-distribution that is getting a bit old, where webgpu.hpp was written for emscripten v3.1.45. You can either use that old version, or update the distribution by replacing webgpu/webgpu.cmake with a newer version (that one is based on emscripten v3.1.61 and may work in newer versions as well).

I am currently going through the whole guide to update multiple things, among which including support for emscripten in the main guide instead of maintaining a specific version of the branches. It has not reached step095 yet but let me know if you need me to focus on it!

aagrawal05 commented 4 months ago

Hey, works great with the new updated webgpu.cmake. Some very minor changes with naming like requiredFeatureCount instead of requiredFeaturesCount. I was able to get it running very quickly by resolving the compiler issues so likely no urgent changes needed to update it right away. Maybe a short disclaimer in the step095 readme, but this issue may be sufficient for that. Thanks!

aagrawal05 commented 4 months ago

Some tough-to-spot changes which I had to find (and which may speed up updating this section in future) was in the current webgpu.hpp where nullptr is not a valid input for the createInstance function. However the new Emscripten interface now requires it so you need to pass nullptr instead of InstanceDescriptor to show its not implemented with an assert.

Screenshot 2024-07-03 at 23 49 17

So I had to write with the vanilla wgpuCreateInstance(nullptr) instead of createInstance(InstanceDescriptor{})—should be a relatively simple fix in webgpu.hpp when updating later.

Also the depth slice was added to the color attachment API so had to find the enum and update by adding this line—perhaps could be added to the webgpu.hpp as well in the default construction. renderPassColorAttachment.depthSlice = WGPU_DEPTH_SLICE_UNDEFINED;