Skip to content

Add WebGPU Wasm bindings and BitonicSortWasm demo#73

Merged
bmedina merged 31 commits intomainfrom
bmedina/260210/wasm-bindings-via-macros
Feb 23, 2026
Merged

Add WebGPU Wasm bindings and BitonicSortWasm demo#73
bmedina merged 31 commits intomainfrom
bmedina/260210/wasm-bindings-via-macros

Conversation

@bmedina
Copy link
Collaborator

@bmedina bmedina commented Feb 20, 2026

Summary

  • Adds Swift WebGPU bindings for WebAssembly using JavaScriptKit's BridgeJS @JSClass/@JSFunction/@JSGetter macros to wrap browser WebGPU APIs (device, pipelines, buffers, encoders, bind groups, textures, etc.). Note that these are manually-coded bindings, and we may migrate to codegen'd bindings in the future. This is just enough to get the demo working.
  • Adds BitonicSortWasm demo, ported from the native BitonicSort demo. This demo can be built and run via:
SWAN_WASM=1 swift package --swift-sdk DEVELOPMENT-SNAPSHOT-2026-02-06-a-wasm32-unknown-wasip1 js --product BitonicSortWasm
python3 -m http.server 3000
open http://localhost:3000/Demos/BitonicSortWasm/index.html
  • Adds JavaScriptKit dependency to the just-released 0.46.0 to access the new BridgeJS macros
  • Wires WebGPUWasm into the existing WebGPU umbrella target, so consumers can import WebGPU on both native and Wasm

Note that the BitonicSortWasm code is copied-and-tweaked from the native version. Next step is to unify the code between the two as much as possible.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

I'm not sure if we actually need @js macros here yet.
There is nothing JavaScriptKit-dependent about these, so we'll want a better strategy for generating these later.
Some depend on GPU types we haven't created yet. Those will be next.
Not sure this is still required, but we needed it at some point.
…emo code.

Note that some are decorated with @_spi(Experimental) to work around build issues. This also results in demo code needing to import things with the same decoration.
Currently doesn't properly render.
…Layout list must be an empty array if ommitted, not nil.
@bmedina bmedina marked this pull request as ready for review February 20, 2026 18:15
@bmedina bmedina changed the title Add WebGPU Wasm bindings via JavaScriptKit BridgeJS macros Add WebGPU Wasm bindings and BitonicSortWasm demo Feb 20, 2026

## Why these files are committed

The `bridge-js` plugin is a development-time tool, not a build-time plugin. It does not run automatically during `swift build`. If the generated files aren't checked in, anyone cloning the repo would need to run the plugin manually before they could build the `WebGPUWasm` target.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For other projects to use Swan as a dependency, we need the files checked in. I'm wondering if there's any way we can detect when they are out-of-date in CI or something?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, these are checked in. I'd like to see how the workflow ends up working for folks before adding more automation, but I agree that it may be necessary.

Copy link
Collaborator

@cuberoot cuberoot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a great step forward. Unifying the APIs will be challenging, but it's great to have this stepping stone.

@bmedina bmedina merged commit 55aafeb into main Feb 23, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants