These files, and several snippets of other files, are generated by Dawn (Chromium's WebGPU library):
The C header is intended to be mostly the same as the “upstream” webgpu.h, but both are in flux, and some experimental elements are included and other native-specific elements are excluded.
The C++ files are currently Dawn-specific, but included in Emscripten for better compatibility with Dawn: it has roughly the same API as Dawn's copy, but is included here because it is strongly tied to an exact webgpu.h revision.
To update these bindings from Dawn:
Copy webgpu_enum_class_bitmasks.h from Dawn's source to system/include/webgpu/webgpu_enum_class_bitmasks.h
Build Dawn's emscripten_bits_gen target (in a gn or CMake build of Dawn, or a build of Chromium) - or, use the Chromium Code Search copy of the generated files if no changes are needed
Copy the generated emscripten-bits/system files into Emscripten's system directory
system/include/webgpu/webgpu.hsystem/include/webgpu/webgpu_cpp.hsystem/include/webgpu/webgpu_cpp_chained_struct.hsystem/lib/webgpu/webgpu_cpp.cppPaste the contents of library_webgpu_enum_tables.js over the “Map from enum number to enum string” section of library_webgpu.js
Paste webgpu_struct_info.json over the “WebGPU” section of struct_info.json.
Manually update the globalThis.gpu compile-time enum tables (AdapterType, BackendType, etc.):
webgpu.h diff for changes to the integer values of any enums used here. (It‘s not necessary to add new enum values to these tables until they’re needed for something.)Manually update the “Map from enum string back to enum number” tables.
webgpu.h diff for changes to these enums. (These tables need to be complete so that we can handle any enum string the browser gives us.)Update Emscripten's auto-generated files:
emcc --clear-cache ./tools/maint/gen_struct_info.py ./tools/maint/gen_struct_info.py --wasm64 ./tools/maint/gen_sig_info.py
There is a browser.test_webgpu_basic_rendering with minimal WebGPU API testing that can be handy to test manually before making a contribution. Use browser64.test_webgpu_basic_rendering to test the MEMORY64 build.
test/runner browser.test_webgpu_basic_rendering test/runner browser64.test_webgpu_basic_rendering
You may need to specify extra browser cmd args to assign the WebGPU supported browser, which is needed if you work on linux where WebGPU is not enabled by default in chrome at present.
test/runner browser.test_webgpu_basic_rendering --browser="google-chrome-unstable --enable-unsafe-webgpu --enable-features=Vulkan,UseSkiaRenderer"
Alternatively you can test your emscripten updates by building the source file, and then serve (e.g. use node http-server) and view in browser to make sure things work fine.
emcc --clear-cache emcc test/webgpu_basic_rendering.cpp -sUSE_WEBGPU -o path/to/index.html