Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The demo really needs to use WASM #26

Open
wave-glsl opened this issue Aug 15, 2020 · 1 comment
Open

The demo really needs to use WASM #26

wave-glsl opened this issue Aug 15, 2020 · 1 comment

Comments

@wave-glsl
Copy link
Contributor

Looking at at the wavelib:gh-pages branch, I see that it loads a script called wavelib.js, which was apparently produced by Emscripten, but it's not really a wasm, but rather that "js asm" dialect. I've tried to fix it by producing a proper wasm binary from the src/*.c sources, but only found out that the demo uses a mysterious function cwave_transform that's not defined in any of those C sources. I've tried searching the entire github for it with no success. I guess that wavelib.js is a really old build of some C lib that's changed since then.

If you replace that wavelib.js with real wasm, the demo will be a lot faster (like 10x faster). Here's a bash script to produce wasm files:

OUTPUT_FILE="./js/wavelib.js";
INPUT_FILES="./src/*.c";

echo "Building wasm from $INPUT_FILES to $OUTPUT_FILE";

emcc $INPUT_FILES -O3 \
  -s WASM=1 \
  -s EXTRA_EXPORTED_RUNTIME_METHODS='["cwrap"]' \
  -s EXPORTED_FUNCTIONS="['_malloc','_free', 'cwave_transform']" \
  -s ALLOW_MEMORY_GROWTH=1 \
  -s FILESYSTEM=0 \
  -o "$OUTPUT_FILE";

The rest of the logic remain the same: index.html still loads wavelib.js, which behind the scenes, loads wavelib.wasm, and all calls to Module._cwave_transform and the like will be transparently routed to the wasm binary.

@rafat
Copy link
Owner

rafat commented Aug 15, 2020 via email

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

No branches or pull requests

2 participants