Skip to content

Commit

Permalink
Merge pull request #69799 from akien-mga/embree-emscripten-fix-side-m…
Browse files Browse the repository at this point in the history
…odule-build

Web: Fix side module build with Embree
  • Loading branch information
akien-mga authored Dec 9, 2022
2 parents 2d02cb6 + a20aabf commit 333449e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 15 deletions.
24 changes: 9 additions & 15 deletions thirdparty/embree/common/sys/sysinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
42 changes: 42 additions & 0 deletions thirdparty/embree/patches/emscripten-nthreads.patch
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 333449e

Please sign in to comment.