manifold
manifold copied to clipboard
emscripten tbb stuff
This is mainly to reproduce the issues, not intended for merging. There are still weird issues with pthread enabled build, and the performance is not that good when running from the browser (it can run significantly slower).
- Enabling the build is actually very easy, just need to specify
-pthread
toCMAKE_CXX_FLAGS
andCMAKE_EXE_LINKER_FLAGS
. We also need to set the cross origin policy bla bla bla to use SharedArrayBuffer, which is required for shared memory between workers. - It turns out the vite issue is https://github.com/vitejs/vite/issues/7015 and https://github.com/emscripten-core/emscripten/issues/20580, and there is also an issue from emscripten that uses
require
from the worker which does not work with ES6 (is this https://github.com/emscripten-core/emscripten/issues/17664 ? they said pthread supports ES6 though). I managed to fix by an ugly script. - For some reason I am unable to get anything run with node when pthread and ES6 module is used. This is the major issue and I am unable to get this work with the latest version of emscripten (3.1.51). You may need to modify the patch function to use
.\/built\/manifold.worker.js
instead ofbuilt\/manifold.worker.js
. Somehow vite is only happy with the latter while node is only happy with the former. - For extra fun, try
and then you will find that nodejs somehow will not rundiff --git a/CMakeLists.txt b/CMakeLists.txt index 881182d..a1137d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,9 +57,10 @@ endif() if(EMSCRIPTEN) message("Building for Emscripten") + set(CMAKE_EXECUTABLE_SUFFIX_CXX ".mjs") set(MANIFOLD_FLAGS -fexceptions -D_LIBCUDACXX_HAS_THREAD_API_EXTERNAL -D_LIBCUDACXX_HAS_THREAD_API_CUDA) # ALLOW_MEMORY_GROWTH is slow, so we just allow 2gb of memory usage - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -sINITIAL_MEMORY=2gb -sALLOW_MEMORY_GROWTH=0 -fexceptions -sDISABLE_EXCEPTION_CATCHING=0") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -sMODULARIZE=1 -sEXPORT_ES6=1 -sINITIAL_MEMORY=2gb -sALLOW_MEMORY_GROWTH=0 -fexceptions -sDISABLE_EXCEPTION_CATCHING=0") set(MANIFOLD_PYBIND OFF) if(MANIFOLD_PAR STREQUAL "TBB") set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -pthread)
test/manifold_test.mjs
no matter how hard you try... Probably similar issue with 3.