-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Support wasm module loading #4235
Conversation
I wonder what is the ideal behaviour with wasm loading for web application that create multiple instances of the engine - do we need just one instance of wasm module, or does it need to be per application. |
I think it depends on the module. Draco probably can be used across-application whereas Ammo might require separate instances. If this became a requirement we could update the config accordingly.
Don't believe you can directly destroy wasm modules. |
I'm wondering about error reporting with this API. Currently all users of I'm thinking the |
Does this also support network retries if the module fails to load from the network? |
I wonder if this should be utilized when supported. (Could be done in a separate PR) |
The wasm binary is downloaded by the emscripten-generated module glue script, which does attempt |
I don't think the glue code has retry logic for the wasm module, but if this was something we needed, we could manage the download & compile of the wasm module ourselves. |
I'm just thinking of the issues that we have with Snapchat where network requests can fail on iOS. It's on a WASM module that doesn't have retry, it could stop loading of the game or prevent the game from working correctly. Here's the PR for basis that we needed for this: #4148 |
They are two different scenarios. The basis code downloadings the script source 'manually' using In this case we're using an html script tag to download and execute the script in place (on the main thread). When we load scripts using script tags elsewhere in the engine there is no retry logic (see https://github.com/playcanvas/engine/blob/main/src/resources/script.js#L100). I don't -think- we need script tag retry logic (and wouldn't know how to implement such a thing). If we wanted manual retry logic we'd have to download the script manually (using http interface) instead. I'm not sure that'd be better and suspect the browser's built-in script tag handling is sufficient. |
It will be something we could test if/when it becomes an issue I guess. Even if it doesn't handle retrying, given this can be lazy loaded, we could potentially mitigate the issue by loading the WASM module first and than other assets that are needed? |
|
Nice! Thanks for the suggestions:
cc @ellthompson - please check changes to examples. |
} | ||
}); | ||
} else { | ||
callback('No supported wasm modules found.', null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- could this add the module name to the error message
- and perhaps even log a debug warning - to help find the problem in case the user does not handle errors correctly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default error handler logs the details as you describe. Otherwise if the caller registers an error handler, it's up to them to do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Approving with one minor comment.
This PR adds standard engine support for loading and initialising emscripten-style wasm modules.
The API supports lazy loading, which is useful for tools that don't require all modules loaded at startup.
The following API is added:
The two functions can be invoked in any order and will resolve correctly.
The Draco decompressor has been updated to use this interface.
Once this PR is merged, the other uses of wasm modules in the codebase (editor applications, examples, model-viewer) should all migrate to this interface.