Add option for experimental use of thread in Web
Might not run well in certain browsers, requires rebuilding all dependencies for Web with `pthread` enabled. Disabled by default (for now).
This commit is contained in:
@@ -54,23 +54,39 @@ public:
|
||||
}
|
||||
FORCE_INLINE static int32 AtomicRead(int32 const volatile* dst)
|
||||
{
|
||||
#ifdef __EMSCRIPTEN_PTHREADS__
|
||||
int32 result;
|
||||
__atomic_load(dst, &result, __ATOMIC_SEQ_CST);
|
||||
return result;
|
||||
#else
|
||||
return *dst;
|
||||
#endif
|
||||
}
|
||||
FORCE_INLINE static int64 AtomicRead(int64 const volatile* dst)
|
||||
{
|
||||
#ifdef __EMSCRIPTEN_PTHREADS__
|
||||
int64 result;
|
||||
__atomic_load(dst, &result, __ATOMIC_SEQ_CST);
|
||||
return result;
|
||||
#else
|
||||
return *dst;
|
||||
#endif
|
||||
}
|
||||
FORCE_INLINE static void AtomicStore(int32 volatile* dst, int32 value)
|
||||
{
|
||||
#ifdef __EMSCRIPTEN_PTHREADS__
|
||||
__atomic_store(dst, &value, __ATOMIC_SEQ_CST);
|
||||
#else
|
||||
*dst = value;
|
||||
#endif
|
||||
}
|
||||
FORCE_INLINE static void AtomicStore(int64 volatile* dst, int64 value)
|
||||
{
|
||||
#ifdef __EMSCRIPTEN_PTHREADS__
|
||||
__atomic_store(dst, &value, __ATOMIC_SEQ_CST);
|
||||
#else
|
||||
*dst = value;
|
||||
#endif
|
||||
}
|
||||
FORCE_INLINE static uint64 GetCurrentThreadID()
|
||||
{
|
||||
|
||||
@@ -37,3 +37,5 @@ FIND_PACKAGE(PxShared REQUIRED)
|
||||
|
||||
# Include all of the projects
|
||||
INCLUDE(NvCloth.cmake)
|
||||
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${NVCLOTH_CXX_FLAGS}")
|
||||
|
||||
@@ -154,6 +154,8 @@ namespace Flax.Deps.Dependencies
|
||||
case TargetPlatform.Web:
|
||||
cmakeArgs += " -DTARGET_BUILD_PLATFORM=web";
|
||||
cmakeArgs += $" -DCMAKE_TOOLCHAIN_FILE=\"{EmscriptenSdk.Instance.CMakeToolchainPath}\"";
|
||||
if (Configuration.WebThreads)
|
||||
cmakeArgs += " -DNVCLOTH_CXX_FLAGS=\"-pthread\"";
|
||||
cmakeName = "web";
|
||||
binariesPrefix = "lib";
|
||||
|
||||
|
||||
@@ -86,6 +86,9 @@ namespace Flax.Deps.Dependencies
|
||||
ConfigureCmakeSwitch(cmakeParams, "CMAKE_OSX_DEPLOYMENT_TARGET", Configuration.iOSMinVer);
|
||||
ConfigureCmakeSwitch(cmakeParams, "CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET", Configuration.iOSMinVer);
|
||||
break;
|
||||
case TargetPlatform.Web:
|
||||
ConfigureCmakeSwitch(cmakeParams, "PHYSX_CXX_FLAGS", Configuration.WebThreads ? "\"-pthread\"" : "");
|
||||
break;
|
||||
}
|
||||
|
||||
// Save preset
|
||||
|
||||
@@ -112,6 +112,8 @@ namespace Flax.Deps.Dependencies
|
||||
foreach (var define in defines)
|
||||
cmakeArgs += $"-D{define.Key}={define.Value} ";
|
||||
}
|
||||
if (platform == TargetPlatform.Web && Configuration.WebThreads)
|
||||
cmakeArgs += "-pthread ";
|
||||
cmakeArgs += "\"";
|
||||
|
||||
var depsFolder = GetThirdPartyFolder(options, platform, architecture);
|
||||
|
||||
@@ -16,6 +16,12 @@ namespace Flax.Build
|
||||
/// </summary>
|
||||
[CommandLine("webInitialMemory", "<size_mb>", "Specifies the initial memory size (in MB) to use by Web app.")]
|
||||
public static int WebInitialMemory = 32;
|
||||
|
||||
/// <summary>
|
||||
/// Enables pthreads support for multithreading using SharedArrayBuffer in browsers. Changing it requires rebuilding deps for Web.
|
||||
/// </summary>
|
||||
[CommandLine("webThreads", "0/1", "Enables pthreads support for multithreading using SharedArrayBuffer in browsers. Changing it requires rebuilding deps for Web.")]
|
||||
public static bool WebThreads = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,6 +100,8 @@ namespace Flax.Build.Platforms
|
||||
options.CompileEnv.PreprocessorDefinitions.Add("PLATFORM_WEB");
|
||||
options.CompileEnv.PreprocessorDefinitions.Add("PLATFORM_UNIX");
|
||||
options.CompileEnv.PreprocessorDefinitions.Add("__EMSCRIPTEN__");
|
||||
if (Configuration.WebThreads)
|
||||
options.CompileEnv.PreprocessorDefinitions.Add("__EMSCRIPTEN_PTHREADS__");
|
||||
options.CompileEnv.EnableExceptions = false;
|
||||
options.CompileEnv.CpuArchitecture = CpuArchitecture.SSE4_2;
|
||||
}
|
||||
@@ -163,6 +171,9 @@ namespace Flax.Build.Platforms
|
||||
args.Add("-fsanitize=undefined");
|
||||
if (sanitizers == Sanitizer.None)
|
||||
args.Add("-fsanitize=null -fsanitize-minimal-runtime"); // Minimal Runtime
|
||||
|
||||
if (Configuration.WebThreads)
|
||||
args.Add("-pthread");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
Reference in New Issue
Block a user