diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2022-12-09 08:10:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-09 08:10:45 +0100 |
commit | 333449e5ee174691e3bf7d7487b37f75f8190dd2 (patch) | |
tree | 276ac62acc356551d9b002e3af27eaa4dd7d709c | |
parent | 2d02cb67ee904b7614a6a5396669c575193fb73f (diff) | |
parent | a20aabf84a9327d5c37d9b7df1414608dcd39753 (diff) |
Merge pull request #69799 from akien-mga/embree-emscripten-fix-side-module-build
Web: Fix side module build with Embree
-rw-r--r-- | thirdparty/embree/common/sys/sysinfo.cpp | 24 | ||||
-rw-r--r-- | thirdparty/embree/patches/emscripten-nthreads.patch | 42 |
2 files changed, 51 insertions, 15 deletions
diff --git a/thirdparty/embree/common/sys/sysinfo.cpp b/thirdparty/embree/common/sys/sysinfo.cpp index c98f61fa53..7f7a009a1e 100644 --- a/thirdparty/embree/common/sys/sysinfo.cpp +++ b/thirdparty/embree/common/sys/sysinfo.cpp @@ -640,6 +640,12 @@ namespace embree #if defined(__EMSCRIPTEN__) #include <emscripten.h> + +// -- GODOT start -- +extern "C" { +extern int godot_js_os_hw_concurrency_get(); +} +// -- GODOT end -- #endif namespace embree @@ -653,21 +659,9 @@ namespace embree nThreads = sysconf(_SC_NPROCESSORS_ONLN); // does not work in Linux LXC container assert(nThreads); #elif defined(__EMSCRIPTEN__) - // WebAssembly supports pthreads, but not pthread_getaffinity_np. Get the number of logical - // threads from the browser or Node.js using JavaScript. - nThreads = MAIN_THREAD_EM_ASM_INT({ - const isBrowser = typeof window !== 'undefined'; - const isNode = typeof process !== 'undefined' && process.versions != null && - process.versions.node != null; - if (isBrowser) { - // Return 1 if the browser does not expose hardwareConcurrency. - return window.navigator.hardwareConcurrency || 1; - } else if (isNode) { - return require('os').cpus().length; - } else { - return 1; - } - }); + // -- GODOT start -- + nThreads = godot_js_os_hw_concurrency_get(); + // -- GODOT end -- #else cpu_set_t set; if (pthread_getaffinity_np(pthread_self(), sizeof(set), &set) == 0) diff --git a/thirdparty/embree/patches/emscripten-nthreads.patch b/thirdparty/embree/patches/emscripten-nthreads.patch new file mode 100644 index 0000000000..e42f203475 --- /dev/null +++ b/thirdparty/embree/patches/emscripten-nthreads.patch @@ -0,0 +1,42 @@ +diff --git a/thirdparty/embree/common/sys/sysinfo.cpp b/thirdparty/embree/common/sys/sysinfo.cpp +index c98f61fa53..7f7a009a1e 100644 +--- a/thirdparty/embree/common/sys/sysinfo.cpp ++++ b/thirdparty/embree/common/sys/sysinfo.cpp +@@ -640,6 +640,12 @@ namespace embree + + #if defined(__EMSCRIPTEN__) + #include <emscripten.h> ++ ++// -- GODOT start -- ++extern "C" { ++extern int godot_js_os_hw_concurrency_get(); ++} ++// -- GODOT end -- + #endif + + namespace embree +@@ -653,21 +659,9 @@ namespace embree + nThreads = sysconf(_SC_NPROCESSORS_ONLN); // does not work in Linux LXC container + assert(nThreads); + #elif defined(__EMSCRIPTEN__) +- // WebAssembly supports pthreads, but not pthread_getaffinity_np. Get the number of logical +- // threads from the browser or Node.js using JavaScript. +- nThreads = MAIN_THREAD_EM_ASM_INT({ +- const isBrowser = typeof window !== 'undefined'; +- const isNode = typeof process !== 'undefined' && process.versions != null && +- process.versions.node != null; +- if (isBrowser) { +- // Return 1 if the browser does not expose hardwareConcurrency. +- return window.navigator.hardwareConcurrency || 1; +- } else if (isNode) { +- return require('os').cpus().length; +- } else { +- return 1; +- } +- }); ++ // -- GODOT start -- ++ nThreads = godot_js_os_hw_concurrency_get(); ++ // -- GODOT end -- + #else + cpu_set_t set; + if (pthread_getaffinity_np(pthread_self(), sizeof(set), &set) == 0) |