From 9490947cd099c32856170777e2f1e13c706507bb Mon Sep 17 00:00:00 2001 From: Christian Oliveros Date: Mon, 11 Nov 2024 00:01:20 +0100 Subject: [PATCH 01/14] Basic EMSCRIPTEN build (not all targets work) --- CMakeLists.txt | 49 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ab5dd8..9a089fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,8 +8,11 @@ project(tiny_bvh LANGUAGES CXX) if (APPLE) find_library(COCOA_LIBRARY Cocoa) -elseif (UNIX) +elseif (UNIX AND NOT EMSCRIPTEN) find_package(X11) +elseif (EMSCRIPTEN) + # To auto generate test pages + set(CMAKE_EXECUTABLE_SUFFIX ".html") endif() enable_testing() @@ -17,15 +20,34 @@ enable_testing() add_executable(tiny_bvh_test tiny_bvh_test.cpp) add_executable(tiny_bvh_renderer tiny_bvh_renderer.cpp) add_executable(tiny_bvh_speedtest tiny_bvh_speedtest.cpp) -add_executable(tiny_bvh_fenster tiny_bvh_fenster.cpp) +if (NOT EMSCRIPTEN) + # EMSCRIPTEN doesn't render anything by default (you would need WebGL/WebGPU) + add_executable(tiny_bvh_fenster tiny_bvh_fenster.cpp) +endif() if (NOT MSVC) + # Produce debug symbols set(common_cxx_flags - -g -march=native + -g ) + + if (NOT EMSCRIPTEN) + # EMSCRIPTEN doesn't know about archs + set(common_cxx_flags + ${common_cxx_flags} -march=native + ) + else() + # EMSCRIPTEN flags: + # - -sALLOW_MEMORY_GROWTH (allow runtime allocations) (note linker will warn as CMAKE passes CMAKE_CXX_FLAGS to it as well) + set(CMAKE_CXX_FLAGS + ${CMAKE_CXX_FLAGS} -sALLOW_MEMORY_GROWTH=1 + ) + endif() + target_compile_options(tiny_bvh_test PRIVATE ${common_cxx_flags}) target_compile_options(tiny_bvh_renderer PRIVATE ${common_cxx_flags}) - if (NOT APPLE) + + if (NOT APPLE AND NOT EMSCRIPTEN) target_compile_options(tiny_bvh_speedtest PRIVATE ${common_cxx_flags} -fopenmp) target_link_options(tiny_bvh_speedtest PRIVATE -fopenmp) else() @@ -33,13 +55,18 @@ if (NOT MSVC) target_compile_options(tiny_bvh_speedtest PRIVATE ${common_cxx_flags}) target_link_options(tiny_bvh_speedtest PRIVATE) endif() - target_compile_options(tiny_bvh_fenster PRIVATE ${common_cxx_flags}) - if (WIN32) - target_link_libraries(tiny_bvh_fenster -mwindows) - elseif (APPLE) - target_link_libraries(tiny_bvh_fenster ${COCOA_LIBRARY}) - elseif (X11_FOUND) - target_link_libraries(tiny_bvh_fenster ${X11_LIBRARIES}) + + if (TARGET tiny_bvh_fenster) + # Not all platforms support all targets. E. g.: + # - EMSCRIPTEN doesn't render anything by default (you would need WebGL/WebGPU) + target_compile_options(tiny_bvh_fenster PRIVATE ${common_cxx_flags}) + if (WIN32) + target_link_libraries(tiny_bvh_fenster -mwindows) + elseif (APPLE) + target_link_libraries(tiny_bvh_fenster ${COCOA_LIBRARY}) + elseif (X11_FOUND) + target_link_libraries(tiny_bvh_fenster ${X11_LIBRARIES}) + endif() endif() else() if (WIN32) From d8bb9c61afd1e6214ce3b59bcfb72e04559fb87e Mon Sep 17 00:00:00 2001 From: Christian Oliveros Date: Mon, 11 Nov 2024 01:15:34 +0100 Subject: [PATCH 02/14] Fixed aligned malloc size non-multiple of alignment issue --- tiny_bvh.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tiny_bvh.h b/tiny_bvh.h index f852b63..623db96 100644 --- a/tiny_bvh.h +++ b/tiny_bvh.h @@ -93,6 +93,24 @@ THE SOFTWARE. #define ALIGNED( x ) __declspec( align( x ) ) #define ALIGNED_MALLOC( x ) ( ( x ) == 0 ? 0 : _aligned_malloc( ( x ), 64 ) ) #define ALIGNED_FREE( x ) _aligned_free( x ) +#elif defined(__EMSCRIPTEN__) +// EMSCRIPTEN (needs to be before gcc and clang to avoid misdetection) +#include +#include +#include +#define ALIGNED( x ) __attribute__( ( aligned( x ) ) ) +#if defined(__x86_64__) || defined(_M_X64) +// https://stackoverflow.com/questions/32612881/why-use-mm-malloc-as-opposed-to-aligned-malloc-alligned-alloc-or-posix-mem +#include +#define ALIGNED_MALLOC( x ) ( ( x ) == 0 ? 0 : _mm_malloc( ( x ), 64 ) ) +#define ALIGNED_FREE( x ) _mm_free( x ) +#else +// Size needs to be a multiple of Alignment in the standard (in EMSCRIPTEN this is enforced) +// See https://en.cppreference.com/w/c/memory/aligned_alloc +#define MAKE_MULIPLE_64( x ) ( ( x + 63 ) & ( ~0x3f ) ) +#define ALIGNED_MALLOC( x ) ( ( x ) == 0 ? 0 : aligned_alloc( 64, MAKE_MULIPLE_64( x ) ) ) +#define ALIGNED_FREE( x ) free( x ) +#endif #else // gcc / clang #include From d1f0ea3fa0a169d48bd4579faa92a5b8d79f1f73 Mon Sep 17 00:00:00 2001 From: Christian Oliveros Date: Mon, 11 Nov 2024 01:39:56 +0100 Subject: [PATCH 03/14] Added emcc compiler identification --- tiny_bvh_speedtest.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tiny_bvh_speedtest.cpp b/tiny_bvh_speedtest.cpp index b8903e0..a3864f1 100644 --- a/tiny_bvh_speedtest.cpp +++ b/tiny_bvh_speedtest.cpp @@ -9,6 +9,9 @@ #ifdef _WIN32 #include // for __cpuidex #endif +#ifdef __EMSCRIPTEN__ +#include // for __EMSCRIPTEN_major__, __EMSCRIPTEN_minor__ +#endif // 'screen resolution': see tiny_bvh_fenster.cpp; this program traces the // same rays, but without visualization - just performance statistics. @@ -122,6 +125,9 @@ int main() // determine compiler #ifdef _MSC_VER printf( "(MSVC %i build)\n", _MSC_VER ); +#elif defined __EMSCRIPTEN__ + // EMSCRIPTEN needs to be before clang or gcc + printf("(emcc %i.%i build)\n", __EMSCRIPTEN_major__, __EMSCRIPTEN_minor__); #elif defined __clang__ printf( "(clang %i.%i build)\n", __clang_major__ , __clang_minor__ ); #elif defined __GNUC__ From 8c21fd4b281e39548f46a308d2d724944d4b11ce Mon Sep 17 00:00:00 2001 From: Christian Oliveros Date: Tue, 12 Nov 2024 12:33:31 +0100 Subject: [PATCH 04/14] Improved flag handling for compiler and linker --- CMakeLists.txt | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a089fc..6ea7dc5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,8 @@ elseif (UNIX AND NOT EMSCRIPTEN) elseif (EMSCRIPTEN) # To auto generate test pages set(CMAKE_EXECUTABLE_SUFFIX ".html") + + option(ENABLE_ASAN "Enable ASAN on the build (it'll slow down the app)" OFF) endif() enable_testing() @@ -31,6 +33,10 @@ if (NOT MSVC) -g ) + set(common_link_flags + -g + ) + if (NOT EMSCRIPTEN) # EMSCRIPTEN doesn't know about archs set(common_cxx_flags @@ -38,28 +44,37 @@ if (NOT MSVC) ) else() # EMSCRIPTEN flags: - # - -sALLOW_MEMORY_GROWTH (allow runtime allocations) (note linker will warn as CMAKE passes CMAKE_CXX_FLAGS to it as well) - set(CMAKE_CXX_FLAGS - ${CMAKE_CXX_FLAGS} -sALLOW_MEMORY_GROWTH=1 - ) + # -sALLOW_MEMORY_GROWTH (allow runtime allocations) (for some reason cmake passes this as a linker flag when in theory it's a compiler one) + set(common_link_flags ${common_link_flags} -sALLOW_MEMORY_GROWTH=1) + + # -fsanitize=address (enable ASAN) + # More at https://emscripten.org/docs/debugging/Sanitizers.html#address-sanitizer + if (ENABLE_ASAN) + set(common_cxx_flags ${common_cxx_flags} -fsanitize=address) + set(common_link_flags ${common_link_flags} -fsanitize=address) + endif() endif() target_compile_options(tiny_bvh_test PRIVATE ${common_cxx_flags}) + target_link_options(tiny_bvh_test PRIVATE ${common_link_flags}) + target_compile_options(tiny_bvh_renderer PRIVATE ${common_cxx_flags}) + target_link_options(tiny_bvh_renderer PRIVATE ${common_link_flags}) if (NOT APPLE AND NOT EMSCRIPTEN) target_compile_options(tiny_bvh_speedtest PRIVATE ${common_cxx_flags} -fopenmp) - target_link_options(tiny_bvh_speedtest PRIVATE -fopenmp) + target_link_options(tiny_bvh_speedtest PRIVATE ${common_link_flags} -fopenmp) else() # No openmp support in default compiler target_compile_options(tiny_bvh_speedtest PRIVATE ${common_cxx_flags}) - target_link_options(tiny_bvh_speedtest PRIVATE) + target_link_options(tiny_bvh_speedtest PRIVATE ${common_link_flags}) endif() if (TARGET tiny_bvh_fenster) # Not all platforms support all targets. E. g.: # - EMSCRIPTEN doesn't render anything by default (you would need WebGL/WebGPU) target_compile_options(tiny_bvh_fenster PRIVATE ${common_cxx_flags}) + target_link_options(tiny_bvh_fenster PRIVATE ${common_link_flags}) if (WIN32) target_link_libraries(tiny_bvh_fenster -mwindows) elseif (APPLE) From 6673bff4a86a276eecd1a93f64acd4515930d4cb Mon Sep 17 00:00:00 2001 From: Christian Oliveros Date: Tue, 12 Nov 2024 12:39:17 +0100 Subject: [PATCH 05/14] normalized variable name --- CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ea7dc5..f69cab1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,8 @@ elseif (EMSCRIPTEN) # To auto generate test pages set(CMAKE_EXECUTABLE_SUFFIX ".html") - option(ENABLE_ASAN "Enable ASAN on the build (it'll slow down the app)" OFF) + option(enable_asan "Enable ASAN on the build (it'll slow down the app)" OFF) + set() endif() enable_testing() @@ -49,7 +50,7 @@ if (NOT MSVC) # -fsanitize=address (enable ASAN) # More at https://emscripten.org/docs/debugging/Sanitizers.html#address-sanitizer - if (ENABLE_ASAN) + if (enable_asan) set(common_cxx_flags ${common_cxx_flags} -fsanitize=address) set(common_link_flags ${common_link_flags} -fsanitize=address) endif() From 01f6956e3181d0d45d328ca938c9efde02dc02ce Mon Sep 17 00:00:00 2001 From: Christian Oliveros Date: Tue, 12 Nov 2024 13:08:12 +0100 Subject: [PATCH 06/14] Added WASM SIMD support --- CMakeLists.txt | 12 +++++++++++- tiny_bvh.h | 6 +++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f69cab1..fc23b39 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,9 @@ elseif (EMSCRIPTEN) set(CMAKE_EXECUTABLE_SUFFIX ".html") option(enable_asan "Enable ASAN on the build (it'll slow down the app)" OFF) - set() + + set(emcc_simd "fixed" CACHE STRING "SIMD type to use in the build (none, fixed, relaxed)") + set_property(CACHE emcc_simd PROPERTY STRINGS none fixed relaxed) endif() enable_testing() @@ -54,6 +56,14 @@ if (NOT MSVC) set(common_cxx_flags ${common_cxx_flags} -fsanitize=address) set(common_link_flags ${common_link_flags} -fsanitize=address) endif() + + string(TOLOWER "${emcc_simd}" emcc_simd_lower) + if (emcc_simd_lower STREQUAL fixed) + set(common_cxx_flags ${common_cxx_flags} -msimd128 -mavx) + elseif (emcc_simd_lower STREQUAL relaxed) + set(common_cxx_flags ${common_cxx_flags} -mrelaxed-simd -mavx) + endif() + endif() target_compile_options(tiny_bvh_test PRIVATE ${common_cxx_flags}) diff --git a/tiny_bvh.h b/tiny_bvh.h index 623db96..4a44b65 100644 --- a/tiny_bvh.h +++ b/tiny_bvh.h @@ -69,7 +69,7 @@ THE SOFTWARE. #define BVHBINS 8 // include fast AVX BVH builder -#if defined(__x86_64__) || defined(_M_X64) +#if defined(__x86_64__) || defined(_M_X64) || defined(__wasm_simd128__) || defined(__wasm_relaxed_simd__) #define BVH_USEAVX #endif @@ -99,8 +99,8 @@ THE SOFTWARE. #include #include #define ALIGNED( x ) __attribute__( ( aligned( x ) ) ) -#if defined(__x86_64__) || defined(_M_X64) -// https://stackoverflow.com/questions/32612881/why-use-mm-malloc-as-opposed-to-aligned-malloc-alligned-alloc-or-posix-mem +#if defined(__wasm_simd128__) || defined(__wasm_relaxed_simd__) +// https://emscripten.org/docs/porting/simd.html #include #define ALIGNED_MALLOC( x ) ( ( x ) == 0 ? 0 : _mm_malloc( ( x ), 64 ) ) #define ALIGNED_FREE( x ) _mm_free( x ) From 4d3645c00123cba8bdb4bcfff067941141cba98b Mon Sep 17 00:00:00 2001 From: Christian Oliveros Date: Tue, 12 Nov 2024 13:42:07 +0100 Subject: [PATCH 07/14] Added optimized builds --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fc23b39..48ee7f6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,9 +31,9 @@ if (NOT EMSCRIPTEN) endif() if (NOT MSVC) - # Produce debug symbols + # Produce debug symbols and set optimization level set(common_cxx_flags - -g + -g $<$:-O3> ) set(common_link_flags From a5d770e1460ed85294354232b3a3d918b2f9792b Mon Sep 17 00:00:00 2001 From: Christian Oliveros Date: Tue, 12 Nov 2024 14:00:52 +0100 Subject: [PATCH 08/14] Fixed asm for wasm --- tiny_bvh.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tiny_bvh.h b/tiny_bvh.h index 4a9a84d..7f0a9ac 100644 --- a/tiny_bvh.h +++ b/tiny_bvh.h @@ -2596,6 +2596,8 @@ static unsigned __bfind( unsigned x ) // https://github.com/mackron/refcode/blob { #if defined(_MSC_VER) && !defined(__clang__) return 31 - __lzcnt( x ); +#elif defined(__EMSCRIPTEN__) + return 31 - __builtin_clz(x); #elif defined(__GNUC__) || defined(__clang__) unsigned r; __asm__ __volatile__( "lzcnt{l %1, %0| %0, %1}" : "=r"(r) : "r"(x) : "cc" ); From 75be9d6e2ba0b4e8e14ab6db3bd92c50ce80eaed Mon Sep 17 00:00:00 2001 From: Christian Oliveros Date: Tue, 12 Nov 2024 15:51:12 +0100 Subject: [PATCH 09/14] Better description for WASM SIMD flags --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 48ee7f6..452bce9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,10 +57,13 @@ if (NOT MSVC) set(common_link_flags ${common_link_flags} -fsanitize=address) endif() + # Enable SIMD instructions and AVX intrinsics string(TOLOWER "${emcc_simd}" emcc_simd_lower) if (emcc_simd_lower STREQUAL fixed) + # Supported by all browsers https://webassembly.org/features/ set(common_cxx_flags ${common_cxx_flags} -msimd128 -mavx) elseif (emcc_simd_lower STREQUAL relaxed) + # Supported some browsers https://webassembly.org/features/ set(common_cxx_flags ${common_cxx_flags} -mrelaxed-simd -mavx) endif() From 7278ea13ff851605375bedeacf86c0977f3f0960 Mon Sep 17 00:00:00 2001 From: Christian Oliveros Date: Tue, 12 Nov 2024 15:54:10 +0100 Subject: [PATCH 10/14] Added missing parethesis for macro safety --- tiny_bvh.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tiny_bvh.h b/tiny_bvh.h index 7f0a9ac..4be0c6f 100644 --- a/tiny_bvh.h +++ b/tiny_bvh.h @@ -109,7 +109,7 @@ THE SOFTWARE. #else // Size needs to be a multiple of Alignment in the standard (in EMSCRIPTEN this is enforced) // See https://en.cppreference.com/w/c/memory/aligned_alloc -#define MAKE_MULIPLE_64( x ) ( ( x + 63 ) & ( ~0x3f ) ) +#define MAKE_MULIPLE_64( x ) ( ( ( x ) + 63 ) & ( ~0x3f ) ) #define ALIGNED_MALLOC( x ) ( ( x ) == 0 ? 0 : aligned_alloc( 64, MAKE_MULIPLE_64( x ) ) ) #define ALIGNED_FREE( x ) free( x ) #endif From 258231e8a8fbf8f80f0bcb432ad75ac32a252513 Mon Sep 17 00:00:00 2001 From: Christian Oliveros Date: Tue, 12 Nov 2024 17:21:47 +0100 Subject: [PATCH 11/14] Sadly no OpenMP for WASM for now --- CMakeLists.txt | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 452bce9..8ab51f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,10 +14,15 @@ elseif (EMSCRIPTEN) # To auto generate test pages set(CMAKE_EXECUTABLE_SUFFIX ".html") + # Enable clang's Address Sanitizer for WASM option(enable_asan "Enable ASAN on the build (it'll slow down the app)" OFF) + # Enable wasm SIMD instructions set(emcc_simd "fixed" CACHE STRING "SIMD type to use in the build (none, fixed, relaxed)") set_property(CACHE emcc_simd PROPERTY STRINGS none fixed relaxed) + + # Enable thread support for WASM (note that you need special http headers now https://emscripten.org/docs/porting/pthreads.html ) + option(emcc_threads "Enable Threads in WASM (note that means you need to change your http headers)" OFF) endif() enable_testing() @@ -75,14 +80,34 @@ if (NOT MSVC) target_compile_options(tiny_bvh_renderer PRIVATE ${common_cxx_flags}) target_link_options(tiny_bvh_renderer PRIVATE ${common_link_flags}) + # No openmp support in default compiler + set(tiny_bvh_speedtest_cxx_flags ${common_cxx_flags}) + set(tiny_bvh_speedtest_link_flags ${common_link_flags}) + if (NOT APPLE AND NOT EMSCRIPTEN) - target_compile_options(tiny_bvh_speedtest PRIVATE ${common_cxx_flags} -fopenmp) - target_link_options(tiny_bvh_speedtest PRIVATE ${common_link_flags} -fopenmp) - else() - # No openmp support in default compiler - target_compile_options(tiny_bvh_speedtest PRIVATE ${common_cxx_flags}) - target_link_options(tiny_bvh_speedtest PRIVATE ${common_link_flags}) + set(tiny_bvh_speedtest_cxx_flags ${tiny_bvh_speedtest_cxx_flags} -fopenmp) + set(tiny_bvh_speedtest_link_flags ${tiny_bvh_speedtest_link_flags} -fopenmp) + elseif (EMSCRIPTEN) + if (emcc_threads) + set(tiny_bvh_speedtest_cxx_flags ${tiny_bvh_speedtest_cxx_flags} -pthread) + set(tiny_bvh_speedtest_link_flags ${tiny_bvh_speedtest_link_flags} -pthread) + + if (FALSE) + # From: + # - https://github.com/llvm/llvm-project/pull/95169 + # - https://github.com/llvm/llvm-project/pull/71297 + # - https://reviews.llvm.org/D142593?id=492403 + # llvm's and clang's OpenMP has been ported to WASM around August 2024 + # Sadly emcc's clang doesn't include a copy of the lib + # So you would need to do compile it yourself https://github.com/abrown/wasm-openmp-examples/blob/main/emscripten.sh + # Then link it here + set(tiny_bvh_speedtest_cxx_flags ${tiny_bvh_speedtest_cxx_flags} -fopenmp) + set(tiny_bvh_speedtest_link_flags ${tiny_bvh_speedtest_link_flags} -fopenmp) + endif() + endif() endif() + target_compile_options(tiny_bvh_speedtest PRIVATE ${tiny_bvh_speedtest_cxx_flags}) + target_link_options(tiny_bvh_speedtest PRIVATE ${tiny_bvh_speedtest_link_flags}) if (TARGET tiny_bvh_fenster) # Not all platforms support all targets. E. g.: From 961cbbb2cd936779c81a756c8efcae57598ca72b Mon Sep 17 00:00:00 2001 From: Christian Oliveros Date: Tue, 12 Nov 2024 19:42:26 +0100 Subject: [PATCH 12/14] Added emcc proxy thread support to avoid blocking DOM/UI thread --- CMakeLists.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ab51f4..f774f94 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,9 @@ elseif (EMSCRIPTEN) # Enable thread support for WASM (note that you need special http headers now https://emscripten.org/docs/porting/pthreads.html ) option(emcc_threads "Enable Threads in WASM (note that means you need to change your http headers)" OFF) + + # Enable C/C++ main thread as a proxy thread to avoid blocking DOM/UI thread https://emscripten.org/docs/porting/pthreads.html + option(emcc_proxy_main "Enable C/C++ main thread as a proxy thread to avoid blocking DOM/UI thread" ${emcc_threads}) endif() enable_testing() @@ -90,7 +93,7 @@ if (NOT MSVC) elseif (EMSCRIPTEN) if (emcc_threads) set(tiny_bvh_speedtest_cxx_flags ${tiny_bvh_speedtest_cxx_flags} -pthread) - set(tiny_bvh_speedtest_link_flags ${tiny_bvh_speedtest_link_flags} -pthread) + set(tiny_bvh_speedtest_link_flags ${tiny_bvh_speedtest_link_flags} -pthread -sUSE_PTHREADS=1 -sPTHREAD_POOL_SIZE=navigator.hardwareConcurrency) if (FALSE) # From: @@ -104,6 +107,10 @@ if (NOT MSVC) set(tiny_bvh_speedtest_cxx_flags ${tiny_bvh_speedtest_cxx_flags} -fopenmp) set(tiny_bvh_speedtest_link_flags ${tiny_bvh_speedtest_link_flags} -fopenmp) endif() + + if (emcc_proxy_main) + set(tiny_bvh_speedtest_link_flags ${tiny_bvh_speedtest_link_flags} -sPROXY_TO_PTHREAD=1) + endif() endif() endif() target_compile_options(tiny_bvh_speedtest PRIVATE ${tiny_bvh_speedtest_cxx_flags}) From a8c362acbc57e19414acc70a2fcef4843a1a9c94 Mon Sep 17 00:00:00 2001 From: Christian Oliveros Date: Tue, 12 Nov 2024 19:55:42 +0100 Subject: [PATCH 13/14] Printf done as a signal --- tiny_bvh_speedtest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tiny_bvh_speedtest.cpp b/tiny_bvh_speedtest.cpp index b89c7ac..4c96425 100644 --- a/tiny_bvh_speedtest.cpp +++ b/tiny_bvh_speedtest.cpp @@ -411,6 +411,6 @@ int main() #endif - // all done. + printf( "all done." ); return 0; } From b9393cb8d855a75f76fef69fd07055fc245e8bd0 Mon Sep 17 00:00:00 2001 From: Christian Oliveros Date: Tue, 12 Nov 2024 20:09:14 +0100 Subject: [PATCH 14/14] Fixed debug symbol generation flag to be based on build type --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f774f94..21224d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,11 +41,11 @@ endif() if (NOT MSVC) # Produce debug symbols and set optimization level set(common_cxx_flags - -g $<$:-O3> + $<$,$>:-g> $<$,$>:-O3> ) set(common_link_flags - -g + $<$,$>:-g> ) if (NOT EMSCRIPTEN)