Add WebAssembly / Emscripten as new compilation target#1
Add WebAssembly / Emscripten as new compilation target#1kaischroeder wants to merge 4 commits intodev-backupfrom
Conversation
Co-authored-by: Roland Ruiters-Christou <roland.ruiters@autodesk.com> Co-authored-by: Sebastian Dunkel <sebastian.dunkel@autodesk.com> Co-authored-by: Aura Munoz <aura.munoz@autodesk.com> Co-authored-by: Philipp Frericks <philipp.frericks@autodesk.com> Co-authored-by: Cedrick Muenstermann <cedrick.muenstermann@autodesk.com>
Co-authored-by: Roland Ruiters-Christou <roland.ruiters@autodesk.com> Co-authored-by: Sebastian Dunkel <sebastian.dunkel@autodesk.com> Co-authored-by: Aura Munoz <aura.munoz@autodesk.com> Co-authored-by: Philipp Frericks <philipp.frericks@autodesk.com> Co-authored-by: Cedrick Muenstermann <cedrick.muenstermann@autodesk.com>
Co-authored-by: Roland Ruiters-Christou <roland.ruiters@autodesk.com> Co-authored-by: Sebastian Dunkel <sebastian.dunkel@autodesk.com> Co-authored-by: Aura Munoz <aura.munoz@autodesk.com> Co-authored-by: Philipp Frericks <philipp.frericks@autodesk.com> Co-authored-by: Cedrick Muenstermann <cedrick.muenstermann@autodesk.com>
|
I tried a build under CentOS, using the command line noted in the instructions above, but got hung up right away: I wonder if there's a little more set up required for emsc. |
Hm, good question. So far I have only tried compiling on Ubuntu - someone else successfully built it on Mac though. Maybe the Dockerfile contains something useful? It looks like cmake cannot find pthread for some reason. Does a standard compile of USD work on this machine? |
|
Minor thing. I successfully build the docker container on my M1 Mac. But the package.json file binding path is "bindings/RelWithDebInfo/jsBindings." but the docker container path is "bindings/Release/jsBindings." |
|
Took some time this weekend to get this up and running with React-Three-Fiber. This is very exciting!
|
|
Just started following this PR. Fantastic work @kaischroeder + team really awesome to see this progress. A few thoughts/questions;
|
yes, but I'll refer to the team working on this currently. :-)
I don't think so. You can fetch assets directly from within WASM (https://emscripten.org/docs/api_reference/fetch.html)
Yes, then we would not need support for a 32bit architecture anymore, which this PR adds. But this can still take a while until all browsers and especially web views support this. |
dirty expression prior to removing it from the collection tables.
Reported by the testLightLinkingSceneIndex test under asan, as:
=1343067==ERROR: AddressSanitizer: heap-use-after-free on address 0x60c0009bd598 at pc 0x7f2b478c6b23 bp 0x7ffff1bf6350 sp 0x7ffff1bf6340
READ of size 8 at 0x60c0009bd598 thread T0
#0 0x7f2b478c6b22 in std::vector<SdfPathExpression::Op, std::allocator<SdfPathExpression::Op> >::size() const /usr/lib/gcc/x86_64-redhat-linux/11/../../../../include/c++/11/bits/stl_vector.h:919
#1 0x7f2b478c6b22 in std::vector<SdfPathExpression::Op, std::allocator<SdfPathExpression::Op> >::vector(std::vector<SdfPathExpression::Op, std::allocator<SdfPathExpression::Op> > const&) /usr/lib/gcc/x86_64-redhat-linux/11/../../../../include/c++/11/bits/stl_vector.h:555
#2 0x7f2b478c6b22 in SdfPathExpression::SdfPathExpression(SdfPathExpression const&) /depts/tools/build_archive/dev/builds/2379295/inst/fedora-gcc64-opt-asan/pxr/include/pxr/usd/sdf/pathExpression.h:54
#3 0x7f2b478cf89d in std::pair<SdfPathExpression, std::optional<std::pair<SdfPath, TfToken> > >::pair<std::pair<SdfPath, TfToken> const&, true>(SdfPathExpression const&, std::pair<SdfPath, TfToken> const&) /usr/lib/gcc/x86_64-redhat-linux/11/../../../../include/c++/11/bits/stl_pair.h:337
#4 0x7f2b478cf89d in HdsiLightLinkingSceneIndex_Impl::_Cache::ProcessCollection(SdfPath const&, TfToken const&, SdfPathExpression const&) imaging/hdsi/lightLinkingSceneIndex.cpp:156
(Internal change: 2379722)
Description of Change(s)
This Draft PR adds support for compiling USD to WebAssembly/Emscripten, which allows us to run the library in a browser or in node.js. It comes with a JavaScript binding for the UsdStage.
The purpose of this PR is to gather early feedback from interested parties before making a real PR to the main USD repository. Please use Github's review functionality to share comments.
Known limitations:
To try this out, install emscripten https://emscripten.org/docs/getting_started/downloads.html and build
The build folder will contain a bin subfolder with a sample (test.html), which creates a USD Stage and prints its content to the console.
The SharedArrayBuffer feature that is used requires cross-origin isolation: https://web.dev/cross-origin-isolation-guide/
For debugging purposes you can run Chrome with a parameter to always enable SharedArrayBuffer so that you don't need to worry about this: --enable-features=SharedArrayBuffer
The better solution is of course to add the proper headers on the server.
Note: This build depends on a version of TBB (Threading Building Blocks) for WebAssembly. https://github.com/hpcwasm/wasmtbb - unfortunately, the corresponding Github project seems to be unmaintained. Luckily it mostly contains changes to build files, so hopefully this situation can be improved in the future. We have also fixed a small problem in this branch: https://github.com/sdunkel/wasmtbb/
In follow-up PRs to be published soon, we intend to open-source:
We have already deployed a few samples using the above mentioned RenderDelegate:
https://autodesk-forks.github.io/USD/
Support for materials in this RenderDelegate is still minimal. Some of the examples use animations, which are directly handled by the USD runtime.