swift-webgpu
swift-webgpu copied to clipboard
Support for browsers via SwiftWASM
Any thoughts of extending your project to also support WebGPU via WASM now that WASM support has been pushed to the mainline of the Swift compiler (although it's not in the official Xcode distro yet...)?
This should be possible - maybe not now, but at some point.
Currently, this project is geared towards Dawn specifically. But once Dawn is compatible with the upstream header (which I think is getting closer), then I will switch to generating from webgpu.yml, which in theory should enable compatibility with Dawn, wgpu-native and indeed Emscripten/WASM.
Thanks for that. I am just getting into Swift. However, I think that the clang-based Swift toolchain is not based on emscripten. It can compile C/C++/Swift to WASM, but it doesn't seem to include the emscripten glue code for C/C++ APIs. I am in the process of seeing how all of this is put together.
In the meantime, I've been pointed to another web-only Swift WebGPU binding based in the IDL for the API.
Ah I see. At a brief glance, that does look like it would be more suitable if you know that you are only targeting web assembly.
That's the issue. We do need to target a wide range of platforms, so your bindings are tempting. However, I don't know that there's a way to use the emscripten bindings. The Switch compiler for WASM doesn't have the system glue code that emscripten does. Their JavaScript binding strategy seems to be JavaScriptKit.
Right, got it. I'll admit, I'm not too familiar with the current state of web assembly in swift. I'll try to find a moment to read up on it.
In theory then, it might be possible to create bindings from the webgpu native api to the JS api, via JavaScriptKit. Whether this can be generated automatically, I'm not sure, since there are some subtle differences between the native and web versions.
It looks like emscripten has the glue code that maps the C api to the JS api. If there's a way to repurpose this but make it compatible with swift-wasm, that could be an efficient solution.