cwoffenden / hello-webgpu

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

Emscripten fails with latest emsdk; Dawn renamed some types #10

Closed tanzle-aames closed 3 years ago

tanzle-aames commented 3 years ago

https://github.com/emscripten-core/emscripten/commit/07f9930c088c2df0dd096d9ca29ebfd626ef4710

I am just joining the party. Does this mean I should activate an earlier Emscripten SDK? Or update Dawn?

I am willing to roll up sleeves here, as I get familiar with the tools.

Thanks in advance for any guidance.

tanzle-aames commented 3 years ago

These are the errors:

src/main.cpp:278:2: error: unknown type name 'WGPURenderPipelineDescriptor2'; did you mean 'WGPURenderPipelineDescriptor'?
        WGPURenderPipelineDescriptor2 desc = {};
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        WGPURenderPipelineDescriptor
C:\Users\andy\projects\emsdk\upstream\emscripten\cache\sysroot/include\webgpu/webgpu.h:936:3: note: 'WGPURenderPipelineDescriptor' declared here
} WGPURenderPipelineDescriptor;
  ^
src/main.cpp:303:13: error: use of undeclared identifier 'wgpuDeviceCreateRenderPipeline2'; did you mean 'wgpuDeviceCreateRenderPipeline'?
        pipeline = wgpuDeviceCreateRenderPipeline2(device, &desc);
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                   wgpuDeviceCreateRenderPipeline
C:\Users\andy\projects\emsdk\upstream\emscripten\cache\sysroot/include\webgpu/webgpu.h:1220:32: note: 'wgpuDeviceCreateRenderPipeline' declared here
WGPU_EXPORT WGPURenderPipeline wgpuDeviceCreateRenderPipeline(WGPUDevice device, WGPURenderPipelineDescriptor const * descriptor);
tanzle-aames commented 3 years ago

Installing and activating emsdk 2.0.27 allowed me to work around this. I will work on a PR to update the symbols. It could be as simple as that.

tanzle-aames commented 3 years ago

All we need to do is remove a few __EMSCRIPTEN__ #ifdef blocks:

#ifdef __EMSCRIPTEN__
       WGPURenderPipelineDescriptor2 desc = {};
#else
       WGPURenderPipelineDescriptor  desc = {};
#endif
#ifdef __EMSCRIPTEN__
       pipeline = wgpuDeviceCreateRenderPipeline2(device, &desc);
#else
       pipeline = wgpuDeviceCreateRenderPipeline (device, &desc);
#endif
cwoffenden commented 3 years ago

Hi! Emscripten's API caught up a little more with Dawn so yes, these 2 postfixed types/functions no longer need to be special-cased. I've removed them and the CI verified it builds with the latest 2.0.29.